Fix the server candidate picker to actually work
Tests do wonders.
This commit is contained in:
parent
43980addd0
commit
52094964a0
1 changed files with 6 additions and 3 deletions
|
@ -102,12 +102,15 @@ export function pickServerCandidates(roomId) {
|
|||
const candidates = [];
|
||||
if (highestPlUser.powerLevel >= 50) candidates.push(highestPlUser.serverName);
|
||||
|
||||
const beforePopulation = candidates.length;
|
||||
const maxCandidates = 3;
|
||||
const serversByPopulation = Object.keys(populationMap)
|
||||
.sort((a, b) => populationMap[a] - populationMap[b])
|
||||
.sort((a, b) => populationMap[b] - populationMap[a])
|
||||
.filter(a => !candidates.includes(a));
|
||||
while(candidates.length < maxCandidates && candidates.length <= serversByPopulation.length) {
|
||||
candidates.push(serversByPopulation[Math.max(0, candidates.length - 1)]);
|
||||
for (let i = beforePopulation; i <= maxCandidates; i++) {
|
||||
const idx = i - beforePopulation;
|
||||
if (idx >= serversByPopulation.length) break;
|
||||
candidates.push(serversByPopulation[idx]);
|
||||
}
|
||||
|
||||
return candidates;
|
||||
|
|
Loading…
Reference in a new issue