Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a359eb4

Browse files
committedJan 9, 2015
Attempt to improve server sorting
1 parent c9c97b0 commit a359eb4

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed
 

‎server.py

+31-2
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,38 @@ def removeServer(self, server):
281281
pass
282282

283283
def sort(self):
284+
def server_points(server):
285+
points = 0
286+
287+
# 1 per client
288+
# Only 1/16 per client with a guest or all-numeric name
289+
for name in server["clients_list"]:
290+
if name.startswith("Guest") or \
291+
name.isdigit():
292+
points += 1/16
293+
else:
294+
points += 1
295+
296+
# 1 per month of age, limited to 8
297+
points += min(8, server["game_time"] / (60*60*24*30))
298+
299+
# -8 for unrealistic max_clients
300+
if server["max_clients"] >= 128:
301+
points -= 8
302+
303+
# -8 per second of ping
304+
points -= server["ping"] * 8
305+
306+
# Up to -8 for less than an hour of uptime (penalty linearly decreasing)
307+
HOUR_SECS = 60 * 60
308+
uptime = server["uptime"]
309+
if uptime < HOUR_SECS:
310+
points -= ((HOUR_SECS - uptime) / HOUR_SECS) * 8
311+
312+
return points
313+
284314
with self.lock:
285-
self.list.sort(key=itemgetter("clients", "start"), reverse=True)
315+
self.list.sort(key=server_points, reverse=True)
286316

287317
def purgeOld(self):
288318
with self.lock:
@@ -339,7 +369,6 @@ def update(self, server):
339369

340370
serverList = ServerList()
341371

342-
343372
if __name__ == "__main__":
344373
app.run(host = app.config["HOST"], port = app.config["PORT"])
345374

0 commit comments

Comments
 (0)
Please sign in to comment.