//跨服聊天提交
parent
3cde69f3b8
commit
0f49dae227
|
@ -12,6 +12,7 @@ import com.ljsd.jieling.exception.ErrorCode;
|
|||
import com.ljsd.jieling.exception.ErrorCodeException;
|
||||
import com.ljsd.jieling.ktbeans.ReportEventEnum;
|
||||
import com.ljsd.jieling.ktbeans.ReportUtil;
|
||||
import com.ljsd.jieling.logic.GlobleSystemLogic;
|
||||
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||
import com.ljsd.jieling.logic.dao.FriendManager;
|
||||
import com.ljsd.jieling.logic.dao.GuilidManager;
|
||||
|
@ -63,7 +64,7 @@ public class ChatLogic {
|
|||
case 0: // 系统
|
||||
chatInfoList = MessageCache.sysMsg.getObjs(messageId);
|
||||
break;
|
||||
case 1: //世界
|
||||
case -1: //世界
|
||||
chatInfoList = MessageCache.worldMsg.getObjs(messageId);
|
||||
break;
|
||||
case 2://公会
|
||||
|
@ -93,6 +94,15 @@ public class ChatLogic {
|
|||
RedisUtil.getInstence().del(GameApplication.serverId + RedisKey.CUser_Chat + uid);
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
int group = GlobleSystemLogic.getInstence().getCrossGroup();
|
||||
if(group==-1){
|
||||
throw new ErrorCodeException(ErrorCode.CHAT_NOT_CROSS);
|
||||
}
|
||||
chatInfoList = MessageCache.getCrossMsg(messageId,String.valueOf(group));
|
||||
|
||||
break;
|
||||
default:{
|
||||
LOGGER.info("getAllChatMessageInfo wrong chatType=>{} uid=>{}", chatType, uid);
|
||||
}
|
||||
|
@ -152,7 +162,7 @@ public class ChatLogic {
|
|||
}
|
||||
boolean result = true;
|
||||
switch (chatType){
|
||||
case 1:
|
||||
case -1:
|
||||
//0|content需要解字符串
|
||||
String s = message;
|
||||
String[] strs = message.split("|",3);
|
||||
|
@ -167,6 +177,9 @@ public class ChatLogic {
|
|||
case 3:
|
||||
result = ShieldedWordUtils.checkName(user,message,false,ChatContentType.PRIVATE_CHAT,UserManager.getUser(friendId));
|
||||
break;
|
||||
case 1:
|
||||
result = ShieldedWordUtils.checkName(user,message,false,ChatContentType.CROSS_CHAT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -187,7 +200,7 @@ public class ChatLogic {
|
|||
}
|
||||
|
||||
switch (chatType){
|
||||
case 1: //世界
|
||||
case -1: //世界
|
||||
long messageId = RedisUtil.getInstence().increment(GameApplication.serverId + RedisKey.CHAT_WORD_MSG_ID + GameApplication.serverId);
|
||||
ChatProto.ChatInfo chatInfo = CBean2Proto.getChatInfoBuilder(user,message,nowTime,messageId);
|
||||
|
||||
|
@ -229,6 +242,18 @@ public class ChatLogic {
|
|||
}
|
||||
|
||||
break;
|
||||
|
||||
case 1: //跨服
|
||||
int group = GlobleSystemLogic.getInstence().getCrossGroup();
|
||||
if(group==-1){
|
||||
throw new ErrorCodeException(ErrorCode.CHAT_NOT_CROSS);
|
||||
}
|
||||
|
||||
messageId = RedisUtil.getInstence().increment( RedisKey.CHAT_CROSS_MSG_ID + group);
|
||||
chatInfo = CBean2Proto.getChatInfoBuilder(user,message,nowTime,messageId);
|
||||
|
||||
MessageCache.addCrossMsg(chatInfo,messageId,String.valueOf(group));
|
||||
break;
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
package com.ljsd.jieling.chat.messge;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.ljsd.jieling.db.redis.RedisKey;
|
||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
import org.luaj.vm2.ast.Str;
|
||||
import rpc.protocols.ChatProto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MessageCache {
|
||||
private static final int capuatiy =200;
|
||||
|
@ -13,7 +21,7 @@ public class MessageCache {
|
|||
public static LoopQueue worldMsg = new LoopQueue(capuatiy,perCaught,-1);
|
||||
public static LoopQueue sysMsg = new LoopQueue(capuatiy,perCaught,msgInterval);
|
||||
public static Map<Integer,LoopQueue> guildMsg = new ConcurrentHashMap();
|
||||
|
||||
private static Gson gson = new Gson();
|
||||
|
||||
public static void addWordMsg(ChatProto.ChatInfo chatInfo,long messageId){
|
||||
worldMsg.push(chatInfo,messageId);
|
||||
|
@ -29,4 +37,60 @@ public class MessageCache {
|
|||
guildMsg.get(guildId).push(chatInfo,messageId);
|
||||
}
|
||||
|
||||
public static void addCrossMsg(ChatProto.ChatInfo chatInfo,long messageId,String group){
|
||||
long index = messageId % capuatiy;
|
||||
String key = RedisKey.CHAT_CROSS_INFO_CACHE+group;
|
||||
|
||||
RedisUtil.getInstence().hset(key,String.valueOf(index),gson.toJson(chatInfo));
|
||||
}
|
||||
|
||||
public static List<ChatProto.ChatInfo> getCrossMsg(long messageId,String group){
|
||||
String key = RedisKey.CHAT_CROSS_INFO_CACHE+group;
|
||||
Map<Integer,ChatProto.ChatInfo> map = new HashMap<>();
|
||||
Map<Object, Object> collect = RedisUtil.getInstence().hmget(key);
|
||||
collect.entrySet().forEach(o -> map.put(Integer.parseInt(o.getKey().toString()),
|
||||
gson.fromJson(o.getValue().toString(),ChatProto.ChatInfo.class)));
|
||||
List<ChatProto.ChatInfo> objs = new ArrayList<>();
|
||||
Object obj = RedisUtil.getInstence().get(RedisKey.CHAT_CROSS_MSG_ID + group);
|
||||
if(obj==null){
|
||||
return objs;
|
||||
}
|
||||
int writeIndex = Integer.parseInt(String.valueOf(obj));
|
||||
|
||||
Integer nextIndex = writeIndex%capuatiy;
|
||||
|
||||
if(nextIndex==-1){
|
||||
nextIndex = capuatiy - 1;
|
||||
}
|
||||
if(collect.size()<=0){
|
||||
return objs;
|
||||
}
|
||||
boolean needCompareTime = (messageId == 0);
|
||||
|
||||
while(map.containsKey(nextIndex)){
|
||||
|
||||
ChatProto.ChatInfo o = map.get(nextIndex);
|
||||
if(!needCompareTime){
|
||||
//比较消息id
|
||||
if(messageId>=o.getMessageId()){
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
objs.add(0, o);
|
||||
if(objs.size()>perCaught){
|
||||
break;
|
||||
}
|
||||
nextIndex--;
|
||||
if(nextIndex == -1){
|
||||
nextIndex = capuatiy - 1;
|
||||
}
|
||||
}
|
||||
if(!needCompareTime && objs.size()>perCaught){
|
||||
return objs.subList(0,perCaught);
|
||||
}
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,8 @@ public enum ChatContentType {
|
|||
FAMILY_HEAD(11,"会长"),
|
||||
FAMILY_NAME(12,"公会名"),
|
||||
ROLE_NAME(13,"角色名"),
|
||||
ANNOUNCE(14,"公告");
|
||||
ANNOUNCE(14,"公告"),
|
||||
CROSS_CHAT(15,"跨服");
|
||||
|
||||
private Integer type;
|
||||
private String text;
|
||||
|
|
|
@ -125,10 +125,14 @@ public class RedisKey {
|
|||
|
||||
public static final String CHAT_GUILD_MSG_ID = ":ChatGuildMsgId:";
|
||||
|
||||
public static final String CHAT_CROSS_MSG_ID = "ChatCrossMsgId:";
|
||||
|
||||
public static final String CHAT_FRIEND_MSG_ID = ":ChatFriendMsgId:";
|
||||
|
||||
public static final String CUser_Chat = ":CUser_Chat:";
|
||||
|
||||
public static final String CHAT_CROSS_INFO_CACHE = "CHAT_CROSS_INFO_CACHE:";//跨服聊天缓存
|
||||
|
||||
public static final String USER_LOGIN_URL = "USER_LOGIN_URL:";
|
||||
|
||||
public static final String CAR_DEALY_PLAY = "CAR_DEALY_PLAY";
|
||||
|
@ -257,6 +261,8 @@ public class RedisKey {
|
|||
|
||||
public static final String CHAT_INFO_CACHE = "CHAT_INFO_CACHE";//聊天信息缓存,gm后台使用
|
||||
|
||||
|
||||
|
||||
public static final String MAIL_RED_POINT = "MAIL_RED_POINT";//全服红点加入
|
||||
|
||||
public static final String PLAYER_INFO_CACHE = "PLAYER_INFO_CACHE";
|
||||
|
|
|
@ -170,8 +170,8 @@ public enum ErrorCode implements IErrorCode {
|
|||
|
||||
LOCK_FILL(140,"锁定数量已满,无法刷新"),
|
||||
REDPACKET_DAILY_LIMIT(141,"今日福利红包已达领取上限"),
|
||||
CHAMPION_BET_GUESS_OVER_TIME(142,"巅峰赛竞猜超时,请重新进入页面")
|
||||
|
||||
CHAMPION_BET_GUESS_OVER_TIME(142,"巅峰赛竞猜超时,请重新进入页面"),
|
||||
CHAT_NOT_CROSS(143,"聊天检查 没有跨服分组"),
|
||||
;
|
||||
private static final Set<Integer> CodeSet = new HashSet<>();
|
||||
|
||||
|
|
Loading…
Reference in New Issue