Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Server list point checker
#!/usr/bin/python3
# list all servers and their points:
# $ python mt_serverlist_points.py
#
# lists all penalties being applied:
# $ python mt_serverlist_points.py pen
#
# penalty -8 uptime for VanessaE's Nostalgia Server/digitalaudioconcepts.com
# penalty -8 uptime for VanessaE's Basic minetest_game server/digitalaudioconcepts.com
# penalty -8 uptime for VanessaE's Realtest Server/digitalaudioconcepts.com
# penalty -8 uptime for VanessaE's Free-for-All Minetest Server/digitalaudioconcepts.com
# penalty -8 uptime for VanessaE's/Nore's Lua mapgen test Server/digitalaudioconcepts.com
# penalty -8 uptime for VanessaE's Survival Server/digitalaudioconcepts.com
# penalty -8 uptime for VanessaE's Creative Server/digitalaudioconcepts.com
# penalty -8 clients_max for The Sentinel Empire Server 1/23.246.86.66
#
# list the point break down of (a) server(s):
# $ python mt_serverlist_points.py digitalaudioconcepts.com
# or
# $ python mt_serverlist_points.py VanessaE's Basic minetest_game
#
# VanessaE's Basic minetest_game server:
# 13 clients: +13
# 0 guests / 8: +0
# months of game_time (max 8): +8
# average clients / 2: +6.40909090909
# = 25
import datetime,re
def server_points(server, v=False, p=False):
if v:
print(server['name'] + ":")
points = 0
# 1 per client, but only 1/8 per client with a guest
# or all-numeric name.
if "clients_list" in server:
clients = 0
guests = 0
for name in server["clients_list"]:
if re.match(r"[A-Z][a-z]{3,}[1-9][0-9]{2,3}", name):
points += 1/8
guests += 1
else:
points += 1
clients += 1
if v:
print(" " + str(clients) + " clients: +" + str(clients))
print(" " + str(guests) + " guests / 8: +" + str(guests/8))
if p and guests > 0:
print("penalty -" + str(guests * 7/8) + " guests for " + server["name"] + "/" + server["address"])
else:
# Old server (1/4 per client)
points = server["clients"] / 4
if v:
print("- clients: +" + str(server["clients"] / 4))
# Penalize highly loaded servers to improve player distribution.
# Note: This doesn't just make more than 16 players stop
# increasing your points, it can actually reduce your points
# if you have guests/all-numerics.
if server["clients"] > 16:
if v:
print(" highly loaded server: -" + str(server["clients"] - 16))
points -= server["clients"] - 16
# 1 per month of age, limited to 8
points += min(8, server["game_time"] / (60*60*24*30))
if v:
print(" months of game_time (max 8): +" + str(min(8, server["game_time"] / (60*60*24*30))))
# 1/2 per average client, limited to 4
points += min(4, server["pop_v"] / 2)
if v:
print(" average clients / 2: +" + str(server["pop_v"] / 2))
# -8 for unrealistic max_clients
if server["clients_max"] >= 128:
points -= 8
if p:
print("penalty -8 clients_max for " + server["name"] + "/" + server["address"])
if v:
print(" unrealistic client_max: -8")
# -8 for unrealistic game time
#before = datetime.datetime(2011, 01, 01)
#now = datetime.datetime.now()
#if server["game_time"] / (60*60*24) >= (now - before).days:
# points -= 8
# if p:
# print("penalty -8 game_time for " + server["name"] + "/" + server["address"])
# if v:
# print(" unrealistic game_time: -8")
# -8 per second of ping over 0.4s
if server["ping"] > 0.4:
points -= (server["ping"] - 0.4) * 8
if p:
print("penalty -"+str((server["ping"] - 0.4) * 8)+" ping for " + server["name"] + "/" + server["address"])
if v:
print(" ping greater than 0.4s: -" + str((server["ping"] - 0.4) * 8))
# Up to -8 for less than an hour of uptime (penalty linearly decreasing)
HOUR_SECS = 60 * 60
uptime = server["uptime"]
if uptime < HOUR_SECS:
points -= ((HOUR_SECS - uptime) / HOUR_SECS) * 8
if p:
print("penalty -"+ str(((HOUR_SECS - uptime) / HOUR_SECS) * 8) +" uptime for " + server["name"] + "/" + server["address"])
if v:
print(" uptime less than one hour: -" + str(((HOUR_SECS - uptime) / HOUR_SECS) * 8))
if v:
print(" = " + str(points))
return points
import urllib, json, io, sys
print("Downloading server list...")
import urllib.request
data = None
with urllib.request.urlopen("http://servers.minetest.net/list") as url:
data = json.loads(url.read().decode('utf-8'))
print("Complete.")
for id, server in enumerate(data['list']):
if len(sys.argv) != 2:
print(str(id + 1) + ") " + server['name'] + " = " + str(server_points(server)))
elif sys.argv[1].strip() == "pen":
server_points(server, False, True)
elif len(sys.argv[1].strip()) > 0 and (sys.argv[1] in server["name"] or
sys.argv[1] in server["address"]):
server_points(server, True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.