自动开服配置
parent
80f71c5ca7
commit
205481e8ab
|
@ -1238,6 +1238,26 @@ public class TimeUtils {
|
||||||
return now();
|
return now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long DifferMintFromLast(Object object){
|
||||||
|
try {
|
||||||
|
String time;
|
||||||
|
if(null!=object){
|
||||||
|
try {
|
||||||
|
time = String.valueOf(object);
|
||||||
|
}catch (Exception e1){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
return (simpleDateFormat.parse(time).getTime()-now())/(60*1000);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
LOGGER.error("", e);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断两个时间是否隔开周几的几点
|
* 判断两个时间是否隔开周几的几点
|
||||||
* @param lastTime
|
* @param lastTime
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class GameApplication {
|
||||||
//http线程池初始化
|
//http线程池初始化
|
||||||
// HttpPool.init();
|
// HttpPool.init();
|
||||||
//todo 设置开服时间
|
//todo 设置开服时间
|
||||||
setRegisterTime();
|
setRegisterTime();// might loop
|
||||||
GuilidManager.init();
|
GuilidManager.init();
|
||||||
|
|
||||||
STableManager.initialize("config");
|
STableManager.initialize("config");
|
||||||
|
@ -142,6 +142,22 @@ public class GameApplication {
|
||||||
ServerConfig serverConfigTmp = MongoUtil.getInstence().getMyMongoTemplate().findById(1, ServerConfig.class);
|
ServerConfig serverConfigTmp = MongoUtil.getInstence().getMyMongoTemplate().findById(1, ServerConfig.class);
|
||||||
if( null == serverConfigTmp ){
|
if( null == serverConfigTmp ){
|
||||||
serverConfigTmp = new ServerConfig();
|
serverConfigTmp = new ServerConfig();
|
||||||
|
if (GameApplication.serverProperties.isAutoOpen()) {
|
||||||
|
int startbefore = 0; //开服白名单时间
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
long serverOenTime = TimeUtils.getAppointTime(0);
|
long serverOenTime = TimeUtils.getAppointTime(0);
|
||||||
String format = simpleDateFormat.format(serverOenTime);
|
String format = simpleDateFormat.format(serverOenTime);
|
||||||
|
|
|
@ -26,6 +26,8 @@ public class ServerProperties {
|
||||||
|
|
||||||
private int areaId;
|
private int areaId;
|
||||||
|
|
||||||
|
private boolean autoOpen;
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -98,6 +100,14 @@ public class ServerProperties {
|
||||||
this.areaId = areaId;
|
this.areaId = areaId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAutoOpen() {
|
||||||
|
return autoOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoOpen(boolean autoOpen) {
|
||||||
|
this.autoOpen = autoOpen;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ServerProperties{" +
|
return "ServerProperties{" +
|
||||||
|
|
|
@ -187,6 +187,7 @@ public class RedisKey {
|
||||||
public static final String LOGIC_SERVER_INFO = "LOGIC_SERVER_INFO";
|
public static final String LOGIC_SERVER_INFO = "LOGIC_SERVER_INFO";
|
||||||
public static final String BLOODY_SERVER_INFO = "BLOODY_SERVER_INFO";
|
public static final String BLOODY_SERVER_INFO = "BLOODY_SERVER_INFO";
|
||||||
public static final String SYSMSG = "SYSMSG";
|
public static final String SYSMSG = "SYSMSG";
|
||||||
|
public static final String AUTOOPENTIME = "AUTOOPENTIME";
|
||||||
|
|
||||||
public final static String CDKEY = "CDKEY";
|
public final static String CDKEY = "CDKEY";
|
||||||
public static Set<String> familyKey = new HashSet<>();
|
public static Set<String> familyKey = new HashSet<>();
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.ljsd.jieling.db.redis;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.ljsd.GameApplication;
|
import com.ljsd.GameApplication;
|
||||||
import com.ljsd.common.mogodb.util.GlobalData;
|
import com.ljsd.common.mogodb.util.GlobalData;
|
||||||
|
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||||
import util.TimeUtils;
|
import util.TimeUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -162,6 +163,28 @@ public class RedisUtil {
|
||||||
return gson.fromJson(source,clazz);
|
return gson.fromJson(source,clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Object
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public <T> T getObject(String type, String key, Class<T> clazz, int expireTime) {
|
||||||
|
try {
|
||||||
|
String valueStr = redisTemplate.opsForValue().get(type + RedisKey.Delimiter_colon + key);
|
||||||
|
if (valueStr == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (expireTime > 0) {
|
||||||
|
redisTemplate.expire(type + key, expireTime, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
return gson.fromJson(valueStr, clazz);
|
||||||
|
} catch (RedisConnectionFailureException e) {
|
||||||
|
LOGGER.error("------------------Redis 连接失败------------------msg={}", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 普通缓存放入并设置时间
|
* 普通缓存放入并设置时间
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue