138 lines
5.4 KiB
Java
138 lines
5.4 KiB
Java
package com.ljsd;
|
|
|
|
import com.ljsd.jieling.config.json.ServerConfiguration;
|
|
import com.ljsd.jieling.config.json.ServerProperties;
|
|
import com.ljsd.jieling.db.mongo.MongoUtil;
|
|
import com.ljsd.jieling.db.redis.RedisKey;
|
|
import com.ljsd.jieling.db.redis.RedisUtil;
|
|
import com.ljsd.jieling.logic.dao.ServerConfig;
|
|
import com.ljsd.jieling.logic.family.CrossDeathPathLogic;
|
|
import com.ljsd.jieling.logic.rank.CrossRankManager;
|
|
import com.ljsd.jieling.network.NetManager;
|
|
import com.ljsd.jieling.util.ConfigurableApplicationContextManager;
|
|
import config.SGameSetting;
|
|
import manager.STableManager;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
import org.springframework.context.annotation.ComponentScan;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import util.TimeUtils;
|
|
|
|
import java.io.File;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Scanner;
|
|
|
|
|
|
@Configuration
|
|
@EnableAutoConfiguration
|
|
@ComponentScan
|
|
@EnableScheduling
|
|
public class GameApplication {
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(GameApplication.class);
|
|
public static ServerProperties serverProperties;
|
|
|
|
public static int serverId = 0;
|
|
public static int areaId = 0;
|
|
public static boolean start = false;
|
|
public static ServerConfig serverConfig;
|
|
public static void main(String[] args) throws Exception {
|
|
start = true;
|
|
ConfigurableApplicationContextManager.init(args);
|
|
|
|
//init servercfg
|
|
ServerConfiguration serverConfiguration = ConfigurableApplicationContextManager.getBean(ServerConfiguration.class);
|
|
|
|
serverProperties = serverConfiguration.getServerProperties();
|
|
serverId = serverProperties.getId();
|
|
// CoreSettings coreSettings = ConfigurableApplicationContextManager.getBean(CoreSettings.class);
|
|
// GameApplication.areaId = coreSettings.getArea();
|
|
LOGGER.info("ServerProperties ->{},coreIp=>{}", serverProperties.toString());
|
|
initReportLog();
|
|
MongoUtil.getInstence().init();
|
|
|
|
GameLogicService.getInstance().init();
|
|
//设置开服时间
|
|
setRegisterTime();// might loop
|
|
GameLogicService.getInstance().onStart();
|
|
NetManager.getInstance().init();
|
|
SkyEyeService.getInstance().onStart();
|
|
CrossDeathPathLogic.getInstance().serverInit();
|
|
CrossRankManager.getInstance().guildCacheHandle();
|
|
//控制台gm
|
|
Scanner sc = new Scanner(System.in);
|
|
while(sc.hasNext())
|
|
{
|
|
try {
|
|
String cmd = sc.nextLine();
|
|
if(cmd.startsWith("//"))
|
|
{
|
|
System.out.println("gmgmgm:" + cmd.substring(2));
|
|
String cmd2 = cmd.substring(2);
|
|
GmService.exeCmd(cmd2);
|
|
}
|
|
}catch (Exception e){
|
|
System.out.print("gmException"+e);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void setRegisterTime() throws Exception {
|
|
ServerConfig serverConfigTmp = MongoUtil.getInstence().getMyMongoTemplate().findById(1, ServerConfig.class);
|
|
if(serverConfigTmp == null){
|
|
serverConfigTmp = new ServerConfig();
|
|
if (GameApplication.serverProperties.isAutoOpen()) {
|
|
int startbefore = 60; //开服白名单时间
|
|
long needtime = TimeUtils.differMintFromLast(RedisUtil.getInstence().getObject(GameApplication.serverId + RedisKey.Delimiter_colon + RedisKey.AUTOOPENTIME ,"",String.class,-1));
|
|
while (needtime - startbefore > 0) {
|
|
long sleepTime = needtime - startbefore;
|
|
try {
|
|
LOGGER.error("预计" + sleepTime + "分钟后开服");
|
|
Thread.sleep(1000 * 60);
|
|
} catch (Exception e) {
|
|
LOGGER.error("休眠异常:{}", e.getMessage(), e);
|
|
}
|
|
needtime = TimeUtils.differMintFromLast(RedisUtil.getInstence().getObject(GameApplication.serverId + RedisKey.Delimiter_colon + RedisKey.AUTOOPENTIME ,"",String.class,-1));
|
|
}
|
|
}
|
|
long serverOenTime = TimeUtils.getAppointTime(0);
|
|
serverConfigTmp.setOpenTime(TimeUtils.getTimeStamp2(serverOenTime));
|
|
serverConfigTmp.setCacheOpenTime(serverOenTime);
|
|
serverConfigTmp.setId(1);
|
|
}else{
|
|
long timeStamp2 = TimeUtils.stringToTimeLong2(serverConfigTmp.getOpenTime());
|
|
serverConfigTmp.setCacheOpenTime(timeStamp2);
|
|
}
|
|
int version = STableManager.getConfig(SGameSetting.class).get(1).getWookbookVersion();
|
|
serverConfigTmp.setVersion(version);
|
|
serverConfigTmp.setRestartTime(TimeUtils.getTimeStamp2(TimeUtils.now()));
|
|
MongoUtil.getInstence().getMyMongoTemplate().saveWithoutMongoRoot(serverConfigTmp);
|
|
serverConfig = serverConfigTmp;
|
|
}
|
|
|
|
|
|
public static void close() throws Exception{
|
|
start = false;
|
|
NetManager.getInstance().exit();
|
|
ConfigurableApplicationContextManager.getInstance().exit();
|
|
|
|
|
|
}
|
|
|
|
|
|
private static void initReportLog(){
|
|
File file = new File("../reportLog_"+GameApplication.serverId);
|
|
if(!file.exists()){
|
|
boolean mkdirs = file.mkdirs();//创建目录
|
|
if(!mkdirs){
|
|
LOGGER.error("ReportLog file create fail");
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|