save
This commit is contained in:
parent
bbd2662f7b
commit
f279de7ba3
@ -33,6 +33,11 @@ type GuildLog struct {
|
|||||||
Content string
|
Content string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PendingReq 待审核请求
|
||||||
|
type PendingReq struct {
|
||||||
|
Users map[string]bool
|
||||||
|
}
|
||||||
|
|
||||||
func (g *Guild) GetGuildId() int64 {
|
func (g *Guild) GetGuildId() int64 {
|
||||||
return g.GuildId
|
return g.GuildId
|
||||||
}
|
}
|
||||||
@ -104,3 +109,27 @@ func (g *Guild) SetNotice(notice *string) {
|
|||||||
func (g *Guild) GetNotice() string {
|
func (g *Guild) GetNotice() string {
|
||||||
return g.Notice
|
return g.Notice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PendingReq) GetUsers() map[string]bool {
|
||||||
|
return p.Users
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PendingReq) AddUser(accountId string) {
|
||||||
|
if _, exists := p.Users[accountId]; !exists {
|
||||||
|
p.Users[accountId] = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p.Users[accountId] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PendingReq) RemoveUser(accountId string) {
|
||||||
|
delete(p.Users, accountId)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PendingReq) IsInReq(accountId string) bool {
|
||||||
|
user, exists := p.Users[accountId]
|
||||||
|
if exists {
|
||||||
|
return user == true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
@ -56,7 +56,7 @@ func (gm *GuildMgr) loadGuildFromDBResult(err error, rows *f5.DataSet) {
|
|||||||
MaxMembers: q5.ToInt32(*rows.GetByIndex(11)),
|
MaxMembers: q5.ToInt32(*rows.GetByIndex(11)),
|
||||||
}
|
}
|
||||||
// init pendingReqs
|
// init pendingReqs
|
||||||
gm.pendingReqs[guildId] = make(map[string]bool)
|
gm.pendingReqs[guildId] = &PendingReq{}
|
||||||
}
|
}
|
||||||
q5.UnSetBitFlag(&gm.loadedFlags, LoadGuildFlag)
|
q5.UnSetBitFlag(&gm.loadedFlags, LoadGuildFlag)
|
||||||
}
|
}
|
||||||
@ -95,10 +95,7 @@ func (gm *GuildMgr) loadGuildMemberFromDBResult(err error, rows *f5.DataSet) {
|
|||||||
Level: level,
|
Level: level,
|
||||||
}
|
}
|
||||||
if guild, ok := gm.guilds[guildId]; ok {
|
if guild, ok := gm.guilds[guildId]; ok {
|
||||||
err := guild.AddMember(guildMember)
|
guild.AddMember(guildMember)
|
||||||
if err != nil {
|
|
||||||
f5.GetSysLog().Info("Guild:%d member is full\n", guildId)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
q5.UnSetBitFlag(&gm.loadedFlags, LoadGuildMemberFlag)
|
q5.UnSetBitFlag(&gm.loadedFlags, LoadGuildMemberFlag)
|
||||||
@ -130,7 +127,11 @@ func (gm *GuildMgr) loadPendingReqsFromDBResult(err error, rows *f5.DataSet) {
|
|||||||
)
|
)
|
||||||
guildId = q5.ToInt64(*rows.GetByIndex(0))
|
guildId = q5.ToInt64(*rows.GetByIndex(0))
|
||||||
accountId = q5.ToString(*rows.GetByIndex(1))
|
accountId = q5.ToString(*rows.GetByIndex(1))
|
||||||
gm.pendingReqs[guildId][accountId] = true
|
|
||||||
|
pendingReq := &PendingReq{}
|
||||||
|
pendingReq.Users = make(map[string]bool)
|
||||||
|
pendingReq.AddUser(accountId)
|
||||||
|
gm.pendingReqs[guildId] = pendingReq
|
||||||
}
|
}
|
||||||
q5.UnSetBitFlag(&gm.loadedFlags, LoadGuildReqFlag)
|
q5.UnSetBitFlag(&gm.loadedFlags, LoadGuildReqFlag)
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,9 @@ const (
|
|||||||
|
|
||||||
type GuildMgr struct {
|
type GuildMgr struct {
|
||||||
cs.MsgHandlerImpl
|
cs.MsgHandlerImpl
|
||||||
guilds map[int64]*Guild // 公会ID -> 公会列表
|
guilds map[int64]*Guild // 公会ID -> 公会列表
|
||||||
pendingReqs map[int64]map[string]bool // 公会ID -> 申请者账户ID -> bool
|
pendingReqs map[int64]*PendingReq // 公会ID -> PendingReq
|
||||||
guildLogs map[int64][]*GuildLog // 公会ID -> 公会日志
|
guildLogs map[int64][]*GuildLog // 公会ID -> 公会日志
|
||||||
loadedFlags int64
|
loadedFlags int64
|
||||||
guildIds []int64 // 公会ids
|
guildIds []int64 // 公会ids
|
||||||
}
|
}
|
||||||
@ -27,7 +27,7 @@ type GuildMgr struct {
|
|||||||
func NewGuildMgr() *GuildMgr {
|
func NewGuildMgr() *GuildMgr {
|
||||||
return &GuildMgr{
|
return &GuildMgr{
|
||||||
guilds: make(map[int64]*Guild),
|
guilds: make(map[int64]*Guild),
|
||||||
pendingReqs: make(map[int64]map[string]bool),
|
pendingReqs: make(map[int64]*PendingReq),
|
||||||
guildLogs: make(map[int64][]*GuildLog),
|
guildLogs: make(map[int64][]*GuildLog),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,18 +112,19 @@ func (gm *GuildMgr) ApplyToGuild(guildId int64, applicantAccountId string) error
|
|||||||
|
|
||||||
if guild.JoinCond == JoinCondStar {
|
if guild.JoinCond == JoinCondStar {
|
||||||
var userStar int32 = 200
|
var userStar int32 = 200
|
||||||
if userStar < guild.JoinCondValue {
|
if userStar >= guild.JoinCondValue {
|
||||||
return fmt.Errorf("joincond error")
|
gm.JoinGuild(guild, applicantAccountId)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IF exists, then replace it fields `isJoinGuild` is 0
|
// IF exists, then replace it fields `isJoinGuild` is 0
|
||||||
gm.upsertPendingReqs(guildId, applicantAccountId, PendingReqIsJoinGuildStatusDefault)
|
gm.upsertPendingReqs(guildId, applicantAccountId, PendingReqIsJoinGuildStatusDefault)
|
||||||
pendReq, exists := gm.pendingReqs[guildId]
|
pendReq, err := gm.GetPendingReq(guildId)
|
||||||
if !exists {
|
if err != nil {
|
||||||
pendReq = make(map[string]bool)
|
pendReq = &PendingReq{}
|
||||||
}
|
}
|
||||||
pendReq[applicantAccountId] = true
|
pendReq.AddUser(applicantAccountId)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -135,6 +136,11 @@ func (gm *GuildMgr) Approve(guildId int64, operatorAccountId, accountId string)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 通常默认为审核加入
|
||||||
|
if guild.JoinCond != JoinCondDefault {
|
||||||
|
return fmt.Errorf("join cond error")
|
||||||
|
}
|
||||||
|
|
||||||
operatorMember, err := guild.GetMember(operatorAccountId)
|
operatorMember, err := guild.GetMember(operatorAccountId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -158,8 +164,13 @@ func (gm *GuildMgr) Approve(guildId int64, operatorAccountId, accountId string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 是否在申请队列中
|
// 是否在申请队列中
|
||||||
_, exists := gm.pendingReqs[guildId][accountId]
|
pendingReq, err := gm.GetPendingReq(guildId)
|
||||||
if !exists {
|
if err == nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
inReq := pendingReq.IsInReq(accountId)
|
||||||
|
if !inReq {
|
||||||
return fmt.Errorf("no pending applications for this guild")
|
return fmt.Errorf("no pending applications for this guild")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,20 +182,20 @@ func (gm *GuildMgr) Approve(guildId int64, operatorAccountId, accountId string)
|
|||||||
|
|
||||||
logContent := fmt.Sprintf("Approve[operator:%s]", operatorAccountId)
|
logContent := fmt.Sprintf("Approve[operator:%s]", operatorAccountId)
|
||||||
gm.WriteLog(guildId, accountId, LogTypeApprove, logContent)
|
gm.WriteLog(guildId, accountId, LogTypeApprove, logContent)
|
||||||
delete(gm.pendingReqs[guildId], accountId)
|
pendingReq.RemoveUser(accountId)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reject 拒绝申请者加入公会
|
// Reject 拒绝申请者加入公会
|
||||||
func (gm *GuildMgr) Reject(guildId int64, applicantAccountId string) error {
|
func (gm *GuildMgr) Reject(guildId int64, accountId string) error {
|
||||||
_, exists := gm.pendingReqs[guildId]
|
pendingReq, err := gm.GetPendingReq(guildId)
|
||||||
if !exists {
|
if err == nil {
|
||||||
return fmt.Errorf("no pending applications for this guild")
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gm.updatePendingReqs(guildId, applicantAccountId, PendingReqIsJoinGuildStatusReject)
|
gm.updatePendingReqs(guildId, accountId, PendingReqIsJoinGuildStatusReject)
|
||||||
delete(gm.pendingReqs[guildId], applicantAccountId)
|
pendingReq.RemoveUser(accountId)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -404,7 +415,7 @@ func (gm *GuildMgr) SetNotice(guildId int64, accountId string, notice *string) e
|
|||||||
|
|
||||||
// 仅会长可操作
|
// 仅会长可操作
|
||||||
if accountId != guild.LeaderId {
|
if accountId != guild.LeaderId {
|
||||||
return fmt.Errorf("cannot disband guild")
|
return fmt.Errorf("cannot set guild notices, only leader")
|
||||||
}
|
}
|
||||||
guild.SetNotice(notice)
|
guild.SetNotice(notice)
|
||||||
|
|
||||||
@ -489,6 +500,13 @@ func (gm *GuildMgr) GetGuild(guildId int64) (*Guild, error) {
|
|||||||
return nil, fmt.Errorf("guild not found")
|
return nil, fmt.Errorf("guild not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gm *GuildMgr) GetPendingReq(guildId int64) (*PendingReq, error) {
|
||||||
|
if pendingReq, exists := gm.pendingReqs[guildId]; exists {
|
||||||
|
return pendingReq, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("pendingReq not found, guildId:%d", guildId)
|
||||||
|
}
|
||||||
|
|
||||||
// GetGuildByAccountId 查询我的工会
|
// GetGuildByAccountId 查询我的工会
|
||||||
func (gm *GuildMgr) GetGuildByAccountId(accountId string) *Guild {
|
func (gm *GuildMgr) GetGuildByAccountId(accountId string) *Guild {
|
||||||
for _, guild := range gm.guilds {
|
for _, guild := range gm.guilds {
|
||||||
@ -508,7 +526,12 @@ func (gm *GuildMgr) Info(accountId string) (*Guild, map[string]bool, []*GuildLog
|
|||||||
guildLogs := make([]*GuildLog, DefaultLogs)
|
guildLogs := make([]*GuildLog, DefaultLogs)
|
||||||
if guild != nil {
|
if guild != nil {
|
||||||
guildId := guild.GuildId
|
guildId := guild.GuildId
|
||||||
pendingReqs = gm.pendingReqs[guildId]
|
if p, exists := gm.pendingReqs[guildId]; exists {
|
||||||
|
pendingReqs = p.GetUsers()
|
||||||
|
} else {
|
||||||
|
pendingReqs = nil
|
||||||
|
}
|
||||||
|
|
||||||
guildLogs = gm.guildLogs[guildId]
|
guildLogs = gm.guildLogs[guildId]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,7 +586,7 @@ func (gm *GuildMgr) RemoveGuildsId(guildId int64) {
|
|||||||
|
|
||||||
func (gm *GuildMgr) GetAllPendingReqs(guildId int64) map[string]bool {
|
func (gm *GuildMgr) GetAllPendingReqs(guildId int64) map[string]bool {
|
||||||
if pendingReq, exists := gm.pendingReqs[guildId]; exists {
|
if pendingReq, exists := gm.pendingReqs[guildId]; exists {
|
||||||
return pendingReq
|
return pendingReq.GetUsers()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user