This commit is contained in:
aozhiwei 2024-04-08 16:03:53 +08:00
parent 479f77fef9
commit 5c368b75e6
4 changed files with 75 additions and 6 deletions

View File

@ -94,7 +94,7 @@ type GuildMgr interface {
AsyncAcceptApply(string, string, func(int32, string)) AsyncAcceptApply(string, string, func(int32, string))
AsyncRejectApply(string, string, func(int32, string)) AsyncRejectApply(string, string, func(int32, string))
AsyncLeave(string, func(int32, string)) AsyncLeave(string, func(int32, string, []string))
AsyncKickout(string, string, func(int32, string)) AsyncKickout(string, string, func(int32, string))
AsyncDisband(string, func(int32, string, []string)) AsyncDisband(string, func(int32, string, []string))
AsyncSetNotice(string, string, func(int32, string)) AsyncSetNotice(string, string, func(int32, string))

View File

@ -32,6 +32,10 @@ func (this *guild) GetGuildName() string {
return this.guildName return this.guildName
} }
func (this *guild) GetMemberNum() int32 {
return int32(len(this.idHash))
}
func (this *guild) loadFromDb(ds *f5.DataSet) { func (this *guild) loadFromDb(ds *f5.DataSet) {
this.guildId = ds.GetByName("guild_id") this.guildId = ds.GetByName("guild_id")
this.guildName = ds.GetByName("guild_name") this.guildName = ds.GetByName("guild_name")

View File

@ -460,12 +460,67 @@ func (this *guildMgr) AsyncRejectApply(accountId string, targetId string,
}) })
} }
func (this *guildMgr) AsyncLeave(accountId string, cb func(int32, string)) { func (this *guildMgr) AsyncLeave(accountId string, cb func(int32, string, []string)) {
guild := this.internalGetGuildByAccountId(accountId) members := []string{}
if guild == nil { keys := [][]string{}
cb(0, "") {
return; guild := this.internalGetGuildByAccountId(accountId)
if guild == nil {
cb(0, "", members)
return
}
keys = [][]string{
{constant.GUILD_ID_LOCK_KEY, guild.guildId},
{constant.GUILD_NAME_LOCK_KEY, guild.guildName},
};
guild.traverseMembers(
func (m *member) bool {
q5.AppendSlice(&keys, []string{constant.GUILD_MEMBER_LOCK_KEY, m.memberId})
q5.AppendSlice(&members, m.memberId)
return true
})
} }
f5.NewLockAsyncTask(
keys,
func (task *f5.LockAsyncTask) {
guild := this.internalGetGuildByAccountId(accountId)
members := []string{}
if guild == nil {
task.SetSucc()
cb(0, "", members)
return
}
if guild.isOwner(accountId) {
} else {
}
if guild.GetMemberNum() <= 0 {
f5.GetJsStyleDb().Update(
constant.FRIEND_DB,
"t_guild",
[][]string{
{"deleted", "1"},
},
[][]string{
{"guild_id", guild.guildId},
},
func (err error, lastInsertId int64, rowsAffected int64) {
if err != nil {
task.SetFail()
cb(500, "server internal error", members)
return
}
task.SetSucc()
guild.disband()
cb(0, "", members)
return
})
} else {
task.SetSucc()
cb(0, "", members)
return
}
})
} }
func (this *guildMgr) AsyncKickout(accountId string, targetId string, cb func(int32, string)) { func (this *guildMgr) AsyncKickout(accountId string, targetId string, cb func(int32, string)) {

View File

@ -424,6 +424,16 @@ func (this *player) CMReject(hdr *f5.MsgHdr, msg *cs.CMReject) {
} }
func (this *player) CMLeaveGuild(hdr *f5.MsgHdr, msg *cs.CMLeaveGuild) { func (this *player) CMLeaveGuild(hdr *f5.MsgHdr, msg *cs.CMLeaveGuild) {
rspMsg := new(cs.SMLeaveGuild)
GetGuildMgr().AsyncLeave(
this.GetAccountId(),
func (errCode int32, errMsg string, members []string) {
if errCode != 0 {
this.SendMsg(rspMsg.Err(errCode, errMsg))
return
}
this.SendMsg(rspMsg)
})
} }
func (this *player) CMDismissMember(hdr *f5.MsgHdr, msg *cs.CMDismissMember) { func (this *player) CMDismissMember(hdr *f5.MsgHdr, msg *cs.CMDismissMember) {