diff --git a/server/imserver/player/playermgr.go b/server/imserver/player/playermgr.go index 57fc63ce..483852c1 100644 --- a/server/imserver/player/playermgr.go +++ b/server/imserver/player/playermgr.go @@ -367,17 +367,29 @@ func (this *playerMgr) GetRecommendPlayers(excludeHums map[string]int32, outHums this.recommendHumans = []*player{} this.traverseHumans( func (hum *player) bool { - if _, ok := excludeHums[hum.GetAccountId()]; !ok { - q5.AppendSlice(&this.recommendHumans, hum) - } + q5.AppendSlice(&this.recommendHumans, hum) return true }) + rand.Shuffle(len(this.recommendHumans), func (i int, j int) { + this.recommendHumans[i], this.recommendHumans[j] = this.recommendHumans[j], this.recommendHumans[i] + }) } - randLen := 10 - if randLen > len(this.recommendHumans) { - randLen = len(this.recommendHumans) + if len(this.recommendHumans) > 0 { + rnd := rand.Int() % len(this.recommendHumans) + for i := rnd; i < len(this.recommendHumans); i++ { + if _, ok := excludeHums[this.recommendHumans[i].accountId]; !ok{ + outHums[this.recommendHumans[i].accountId] = 1 + } + } + for i := 0; i < len(this.recommendHumans); i++ { + if _, ok := excludeHums[this.recommendHumans[i].accountId]; !ok{ + if len(outHums) > 5 { + break + } + if _, ok2 := outHums[this.recommendHumans[i].accountId]; !ok2 { + outHums[this.recommendHumans[i].accountId] = 1 + } + } + } } - rand.Shuffle(randLen, func (i int, j int) { - this.recommendHumans[i], this.recommendHumans[j] = this.recommendHumans[j], this.recommendHumans[i] - }) }