back_recharge
lvxinran 2019-11-06 13:54:48 +08:00
commit b41d7217ca
2 changed files with 28 additions and 19 deletions

View File

@ -4,18 +4,34 @@ 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 io.netty.util.internal.ConcurrentSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Description:
* Description:
* Author: zsx
* CreateDate: 2019/11/5 14:42
*/
public class Blocker {
public static final AtomicInteger maxAllowedOnlineAccountCount = new AtomicInteger(5000);
private static ConcurrentSet<Integer> forbidLogin = new ConcurrentSet<>();
public static boolean checkForbidUser(ISession iSession){
if(forbidLogin.size()<1){
return false;
}
if(iSession!=null) {
if(forbidLogin.contains(iSession.getUid())){
MessageUtil.sendErrorCode(iSession, ErrorCode.reloginCode, "您已被踢下线!");
iSession.setOfflineType(ErrorCode.reloginCode);
return true;
}
}
return false;
}
public static boolean checkFlow(ISession iSession){
if(iSession!=null) {
@ -28,6 +44,12 @@ public class Blocker {
return true;
}
static Set<Integer> getForbidLogin() {
return forbidLogin;
}
static void setForbidLogin(Set<Integer> forbidLogin) {
Blocker.forbidLogin.clear();
Blocker.forbidLogin.addAll(forbidLogin);
}
}

View File

@ -54,7 +54,6 @@ public class ProtocolsManager implements ProtocolsAbstract {
public static Map<MessageTypeProto.MessageType, String> gameMessageForLogin = new ConcurrentHashMap<>();
private Map<Integer, BaseHandler> handlers = new HashMap<>();
private static ClassLoader classLoader = GameApplication.class.getClassLoader();
private static Set<Integer> forbidLogin = new HashSet<>();
public final int HANDLER_THREAD_NUM = 50;
public HandlerLogicThread[] handlerThreads = new HandlerLogicThread[HANDLER_THREAD_NUM];
@ -202,7 +201,7 @@ public class ProtocolsManager implements ProtocolsAbstract {
if (checkIndex(session,packetNetData) != 0){
return;
}
boolean b = checkForbidUser(session);
boolean b = Blocker.checkForbidUser(session);
if(b){
return;
}
@ -480,31 +479,19 @@ public class ProtocolsManager implements ProtocolsAbstract {
}
public boolean checkForbidUser(ISession iSession){
if(forbidLogin.size()<1){
return false;
}
if(iSession!=null) {
if(forbidLogin.contains(iSession.getUid())){
MessageUtil.sendErrorCode(iSession, ErrorCode.reloginCode, "您已被踢下线!");
iSession.setOfflineType(ErrorCode.reloginCode);
return true;
}
}
return false;
}
public void minuteCheckForbidUser(){
RedisUtil redisUtil = RedisUtil.getInstence();
String key = RedisKey.getKey(RedisKey.FORBID_LOGIN, "", false);
if(!redisUtil.hasKey(key)){
forbidLogin.clear();
Blocker.getForbidLogin().clear();
return;
}
Map<Integer, Integer> forbidMap = redisUtil.getMapValues(RedisKey.FORBID_LOGIN, "", Integer.class, Integer.class);
if(forbidMap==null||forbidMap.size()<1){
return;
}
forbidLogin = forbidMap.keySet();
Blocker.setForbidLogin(forbidMap.keySet());
}