save
This commit is contained in:
parent
ae1b96faf5
commit
8b94922a4b
@ -94,6 +94,7 @@ func (gm *GuildMgr) loadGuildMemberFromDBResult(err error, rows *f5.DataSet) {
|
|||||||
}
|
}
|
||||||
if guild, ok := gm.guilds[guildId]; ok {
|
if guild, ok := gm.guilds[guildId]; ok {
|
||||||
guild.AddMember(guildMember)
|
guild.AddMember(guildMember)
|
||||||
|
gm.userGuilds[accountId] = guildId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
q5.UnSetBitFlag(&gm.loadedFlags, LoadGuildMemberFlag)
|
q5.UnSetBitFlag(&gm.loadedFlags, LoadGuildMemberFlag)
|
||||||
|
@ -17,16 +17,18 @@ const (
|
|||||||
|
|
||||||
type GuildMgr struct {
|
type GuildMgr struct {
|
||||||
cs.MsgHandlerImpl
|
cs.MsgHandlerImpl
|
||||||
guilds map[int64]*Guild // 公会ID -> 公会列表
|
guildIds []int64 // 公会列表 guild ids
|
||||||
|
guilds map[int64]*Guild // 公会ID -> 公会
|
||||||
guildLogs map[int64][]*GuildLog // 公会ID -> []公会日志列表
|
guildLogs map[int64][]*GuildLog // 公会ID -> []公会日志列表
|
||||||
|
userGuilds map[string]int64 // accountId -> 公会ID
|
||||||
loadedFlags int64
|
loadedFlags int64
|
||||||
guildIds []int64 // 公会ids
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGuildMgr() *GuildMgr {
|
func NewGuildMgr() *GuildMgr {
|
||||||
return &GuildMgr{
|
return &GuildMgr{
|
||||||
guilds: make(map[int64]*Guild),
|
guilds: make(map[int64]*Guild),
|
||||||
guildLogs: make(map[int64][]*GuildLog),
|
guildLogs: make(map[int64][]*GuildLog),
|
||||||
|
userGuilds: make(map[string]int64),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,13 +60,13 @@ func (gm *GuildMgr) loadFromDB() {
|
|||||||
// CreateGuild 创建公会
|
// CreateGuild 创建公会
|
||||||
func (gm *GuildMgr) CreateGuild(name string, leaderId string,
|
func (gm *GuildMgr) CreateGuild(name string, leaderId string,
|
||||||
cb func(errCode int32, errMsg string, guildId int64)) {
|
cb func(errCode int32, errMsg string, guildId int64)) {
|
||||||
if !gm.checkJoinGuild(leaderId) {
|
if !gm.CheckJoinGuild(leaderId) {
|
||||||
cb(1, "xxx", 0)
|
cb(1, "xxx", 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
guildId := f5.GetApp().NewUuid()
|
guildId := f5.GetApp().NewUuid()
|
||||||
if gm.existsGuild(guildId) {
|
if gm.ExistsGuild(guildId) {
|
||||||
cb(1, "xxx", 0)
|
cb(1, "xxx", 0)
|
||||||
return
|
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")
|
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")
|
cb(1, "XXX")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,7 +249,7 @@ func (gm *GuildMgr) Reject(operatorAccountId, accountId string, cb func(errCode
|
|||||||
cb(1, "XXX")
|
cb(1, "XXX")
|
||||||
}
|
}
|
||||||
// 是否加入其他公会
|
// 是否加入其他公会
|
||||||
if !gm.checkJoinGuild(accountId) {
|
if !gm.CheckJoinGuild(accountId) {
|
||||||
cb(1, "XXX")
|
cb(1, "XXX")
|
||||||
}
|
}
|
||||||
// 是否在申请队列中
|
// 是否在申请队列中
|
||||||
@ -446,7 +448,6 @@ func (gm *GuildMgr) Disband(operatorAccountId string, cb func(errCode int32, err
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetNotice 设置公告
|
// SetNotice 设置公告
|
||||||
@ -532,7 +533,14 @@ func (gm *GuildMgr) RandomGuilds() []*Guild {
|
|||||||
return results
|
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]
|
_, ok := gm.guilds[guildId]
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
@ -551,35 +559,25 @@ func (gm *GuildMgr) GetGuild(guildId int64) (*Guild, error) {
|
|||||||
return nil, fmt.Errorf("guild not found")
|
return nil, fmt.Errorf("guild not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetGuildByAccountId 查询我的工会
|
|
||||||
func (gm *GuildMgr) GetGuildByAccountId(accountId string) *Guild {
|
func (gm *GuildMgr) GetGuildByAccountId(accountId string) *Guild {
|
||||||
for _, guild := range gm.guilds {
|
if guildId, exists := gm.userGuilds[accountId]; exists {
|
||||||
for _, member := range guild.members {
|
if guild, exists2 := gm.guilds[guildId]; exists2 {
|
||||||
if accountId == member.accountId {
|
return guild
|
||||||
return guild
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
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 {
|
func (gm *GuildMgr) GetGuildIdByAccountId(accountId string) int64 {
|
||||||
guild := gm.GetGuildByAccountId(accountId)
|
if guildId, exists := gm.userGuilds[accountId]; exists {
|
||||||
if guild != nil {
|
return guildId
|
||||||
return guild.guildId
|
|
||||||
}
|
}
|
||||||
return 0
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gm *GuildMgr) CheckJoinGuild(accountId string) bool {
|
||||||
|
_, exists := gm.userGuilds[accountId]
|
||||||
|
return exists
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gm *GuildMgr) loadGuildIds() {
|
func (gm *GuildMgr) loadGuildIds() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user