diff --git a/server/imserver_new/constant/constant.go b/server/imserver_new/constant/constant.go index 85b31615..9533a5ae 100644 --- a/server/imserver_new/constant/constant.go +++ b/server/imserver_new/constant/constant.go @@ -27,6 +27,7 @@ const ( const ( MAX_PACKET_LEN = 1024 * 64 + MAX_GUILD_TOP = 50 ) const ( diff --git a/server/imserver_new/guild/guild.go b/server/imserver_new/guild/guild.go index 20fe59f3..9bb8ccad 100644 --- a/server/imserver_new/guild/guild.go +++ b/server/imserver_new/guild/guild.go @@ -21,6 +21,7 @@ type guild struct { maxMemberNum int32 createTime int32 modifyTime int32 + totalStars int32 idHash map[string]*member } diff --git a/server/imserver_new/guild/guildmgr.go b/server/imserver_new/guild/guildmgr.go index 2b3a2b6d..f29715b0 100644 --- a/server/imserver_new/guild/guildmgr.go +++ b/server/imserver_new/guild/guildmgr.go @@ -9,16 +9,11 @@ import ( "mt" ) -const ( - LoadGuildFlag = iota - LoadGuildMemberFlag - LoadGuildReqFlag - LoadGuildLogFlag -) - type guildMgr struct { idHash map[string]*guild nameHash map[string]*guild + guildRankList []*guild + guildRankHash map[string]*guild memberIdHash map[string]*member usingNameHash map[string]int64 } @@ -26,6 +21,8 @@ type guildMgr struct { func (this *guildMgr) Init() { this.idHash = make(map[string]*guild) this.nameHash = make(map[string]*guild) + this.guildRankList = []*guild{} + this.guildRankHash = make(map[string]*guild) this.memberIdHash = make(map[string]*member) this.usingNameHash = make(map[string]int64) this.loadFromDB() @@ -834,10 +831,51 @@ func (this *guildMgr) asyncSetApplyStatus(accountId string, guildId string, stat cb) } -func (this *guildMgr) AsyncGetGuildRank(int32, func(int32, string, []string)) { - +func (this *guildMgr) AsyncGetGuildRank(num int32, cb func(int32, string, []string)) { + guildIds := []string{} + this.rearrangement() + cb(0, "", guildIds) } func (this *guildMgr) AsyncGetRecommendGuild(int32, func(int32, string, []string)) { } + +func (this *guildMgr) rearrangement() { + this.guildRankList = []*guild{} + this.guildRankHash = make(map[string]*guild) + this.traverseGuild( + func (g *guild) bool { + this.updateGuildRank(g) + return true + }) +} + +func (this* guildMgr) updateGuildRank(guild *guild) { + if _, ok := this.guildRankHash[guild.guildId]; ok { + this.rankSort() + return + } + if len(this.guildRankList) < constant.MAX_GUILD_TOP { + q5.AppendSlice(&this.guildRankList, guild) + this.guildRankHash[guild.guildId] = guild + this.rankSort() + } else if guild.totalStars > this.guildRankList[len(this.guildRankList) - 1].totalStars { + lastGuild := this.guildRankList[len(this.guildRankList) - 1] + delete(this.guildRankHash, lastGuild.guildId) + this.guildRankList[len(this.guildRankList) - 1] = guild + this.rankSort() + } +} + +func (this* guildMgr) rankSort() { + +} + +func (this* guildMgr) traverseGuild(cb func(*guild) bool) { + for _, g := range(this.idHash) { + if !cb(g) { + break + } + } +}