Compare commits

..

2 Commits

Author SHA1 Message Date
54653282aa Fixed get_nations returning nothing 2026-04-21 18:21:04 +02:00
c9811a9a01 First attempt of modular nation list. 2026-04-21 18:16:50 +02:00

View File

@@ -2,6 +2,7 @@ import subprocess
from dotenv import load_dotenv
import os
from dom5game import Dom5game
import re
load_dotenv()
SERVER_PATH = os.getenv("SERVERPATH")
@@ -24,7 +25,30 @@ def create_server(name, port, channel):
except Exception as e:
return "EXCEPTION OCCURED: " + str(e)
return "SUCCESS"
p.wait()
# p.wait()
def get_nations():
# TODO mod support
nation_string = subprocess.check_output([SERVER_PATH, "--listnations"]).decode()
nations = {}
current_era = None
for line in nation_string.splitlines():
line = line.strip()
era_match = re.match(r"-+ Era (\d+) -+", line)
if era_match:
current_era = f"Era {era_match.group(1)}"
nations[current_era] = {}
continue
entry_match = re.match(r"(\d+)\s+(.*?),\s+(.*)", line)
if entry_match and current_era:
nation_id = int(entry_match.group(1))
name = entry_match.group(2), entry_match.group(3)
nations[current_era][nation_id] = {"name": name}
return nations
# This is terrible.
@@ -66,7 +90,7 @@ def server_command_builder(
required_apoints: int = 0,
cataclysm: int = 0,
):
if not ((random_map == 0) ^ (mapfile == "")):
if (not ((random_map == 0) ^ (mapfile == ""))) or random_map not in {0, 10, 15, 20}:
return "ERROR_MAP"
if not (0 < era < 4):
@@ -84,16 +108,23 @@ def server_command_builder(
command = [
SERVER_PATH,
" -TS ",
"-TS ",
name,
" --port ",
"--port ",
str(port),
" --statuspage ",
"--statuspage ",
os.getcwd() + "/games/" + name + "/turnstats.html",
" --era ",
"--era ",
era,
]
if team_game:
for team in teams:
# TODO Check valid inputs
command.append(
" --team " + str(team[0]) + " " + str(team[1]) + " " + str(team[2])
)
if clustered_start:
command.append(" --clustered ")
if not client_start:
command.append(" --noclientstart ")