From 947c4f9d30511704ce0750410bbf60ff52c425ea Mon Sep 17 00:00:00 2001 From: sqozz Date: Thu, 2 Feb 2023 13:24:05 +0100 Subject: [PATCH] Fix homepage if mcrcon is not available --- homepage/main.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/homepage/main.py b/homepage/main.py index f339e96..f820ea9 100644 --- a/homepage/main.py +++ b/homepage/main.py @@ -131,19 +131,24 @@ def paper_version(): return {"paper": paper_version, "minecraft": mc_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) + try: + 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) + except ConnectionRefusedError: + datapacks = [] + return datapacks def server_details():