mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-23 14:32:27 +08:00
拆分了聊天数据,减小玩家数据结构大小
This commit is contained in:
@@ -12,6 +12,10 @@ import (
|
||||
pb "google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
MaxMsgListLen = 1000 // 与某人的最大聊天记录条数
|
||||
)
|
||||
|
||||
func (g *GameManager) PullRecentChatReq(player *model.Player, payloadMsg pb.Message) {
|
||||
logger.Debug("user pull recent chat, uid: %v", player.PlayerID)
|
||||
req := payloadMsg.(*proto.PullRecentChatReq)
|
||||
@@ -94,7 +98,7 @@ func (g *GameManager) SendPrivateChat(player *model.Player, targetUid uint32, co
|
||||
chatInfo.Content = &proto.ChatInfo_Text{
|
||||
Text: content.(string),
|
||||
}
|
||||
case int, int32, uint32:
|
||||
case uint32:
|
||||
// 图标消息
|
||||
chatInfo.Content = &proto.ChatInfo_Icon{
|
||||
Icon: content.(uint32),
|
||||
@@ -106,6 +110,9 @@ func (g *GameManager) SendPrivateChat(player *model.Player, targetUid uint32, co
|
||||
if !exist {
|
||||
msgList = make([]*model.ChatMsg, 0)
|
||||
}
|
||||
if len(msgList) > MaxMsgListLen {
|
||||
msgList = msgList[1:]
|
||||
}
|
||||
msgList = append(msgList, chatMsg)
|
||||
player.ChatMsgMap[targetUid] = msgList
|
||||
|
||||
@@ -136,7 +143,10 @@ func (g *GameManager) SendPrivateChat(player *model.Player, targetUid uint32, co
|
||||
})
|
||||
} else {
|
||||
// 目标玩家全服离线
|
||||
// TODO 接入redis直接同步写入数据
|
||||
chatMsgMap := map[uint32][]*model.ChatMsg{
|
||||
player.PlayerID: {chatMsg},
|
||||
}
|
||||
go USER_MANAGER.AppendOfflineUserChatMsgToDbSync(targetUid, chatMsgMap)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -145,6 +155,9 @@ func (g *GameManager) SendPrivateChat(player *model.Player, targetUid uint32, co
|
||||
if !exist {
|
||||
msgList = make([]*model.ChatMsg, 0)
|
||||
}
|
||||
if len(msgList) > MaxMsgListLen {
|
||||
msgList = msgList[1:]
|
||||
}
|
||||
msgList = append(msgList, chatMsg)
|
||||
targetPlayer.ChatMsgMap[player.PlayerID] = msgList
|
||||
|
||||
@@ -167,7 +180,8 @@ func (g *GameManager) PrivateChatReq(player *model.Player, payloadMsg pb.Message
|
||||
switch content.(type) {
|
||||
case *proto.PrivateChatReq_Text:
|
||||
text := content.(*proto.PrivateChatReq_Text).Text
|
||||
if len(text) == 0 {
|
||||
if len(text) == 0 || len(text) > 80 {
|
||||
g.SendError(cmd.PrivateChatRsp, player, &proto.PrivateChatRsp{}, proto.Retcode_RET_PRIVATE_CHAT_CONTENT_TOO_LONG)
|
||||
return
|
||||
}
|
||||
// 发送私聊文本消息
|
||||
|
||||
Reference in New Issue
Block a user