|
1 | 1 | #!/usr/bin/env python3
|
2 | 2 | import os, sys, json, time, socket
|
3 | 3 | from threading import Thread, RLock
|
4 |
| -from operator import itemgetter |
5 | 4 |
|
6 | 5 | from apscheduler.schedulers.background import BackgroundScheduler
|
7 | 6 | from flask import Flask, request, send_from_directory
|
@@ -281,8 +280,38 @@ def removeServer(self, server):
|
281 | 280 | pass
|
282 | 281 |
|
283 | 282 | def sort(self):
|
| 283 | + def server_points(server): |
| 284 | + points = 0 |
| 285 | + |
| 286 | + # 1 per client |
| 287 | + # Only 1/16 per client with a guest or all-numeric name |
| 288 | + for name in server["clients_list"]: |
| 289 | + if name.startswith("Guest") or \ |
| 290 | + name.isdigit(): |
| 291 | + points += 1/16 |
| 292 | + else: |
| 293 | + points += 1 |
| 294 | + |
| 295 | + # 1 per month of age, limited to 8 |
| 296 | + points += min(8, server["game_time"] / (60*60*24*30)) |
| 297 | + |
| 298 | + # -8 for unrealistic max_clients |
| 299 | + if server["max_clients"] >= 128: |
| 300 | + points -= 8 |
| 301 | + |
| 302 | + # -8 per second of ping |
| 303 | + points -= server["ping"] * 8 |
| 304 | + |
| 305 | + # Up to -8 for less than an hour of uptime (penalty linearly decreasing) |
| 306 | + HOUR_SECS = 60 * 60 |
| 307 | + uptime = server["uptime"] |
| 308 | + if uptime < HOUR_SECS: |
| 309 | + points -= ((HOUR_SECS - uptime) / HOUR_SECS) * 8 |
| 310 | + |
| 311 | + return points |
| 312 | + |
284 | 313 | with self.lock:
|
285 |
| - self.list.sort(key=itemgetter("clients", "start"), reverse=True) |
| 314 | + self.list.sort(key=server_points, reverse=True) |
286 | 315 |
|
287 | 316 | def purgeOld(self):
|
288 | 317 | with self.lock:
|
@@ -339,7 +368,6 @@ def update(self, server):
|
339 | 368 |
|
340 | 369 | serverList = ServerList()
|
341 | 370 |
|
342 |
| - |
343 | 371 | if __name__ == "__main__":
|
344 | 372 | app.run(host = app.config["HOST"], port = app.config["PORT"])
|
345 | 373 |
|
0 commit comments