From 28337e69aebd2df5d882f726a79e4a1ddf04269c Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 4 Apr 2024 12:52:09 +0800 Subject: [PATCH] 1 --- server/imserver_new/guild/guildmgr.go | 36 ++++++++++++++++----------- server/imserver_new/guild/member.go | 15 ++++++++--- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/server/imserver_new/guild/guildmgr.go b/server/imserver_new/guild/guildmgr.go index 705f45b7..d714be0c 100644 --- a/server/imserver_new/guild/guildmgr.go +++ b/server/imserver_new/guild/guildmgr.go @@ -18,14 +18,14 @@ const ( type guildMgr struct { idHash map[string]*guild nameHash map[string]*guild - accountIdHash map[string]*guild + memberIdHash map[string]*member usingNameHash map[string]int64 } func (this *guildMgr) Init() { this.idHash = make(map[string]*guild) this.nameHash = make(map[string]*guild) - this.accountIdHash = make(map[string]*guild) + this.memberIdHash = make(map[string]*member) this.usingNameHash = make(map[string]int64) this.loadFromDB() } @@ -69,9 +69,9 @@ func (this *guildMgr) loadGuildMember() { g := this.internalGetGuildByGuildId(guildId) if g != nil { p := newMember() - p.init(g.guildId, memberId, joinTime) + p.init(g, memberId, joinTime) g.addMember(p) - this.accountIdHash[memberId] = g + this.memberIdHash[memberId] = p } }, func (err error) { @@ -79,28 +79,36 @@ func (this *guildMgr) loadGuildMember() { }) f5.GetSysLog().Info("loadGuildMember end memberNum:%d", lastIdx, - len(this.accountIdHash)) + len(this.memberIdHash)) } func (this *guildMgr) isNameTooLong(name string, maxNum int) bool { return len(name) > maxNum } -func (this *guildMgr) GetGuildByAccountId(accountId string) common.Guild { - return this.internalGetGuildByAccountId(accountId) -} - func (this *guildMgr) GetGuildByGuildId(guildId string) common.Guild { return this.internalGetGuildByGuildId(guildId) } +func (this *guildMgr) GetGuildByAccountId(accountId string) common.Guild { + return this.internalGetGuildByGuildId(accountId) +} + func (this *guildMgr) GetGuildByGuildName(guildName string) common.Guild { return this.internalGetGuildByGuildName(guildName) } func (this *guildMgr) internalGetGuildByAccountId(accountId string) *guild { - if guild, ok := this.accountIdHash[accountId]; ok { - return guild + m := this.internalGetMemberByAccountId(accountId) + if m != nil { + + } + return nil +} + +func (this *guildMgr) internalGetMemberByAccountId(accountId string) *member { + if m, ok := this.memberIdHash[accountId]; ok { + return m } return nil } @@ -206,15 +214,15 @@ func (this *guildMgr) AsyncCreateGuild(accountId string, avatar int32, name stri guild := newGuild() this.idHash[guild.guildId] = guild this.nameHash[guild.guildName] = guild - this.accountIdHash[accountId] = guild + //this.accountIdHash[accountId] = guild oldGuild := this.internalGetGuildByAccountId(accountId) if oldGuild != nil { } else { m := newMember() - m.init(guildId, accountId, q5.ToInt32(nowTime)) + m.init(guild, accountId, q5.ToInt32(nowTime)) guild.addMember(m) - this.accountIdHash[accountId] = guild + //this.accountIdHash[accountId] = guild } }) }) diff --git a/server/imserver_new/guild/member.go b/server/imserver_new/guild/member.go index 8c40c422..14cba0de 100644 --- a/server/imserver_new/guild/member.go +++ b/server/imserver_new/guild/member.go @@ -4,17 +4,26 @@ import ( ) type member struct { - guildId string + guild *guild memberId string joinTime int32 + wLock int32 } -func (this *member) init(guildId string, memberId string, joinTime int32) { - this.guildId = guildId +func (this *member) init(guild *guild, memberId string, joinTime int32) { + this.guild = guild this.memberId = memberId this.joinTime = joinTime } +func (this *member) lock() { + this.wLock++ +} + +func (this *member) unlock() { + this.wLock-- +} + func newMember() *member { p := new(member) return p