From b156df6fb040740b60b83a6b377257312f25af27 Mon Sep 17 00:00:00 2001 From: gaojie Date: Wed, 19 Jun 2019 15:47:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=8A=E5=A4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chat/handler/GetChatMessageHandler.java | 3 +- .../ljsd/jieling/chat/logic/ChatLogic.java | 30 ++++++++++--------- .../jieling/chat/messge/MessageCache.java | 9 ++---- .../com/ljsd/jieling/util/CBean2Proto.java | 6 ++-- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/serverlogic/src/main/java/com/ljsd/jieling/chat/handler/GetChatMessageHandler.java b/serverlogic/src/main/java/com/ljsd/jieling/chat/handler/GetChatMessageHandler.java index 087460144..3d67c8aa0 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/chat/handler/GetChatMessageHandler.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/chat/handler/GetChatMessageHandler.java @@ -19,6 +19,7 @@ public class GetChatMessageHandler extends BaseHandler{ public void process(ISession iSession, PacketNetData netData) throws Exception { ChatProto.GetChatMessageInfoRequest getChatMessageInfoRequest = ChatProto.GetChatMessageInfoRequest.parseFrom(netData.parseClientProtoNetData()); int chatType = getChatMessageInfoRequest.getChatType(); - ChatLogic.getInstance().getAllChatMessageInfo(iSession,chatType); + int messageId = getChatMessageInfoRequest.getMessageId(); + ChatLogic.getInstance().getAllChatMessageInfo(iSession,chatType,messageId); } } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/chat/logic/ChatLogic.java b/serverlogic/src/main/java/com/ljsd/jieling/chat/logic/ChatLogic.java index c1309b9db..9e3885865 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/chat/logic/ChatLogic.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/chat/logic/ChatLogic.java @@ -5,7 +5,6 @@ import com.ljsd.GameApplication; import com.ljsd.jieling.chat.messge.MessageCache; import com.ljsd.jieling.db.redis.RedisKey; import com.ljsd.jieling.db.redis.RedisUtil; -import com.ljsd.jieling.globals.Global; import com.ljsd.jieling.logic.OnlineUserManager; import com.ljsd.jieling.logic.dao.FriendManager; import com.ljsd.jieling.logic.dao.UserManager; @@ -35,20 +34,20 @@ public class ChatLogic { * 获取聊天信息 * @param chatType */ - public void getAllChatMessageInfo(ISession iSession, int chatType) throws Exception { + public void getAllChatMessageInfo(ISession iSession, int chatType,int messageId) throws Exception { int uid = iSession.getUid(); FriendManager friendManager = UserManager.getUser(uid).getFriendManager(); List friends = friendManager.getFriends(); List chatInfoList = new ArrayList<>(); switch (chatType){ case 0: // 系统 - chatInfoList = MessageCache.sysMsg.getObjs(0); + chatInfoList = MessageCache.sysMsg.getObjs(messageId); break; case 1: //世界 - chatInfoList = MessageCache.worldMsg.getObjs(0); + chatInfoList = MessageCache.worldMsg.getObjs(messageId); break; case 2: //公会 - chatInfoList = MessageCache.guildMsg.getObjs(0); + chatInfoList = MessageCache.guildMsg.getObjs(messageId); break; case 3: //好友 Map hmget = RedisUtil.getInstence().hmget(GameApplication.serverId + RedisKey.CUser_Chat + uid); @@ -62,7 +61,7 @@ public class ChatLogic { } long time = Long.parseLong(split[1]); User user = UserManager.getUser(userid); - chatInfoList.add(CBean2Proto.getChatInfoBuilder(user,message,time)); + chatInfoList.add(CBean2Proto.getChatInfoBuilder(user, message,time,0)); } } if (hmget!= null && hmget.size() != 0){ @@ -91,23 +90,25 @@ public class ChatLogic { long nowTime = System.currentTimeMillis(); switch (chatType){ case 1: //世界 - ChatProto.ChatInfo chatInfo = CBean2Proto.getChatInfoBuilder(user,message,nowTime); - MessageCache.addWordMsg(chatInfo); + long messageId = RedisUtil.getInstence().increment(GameApplication.serverId + RedisKey.CHAT_WORD_MSG_ID + GameApplication.serverId); + ChatProto.ChatInfo chatInfo = CBean2Proto.getChatInfoBuilder(user,message,nowTime,messageId); + MessageCache.addWordMsg(chatInfo,messageId); break; case 2: //公会 - chatInfo = CBean2Proto.getChatInfoBuilder(user,message,nowTime); - MessageCache.addGuildMsg(chatInfo); + messageId = RedisUtil.getInstence().increment(GameApplication.serverId + RedisKey.CHAT_GUILD_MSG_ID+ GameApplication.serverId); + chatInfo = CBean2Proto.getChatInfoBuilder(user,message,nowTime,messageId); + MessageCache.addGuildMsg(chatInfo,messageId); break; case 3: //好友 List friends = friendManager.getFriends(); if (!friends.contains(friendId)){ - MessageUtil.sendErrorResponse(iSession,0, msgId, "不能查找自己"); + MessageUtil.sendErrorResponse(iSession,0, msgId, ""); return; } //现在好友推送 if (OnlineUserManager.checkUidOnline(friendId)){ ISession sessionByUid = OnlineUserManager.getSessionByUid(friendId); - chatInfo = CBean2Proto.getChatInfoBuilder(user,message,nowTime); + chatInfo = CBean2Proto.getChatInfoBuilder(user,message,nowTime,0); ChatProto.SendChatInfoIndication sendChatInfoIndication = ChatProto.SendChatInfoIndication.newBuilder() .setChatInfo(chatInfo) .build(); @@ -126,7 +127,8 @@ public class ChatLogic { * 系统消息跑马灯 */ public void sendSysChatMessage(String message,int messageType ,int itemId, int type,int startTime, int endTime, int priorityLevel, int frequency) { - ChatProto.ChatInfo chatInfo = CBean2Proto.getSysChatInfoBuilder(message,messageType,itemId ,type,startTime,endTime,priorityLevel,frequency); - MessageCache.addSystemMsg(chatInfo); + long messageId = RedisUtil.getInstence().increment(GameApplication.serverId + RedisKey.CHAT_SYS_MSG_ID+ GameApplication.serverId); + ChatProto.ChatInfo chatInfo = CBean2Proto.getSysChatInfoBuilder(message,messageType,itemId ,type,startTime,endTime,priorityLevel,frequency,messageId); + MessageCache.addSystemMsg(chatInfo,messageId); } } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/chat/messge/MessageCache.java b/serverlogic/src/main/java/com/ljsd/jieling/chat/messge/MessageCache.java index a48776798..aca166cbf 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/chat/messge/MessageCache.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/chat/messge/MessageCache.java @@ -15,18 +15,15 @@ public class MessageCache { public static LoopQueue guildMsg = new LoopQueue(capuatiy,perCaught,msgInterval); - public static void addWordMsg(ChatProto.ChatInfo chatInfo){ - long messageId = RedisUtil.getInstence().increment(GameApplication.serverId + RedisKey.CHAT_WORD_MSG_ID + GameApplication.serverId); + public static void addWordMsg(ChatProto.ChatInfo chatInfo,long messageId){ worldMsg.push(chatInfo,messageId); } - public static void addSystemMsg(ChatProto.ChatInfo chatInfo){ - long messageId = RedisUtil.getInstence().increment(GameApplication.serverId + RedisKey.CHAT_SYS_MSG_ID+ GameApplication.serverId); + public static void addSystemMsg(ChatProto.ChatInfo chatInfo,long messageId ){ sysMsg.push(chatInfo,messageId); } - public static void addGuildMsg(ChatProto.ChatInfo chatInfo){ - long messageId = RedisUtil.getInstence().increment(GameApplication.serverId + RedisKey.CHAT_GUILD_MSG_ID+ GameApplication.serverId); + public static void addGuildMsg(ChatProto.ChatInfo chatInfo,long messageId ){ guildMsg.push(chatInfo,messageId); } } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/util/CBean2Proto.java b/serverlogic/src/main/java/com/ljsd/jieling/util/CBean2Proto.java index 2fc03ea68..80ec2f577 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/util/CBean2Proto.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/util/CBean2Proto.java @@ -222,7 +222,7 @@ public class CBean2Proto { } - public static ChatProto.ChatInfo getChatInfoBuilder(User user,String message,long time) { + public static ChatProto.ChatInfo getChatInfoBuilder(User user,String message,long time,long messageId) { ChatProto.ChatInfo.Builder chatInfo = ChatProto.ChatInfo.newBuilder(); PlayerManager playerInfoManager = user.getPlayerInfoManager(); chatInfo.setSenderId(user.getId()); @@ -234,12 +234,14 @@ public class CBean2Proto { chatInfo.setHead(playerInfoManager.getHead()); chatInfo.setFrame(playerInfoManager.getFamilyId()); chatInfo.setSoulVal(playerInfoManager.getMaxForce()); + chatInfo.setMessageId(messageId); return chatInfo.build(); } - public static ChatProto.ChatInfo getSysChatInfoBuilder(String message,int messageType,int itemId,int type,int startTime, int endTime, int priorityLevel, int frequency) { + public static ChatProto.ChatInfo getSysChatInfoBuilder(String message,int messageType,int itemId,int type,int startTime, int endTime, int priorityLevel, int frequency,long messageId) { ChatProto.ChatInfo.Builder chatInfo = ChatProto.ChatInfo.newBuilder(); chatInfo.setItemId(itemId); + chatInfo.setMessageId(messageId); chatInfo.setTimes(System.currentTimeMillis()); chatInfo.setMsg(message); chatInfo.setType(type);