This commit is contained in:
殷勇 2023-09-05 17:20:32 +08:00
parent ae1b96faf5
commit 8b94922a4b
2 changed files with 31 additions and 32 deletions

View File

@ -94,6 +94,7 @@ func (gm *GuildMgr) loadGuildMemberFromDBResult(err error, rows *f5.DataSet) {
}
if guild, ok := gm.guilds[guildId]; ok {
guild.AddMember(guildMember)
gm.userGuilds[accountId] = guildId
}
}
q5.UnSetBitFlag(&gm.loadedFlags, LoadGuildMemberFlag)

View File

@ -17,16 +17,18 @@ const (
type GuildMgr struct {
cs.MsgHandlerImpl
guilds map[int64]*Guild // 公会ID -> 公会列表
guildIds []int64 // 公会列表 guild ids
guilds map[int64]*Guild // 公会ID -> 公会
guildLogs map[int64][]*GuildLog // 公会ID -> []公会日志列表
userGuilds map[string]int64 // accountId -> 公会ID
loadedFlags int64
guildIds []int64 // 公会ids
}
func NewGuildMgr() *GuildMgr {
return &GuildMgr{
guilds: make(map[int64]*Guild),
guildLogs: make(map[int64][]*GuildLog),
guilds: make(map[int64]*Guild),
guildLogs: make(map[int64][]*GuildLog),
userGuilds: make(map[string]int64),
}
}
@ -58,13 +60,13 @@ func (gm *GuildMgr) loadFromDB() {
// CreateGuild 创建公会
func (gm *GuildMgr) CreateGuild(name string, leaderId string,
cb func(errCode int32, errMsg string, guildId int64)) {
if !gm.checkJoinGuild(leaderId) {
if !gm.CheckJoinGuild(leaderId) {
cb(1, "xxx", 0)
return
}
guildId := f5.GetApp().NewUuid()
if gm.existsGuild(guildId) {
if gm.ExistsGuild(guildId) {
cb(1, "xxx", 0)
return
}
@ -112,7 +114,7 @@ func (gm *GuildMgr) ApplyToGuild(guildId int64, applicantAccountId string, cb fu
}
// 是否加入其他公会
if !gm.checkJoinGuild(applicantAccountId) {
if !gm.CheckJoinGuild(applicantAccountId) {
cb(1, "xxx")
}
@ -195,7 +197,7 @@ func (gm *GuildMgr) Approve(operatorAccountId, accountId string, cb func(errCode
}
// 是否加入其他公会
if !gm.checkJoinGuild(accountId) {
if !gm.CheckJoinGuild(accountId) {
cb(1, "XXX")
}
@ -247,7 +249,7 @@ func (gm *GuildMgr) Reject(operatorAccountId, accountId string, cb func(errCode
cb(1, "XXX")
}
// 是否加入其他公会
if !gm.checkJoinGuild(accountId) {
if !gm.CheckJoinGuild(accountId) {
cb(1, "XXX")
}
// 是否在申请队列中
@ -446,7 +448,6 @@ func (gm *GuildMgr) Disband(operatorAccountId string, cb func(errCode int32, err
})
})
})
}
// SetNotice 设置公告
@ -532,7 +533,14 @@ func (gm *GuildMgr) RandomGuilds() []*Guild {
return results
}
func (gm *GuildMgr) existsGuild(guildId int64) bool {
func (gm *GuildMgr) checkOperatorPerm(operatorMember *GuildMember, level int) error {
if operatorMember.level > level {
return fmt.Errorf("checkOperatorPerm: no permission[%s-%d]", operatorMember.accountId, operatorMember.level)
}
return nil
}
func (gm *GuildMgr) ExistsGuild(guildId int64) bool {
_, ok := gm.guilds[guildId]
return ok
}
@ -551,35 +559,25 @@ func (gm *GuildMgr) GetGuild(guildId int64) (*Guild, error) {
return nil, fmt.Errorf("guild not found")
}
// GetGuildByAccountId 查询我的工会
func (gm *GuildMgr) GetGuildByAccountId(accountId string) *Guild {
for _, guild := range gm.guilds {
for _, member := range guild.members {
if accountId == member.accountId {
return guild
}
if guildId, exists := gm.userGuilds[accountId]; exists {
if guild, exists2 := gm.guilds[guildId]; exists2 {
return guild
}
}
return nil
}
func (gm *GuildMgr) checkOperatorPerm(operatorMember *GuildMember, level int) error {
if operatorMember.level > level {
return fmt.Errorf("checkOperatorPerm: no permission[%s-%d]", operatorMember.accountId, operatorMember.level)
}
return nil
}
func (gm *GuildMgr) checkJoinGuild(accountId string) bool {
return gm.GetGuildByAccountId(accountId) == nil
}
func (gm *GuildMgr) GetGuildIdByAccountId(accountId string) int64 {
guild := gm.GetGuildByAccountId(accountId)
if guild != nil {
return guild.guildId
if guildId, exists := gm.userGuilds[accountId]; exists {
return guildId
}
return 0
return -1
}
func (gm *GuildMgr) CheckJoinGuild(accountId string) bool {
_, exists := gm.userGuilds[accountId]
return exists
}
func (gm *GuildMgr) loadGuildIds() {