This commit is contained in:
aozhiwei 2024-04-11 15:40:17 +08:00
parent 8eeeb199fc
commit 22aad31c74
2 changed files with 30 additions and 33 deletions

View File

@ -49,6 +49,17 @@ func (this *guild) loadFromDb(ds *f5.DataSet) {
this.modifyTime = q5.ToInt32(ds.GetByName("modifytime")) this.modifyTime = q5.ToInt32(ds.GetByName("modifytime"))
} }
func (this *guild) init(guildId string, guildName string, creatorId string, badge int32,
maxMemberNum int32, nowTime int32) {
this.guildId = guildId
this.guildName = guildName
this.creatorId = creatorId
this.badge = badge
this.maxMemberNum = maxMemberNum
this.createTime = nowTime
this.modifyTime = nowTime
}
func (this *guild) addMember(m *member) { func (this *guild) addMember(m *member) {
this.idHash[m.memberId] = m this.idHash[m.memberId] = m
} }

View File

@ -49,8 +49,7 @@ func (this *guildMgr) loadGuild() {
func (ds *f5.DataSet) { func (ds *f5.DataSet) {
p := newGuild() p := newGuild()
p.loadFromDb(ds) p.loadFromDb(ds)
this.idHash[p.guildId] = p this.addGuild(p)
this.nameHash[p.guildName] = p
}, },
func (err error) { func (err error) {
panic(fmt.Sprintf("loadGuild dberror:%s", err)) panic(fmt.Sprintf("loadGuild dberror:%s", err))
@ -180,56 +179,38 @@ func (this *guildMgr) isValidGuildJob(guildJob int32) bool {
} }
func (this *guildMgr) asyncCreateGuildTask(task *f5.LockAsyncTask, func (this *guildMgr) asyncCreateGuildTask(task *f5.LockAsyncTask,
guildId string, accountId string, avatar int32, name string, guildId string, creatorId string, badge int32, guildName string,
cb func(int32, string, string)) { cb func(int32, string, string)) {
this.addUsingName(name) this.addUsingName(guildName)
nowTime := f5.GetApp().GetNowSeconds() nowTime := f5.GetApp().GetNowSeconds()
model.Guild.New( model.Guild.New(guildId, guildName, creatorId, badge, nowTime,
guildId,
name,
accountId,
avatar,
nowTime,
func (err error, lastInsertId int64, rowsAffected int64) { func (err error, lastInsertId int64, rowsAffected int64) {
defer this.removeUsingName(name) defer this.removeUsingName(guildName)
if err != nil { if err != nil {
task.SetFail() task.SetFail()
cb(500, "server internal error", "") cb(500, "server internal error", "")
return return
} }
model.GuildMember.Force( model.GuildMember.Force(creatorId, guildId, constant.GuildMemberLevelLeader, nowTime,
accountId,
guildId,
constant.GuildMemberLevelLeader,
nowTime,
func (err error, lastInsertId int64, rowsAffected int64) { func (err error, lastInsertId int64, rowsAffected int64) {
if err != nil { if err != nil {
task.SetFail() task.SetFail()
cb(500, "server internal error", "") cb(500, "server internal error", "")
return return
} }
guild := newGuild() g := newGuild()
{ g.init(guildId, guildName, creatorId, badge, constant.GuildMaxMembers, int32(nowTime))
guild.guildId = guildId this.addGuild(g)
guild.guildName = name oldGuild := this.internalGetGuildByAccountId(creatorId)
guild.creatorId = accountId
guild.badge = avatar
guild.maxMemberNum = constant.GuildMaxMembers
guild.createTime = int32(nowTime)
guild.modifyTime = int32(nowTime)
}
this.idHash[guild.guildId] = guild
this.nameHash[guild.guildName] = guild
oldGuild := this.internalGetGuildByAccountId(accountId)
if oldGuild != nil { if oldGuild != nil {
task.SetFail() task.SetFail()
panic(fmt.Sprintf("asyncCreateGuildTask:%s", "")) panic(fmt.Sprintf("asyncCreateGuildTask:%s", ""))
} else { } else {
m := newMember() m := newMember()
m.init(guild, constant.GuildMemberLevelLeader, m.init(g, constant.GuildMemberLevelLeader,
accountId, q5.ToInt32(nowTime)) creatorId, q5.ToInt32(nowTime))
guild.addMember(m) g.addMember(m)
this.memberIdHash[accountId] = m this.memberIdHash[creatorId] = m
task.SetSucc() task.SetSucc()
cb(0, "", guildId) cb(0, "", guildId)
} }
@ -946,3 +927,8 @@ func (this* guildMgr) traverseGuild(cb func(*guild) bool) {
} }
} }
} }
func (this* guildMgr) addGuild(g *guild) {
this.idHash[g.guildId] = g
this.nameHash[g.guildName] = g
}