2019-01-23 11:46:49 +08:00
|
|
|
package com.ljsd;
|
2018-12-27 17:54:23 +08:00
|
|
|
|
2019-09-16 15:40:18 +08:00
|
|
|
import com.google.gson.Gson;
|
2019-07-11 10:02:18 +08:00
|
|
|
import com.ljsd.common.mogodb.util.MongoKeys;
|
2019-09-09 16:07:11 +08:00
|
|
|
import com.ljsd.jieling.config.json.CoreSettings;
|
2019-01-09 09:57:46 +08:00
|
|
|
import com.ljsd.jieling.config.json.ServerConfiguration;
|
|
|
|
|
import com.ljsd.jieling.config.json.ServerProperties;
|
2019-09-12 18:06:28 +08:00
|
|
|
import com.ljsd.jieling.core.CoreLogic;
|
2019-03-06 15:07:12 +08:00
|
|
|
import com.ljsd.jieling.db.mongo.MongoUtil;
|
2019-09-16 15:40:18 +08:00
|
|
|
import com.ljsd.jieling.db.redis.RedisKey;
|
2019-01-08 18:46:36 +08:00
|
|
|
import com.ljsd.jieling.db.redis.RedisUtil;
|
2019-02-25 17:35:38 +08:00
|
|
|
import com.ljsd.jieling.handler.map.MapLogic;
|
2019-05-13 16:10:03 +08:00
|
|
|
import com.ljsd.jieling.logic.GlobalDataManaager;
|
2019-04-22 19:25:03 +08:00
|
|
|
import com.ljsd.jieling.logic.activity.ActivityLogic;
|
2019-09-11 22:21:02 +08:00
|
|
|
import com.ljsd.jieling.logic.dao.GuilidManager;
|
2019-01-24 14:35:59 +08:00
|
|
|
import com.ljsd.jieling.logic.dao.MailingSystemManager;
|
2019-03-12 17:01:40 +08:00
|
|
|
import com.ljsd.jieling.logic.fight.CheckFight;
|
2019-05-10 17:44:44 +08:00
|
|
|
import com.ljsd.jieling.logic.hero.HeroLogic;
|
2019-11-23 12:11:03 +08:00
|
|
|
import com.ljsd.jieling.network.NetManager;
|
2018-12-27 17:54:23 +08:00
|
|
|
import com.ljsd.jieling.network.server.ProtocolsManager;
|
2019-01-08 18:46:36 +08:00
|
|
|
import com.ljsd.jieling.thread.ThreadManager;
|
2019-07-11 10:02:18 +08:00
|
|
|
import com.ljsd.jieling.thread.task.MongoDataHandlerTask;
|
2019-09-06 11:04:28 +08:00
|
|
|
import com.ljsd.jieling.thrift.pool.ThriftPoolUtils;
|
2019-11-23 12:11:03 +08:00
|
|
|
import com.ljsd.jieling.util.ConfigurableApplicationContextManager;
|
2019-01-22 14:44:02 +08:00
|
|
|
import com.ljsd.jieling.util.KeyGenUtils;
|
2019-04-25 14:55:06 +08:00
|
|
|
import com.ljsd.jieling.util.SensitivewordFilter;
|
2019-10-11 16:32:20 +08:00
|
|
|
import util.TimeUtils;
|
2019-07-04 11:33:18 +08:00
|
|
|
import com.ljsd.jieling.util.http.HttpPool;
|
2019-10-11 16:32:20 +08:00
|
|
|
import com.ljsd.jieling.logic.dao.ServerConfig;
|
|
|
|
|
import manager.STableManager;
|
2018-12-27 17:54:23 +08:00
|
|
|
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;
|
|
|
|
|
|
2019-09-12 13:51:19 +08:00
|
|
|
import java.net.URL;
|
2019-01-21 15:31:02 +08:00
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Date;
|
2018-12-27 17:54:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@EnableAutoConfiguration
|
|
|
|
|
@ComponentScan
|
|
|
|
|
@EnableScheduling
|
|
|
|
|
public class GameApplication {
|
|
|
|
|
|
2019-11-23 12:11:03 +08:00
|
|
|
|
2018-12-27 17:54:23 +08:00
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(GameApplication.class);
|
2019-01-09 09:57:46 +08:00
|
|
|
public static ServerProperties serverProperties;
|
2019-11-23 12:11:03 +08:00
|
|
|
|
2018-12-27 17:54:23 +08:00
|
|
|
public static int serverId = 0;
|
2019-04-28 17:26:43 +08:00
|
|
|
public static int areaId = 0;
|
2018-12-27 17:54:23 +08:00
|
|
|
public static boolean start = false;
|
2019-01-21 15:31:02 +08:00
|
|
|
public static ServerConfig serverConfig;
|
2019-01-04 13:39:02 +08:00
|
|
|
public static void main(String[] args) throws Exception {
|
2018-12-27 17:54:23 +08:00
|
|
|
start = true;
|
2019-11-23 12:11:03 +08:00
|
|
|
ConfigurableApplicationContextManager.init(args);
|
2018-12-27 17:54:23 +08:00
|
|
|
|
2019-11-23 12:11:03 +08:00
|
|
|
//init servercfg
|
|
|
|
|
ServerConfiguration serverConfiguration = ConfigurableApplicationContextManager.getBean(ServerConfiguration.class);
|
2019-11-06 16:21:40 +08:00
|
|
|
|
2019-01-09 09:57:46 +08:00
|
|
|
serverProperties = serverConfiguration.getServerProperties();
|
2019-01-09 13:58:05 +08:00
|
|
|
serverId = serverProperties.getId();
|
2019-11-23 12:11:03 +08:00
|
|
|
|
|
|
|
|
CoreSettings coreSettings = ConfigurableApplicationContextManager.getBean(CoreSettings.class);
|
2019-09-09 16:07:11 +08:00
|
|
|
GameApplication.areaId = coreSettings.getArea();
|
2019-01-09 17:52:01 +08:00
|
|
|
LOGGER.info("ServerProperties ->{},coreIp=>{}", serverProperties.toString());
|
2019-09-12 13:51:19 +08:00
|
|
|
|
2019-11-23 12:11:03 +08:00
|
|
|
GameLogicService.getInstance().init();
|
|
|
|
|
//设置开服时间
|
|
|
|
|
setRegisterTime();// might loop
|
|
|
|
|
GameLogicService.getInstance().onStart();
|
|
|
|
|
NetManager.getInstance().init();
|
2018-12-27 17:54:23 +08:00
|
|
|
}
|
|
|
|
|
|
2019-09-10 10:05:03 +08:00
|
|
|
private static void setRegisterTime() throws Exception {
|
|
|
|
|
ServerConfig serverConfigTmp = MongoUtil.getInstence().getMyMongoTemplate().findById(1, ServerConfig.class);
|
|
|
|
|
if( null == serverConfigTmp ){
|
|
|
|
|
serverConfigTmp = new ServerConfig();
|
2019-11-04 18:25:48 +08:00
|
|
|
if (GameApplication.serverProperties.isAutoOpen()) {
|
2019-11-23 12:11:03 +08:00
|
|
|
int startbefore = 60; //开服白名单时间
|
2019-11-04 18:25:48 +08:00
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-10 10:05:03 +08:00
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
long serverOenTime = TimeUtils.getAppointTime(0);
|
|
|
|
|
String format = simpleDateFormat.format(serverOenTime);
|
|
|
|
|
serverConfigTmp.setOpenTime(format);
|
|
|
|
|
serverConfigTmp.setCacheOpenTime(serverOenTime);
|
|
|
|
|
serverConfigTmp.setId(1);
|
|
|
|
|
serverConfigTmp.setWorldLevel(1);
|
|
|
|
|
MongoUtil.getInstence().getMyMongoTemplate().saveWithoutMongoRoot(serverConfigTmp);
|
|
|
|
|
}else{
|
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
String openTime = serverConfigTmp.getOpenTime();
|
|
|
|
|
Date date = simpleDateFormat.parse(openTime);
|
|
|
|
|
serverConfigTmp.setCacheOpenTime(date.getTime());
|
|
|
|
|
}
|
|
|
|
|
serverConfig = serverConfigTmp;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-16 15:40:18 +08:00
|
|
|
|
2019-11-23 12:11:03 +08:00
|
|
|
public static void close() throws Exception{
|
2018-12-27 17:54:23 +08:00
|
|
|
start = false;
|
2019-11-23 12:11:03 +08:00
|
|
|
NetManager.getInstance().exit();
|
|
|
|
|
ConfigurableApplicationContextManager.getInstance().exit();
|
2018-12-27 17:54:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|