错误码
parent
ab03ce293e
commit
d809b04af5
|
@ -2,4 +2,14 @@ package com.ljsd.jieling.exception;
|
|||
|
||||
public class ErrorCode {
|
||||
|
||||
//系统错误
|
||||
public static final int sysErrorCode = -100;
|
||||
|
||||
//重复登陆
|
||||
public static final int reloginCode = -101;
|
||||
|
||||
//踢用户下线
|
||||
public static final int kickUserCode = -102;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,4 +12,7 @@ public class CalHeroFinalAttri {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -8,19 +8,16 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
|
||||
public class OnlineUserManager {
|
||||
|
||||
public static Map<Integer, Integer> onlineUidMap = new ConcurrentHashMap<>();
|
||||
public static Map<Integer, ISession> sessionMap = new ConcurrentHashMap<>();
|
||||
|
||||
public static Map<Integer, PlayerManager> onlineUserMap = new ConcurrentHashMap<>(10000);
|
||||
|
||||
|
||||
public static void registUser(int uid, int serverId, ISession session) {
|
||||
onlineUidMap.put(uid, serverId);
|
||||
public static void userOnline(int uid, ISession session) {
|
||||
sessionMap.put(uid, session);
|
||||
}
|
||||
|
||||
public static void unRegistUser(int uid) {
|
||||
onlineUidMap.remove(uid);
|
||||
public static void userOffline(int uid) {
|
||||
sessionMap.remove(uid);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,11 @@ package com.ljsd.jieling.network.server;
|
|||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.google.protobuf.MessageLite;
|
||||
import com.ljsd.GameApplication;
|
||||
import com.ljsd.jieling.exception.ErrorCode;
|
||||
import com.ljsd.jieling.handler.BaseHandler;
|
||||
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||
import com.ljsd.jieling.netty.handler.GameMessageHandler;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
|
@ -207,7 +211,7 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
|||
|
||||
int resultCode = checkAndRefresh(session,packetNetData);
|
||||
if (resultCode != 0 ){
|
||||
MessageUtil.sendErrorCode(session);
|
||||
MessageUtil.sendErrorCode(session,0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -251,8 +255,9 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
|||
|
||||
private int checkAndRefresh(ISession session, PacketNetData packetNetData) {
|
||||
int myToken = 0;
|
||||
|
||||
if (packetNetData.getMsgId()== MessageTypeProto.MessageType.LOGIN_REQUEST_VALUE){
|
||||
OnlineUserManager.userOnline(session.getUid(),session);
|
||||
|
||||
//TODO 更新token
|
||||
}else if (packetNetData.getMsgId()== MessageTypeProto.MessageType.RECONNECT_REQUEST_VALUE){
|
||||
//TODO 更新token
|
||||
|
@ -260,6 +265,13 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
|||
}else {
|
||||
|
||||
}
|
||||
|
||||
if (OnlineUserManager.checkUidOnline(session.getUid())){
|
||||
ISession iSession = OnlineUserManager.getSessionByUid(session.getUid());
|
||||
MessageUtil.sendErrorCode(session, ErrorCode.reloginCode);
|
||||
iSession.close();
|
||||
}
|
||||
|
||||
// if (myToken != packetNetData.getToken()){
|
||||
// return 1;
|
||||
// }
|
||||
|
@ -295,14 +307,10 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
|||
return;
|
||||
}
|
||||
|
||||
if (nowSession != null) {
|
||||
LOGGER.error("offLine->uid={},session={},nowUid={},nowSession={}",
|
||||
session.getUid(), session, nowSession.getUid(), nowSession);
|
||||
}
|
||||
GameMessageHandler.currentSessions.remove(session.getUid());
|
||||
|
||||
try {
|
||||
|
||||
OnlineUserManager.userOffline(session.getUid());
|
||||
// 下线处理的逻辑需要添加在这里
|
||||
} finally {
|
||||
//保证数据的保存
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.ljsd.jieling.logic.dao.UserManager;
|
|||
import com.ljsd.jieling.netty.PackageConstant;
|
||||
import com.ljsd.jieling.netty.cocdex.Tea;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -43,10 +44,14 @@ public class MessageUtil {
|
|||
}
|
||||
|
||||
|
||||
public static void sendMessage(ISession session, int result, int msgId, GeneratedMessage generatedMessage, boolean flush) throws Exception {
|
||||
public static void sendMessage(ISession session, int result, int msgId, GeneratedMessage generatedMessage, boolean flush) {
|
||||
byte[] byteBuf = wrappedBuffer(session.getUid(), session.getToken(), session.getIndex(), result, msgId, generatedMessage);
|
||||
UserManager.ljsdMongoTemplate.lastUpdate();
|
||||
System.out.println("-----> msgId : "+ msgId+"; length : "+byteBuf.length+"; content : "+byteBuf);
|
||||
try {
|
||||
UserManager.ljsdMongoTemplate.lastUpdate();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// System.out.println("-----> msgId : "+ msgId+"; length : "+byteBuf.length+"; content : "+byteBuf);
|
||||
if (flush) {
|
||||
session.writeAndFlush(byteBuf);
|
||||
} else {
|
||||
|
@ -59,23 +64,19 @@ public class MessageUtil {
|
|||
+ PackageConstant.MSG_ID_FIELD_LEN ;
|
||||
byte[] bytes = new byte[length];
|
||||
int pos = 0;
|
||||
Tea.intToByte(bytes, pos, 100001);
|
||||
Tea.intToByte(bytes, pos, session.getUid());
|
||||
pos += PackageConstant.UID_FIELD_LEN;
|
||||
Tea.intToByte(bytes, pos, 123456);
|
||||
Tea.intToByte(bytes, pos, session.getToken());
|
||||
pos += PackageConstant.TOKEN_LEN;
|
||||
Tea.intToByte(bytes, pos, 1001);
|
||||
Tea.intToByte(bytes, pos, MessageTypeProto.MessageType.HEART_BEAT_RESPONSE_VALUE);
|
||||
byte[] byteBuf = Tea.encrypt2(bytes, Tea.KEY);
|
||||
session.writeAndFlush(byteBuf);
|
||||
}
|
||||
|
||||
public static void sendErrorCode(ISession session,int result,int msgId,String errMsg) throws Exception {
|
||||
/* if(StringUtils.isEmpty(errMsg)){
|
||||
sendMessage(session, result, msgId, null, true);
|
||||
}else{
|
||||
PlayerInfoProto.ErrorMsgResponse build = PlayerInfoProto.ErrorMsgResponse.newBuilder().setMsg(errMsg).build();
|
||||
sendMessage(session, result, msgId, build, true);
|
||||
}*/
|
||||
|
||||
public static void sendErrorCode(ISession session,int errorCode) {
|
||||
byte[] byteBuf = wrappedBuffer(session.getUid(), session.getToken(), session.getIndex(),
|
||||
errorCode, MessageTypeProto.MessageType.ERROR_CODE_INDICATION_VALUE, null);
|
||||
session.writeAndFlush(byteBuf);
|
||||
}
|
||||
|
||||
// public static void sendErrorResponse(Msg msg, GeneratedMessage error_message, int msgId) throws Exception {
|
||||
|
|
Loading…
Reference in New Issue