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"))
}
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) {
this.idHash[m.memberId] = m
}

View File

@ -49,8 +49,7 @@ func (this *guildMgr) loadGuild() {
func (ds *f5.DataSet) {
p := newGuild()
p.loadFromDb(ds)
this.idHash[p.guildId] = p
this.nameHash[p.guildName] = p
this.addGuild(p)
},
func (err error) {
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,
guildId string, accountId string, avatar int32, name string,
guildId string, creatorId string, badge int32, guildName string,
cb func(int32, string, string)) {
this.addUsingName(name)
this.addUsingName(guildName)
nowTime := f5.GetApp().GetNowSeconds()
model.Guild.New(
guildId,
name,
accountId,
avatar,
nowTime,
model.Guild.New(guildId, guildName, creatorId, badge, nowTime,
func (err error, lastInsertId int64, rowsAffected int64) {
defer this.removeUsingName(name)
defer this.removeUsingName(guildName)
if err != nil {
task.SetFail()
cb(500, "server internal error", "")
return
}
model.GuildMember.Force(
accountId,
guildId,
constant.GuildMemberLevelLeader,
nowTime,
model.GuildMember.Force(creatorId, guildId, constant.GuildMemberLevelLeader, nowTime,
func (err error, lastInsertId int64, rowsAffected int64) {
if err != nil {
task.SetFail()
cb(500, "server internal error", "")
return
}
guild := newGuild()
{
guild.guildId = guildId
guild.guildName = name
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)
g := newGuild()
g.init(guildId, guildName, creatorId, badge, constant.GuildMaxMembers, int32(nowTime))
this.addGuild(g)
oldGuild := this.internalGetGuildByAccountId(creatorId)
if oldGuild != nil {
task.SetFail()
panic(fmt.Sprintf("asyncCreateGuildTask:%s", ""))
} else {
m := newMember()
m.init(guild, constant.GuildMemberLevelLeader,
accountId, q5.ToInt32(nowTime))
guild.addMember(m)
this.memberIdHash[accountId] = m
m.init(g, constant.GuildMemberLevelLeader,
creatorId, q5.ToInt32(nowTime))
g.addMember(m)
this.memberIdHash[creatorId] = m
task.SetSucc()
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
}