From 84b84f45b6471f2048c2b5742d691438cde1d5db Mon Sep 17 00:00:00 2001 From: Carl Date: Sat, 30 May 2026 14:40:52 +0200 Subject: [PATCH] Added function to check if folder exists. --- servermanager.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/servermanager.py b/servermanager.py index a8a5cf6..505a44c 100644 --- a/servermanager.py +++ b/servermanager.py @@ -8,17 +8,15 @@ load_dotenv() SERVER_PATH = os.getenv("SERVERPATH") -def create_server(name, port, channel): +def create_server(name: str, port: int, channel: int, command: str): if is_port_in_use(port): return "ERROR_PORT_IN_USE" os.mkdir("games/" + name) - # print(SERVER_PATH) - # print(server_command_builder(name, port, channel)) game = Dom5game(name, channel, [], 0, {}) game.to_json() try: p = subprocess.Popen( - server_command_builder(name, port), + command, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, ) @@ -55,9 +53,11 @@ def get_nations(): def server_command_builder( name: str, port: int, - era: int, - closed_slots: list[int] = [], - ai_slots: list[tuple[int, int]] = [], + era: int, # 1 EA, 2 MA, 3 LA + closed_slots: list[int] = [], # list of nations that will be closed + ai_slots: list[ + tuple[int, int] + ] = [], # list of nations that will be ai tuple format: NationID, AI Level (1-6) client_start: bool = True, teams: list[tuple[int, int, int]] = [], clustered_start: bool = False, @@ -253,3 +253,7 @@ def is_port_in_use(port: int) -> bool: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: return s.connect_ex(("localhost", port)) == 0 + + +def does_game_folder_exist(folder: str) -> bool: + return not (os.path.isdir(SERVER_PATH + "/" + folder))