Replace rcon with "server list ping" for basic information
See https://wiki.vg/Server_List_Ping for details. It should allow to run the landing page more stable as less parsing is involved. Also it does not need to wait for the version reply anymore. This should fix several 500 errors if the version response is to slow.
This commit is contained in:
parent
095131bf08
commit
fb452da28f
|
@ -38,8 +38,7 @@ Hardware:
|
||||||
|
|
||||||
Versions:
|
Versions:
|
||||||
• Minecraft: {{server_details["versions"]["minecraft"]}}
|
• Minecraft: {{server_details["versions"]["minecraft"]}}
|
||||||
• Paper: {{server_details["versions"]["paper"]}}
|
• Server: {{server_details["versions"]["paper"]}}
|
||||||
• API: {{server_details["versions"]["api"]}}
|
|
||||||
|
|
||||||
Datapacks:
|
Datapacks:
|
||||||
% for datapack in server_details["datapacks"]:
|
% for datapack in server_details["datapacks"]:
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from bottle import route, run, static_file, template
|
from mcstatus import MinecraftServer
|
||||||
from os import listdir, sysconf
|
|
||||||
from os.path import join as pathjoin
|
from os.path import join as pathjoin
|
||||||
|
from bottle import route, run, static_file, template
|
||||||
from random import random, choice
|
from random import random, choice
|
||||||
from mcrcon import MCRcon
|
from mcrcon import MCRcon
|
||||||
|
from os import listdir, sysconf
|
||||||
import configparser
|
import configparser
|
||||||
import platform
|
import platform
|
||||||
import requests
|
import requests
|
||||||
|
@ -48,29 +49,14 @@ def callback(path):
|
||||||
return static_file(path, root="static")
|
return static_file(path, root="static")
|
||||||
|
|
||||||
def currentPlayerData():
|
def currentPlayerData():
|
||||||
|
status = server_status()
|
||||||
player = {}
|
player = {}
|
||||||
with MCRcon(CONFIG["mcrcon"]["host"], CONFIG["mcrcon"]["password"], port=int(CONFIG["mcrcon"]["port"])) as mcr:
|
|
||||||
resp = mcr.command("list uuids")
|
|
||||||
resp = resp.split(":")
|
|
||||||
player_string = resp[1].strip()
|
|
||||||
if player_string != "":
|
|
||||||
player_list = player_string.split(",")
|
|
||||||
else:
|
|
||||||
player_list = []
|
|
||||||
player_list = list(map(lambda x: x.strip(), player_list))
|
|
||||||
count_regex = re.match("There are ([0-9]+) of a max of ([0-9]+) players online", resp[0])
|
|
||||||
num_players = count_regex.group(1)
|
|
||||||
max_players = count_regex.group(2)
|
|
||||||
|
|
||||||
player["count"] = {}
|
player["count"] = {}
|
||||||
player["count"]["current"] = num_players
|
player["count"]["current"] = status.players.online
|
||||||
player["count"]["max"] = max_players
|
player["count"]["max"] = status.players.max
|
||||||
player["players"] = []
|
player["players"] = []
|
||||||
for p in player_list:
|
for p in status.players.sample:
|
||||||
data = p.split(" ")
|
player["players"].append({"name": p.name, "uuid": p.id})
|
||||||
name = data[0].strip()
|
|
||||||
uuid = data[1].strip().replace("(", "").replace(")", "")
|
|
||||||
player["players"].append({"name": name, "uuid": uuid})
|
|
||||||
return player
|
return player
|
||||||
|
|
||||||
def fetchSkin(uuid):
|
def fetchSkin(uuid):
|
||||||
|
@ -107,17 +93,10 @@ def hardware_info():
|
||||||
return {"cpu": processor, "ram": mem_pretty}
|
return {"cpu": processor, "ram": mem_pretty}
|
||||||
|
|
||||||
def paper_version():
|
def paper_version():
|
||||||
with MCRcon(CONFIG["mcrcon"]["host"], CONFIG["mcrcon"]["password"], port=int(CONFIG["mcrcon"]["port"])) as mcr:
|
status = server_status()
|
||||||
for i in range(0, 10):
|
paper_version = status.version.name
|
||||||
resp = mcr.command("version")
|
mc_version = status.version.protocol
|
||||||
if not "please wait" in resp:
|
return {"paper": paper_version, "minecraft": mc_version}
|
||||||
break
|
|
||||||
match = re.match(".*(This server is running Paper version )(.*) \((.*)\) \(Implementing API version (.*)\).*", resp)
|
|
||||||
paper_version = match.group(2)
|
|
||||||
mc_version = match.group(3)
|
|
||||||
mc_version = mc_version.split(":")[1].strip()
|
|
||||||
api_version = match.group(4)
|
|
||||||
return {"paper": paper_version, "minecraft": mc_version, "api": api_version}
|
|
||||||
|
|
||||||
def datapack_info():
|
def datapack_info():
|
||||||
with MCRcon(CONFIG["mcrcon"]["host"], CONFIG["mcrcon"]["password"], port=int(CONFIG["mcrcon"]["port"])) as mcr:
|
with MCRcon(CONFIG["mcrcon"]["host"], CONFIG["mcrcon"]["password"], port=int(CONFIG["mcrcon"]["port"])) as mcr:
|
||||||
|
@ -141,6 +120,11 @@ def server_details():
|
||||||
datapacks = datapack_info()
|
datapacks = datapack_info()
|
||||||
return {"hardware": hardware, "versions": versions, "datapacks": datapacks}
|
return {"hardware": hardware, "versions": versions, "datapacks": datapacks}
|
||||||
|
|
||||||
|
def server_status():
|
||||||
|
server = MinecraftServer.lookup(CONFIG["mcrcon"]["host"])
|
||||||
|
status = server.status()
|
||||||
|
return status
|
||||||
|
|
||||||
|
|
||||||
CONFIG = parseConfig()
|
CONFIG = parseConfig()
|
||||||
run(host="localhost", port=8080)
|
run(host="localhost", port=8080)
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
bottle==0.12.19
|
bottle==0.12.19
|
||||||
mcrcon==0.6.0
|
mcrcon==0.6.0
|
||||||
|
mcstatus==5.2.0
|
||||||
|
|
Loading…
Reference in a new issue