From cc7b58078df3a83f90deb9660bc50614e5d69cef Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 12 Apr 2024 13:08:28 +0800 Subject: [PATCH] 1 --- server/imserver_new/common/types.go | 4 +++- server/imserver_new/guild/guildmgr.go | 31 ++++++++++++++++++++------- server/imserver_new/player/player.go | 20 ++++++++++++++++- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/server/imserver_new/common/types.go b/server/imserver_new/common/types.go index 71c9ec31..7e5f0496 100644 --- a/server/imserver_new/common/types.go +++ b/server/imserver_new/common/types.go @@ -86,7 +86,7 @@ type GuildMgr interface { AsyncCreateGuild(string, string, int32, string, func(int32, string, string)) AsyncGetApplyList(int64, string, func(int32, string, int64, []string)) AsyncApplyJoin(string, string, func(int32, string)) - AsyncAcceptApply(string, string, func(int32, string)) + AsyncAcceptApply(string, string, func(int32, string, string, string)) AsyncRejectApply(string, string, func(int32, string)) AsyncGetGuildRank(int32, func(int32, string, []string)) AsyncGetRecommendGuild(int32, func(int32, string, []string)) @@ -98,6 +98,8 @@ type GuildMgr interface { AsyncSearch(int64, string, func(int32, string, int64, []string)) AsyncGetGuildLogs(string, string, func(int32, string)) AsyncUpdateGuild(string, map[int32]string, func(int32, string)) + + NotifyGuildMsg(string, proto.Message) } type CacheMgr interface { diff --git a/server/imserver_new/guild/guildmgr.go b/server/imserver_new/guild/guildmgr.go index 62d36e38..ec041660 100644 --- a/server/imserver_new/guild/guildmgr.go +++ b/server/imserver_new/guild/guildmgr.go @@ -10,6 +10,7 @@ import ( "mt" "strings" . "main/global" + "github.com/golang/protobuf/proto" ) type guildMgr struct { @@ -339,20 +340,21 @@ func (this *guildMgr) AsyncApplyJoin(accountId string, guildId string, cb func(i } func (this *guildMgr) asyncAcceptApplyTask(task *f5.LockAsyncTask, guild *guild, - accountId string, targetId string, cb func(int32, string)) { + accountId string, targetId string, + cb func(int32, string, string, string)) { if !guild.isOwner(accountId) { task.SetFail() - cb(1, "") + cb(1, "", "", "") return } if accountId == targetId { task.SetFail() - cb(1, "") + cb(1, "", "", "") return } if this.internalGetMemberByAccountId(targetId) != nil { task.SetFail() - cb(1, "") + cb(1, "", "", "") return } nowTime := f5.GetApp().GetNowSeconds() @@ -360,7 +362,7 @@ func (this *guildMgr) asyncAcceptApplyTask(task *f5.LockAsyncTask, guild *guild, func (err error, lastInsertId int64, rowsAffected int64) { if err != nil { task.SetFail() - cb(500, "server internal error") + cb(500, "server internal error", "", "") return } m := newMember() @@ -370,16 +372,17 @@ func (this *guildMgr) asyncAcceptApplyTask(task *f5.LockAsyncTask, guild *guild, model.GuildApply.SetStatus(guild.guildId, targetId, constant.GUILD_APPLY_STATUS_ACCEPT, func (err error, lastInsertId int64, rowsAffected int64) { task.SetSucc() - cb(0, "") + cb(0, "", guild.guildId, guild.guildName) return }) }) } -func (this *guildMgr) AsyncAcceptApply(accountId string, targetId string, cb func(int32, string)) { +func (this *guildMgr) AsyncAcceptApply(accountId string, targetId string, + cb func(int32, string, string, string)) { guild := this.internalGetGuildByAccountId(accountId) if guild == nil { - cb(0, "") + cb(0, "", guild.guildId, guild.guildName) return; } f5.NewLockAsyncTask([][]string{ @@ -711,6 +714,18 @@ func (this *guildMgr) AsyncUpdateGuild(accountId string, kv map[int32]string, cb }) } +func (this *guildMgr) NotifyGuildMsg(guildId string, msg proto.Message) { + g := this.internalGetGuildByGuildId(guildId) + g.traverseMembers( + func (m *member) bool { + hum := GetPlayerMgr().GetPlayerByAccountId(m.memberId) + if hum != nil { + hum.SendMsg(msg) + } + return true + }) +} + func (this *guildMgr) AsyncGetGuildRank(num int32, cb func(int32, string, []string)) { guildIds := []string{} for _, m := range(this.guildRankList) { diff --git a/server/imserver_new/player/player.go b/server/imserver_new/player/player.go index a159c44f..aadb96a9 100644 --- a/server/imserver_new/player/player.go +++ b/server/imserver_new/player/player.go @@ -515,12 +515,30 @@ func (this *player) CMApprove(hdr *f5.MsgHdr, msg *cs.CMApprove) { GetGuildMgr().AsyncAcceptApply( this.GetAccountId(), msg.GetApplicantAccountId(), - func (errCode int32, errMsg string) { + func (errCode int32, errMsg string, guildId string, guildName string) { if errCode != 0 { this.SendMsg(rspMsg.Err(errCode, errMsg)) return } this.SendMsg(rspMsg) + { + pbGuilds := []*cs.MFGuildMember{} + GetCacheMgr().AsyncGetUsersAndFillMFGuildMember( + []string{ + msg.GetApplicantAccountId(), + }, + &pbGuilds, + func (errCode int32, errMsg string) { + if errCode == 0 && len(pbGuilds) > 0 { + notifyMsg := new(cs.SMApproveJoinGuildNotify) + notifyMsg.GuildId = proto.Int64(q5.ToInt64(guildId)) + notifyMsg.Name = proto.String(guildName) + notifyMsg.AccountId = proto.String(pbGuilds[0].GetAccountId()) + notifyMsg.Username = proto.String(pbGuilds[0].GetUsername()) + GetGuildMgr().NotifyGuildMsg(guildId, notifyMsg) + } + }) + } }) }