diff --git a/serverlogic/src/main/java/com/ljsd/jieling/network/server/ProtocolsManager.java b/serverlogic/src/main/java/com/ljsd/jieling/network/server/ProtocolsManager.java index 302972c80..4c88bd2fd 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/network/server/ProtocolsManager.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/network/server/ProtocolsManager.java @@ -359,14 +359,20 @@ public class ProtocolsManager implements ProtocolsAbstract { @Override public void offLine(GameSession gameSession) { - LOGGER.info("player offLine ..."); + ISession session = (ISession) gameSession; + LOGGER.info("player offLine ..{}",session.getUid()); synchronized (session) { + if (session.getUid() == 0) { + LOGGER.error("offLine->uid={}", session.getUid()); + return; + } if(session.getOfflineType() == ErrorCode.reloginCode){ return; } User user = UserManager.getUserInMem(session.getUid()); if(user == null){ + LOGGER.info("the uid={},not in mem",session.getUid()); return; } KtEventUtils.onKtEvent(user, ParamEventBean.UserLoginOutEvent,1); @@ -377,10 +383,7 @@ public class ProtocolsManager implements ProtocolsAbstract { GameMessageHandler.allChannels.remove(session.getCtx().channel()); } - if (session.getUid() == 0) { - LOGGER.error("offLine->uid={}", session.getUid()); - return; - } + GameMessageHandler.currentSessions.remove(session.getUid()); try { diff --git a/serverlogic/src/main/java/com/ljsd/jieling/thread/task/RetrySendIndicationThread.java b/serverlogic/src/main/java/com/ljsd/jieling/thread/task/RetrySendIndicationThread.java index a7a14c4bc..708d6d1bc 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/thread/task/RetrySendIndicationThread.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/thread/task/RetrySendIndicationThread.java @@ -4,6 +4,8 @@ import com.ljsd.jieling.logic.OnlineUserManager; import com.ljsd.jieling.network.session.ISession; import com.ljsd.jieling.protocols.MessageTypeProto; import com.ljsd.jieling.util.MessageUtil; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelHandlerContext; import util.TimeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,35 +42,24 @@ public class RetrySendIndicationThread extends Thread{ long now = TimeUtils.now(); Set removeIds = new HashSet<>(); for(ISession session : sessionMap.values()){ - if(session.getCtx() == null || session.getCtx().channel() == null){ - removeIds.add(session.getUid()); - continue; - } - if(session.getFiveReady() == 1 && session.getFiveByteBuf()!=null){ - session.putBackIndicationToMap(MessageTypeProto.MessageType.FIVE_PLAYER_REFLUSH_INDICATION_VALUE,session.getFiveByteBuf()); - session.setFiveByteBuf(null); - } - ConcurrentHashMap indexToIndication = session.getIndexToIndication(); - boolean send = false; - for(ISession.IndicationMsg indicationMsg : indexToIndication.values()){ - long create = indicationMsg.getCreate(); - int retryTimes = indicationMsg.getRetryTimes()+1; - if(now-create>retryTimes*300){ - if(session.getUid() == 20000739){ - Calendar calendar = Calendar.getInstance(); - int i = calendar.get(Calendar.MINUTE); - if(i%2==0 && !send){ - for(Integer id : indexToIndication.keySet()){ - LOGGER.info("indication id={}",id); - } - send = true; - } - - - } - MessageUtil.retrySendIndication(session,indicationMsg.getMsg()); - indicationMsg.setRetryTimes(retryTimes); + ChannelHandlerContext localCtx = session.getCtx(); + if ((localCtx != null) && (localCtx.channel() != null) && (localCtx.channel().isOpen()) + && (localCtx.channel().isActive()) && (localCtx.channel().isWritable())) { + if(session.getFiveReady() == 1 && session.getFiveByteBuf()!=null){ + session.putBackIndicationToMap(MessageTypeProto.MessageType.FIVE_PLAYER_REFLUSH_INDICATION_VALUE,session.getFiveByteBuf()); + session.setFiveByteBuf(null); } + ConcurrentHashMap indexToIndication = session.getIndexToIndication(); + for(ISession.IndicationMsg indicationMsg : indexToIndication.values()){ + long create = indicationMsg.getCreate(); + int retryTimes = indicationMsg.getRetryTimes()+1; + if(now-create>retryTimes*300){ + MessageUtil.retrySendIndication(session,indicationMsg.getMsg()); + indicationMsg.setRetryTimes(retryTimes); + } + } + }else{ + removeIds.add(session.getUid()); } } for(Integer removeId:removeIds ){