优化
This commit is contained in:
parent
710b28fbc0
commit
c836719666
@ -4,6 +4,8 @@ import (
|
||||
"cs"
|
||||
)
|
||||
|
||||
const ChatMsgMaxSize = 60
|
||||
|
||||
type ChatUserRec struct {
|
||||
HasUnreadMsg bool
|
||||
Dirty bool
|
||||
@ -15,3 +17,10 @@ type ChatMsgRec struct {
|
||||
LastID uint64
|
||||
ChatMsgList []*cs.MFChatMsg
|
||||
}
|
||||
|
||||
func (c *ChatMsgRec) AddChatMsg(msg *cs.MFChatMsg) {
|
||||
if len(c.ChatMsgList) >= ChatMsgMaxSize {
|
||||
c.ChatMsgList = c.ChatMsgList[1:]
|
||||
}
|
||||
c.ChatMsgList = append(c.ChatMsgList, msg)
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"cs"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -14,9 +15,9 @@ type ChatMgr struct {
|
||||
guildMsgRec map[int64]*ChatMsgRec
|
||||
privateChatUsers map[string]*ChatUserRec
|
||||
|
||||
WorldMsgId uint64
|
||||
GuildMsgId uint64
|
||||
TmpMsgId uint64
|
||||
worldMsgId uint64
|
||||
guildMsgId uint64
|
||||
tmpMsgId uint64
|
||||
}
|
||||
|
||||
func NewChatMgr(pm *PlayerMgr, fm *FriendsMgr, gm *GuildMgr) *ChatMgr {
|
||||
@ -29,9 +30,9 @@ func NewChatMgr(pm *PlayerMgr, fm *FriendsMgr, gm *GuildMgr) *ChatMgr {
|
||||
privateChatUsers: make(map[string]*ChatUserRec),
|
||||
}
|
||||
// Default values
|
||||
cm.WorldMsgId = 1000
|
||||
cm.GuildMsgId = 1000
|
||||
cm.TmpMsgId = 1000
|
||||
cm.worldMsgId = 1000
|
||||
cm.guildMsgId = 1000
|
||||
cm.tmpMsgId = 1000
|
||||
|
||||
return cm
|
||||
}
|
||||
@ -92,11 +93,11 @@ func (cm *ChatMgr) FillSMUpdatePrivateChatRedPointNotify(p *Player, msg *cs.SMUp
|
||||
func (cm *ChatMgr) ProcWorldChat(p *Player, msg *cs.CMSendChatMsg) {
|
||||
accountId := p.GetAccountId()
|
||||
chatMsg := new(cs.MFChatMsg)
|
||||
cm.WorldMsgId++
|
||||
cm.FillMFChatMsg(chatMsg, &accountId, cm.WorldMsgId, *msg.ChatChannel, *msg.MsgType, msg.MsgBody)
|
||||
cm.worldMsgId++
|
||||
cm.FillMFChatMsg(chatMsg, &accountId, cm.worldMsgId, *msg.ChatChannel, *msg.MsgType, msg.MsgBody)
|
||||
|
||||
cm.worldMsgRec.CurrID = cm.WorldMsgId
|
||||
cm.worldMsgRec.ChatMsgList = append(cm.worldMsgRec.ChatMsgList, chatMsg)
|
||||
cm.worldMsgRec.CurrID = cm.worldMsgId
|
||||
cm.worldMsgRec.AddChatMsg(chatMsg)
|
||||
|
||||
// TraversePlayer
|
||||
for _, p2 := range cm.pm.GetPlayers() {
|
||||
@ -110,16 +111,16 @@ func (cm *ChatMgr) ProcGuildChat(p *Player, msg *cs.CMSendChatMsg) {
|
||||
return
|
||||
}
|
||||
guildId := guild.GuildId
|
||||
cm.GuildMsgId++
|
||||
cm.guildMsgId++
|
||||
|
||||
chatMsg := new(cs.MFChatMsg)
|
||||
cm.FillMFChatMsg(chatMsg, &p.accountId, cm.GuildMsgId, *msg.ChatChannel, *msg.MsgType, msg.MsgBody)
|
||||
cm.FillMFChatMsg(chatMsg, &p.accountId, cm.guildMsgId, *msg.ChatChannel, *msg.MsgType, msg.MsgBody)
|
||||
|
||||
if msgRec, exists := cm.guildMsgRec[guildId]; exists {
|
||||
msgRec.ChatMsgList = append(msgRec.ChatMsgList, chatMsg)
|
||||
msgRec.AddChatMsg(chatMsg)
|
||||
} else {
|
||||
msgRec := &ChatMsgRec{}
|
||||
msgRec.CurrID = cm.GuildMsgId
|
||||
msgRec.CurrID = cm.guildMsgId
|
||||
cm.guildMsgRec[guildId] = msgRec
|
||||
}
|
||||
|
||||
@ -229,7 +230,7 @@ func (cm *ChatMgr) SyncGuildChatMsg(p *Player) {
|
||||
|
||||
func (cm *ChatMgr) AddChatUser(senderAccountId, receiverAccountId string, chatMsg *cs.MFChatMsg, lastId uint64) {
|
||||
chatMsgCopy := new(cs.MFChatMsg)
|
||||
*chatMsgCopy = *chatMsg
|
||||
proto.Merge(chatMsgCopy, chatMsg)
|
||||
chatMsgCopy.MsgUuid = &lastId
|
||||
|
||||
if _, exists := cm.privateChatUsers[senderAccountId]; !exists {
|
||||
@ -246,8 +247,7 @@ func (cm *ChatMgr) AddChatUser(senderAccountId, receiverAccountId string, chatMs
|
||||
|
||||
receiverUserRec := cm.privateChatUsers[senderAccountId].Users[receiverAccountId]
|
||||
receiverUserRec.LastID = lastId
|
||||
receiverUserRec.ChatMsgList = append(receiverUserRec.ChatMsgList, chatMsgCopy)
|
||||
// 队列 保持最近50条
|
||||
receiverUserRec.AddChatMsg(chatMsgCopy)
|
||||
}
|
||||
|
||||
func (cm *ChatMgr) GetChatUser(accountId *string) *ChatUserRec {
|
||||
|
@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"cs"
|
||||
"f5"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"q5"
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user