diff --git a/conf/plat-configure.json b/conf/plat-configure.json new file mode 100644 index 000000000..96cf73b8c --- /dev/null +++ b/conf/plat-configure.json @@ -0,0 +1,3 @@ +{ + "version":"1" +} \ No newline at end of file diff --git a/serverlogic/build.gradle b/serverlogic/build.gradle index e802635ab..fc1fa73eb 100644 --- a/serverlogic/build.gradle +++ b/serverlogic/build.gradle @@ -28,6 +28,7 @@ dependencies { compile("com.google.protobuf:protobuf-java:2.5.0") compile("com.fasterxml.jackson.core:jackson-core:2.3.1") compile("com.fasterxml.jackson.core:jackson-databind:2.3.3") + compile files("${System.properties['java.home']}/../lib/tools.jar") } jar { diff --git a/serverlogic/src/main/java/com/ljsd/GameApplication.java b/serverlogic/src/main/java/com/ljsd/GameApplication.java index e62411d37..f703fc197 100644 --- a/serverlogic/src/main/java/com/ljsd/GameApplication.java +++ b/serverlogic/src/main/java/com/ljsd/GameApplication.java @@ -1,5 +1,8 @@ package com.ljsd; +import com.ljsd.jieling.config.json.ConfMessage; +import com.ljsd.jieling.config.json.ServerConfiguration; +import com.ljsd.jieling.config.json.ServerProperties; import com.ljsd.jieling.handler.BaseHandler; import com.ljsd.jieling.logic.STableManager; import com.ljsd.jieling.netty.server.NettyGameServer; @@ -28,7 +31,7 @@ public class GameApplication { private static SpringApplication app = null; private static ConfigurableApplicationContext configurableApplicationContext = null; private static final Logger LOGGER = LoggerFactory.getLogger(GameApplication.class); - + public static ServerProperties serverProperties; private static NettyGameServer nettyServer = null; public static int serverId = 0; // public static ServerProperties serverProperties; @@ -42,7 +45,11 @@ public class GameApplication { app.setWebEnvironment(false); configurableApplicationContext = app.run(args); + ServerConfiguration serverConfiguration = configurableApplicationContext.getBean(ServerConfiguration.class); + serverProperties = serverConfiguration.getServerProperties(); + //加载配置开关 + ConfMessage.doWork(); //注册消息处理方法 ProtocolsManager protocolsManager = ProtocolsManager.getInstance(); diff --git a/serverlogic/src/main/java/com/ljsd/jieling/config/json/ConfMessage.java b/serverlogic/src/main/java/com/ljsd/jieling/config/json/ConfMessage.java new file mode 100644 index 000000000..b5ca794e0 --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/config/json/ConfMessage.java @@ -0,0 +1,44 @@ +package com.ljsd.jieling.config.json; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +public class ConfMessage { + + private static String currVerion; + private static final Logger LOGGER = LoggerFactory.getLogger(ConfMessage.class); + + //加载配置开关 + public static void doWork() throws IOException { + File file = new File("conf/plat-configure.json"); +// File file = new File("C://ljsd/gameserver_new/conf/plat-configure.json"); + if (!file.exists()) { + LOGGER.error("the file plat-configure.json is not exists"); + return; + } + InputStream in = new FileInputStream(file); + ObjectMapper mapper = new ObjectMapper(); + mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + + PlatConfigure platConfigure = mapper.readValue(in, PlatConfigure.class); + in.close(); + + String version = platConfigure.getVersion(); + if (version.equalsIgnoreCase(currVerion)) { + return; + } + GlobalPlatConfigure.platConfigure = platConfigure; + currVerion = version; + LOGGER.info("PlatConfigure ->{}", GlobalPlatConfigure.platConfigure.toString()); + LOGGER.debug("doWork update PlatConfigure->currVerion={},version={}", currVerion, version); + + } + +} diff --git a/serverlogic/src/main/java/com/ljsd/jieling/config/json/GlobalPlatConfigure.java b/serverlogic/src/main/java/com/ljsd/jieling/config/json/GlobalPlatConfigure.java new file mode 100644 index 000000000..5328aa57d --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/config/json/GlobalPlatConfigure.java @@ -0,0 +1,5 @@ +package com.ljsd.jieling.config.json; + +public class GlobalPlatConfigure { + public static PlatConfigure platConfigure = new PlatConfigure(); +} diff --git a/serverlogic/src/main/java/com/ljsd/jieling/config/json/PlatConfigure.java b/serverlogic/src/main/java/com/ljsd/jieling/config/json/PlatConfigure.java new file mode 100644 index 000000000..897c52945 --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/config/json/PlatConfigure.java @@ -0,0 +1,22 @@ +package com.ljsd.jieling.config.json; + +public class PlatConfigure { + public String version = "1"; + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + @Override + public String toString() { + return "PlatConfigure{" + + "version='" + version + '\'' + + '}'; + } + + +} diff --git a/serverlogic/src/main/java/com/ljsd/jieling/config/json/ServerConfiguration.java b/serverlogic/src/main/java/com/ljsd/jieling/config/json/ServerConfiguration.java new file mode 100644 index 000000000..990e218d1 --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/config/json/ServerConfiguration.java @@ -0,0 +1,21 @@ +package com.ljsd.jieling.config.json; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +/** + * Created by a on 2017/7/5. + */ +@Configuration(value = "serverConfiguration") +@EnableConfigurationProperties(ServerProperties.class) +public class ServerConfiguration { + + @Autowired + private ServerProperties serverProperties; + + public ServerProperties getServerProperties() { + return serverProperties; + } + +} diff --git a/serverlogic/src/main/java/com/ljsd/jieling/config/json/ServerProperties.java b/serverlogic/src/main/java/com/ljsd/jieling/config/json/ServerProperties.java new file mode 100644 index 000000000..3e8cfc525 --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/config/json/ServerProperties.java @@ -0,0 +1,60 @@ +package com.ljsd.jieling.config.json; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * Created by a on 2017/7/5. + */ +@ConfigurationProperties(prefix = "server") +public class ServerProperties { + + private int id; + + private String plat; + + private String channel; + + private int isLAN; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getPlat() { + return plat; + } + + public void setPlat(String plat) { + this.plat = plat; + } + + public String getChannel() { + return channel; + } + + public void setChannel(String channel) { + this.channel = channel; + } + + public int getIsLAN() { + return isLAN; + } + + public void setIsLAN(int isLAN) { + this.isLAN = isLAN; + } + + @Override + public String toString() { + return "ServerProperties{" + + "id=" + id + + ", plat='" + plat + '\'' + + ", channel='" + channel + '\'' + + ", isLAN=" + isLAN + + '}'; + } +}