From f0eb65891339d960f6e345d0f037fbdcd21f5585 Mon Sep 17 00:00:00 2001 From: Carl Date: Wed, 15 Apr 2026 17:31:46 +0200 Subject: [PATCH] Started work on implementing most server args. --- servermanager.py | 90 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 12 deletions(-) diff --git a/servermanager.py b/servermanager.py index ff2bfe8..c52067e 100644 --- a/servermanager.py +++ b/servermanager.py @@ -10,32 +10,98 @@ SERVER_PATH = os.getenv("SERVERPATH") def create_server(name, port, channel): if is_port_in_use(port): return "ERROR_PORT_IN_USE" - # os.mkdir("games/" + name) + os.mkdir("games/" + name) # print(SERVER_PATH) # print(server_command_builder(name, port, channel)) + game = Dom5game(name, channel, [], 0, {}) + game.to_json() try: - subprocess.Popen( - server_command_builder(name, port, channel), - stdin=None, - stdout=None, - stderr=None, + p = subprocess.Popen( + server_command_builder(name, port), + stdout=subprocess.DEVNULL, + stderr=subprocess.STDOUT, ) except Exception as e: return "EXCEPTION OCCURED: " + str(e) + return "SUCCESS" + p.wait() -def server_command_builder(name, port, channel): +# This is terrible. +def server_command_builder( + name: str, + port: int, + era: int, + closed_slots: list[int] = [], + ai_slots: list[tuple[int, int]] = [], + client_start: bool = True, + teams: list[tuple[int, int, int]] = [], + clustered_start: bool = False, + team_game: bool = False, + mapfile: str = "", + random_map: int = 0, + research_difficulty: int = 2, + random_start_research: bool = True, + hof_size: int = 10, + global_slots: int = 5, + inde_strength: int = 5, + magic_sites: int = 40, + event_rarity: int = 1, + richness: int = 100, + resources: int = 100, + recruitment: int = 100, + supplies: int = 100, + masterpass: str = "", + start_prov: int = 1, + renaming: bool = True, + score_graphs: bool = False, + no_nation_info: bool = False, + no_cheat_det: bool = False, + no_artifact_rest: bool = False, + story_events: int = 1, + new_ai_lvl: int = 2, + no_new_ai: bool = False, + conq_all: bool = False, + thrones: tuple[int, int, int] = (1, 1, 1), + required_apoints: int = 0, + cataclysm: int = 0, +): + if not ((random_map == 0) ^ (mapfile == "")): + return "ERROR_MAP" + + if not (0 < era < 4): + return "ERROR_ERA" + + ai_indexes = [t[1] for t in ai_slots] + if not (len(ai_indexes) == len(set(ai_indexes))): + return "ERROR_AIS" + + if bool(set(closed_slots) & set(ai_indexes)): + return "ERROR_CLOSED_AIS" + + if required_apoints == 0: + required_apoints = thrones[0] + (2 * thrones[1]) + (3 * thrones[2]) - 1 + command = [ SERVER_PATH, - "-TS", + " -TS ", name, - "--port", + " --port ", str(port), - "--statuspage", + " --statuspage ", os.getcwd() + "/games/" + name + "/turnstats.html", + " --era ", + era, ] - game = Dom5game(name, channel, [], 0, {}) - game.to_json() + if team_game: + + if not client_start: + command.append(" --noclientstart ") + if cataclysm > 0: + command.append(" --cataclysm " + str(cataclysm)) + if conq_all: + command.append(" --conqall") + return command