diff --git a/homepage/html/index.html b/homepage/html/index.html index 809a947..2121d02 100644 --- a/homepage/html/index.html +++ b/homepage/html/index.html @@ -26,10 +26,32 @@
- +
-
World Download
+
Server
+
+ + +
+
Download world
+
+
diff --git a/homepage/main.py b/homepage/main.py index e5488ba..3b102b6 100644 --- a/homepage/main.py +++ b/homepage/main.py @@ -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) diff --git a/homepage/static/css/styles.css b/homepage/static/css/styles.css index 97f92cf..6952c15 100644 --- a/homepage/static/css/styles.css +++ b/homepage/static/css/styles.css @@ -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'); } diff --git a/homepage/static/img/extract_resources.sh b/homepage/static/img/extract_resources.sh index 5e8b5a5..f4c407e 100755 --- a/homepage/static/img/extract_resources.sh +++ b/homepage/static/img/extract_resources.sh @@ -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 {} . \;