This commit is contained in:
aozhiwei 2024-02-17 20:15:39 +08:00
parent 1b45056fed
commit 6d75fe9387
4 changed files with 26 additions and 11 deletions

View File

@ -10,7 +10,6 @@ import (
) )
type ChatMgr struct { type ChatMgr struct {
gm *GuildMgr
worldMsgRec *ChatMsgRec worldMsgRec *ChatMsgRec
guildMsgRec map[int64]*ChatMsgRec guildMsgRec map[int64]*ChatMsgRec
@ -22,9 +21,8 @@ type ChatMgr struct {
//tmpMsgId uint64 //tmpMsgId uint64
} }
func NewChatMgr(gm *GuildMgr) *ChatMgr { func NewChatMgr() *ChatMgr {
cm := &ChatMgr{ cm := &ChatMgr{
gm: gm,
worldMsgRec: &ChatMsgRec{}, worldMsgRec: &ChatMsgRec{},
guildMsgRec: make(map[int64]*ChatMsgRec), guildMsgRec: make(map[int64]*ChatMsgRec),
privateChatUsers: make(map[string]*ChatUserRec), privateChatUsers: make(map[string]*ChatUserRec),
@ -57,7 +55,7 @@ func (cm *ChatMgr) FillSMUpdateChatRedPointNotify(p common.Player, msg *cs.SMUpd
if cm.worldMsgRec.CurrID > p.GetWorldChannelLastId() { if cm.worldMsgRec.CurrID > p.GetWorldChannelLastId() {
msg.HasUnreadMsgChannels = append(msg.HasUnreadMsgChannels, constant.CCWorld) msg.HasUnreadMsgChannels = append(msg.HasUnreadMsgChannels, constant.CCWorld)
} }
guildId := cm.gm.GetGuildIdByAccountId(p.GetAccountId()) guildId := GetGuildMgr().GetGuildIdByAccountId(p.GetAccountId())
if guildId > 0 { if guildId > 0 {
if msgRec, exists := cm.guildMsgRec[guildId]; exists { if msgRec, exists := cm.guildMsgRec[guildId]; exists {
if msgRec.CurrID > p.GetGuildChannelLastId() { if msgRec.CurrID > p.GetGuildChannelLastId() {
@ -105,7 +103,7 @@ func (cm *ChatMgr) ProcWorldChat(p common.Player, msg *cs.CMSendChatMsg) {
} }
func (cm *ChatMgr) ProcGuildChat(p common.Player, msg *cs.CMSendChatMsg) { func (cm *ChatMgr) ProcGuildChat(p common.Player, msg *cs.CMSendChatMsg) {
guild := cm.gm.GetGuildByAccountId(p.GetAccountId()) guild := GetGuildMgr().GetGuildByAccountId(p.GetAccountId())
if guild == nil { if guild == nil {
return return
} }
@ -125,7 +123,7 @@ func (cm *ChatMgr) ProcGuildChat(p common.Player, msg *cs.CMSendChatMsg) {
} }
// TraverseMember // TraverseMember
for _, member := range guild.Members { for _, member := range guild.GetMembers() {
guildMember := GetPlayerMgr().GetPlayerByAccountId(member.GetAccountId()) guildMember := GetPlayerMgr().GetPlayerByAccountId(member.GetAccountId())
if guildMember != nil { if guildMember != nil {
cm.SyncGuildChatMsg(guildMember) cm.SyncGuildChatMsg(guildMember)
@ -223,7 +221,7 @@ func (cm *ChatMgr) SyncPrivateChatMsg(p common.Player) {
} }
func (cm *ChatMgr) SyncGuildChatMsg(p common.Player) { func (cm *ChatMgr) SyncGuildChatMsg(p common.Player) {
guildId := cm.gm.GetGuildIdByAccountId(p.GetAccountId()) guildId := GetGuildMgr().GetGuildIdByAccountId(p.GetAccountId())
if guildId <= 0 { if guildId <= 0 {
return return
} }

View File

@ -54,5 +54,19 @@ type User interface {
} }
type FriendMgr interface { type FriendMgr interface {
GetFriendByAccountId(account1Id, account2Id string) *User GetFriendByAccountId(account1Id, account2Id string) User
}
type Guild interface {
GetGuildId() int64
GetMembers() map[string]GuildMember
}
type GuildMember interface {
GetAccountId() string
}
type GuildMgr interface {
GetGuildByAccountId(string) Guild
GetGuildIdByAccountId(string) int64
} }

View File

@ -3,6 +3,4 @@ package main
var handlerMgr = new(HandlerMgr) var handlerMgr = new(HandlerMgr)
var cacheMgr = new(CacheMgr) var cacheMgr = new(CacheMgr)
// var guildMgr = new(GuildMgr) var chatMgr = NewChatMgr()
var guildMgr = NewGuildMgr()
var chatMgr = NewChatMgr(guildMgr)

View File

@ -20,6 +20,7 @@ var app common.App
var playerMgr common.PlayerMgr var playerMgr common.PlayerMgr
var wspListener common.WspListener var wspListener common.WspListener
var friendMgr common.FriendMgr var friendMgr common.FriendMgr
var guildMgr common.GuildMgr
func GetPlayerMgr() common.PlayerMgr { func GetPlayerMgr() common.PlayerMgr {
return playerMgr return playerMgr
@ -29,6 +30,10 @@ func GetFriendMgr() common.FriendMgr {
return friendMgr return friendMgr
} }
func GetGuildMgr() common.GuildMgr {
return guildMgr
}
func GetWspListener() common.WspListener { func GetWspListener() common.WspListener {
return wspListener return wspListener
} }