起服前检查
parent
4da9bc7b7d
commit
9a5dd40e29
|
@ -190,6 +190,9 @@ public class RedisKey {
|
|||
public static final String AUTOOPENTIME = "AUTOOPENTIME";
|
||||
|
||||
public final static String CDKEY = "CDKEY";
|
||||
public final static String GLOBAL_SYS_PRO = "GLOBAL_SYS_PRO";
|
||||
|
||||
|
||||
public static Set<String> familyKey = new HashSet<>();
|
||||
static {
|
||||
familyKey.add(FAMILY_FIGHT);
|
||||
|
|
|
@ -992,6 +992,20 @@ public class RedisUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
public <T> T getMapValue(String type, String key, String mapKey, Class<T> clazz) {
|
||||
String rkey = getKey(type, key);
|
||||
for (int i = 0; i < MAX_TRY_TIMES; i++) {
|
||||
try {
|
||||
String valueStr = (String) redisTemplate.opsForHash().get(type + RedisKey.Delimiter_colon + key, mapKey);
|
||||
if (valueStr != null)
|
||||
return gson.fromJson(valueStr, clazz);
|
||||
} catch (Exception e) {
|
||||
TimeUtils.sleep(FAILED_SLEEP);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public <T> List<T> getMapEntrys(String type, String key, Collection<Object> mapKeys, Class<T> valueClazz){
|
||||
String rkey = getKey(type, key);
|
||||
List<T> result = new ArrayList<>();
|
||||
|
|
|
@ -26,6 +26,7 @@ public enum ErrorCode implements IErrorCode {
|
|||
SYS_ERROR_CODE(-100, "系统错误"),
|
||||
RELOGIN_CODE(-101, "重复登陆"),
|
||||
KICK_USER_CODE(-102, "踢用户下线"),
|
||||
ONLINE_FLOW(-110, "当前在线人数过多,请稍等哦"),
|
||||
|
||||
SERVER_SELF_DEFINE(-1, "操作失败"),
|
||||
SERVER_DEFINE(-1, "操作失败"),
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.ljsd.jieling.handler;
|
|||
import com.ljsd.GameApplication;
|
||||
import com.ljsd.jieling.db.redis.RedisKey;
|
||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
import com.ljsd.jieling.exception.ErrorCodeException;
|
||||
import com.ljsd.jieling.handler.map.MapLogic;
|
||||
import com.ljsd.jieling.ktbeans.KTRequestBeans.LoginParamType;
|
||||
import com.ljsd.jieling.ktbeans.KtEventUtils;
|
||||
|
@ -13,6 +14,8 @@ import com.ljsd.jieling.logic.dao.UserRecentLoginInfo;
|
|||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||
import com.ljsd.jieling.network.server.Blocker;
|
||||
import com.ljsd.jieling.network.server.ProtocolsManager;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||
import com.ljsd.jieling.protocols.PlayerInfoProto;
|
||||
|
@ -41,7 +44,9 @@ public class LoginRequestHandler extends BaseHandler<PlayerInfoProto.LoginReques
|
|||
public void processWithProto(ISession iSession, PlayerInfoProto.LoginRequest loginRequest) throws Exception {
|
||||
|
||||
int userId = iSession.getUid();
|
||||
|
||||
if(!Blocker.checkFlow(iSession)){
|
||||
return;
|
||||
}
|
||||
ParamEnvironmentBean paramEnvironmentBean = new ParamEnvironmentBean();
|
||||
paramEnvironmentBean.setDevice_id_s(loginRequest.getDeviceIdS());
|
||||
paramEnvironmentBean.setIp_s(loginRequest.getIpS());
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package com.ljsd.jieling.network.server;
|
||||
|
||||
import com.ljsd.jieling.exception.ErrorCode;
|
||||
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.util.MessageUtil;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Description: 进服前检查
|
||||
* Author: zsx
|
||||
* CreateDate: 2019/11/5 14:42
|
||||
*/
|
||||
public class Blocker {
|
||||
|
||||
public static final AtomicInteger maxAllowedOnlineAccountCount = new AtomicInteger(5000);
|
||||
|
||||
|
||||
public static boolean checkFlow(ISession iSession){
|
||||
if(iSession!=null) {
|
||||
if(OnlineUserManager.sessionMap.size()>maxAllowedOnlineAccountCount.get()){
|
||||
MessageUtil.sendErrorCode(iSession, ErrorCode.ONLINE_FLOW.code(), "当前在线人数过多,请稍等哦!");
|
||||
iSession.setOfflineType(ErrorCode.reloginCode);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -58,6 +58,7 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
|||
public final int HANDLER_THREAD_NUM = 50;
|
||||
public HandlerLogicThread[] handlerThreads = new HandlerLogicThread[HANDLER_THREAD_NUM];
|
||||
|
||||
|
||||
private ProtocolsManager() {
|
||||
initContext();
|
||||
}
|
||||
|
@ -504,6 +505,19 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
|||
return;
|
||||
}
|
||||
forbidLogin = forbidMap.keySet();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void minuteCheckFlowUser(){
|
||||
try {
|
||||
String crowdnum = RedisUtil.getInstence().getMapValue(RedisKey.GLOBAL_SYS_PRO,"","onlinenum",String.class);
|
||||
if(null!=crowdnum&&!crowdnum.equals("")){
|
||||
Blocker.maxAllowedOnlineAccountCount.set(Integer.valueOf(crowdnum));
|
||||
}
|
||||
}catch (Exception e){
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void initHandler(String pck, ConfigurableApplicationContext configurableApplicationContext){
|
||||
|
|
|
@ -64,6 +64,7 @@ public class MinuteTask extends Thread {
|
|||
QuestionLogic.getInstence().checkQuestion();
|
||||
MailLogic.getInstance().checkReadyToMail();
|
||||
ProtocolsManager.getInstance().minuteCheckForbidUser();
|
||||
ProtocolsManager.getInstance().minuteCheckFlowUser();
|
||||
CoreLogic.getInstance().checkCoreCdk();
|
||||
BuyGoodsLogic.minuteCheckReharge();
|
||||
RedisUtil.getInstence().set(RedisKey.ONLINE_NUM+RedisKey.Delimiter_colon+GameApplication.serverId, String.valueOf(OnlineUserManager.sessionMap.entrySet().size()));
|
||||
|
|
Loading…
Reference in New Issue