diff --git a/.gitignore b/.gitignore index b2a0836..449049a 100644 --- a/.gitignore +++ b/.gitignore @@ -161,7 +161,7 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ -/server/ +/servers/ /users/ unit_test.py !*.py diff --git a/__pycache__/file_manager.cpython-312.pyc b/__pycache__/file_manager.cpython-312.pyc index dc76a39..5fda88f 100644 Binary files a/__pycache__/file_manager.cpython-312.pyc and b/__pycache__/file_manager.cpython-312.pyc differ diff --git a/__pycache__/generic_executor.cpython-312.pyc b/__pycache__/generic_executor.cpython-312.pyc index cf68c6b..6008a22 100644 Binary files a/__pycache__/generic_executor.cpython-312.pyc and b/__pycache__/generic_executor.cpython-312.pyc differ diff --git a/__pycache__/server_mc_manager.cpython-312.pyc b/__pycache__/server_mc_manager.cpython-312.pyc index 2d8b9c6..585a4b5 100644 Binary files a/__pycache__/server_mc_manager.cpython-312.pyc and b/__pycache__/server_mc_manager.cpython-312.pyc differ diff --git a/file_manager.py b/file_manager.py index 7d6e160..663f4a9 100644 --- a/file_manager.py +++ b/file_manager.py @@ -2,6 +2,17 @@ import os import shutil import re +supported_versions = ["bukkit", "paper", "spigot"] + +def get_all_versions(folder_path="servers/paper"): + return [name for name in os.listdir(folder_path) if os.path.isdir(os.path.join(folder_path, name))] + +def version_exists(version, framework = "paper")->bool: + if framework not in supported_versions: + return False + folder_names = get_all_versions("servers/"+framework) + return any(version in name for name in folder_names) + def create_folder(path): os.makedirs(path, exist_ok=True) diff --git a/generic_executor.py b/generic_executor.py index fd14749..ec9e23a 100644 --- a/generic_executor.py +++ b/generic_executor.py @@ -3,35 +3,36 @@ import file_manager mc_manager: MinecraftServerManager = MinecraftServerManager() -def AccountCreate(port) -> bool: +def AccountCreate(port : str) -> bool: file_manager.create_folder("users/"+port) -def ServerCreate(port, name, version) -> bool: +def ServerCreate(port : str, name : str, version : str) -> bool: server_path: str = f"users/{port}/{name}" - server_template_path: str = "servers/"+version + server_template_path: str = "servers/paper/"+version file_manager.create_folder(server_path) file_manager.copy_folder_contents(server_template_path, server_path) + file_manager.copy_folder_contents("servers/shared", server_path) file_manager.update_server_property(server_path+"/server.properties", "server-port", port) -def ServerDelete(port, name) -> bool: +def ServerDelete(port : str, name : str) -> bool: server_path: str = f"users/{port}/{name}" file_manager.delete_non_empty_folder(server_path) -def AccountDelete(port) -> bool: +def AccountDelete(port : str) -> bool: file_manager.delete_non_empty_folder("users/"+port) -def ServerRun(port, name) -> bool: +def ServerRun(port : str, name : str) -> bool: server_id = mc_manager.start_server(f"users/{port}/{name}") mc_manager.servers[server_id]['port'] = int(port) -def ServerStop(port, name) -> bool: +def ServerStop(port : str, name : str) -> bool: server_id = mc_manager.get_server_id_by_port(int(port)) mc_manager.stop_server(server_id) -def UpdateProperty(port, name, prop, value) -> bool: +def UpdateProperty(port : str, name : str, prop : str, value : str) -> bool: property_file_path: str = f"users/{port}/{name}/server.properties" file_manager.update_server_property(property_file_path, prop, value) -def RunCommand(port, command) -> bool: +def RunCommand(port : str, command : str) -> bool: server_id = mc_manager.get_server_id_by_port(int(port)) mc_manager.execute_server_command(server_id, command) \ No newline at end of file diff --git a/server_mc_manager.py b/server_mc_manager.py index aa4a4da..914fc42 100644 --- a/server_mc_manager.py +++ b/server_mc_manager.py @@ -22,7 +22,6 @@ class MinecraftServerManager: def execute_server_command(self, server_id, command): if server_id in self.servers: process = self.servers[server_id]['process'] - #process.communicate(input=(command + "\n").encode()) process.stdin.write(command.encode() + b'\n') print(f"Server {server_id} executed command : {command}") else: