[Server] Use official server list instead of servers.minetest.ru
This commit is contained in:
parent
3249e143a2
commit
b3f839398f
38
server.py
38
server.py
@ -4,34 +4,22 @@ server.py - Phenny Minetest Server Module
|
||||
Copyright 2012, Sfan5
|
||||
"""
|
||||
|
||||
import web, math, random
|
||||
from xml.dom import minidom
|
||||
import web, json, random
|
||||
|
||||
def read_server():
|
||||
bytes = web.get("http://servers.minetest.ru/")
|
||||
shim = '<table>'
|
||||
shim2 = '</table>'
|
||||
if shim in bytes and shim2 in bytes:
|
||||
bytes = bytes.split(shim, 1).pop()
|
||||
bytes = bytes.split(shim2, 1)[0]
|
||||
bytes = "<table>" + bytes + "</table>" # Root Tag needed
|
||||
dom = minidom.parseString(bytes)
|
||||
l = dom.getElementsByTagName("tr")
|
||||
chosen = l[int(math.floor(random.random()*(len(l)-1))+1)]
|
||||
datas = chosen.getElementsByTagName("td")
|
||||
name = datas[0].firstChild.data # Server Name
|
||||
addr = datas[1].firstChild.data # Server Address
|
||||
status = datas[3].firstChild.data # Status (up/down)
|
||||
statuspercent = datas[4].firstChild.firstChild.data # Status Percent
|
||||
return format(name,addr,status,statuspercent)
|
||||
return "Unknown Error"
|
||||
|
||||
text = web.get("http://servers.minetest.net/list")
|
||||
server_list = json.loads(text)["list"]
|
||||
choice = random.randrange(0, len(server_list))
|
||||
|
||||
name = server_list[choice]["name"]
|
||||
address = server_list[choice]["address"]
|
||||
clients = server_list[choice]["clients"]
|
||||
version = server_list[choice]["version"]
|
||||
ping = server_list[choice]["ping"]
|
||||
clients_top = server_list[choice]["clients_top"]
|
||||
|
||||
return "%s | %s | Clients: %s/%s | Version: %s | ping: %s" % (name, address, clients, clients_top, version, ping)
|
||||
|
||||
def format(name,addr,status,statuspercent):
|
||||
if status == "up":
|
||||
return "%s | %s %s (%s)" % (name,addr,status,statuspercent)
|
||||
else:
|
||||
return "%s | %s %s" % (name,addr,status)
|
||||
def server(phenny, input):
|
||||
for x in phenny.bot.commands["high"].values():
|
||||
if x[0].__name__ == "aa_hook":
|
||||
|
Loading…
x
Reference in New Issue
Block a user