Browse Source

:whale: 统一的默认配置

渔民小镇 1 year ago
parent
commit
06f4505f1a

+ 4 - 0
broker/src/main/java/com/iohao/mmo/broker/MyBrokerServer.java

@@ -21,6 +21,7 @@ package com.iohao.mmo.broker;
 import com.iohao.game.bolt.broker.core.common.IoGameGlobalConfig;
 import com.iohao.game.bolt.broker.server.BrokerServer;
 import com.iohao.game.bolt.broker.server.BrokerServerBuilder;
+import com.iohao.mmo.common.config.MyGlobalSetting;
 
 import java.util.concurrent.TimeUnit;
 
@@ -37,6 +38,9 @@ public class MyBrokerServer {
     }
 
     public BrokerServer createBrokerServer(int port) {
+        // 统一的默认配置
+        MyGlobalSetting.defaultSetting();
+        
         // Broker Server (游戏网关服) 构建器
         BrokerServerBuilder brokerServerBuilder = BrokerServer.newBuilder()
                 // broker (游戏网关)端口

+ 57 - 0
common/common-core/src/main/java/com/iohao/mmo/common/config/MyGlobalSetting.java

@@ -0,0 +1,57 @@
+/*
+ * ioGame
+ * Copyright (C) 2021 - 2023  渔民小镇 (262610965@qq.com、luoyizhu@gmail.com) . All Rights Reserved.
+ * # iohao.com . 渔民小镇
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+package com.iohao.mmo.common.config;
+
+import com.iohao.game.action.skeleton.core.IoGameGlobalSetting;
+import com.iohao.game.action.skeleton.core.codec.DataCodec;
+import com.iohao.game.action.skeleton.core.codec.JsonDataCodec;
+import com.iohao.game.bolt.broker.core.common.IoGameGlobalConfig;
+import com.iohao.mmo.common.logic.server.MyUserProcessorExecutorStrategy;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.experimental.FieldDefaults;
+import lombok.experimental.UtilityClass;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-08-28
+ */
+@UtilityClass
+public class MyGlobalSetting {
+    AtomicBoolean setting = new AtomicBoolean();
+
+    public void defaultSetting() {
+        if (setting.get()) {
+            return;
+        }
+
+        if (!setting.compareAndSet(false, true)) {
+            return;
+        }
+
+        // 使用自定义 UserProcessor 构建 Executor 的策略
+        IoGameGlobalConfig.userProcessorExecutorStrategy = new MyUserProcessorExecutorStrategy();
+
+        IoGameGlobalSetting.setDataCodec(new JsonDataCodec());
+    }
+
+}

+ 4 - 0
common/common-core/src/main/java/com/iohao/mmo/common/logic/server/LogicServerKit.java

@@ -25,6 +25,7 @@ import com.iohao.game.bolt.broker.core.client.BrokerClient;
 import com.iohao.game.bolt.broker.core.client.BrokerClientBuilder;
 import com.iohao.game.bolt.broker.core.common.processor.hook.ClientProcessorHooks;
 import com.iohao.mmo.common.config.GameCode;
+import com.iohao.mmo.common.config.MyGlobalSetting;
 import com.iohao.mmo.common.core.flow.MyFlowContext;
 import com.iohao.mmo.common.core.flow.internal.DebugActionAfter;
 import com.iohao.mmo.common.core.flow.internal.DebugActionMethodExceptionProcess;
@@ -59,6 +60,9 @@ public class LogicServerKit {
     }
 
     public BrokerClientBuilder newBrokerClientBuilder() {
+        // 统一的默认配置
+        MyGlobalSetting.defaultSetting();
+
         ClientProcessorHooks hooks = ofClientProcessorHooks();
         return BrokerClient.newBuilder()
                 .clientProcessorHooks(hooks);

+ 4 - 1
external/src/main/java/com/iohao/mmo/external/MyExternalServer.java

@@ -29,6 +29,7 @@ import com.iohao.game.external.core.netty.DefaultExternalServer;
 import com.iohao.game.external.core.netty.DefaultExternalServerBuilder;
 import com.iohao.game.external.core.netty.handler.ws.HttpRealIpHandler;
 import com.iohao.game.external.core.netty.micro.WebSocketMicroBootstrapFlow;
+import com.iohao.mmo.common.config.MyGlobalSetting;
 import com.iohao.mmo.external.core.broker.client.ext.impl.UserIpExternalBizRegion;
 import com.iohao.mmo.login.cmd.LoginCmd;
 
@@ -39,7 +40,6 @@ import com.iohao.mmo.login.cmd.LoginCmd;
 public class MyExternalServer {
 
     public ExternalServer createExternalServer(int externalPort) {
-
         // 游戏对外服配置
         extractedConfig();
 
@@ -67,6 +67,9 @@ public class MyExternalServer {
     }
 
     private static void extractedConfig() {
+        // 统一的默认配置
+        MyGlobalSetting.defaultSetting();
+
         // 对外服业务扩展
         extractedExternalBizRegion();
 

+ 2 - 6
one-application/src/main/java/com/iohao/mmo/OneApplication.java

@@ -30,6 +30,7 @@ import com.iohao.game.external.core.config.ExternalGlobalConfig;
 import com.iohao.game.external.core.netty.simple.NettyRunOne;
 import com.iohao.mmo.bag.BagLogicServer;
 import com.iohao.mmo.broker.MyBrokerServer;
+import com.iohao.mmo.common.config.MyGlobalSetting;
 import com.iohao.mmo.common.logic.server.MyUserProcessorExecutorStrategy;
 import com.iohao.mmo.equip.EquipLogicServer;
 import com.iohao.mmo.external.MyExternalServer;
@@ -110,12 +111,7 @@ public class OneApplication {
     }
 
     private static void extractedConfig() {
-        // 使用自定义 UserProcessor 构建 Executor 的策略
-        IoGameGlobalConfig.userProcessorExecutorStrategy = new MyUserProcessorExecutorStrategy();
-
-        if (OsInfo.me().isMac()) {
-            IoGameGlobalSetting.setDataCodec(new JsonDataCodec());
-        }
+        MyGlobalSetting.defaultSetting();
     }
 
     @Bean