Add server information

This commit is contained in:
sqozz 2021-04-30 15:25:02 +02:00
parent adb8f37e37
commit c85aac8893
4 changed files with 76 additions and 6 deletions

View file

@ -26,10 +26,32 @@
</a>
</div>
<div class="row">
<a class="item worlddownload" href="https://play.geekify.de/map/recent.tar.gz" target="_blank">
<a class="item server" onclick="return toggleDetails(this)">
<div class="icon"></div>
<div class="text">World Download</div>
<div class="text">Server</div>
</a>
<div class="server details">
<textarea name="specs" rows=20 readonly>
Hardware:
• CPU: {{server_details["hardware"]["cpu"]}}
• RAM: {{server_details["hardware"]["ram"]}} GB
Versions:
• Minecraft: {{server_details["versions"]["minecraft"]}}
• Paper: {{server_details["versions"]["paper"]}}
• API: {{server_details["versions"]["api"]}}
Datapacks:
% for datapack in server_details["datapacks"]:
• {{datapack}}
% end
Datapacks can be found on https://vanillatweaks.net/</textarea>
<a class="subitem worlddownload" href="/map/recent.tar.gz" target="_blank">
<div class="icon"></div>
<div class="text">Download world</div>
</a>
</div>
</div>
<div class="row">
<a class="item whitelist" id="whitelist" onclick="return toggleDetails(this)">

View file

@ -1,10 +1,11 @@
#!/usr/bin/env python3
from bottle import route, run, static_file, template
from os import listdir
from os import listdir, sysconf
from os.path import join as pathjoin
from random import random, choice
from mcrcon import MCRcon
import configparser
import platform
import requests
import hashlib
import base64
@ -16,8 +17,9 @@ BG_IMAGES = listdir("./static/img/background")
@route("/")
def index():
print(server_details())
players = currentPlayerData()
return template("html/index.html", **{"player_count": players["count"]["current"] , "max_players": players["count"]["max"], "news": news(), "donations": donations()})
return template("html/index.html", **{"player_count": players["count"]["current"] , "max_players": players["count"]["max"], "news": news(), "donations": donations(), "server_details": server_details()})
@route("/getPlayerSkins")
def getPlayerSkins():
@ -97,6 +99,48 @@ def news():
with open("news.txt", "r") as news_file:
news = news_file.read()
def hardware_info():
processor = platform.processor()
mem_bytes = sysconf('SC_PAGE_SIZE') * sysconf('SC_PHYS_PAGES')
mem_gib = mem_bytes/(1024.**3)
mem_pretty = round(mem_gib, 1)
return {"cpu": processor, "ram": mem_pretty}
def paper_version():
with MCRcon(CONFIG["mcrcon"]["host"], CONFIG["mcrcon"]["password"], port=int(CONFIG["mcrcon"]["port"])) as mcr:
for i in range(0, 10):
resp = mcr.command("version")
if not "please wait" in resp:
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():
with MCRcon(CONFIG["mcrcon"]["host"], CONFIG["mcrcon"]["password"], port=int(CONFIG["mcrcon"]["port"])) as mcr:
resp = mcr.command("datapack list")
match = re.match("There are [0-9]* data packs enabled: (\[.*\])*.*", resp)
datapacks = []
datapacks_string = match.group(1)
for datapack in datapacks_string.split(","):
match = re.match("\[(.*)\(.*\)\]", datapack.strip())
datapack_name = match.group(1)
datapack_name = datapack_name.strip()
datapack_name = datapack_name.replace("file/", "")
datapack_name = datapack_name.replace(".zip", "")
if not datapack_name in ["vanilla", "bukkit"]:
datapacks.append(datapack_name)
return datapacks
def server_details():
hardware = hardware_info()
versions = paper_version()
datapacks = datapack_info()
return {"hardware": hardware, "versions": versions, "datapacks": datapacks}
CONFIG = parseConfig()
run(host="localhost", port=8080)

View file

@ -40,7 +40,11 @@ body {
content:url('/img/map.png');
}
.worlddownload .icon {
.server .icon {
content:url('/img/comparator.png');
}
.server.details .worlddownload.subitem > .icon {
content:url('/img/hopper.png');
}

View file

@ -11,7 +11,7 @@ echo "done!"
echo "Unzipped resources at $TMP_PATH"
popd
FILES="birch_sign.png map.png redstone_lamp_on.png redstone_lamp.png writable_book.png diamond.png gold_ingot.png hopper.png"
FILES="birch_sign.png map.png redstone_lamp_on.png redstone_lamp.png writable_book.png diamond.png gold_ingot.png hopper.png comparator.png"
for FILE in $FILES; do
echo -n "Grabbing asset from: "
find $TMP_PATH -name $FILE -print -exec cp {} . \;