reconnect
parent
f05b764cfa
commit
43883d4722
|
@ -2,44 +2,31 @@ package com.ljsd.jieling.network.server;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import com.google.protobuf.GeneratedMessage;
|
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
|
||||||
import com.ljsd.GameApplication;
|
import com.ljsd.GameApplication;
|
||||||
import com.ljsd.common.mogodb.LjsdMongoTemplate;
|
|
||||||
import com.ljsd.jieling.battle.actor.Scene;
|
import com.ljsd.jieling.battle.actor.Scene;
|
||||||
import com.ljsd.jieling.battle.actor.StateType;
|
import com.ljsd.jieling.battle.actor.StateType;
|
||||||
import com.ljsd.jieling.battle.room.SceneManager;
|
import com.ljsd.jieling.battle.room.SceneManager;
|
||||||
import com.ljsd.jieling.config.SGlobalSystemConfig;
|
|
||||||
import com.ljsd.jieling.core.FunctionIdEnum;
|
|
||||||
import com.ljsd.jieling.core.HandlerLogicThread;
|
import com.ljsd.jieling.core.HandlerLogicThread;
|
||||||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||||||
import com.ljsd.jieling.db.redis.RedisKey;
|
import com.ljsd.jieling.db.redis.RedisKey;
|
||||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||||
import com.ljsd.jieling.exception.ErrorCode;
|
import com.ljsd.jieling.exception.ErrorCode;
|
||||||
import com.ljsd.jieling.globals.Global;
|
|
||||||
import com.ljsd.jieling.handler.BaseHandler;
|
import com.ljsd.jieling.handler.BaseHandler;
|
||||||
import com.ljsd.jieling.ktbeans.KtEventUtils;
|
import com.ljsd.jieling.ktbeans.KtEventUtils;
|
||||||
import com.ljsd.jieling.ktbeans.parmsBean.ParamEventBean;
|
import com.ljsd.jieling.ktbeans.parmsBean.ParamEventBean;
|
||||||
import com.ljsd.jieling.logic.OnlineUserManager;
|
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||||
import com.ljsd.jieling.logic.activity.ActivityLogic;
|
import com.ljsd.jieling.logic.activity.ActivityLogic;
|
||||||
import com.ljsd.jieling.logic.activity.ActivityType;
|
import com.ljsd.jieling.logic.activity.ActivityType;
|
||||||
import com.ljsd.jieling.logic.dao.LevelDifficulty;
|
|
||||||
import com.ljsd.jieling.logic.dao.PlayerManager;
|
import com.ljsd.jieling.logic.dao.PlayerManager;
|
||||||
import com.ljsd.jieling.logic.dao.UserManager;
|
import com.ljsd.jieling.logic.dao.UserManager;
|
||||||
import com.ljsd.jieling.logic.dao.root.GuildLog;
|
|
||||||
import com.ljsd.jieling.logic.dao.root.User;
|
import com.ljsd.jieling.logic.dao.root.User;
|
||||||
import com.ljsd.jieling.logic.family.GuildLogic;
|
import com.ljsd.jieling.logic.family.GuildLogic;
|
||||||
import com.ljsd.jieling.logic.fight.CombatLogic;
|
|
||||||
import com.ljsd.jieling.logic.room.Room;
|
|
||||||
import com.ljsd.jieling.logic.room.RoomManager;
|
|
||||||
import com.ljsd.jieling.logic.room.RoomPlayerInfo;
|
|
||||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||||
import com.ljsd.jieling.netty.cocdex.Tea;
|
|
||||||
import com.ljsd.jieling.netty.handler.GameMessageHandler;
|
import com.ljsd.jieling.netty.handler.GameMessageHandler;
|
||||||
import com.ljsd.jieling.network.session.ISession;
|
import com.ljsd.jieling.network.session.ISession;
|
||||||
import com.ljsd.jieling.protocol.ProtocolsAbstract;
|
import com.ljsd.jieling.protocol.ProtocolsAbstract;
|
||||||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||||
import com.ljsd.jieling.protocols.RoomFightProto;
|
|
||||||
import com.ljsd.jieling.session.GameSession;
|
import com.ljsd.jieling.session.GameSession;
|
||||||
import com.ljsd.jieling.util.MathUtils;
|
import com.ljsd.jieling.util.MathUtils;
|
||||||
import com.ljsd.jieling.util.MessageUtil;
|
import com.ljsd.jieling.util.MessageUtil;
|
||||||
|
@ -47,9 +34,6 @@ import com.ljsd.jieling.util.TimeUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import sun.misc.BASE64Encoder;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
@ -130,6 +114,7 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
||||||
iSession.setHeartBreatNums(heartBreatNums);
|
iSession.setHeartBreatNums(heartBreatNums);
|
||||||
}
|
}
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processMessage(GameSession gameSession, Object obj) {
|
public void processMessage(GameSession gameSession, Object obj) {
|
||||||
|
|
||||||
|
@ -202,6 +187,13 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
||||||
// MessageUtil.sendErrorCode(session,0,"您的账号token不正确,请退出游戏重新登陆!");
|
// MessageUtil.sendErrorCode(session,0,"您的账号token不正确,请退出游戏重新登陆!");
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
if( packetNetData.getMsgId()== MessageTypeProto.MessageType.RECONNECT_REQUEST_VALUE){
|
||||||
|
processReconnect(session);
|
||||||
|
LOGGER.info("the uid={} process reconnect",session.getUid());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (checkIndex(session,packetNetData) != 0){
|
if (checkIndex(session,packetNetData) != 0){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -209,11 +201,6 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
||||||
if(b){
|
if(b){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if( packetNetData.getMsgId()== MessageTypeProto.MessageType.RECONNECT_REQUEST_VALUE){
|
|
||||||
processReconnect(session);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//LOGGER.info("process the uid={},the msg={},the index={}",packetNetData.getUserId(), MessageTypeProto.MessageType.valueOf(packetNetData.getMsgId()),packetNetData.getIndex());
|
|
||||||
BaseHandler baseHandler = handlers.get(packetNetData.getMsgId());
|
BaseHandler baseHandler = handlers.get(packetNetData.getMsgId());
|
||||||
if (baseHandler == null) {
|
if (baseHandler == null) {
|
||||||
LOGGER.info("request unknow commond : " + packetNetData.getMsgId());
|
LOGGER.info("request unknow commond : " + packetNetData.getMsgId());
|
||||||
|
@ -243,12 +230,13 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
||||||
public void processReconnect(ISession session){
|
public void processReconnect(ISession session){
|
||||||
String key = RedisUtil.getInstence().getKey(RedisKey.INDICATION_OFFLINE, Integer.toString(session.getUid()));
|
String key = RedisUtil.getInstence().getKey(RedisKey.INDICATION_OFFLINE, Integer.toString(session.getUid()));
|
||||||
Type type = new TypeToken<Map<Integer, ISession.IndicationMsg>>(){}.getType();
|
Type type = new TypeToken<Map<Integer, ISession.IndicationMsg>>(){}.getType();
|
||||||
Map<Integer, ISession.IndicationMsg> map= gson.fromJson(RedisUtil.getInstence().get(key).toString(),type);
|
Object indicationInRedis = RedisUtil.getInstence().get(key);
|
||||||
int maxMsgId = 0;
|
int maxMsgId = 0;
|
||||||
if(map!=null && map.isEmpty()){
|
if(indicationInRedis!=null){
|
||||||
|
Map<Integer, ISession.IndicationMsg> map= gson.fromJson(indicationInRedis.toString(),type);
|
||||||
for(Map.Entry<Integer,ISession.IndicationMsg> info : map.entrySet()){
|
for(Map.Entry<Integer,ISession.IndicationMsg> info : map.entrySet()){
|
||||||
Integer msgIndex = info.getKey();
|
Integer msgIndex = info.getKey();
|
||||||
session.writeAndFlush(info.getValue());
|
session.writeAndFlush(info.getValue().getMsg());
|
||||||
session.putBackIndicationToMap(msgIndex,info.getValue().getMsg());
|
session.putBackIndicationToMap(msgIndex,info.getValue().getMsg());
|
||||||
if(maxMsgId<msgIndex){
|
if(maxMsgId<msgIndex){
|
||||||
maxMsgId = msgIndex;
|
maxMsgId = msgIndex;
|
||||||
|
@ -256,16 +244,21 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
||||||
}
|
}
|
||||||
RedisUtil.getInstence().del(key);
|
RedisUtil.getInstence().del(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
key = RedisUtil.getInstence().getKey(RedisKey.RESPONSE_OFFLINE, Integer.toString(session.getUid()));
|
key = RedisUtil.getInstence().getKey(RedisKey.RESPONSE_OFFLINE, Integer.toString(session.getUid()));
|
||||||
type = new TypeToken<Map<Integer, byte[]>>(){}.getType();
|
type = new TypeToken<Map<Integer, byte[]>>(){}.getType();
|
||||||
Map<Integer, byte[]> response = gson.fromJson(RedisUtil.getInstence().get(key).toString(), type);
|
Object responsInRedis = RedisUtil.getInstence().get(key);
|
||||||
session.setFiveReady(1);
|
session.setFiveReady(1);
|
||||||
session.updateIndicationIndex(maxMsgId);
|
session.updateIndicationIndex(maxMsgId);
|
||||||
|
if(responsInRedis!=null){
|
||||||
|
Map<Integer, byte[]> response = gson.fromJson(responsInRedis.toString(), type);
|
||||||
if(response!=null && !response.isEmpty()){
|
if(response!=null && !response.isEmpty()){
|
||||||
session.setIndexToMessage(new ConcurrentHashMap<Integer, byte[]> (response));
|
session.setIndexToMessage(new ConcurrentHashMap<Integer, byte[]> (response));
|
||||||
session.setIndex(response.keySet().iterator().next());
|
Integer index = response.keySet().iterator().next();
|
||||||
|
session.setIndex(index);
|
||||||
RedisUtil.getInstence().del(key);
|
RedisUtil.getInstence().del(key);
|
||||||
|
LOGGER.info("the uid={} cache repsponse is ={},session={}",session.getUid(),index,session.getCtx().channel());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
MessageUtil.sendMessageWithoutBack(session,1, MessageTypeProto.MessageType.RECONNECT_RESPONSE_VALUE,null,true);
|
MessageUtil.sendMessageWithoutBack(session,1, MessageTypeProto.MessageType.RECONNECT_RESPONSE_VALUE,null,true);
|
||||||
}
|
}
|
||||||
|
@ -308,11 +301,12 @@ public class ProtocolsManager implements ProtocolsAbstract {
|
||||||
int index = packetNetData.getIndex();
|
int index = packetNetData.getIndex();
|
||||||
if (iSession.getIndex() >= index){
|
if (iSession.getIndex() >= index){
|
||||||
byte[] message = iSession.getCacheMessage(index);
|
byte[] message = iSession.getCacheMessage(index);
|
||||||
if (message==null && packetNetData.getMsgId() != 11100){
|
if (message==null &&( packetNetData.getMsgId() != MessageTypeProto.MessageType.LOGIN_REQUEST_VALUE || packetNetData.getMsgId() != MessageTypeProto.MessageType.RECONNECT_REQUEST_VALUE)){
|
||||||
//TODO error
|
//TODO error
|
||||||
LOGGER.info("the uid={},the msg={} is processing",iSession.getUid(), MessageTypeProto.MessageType.valueOf(packetNetData.getMsgId()));
|
LOGGER.info("the uid={},the msg={} is processing",iSession.getUid(), MessageTypeProto.MessageType.valueOf(packetNetData.getMsgId()));
|
||||||
return 1;
|
return 1;
|
||||||
}else {
|
}else {
|
||||||
|
LOGGER.info("the uid={},the msg={} reback",iSession.getUid(), MessageTypeProto.MessageType.valueOf(packetNetData.getMsgId()));
|
||||||
iSession.writeAndFlush(message);
|
iSession.writeAndFlush(message);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue