[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
|
Copyright 2012, Sfan5
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import web, math, random
|
import web, json, random
|
||||||
from xml.dom import minidom
|
|
||||||
|
|
||||||
def read_server():
|
def read_server():
|
||||||
bytes = web.get("http://servers.minetest.ru/")
|
text = web.get("http://servers.minetest.net/list")
|
||||||
shim = '<table>'
|
server_list = json.loads(text)["list"]
|
||||||
shim2 = '</table>'
|
choice = random.randrange(0, len(server_list))
|
||||||
if shim in bytes and shim2 in bytes:
|
|
||||||
bytes = bytes.split(shim, 1).pop()
|
name = server_list[choice]["name"]
|
||||||
bytes = bytes.split(shim2, 1)[0]
|
address = server_list[choice]["address"]
|
||||||
bytes = "<table>" + bytes + "</table>" # Root Tag needed
|
clients = server_list[choice]["clients"]
|
||||||
dom = minidom.parseString(bytes)
|
version = server_list[choice]["version"]
|
||||||
l = dom.getElementsByTagName("tr")
|
ping = server_list[choice]["ping"]
|
||||||
chosen = l[int(math.floor(random.random()*(len(l)-1))+1)]
|
clients_top = server_list[choice]["clients_top"]
|
||||||
datas = chosen.getElementsByTagName("td")
|
|
||||||
name = datas[0].firstChild.data # Server Name
|
return "%s | %s | Clients: %s/%s | Version: %s | ping: %s" % (name, address, clients, clients_top, version, ping)
|
||||||
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"
|
|
||||||
|
|
||||||
|
|
||||||
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):
|
def server(phenny, input):
|
||||||
for x in phenny.bot.commands["high"].values():
|
for x in phenny.bot.commands["high"].values():
|
||||||
if x[0].__name__ == "aa_hook":
|
if x[0].__name__ == "aa_hook":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user