From 8ae3760b0bfffe17eb82206f66d9aefedb02e4ae Mon Sep 17 00:00:00 2001 From: Charles Le Maux Date: Sun, 15 Sep 2024 23:01:23 +0200 Subject: [PATCH] [+] Modded patch pre-0.7 --- generic_executor.py | 13 +++++++++---- server_mc_manager.py | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/generic_executor.py b/generic_executor.py index c22905f..248a483 100644 --- a/generic_executor.py +++ b/generic_executor.py @@ -180,7 +180,7 @@ def account_delete(user: UserRecord) -> tuple[HTTPStatus, Union[str, None]]: return HTTPStatus.INTERNAL_SERVER_ERROR, f"Error deleting user '{user_id}' on the server." -allowed_frameworks: list[str] = ["paper", "spigot", "bukkit"] +allowed_frameworks: list[str] = ["bukkit", "fabric", "forge", "spigot", "paper"] def server_create(user: UserRecord, name: str, version: str, framework: str = "paper") -> ( tuple)[HTTPStatus, Union[str, None]]: @@ -237,11 +237,16 @@ def server_run(user: UserRecord, name: str) -> tuple[HTTPStatus, Union[str, None try: port: int = firebase_manager.get_server_port(user_id) version: str = firebase_manager.get_server_field(user_id, name, "version") - if version is None: + framework: str = firebase_manager.get_server_field(user_id, name, "framework") + if version is None or framework is None: return HTTPStatus.NOT_FOUND, f"Server {name} not found." - server_id = mc_manager.start_server(f"users/{user_id}/{name}", port, user_id, name, version) + if (framework == "forge") or (framework == "fabric"): + server_id = mc_manager.start_server(f"users/{user_id}/{name}", port, user_id, + name, version, modded=True) + else: + server_id = mc_manager.start_server(f"users/{user_id}/{name}", port, user_id, name, version) if server_id is None: - return HTTPStatus.OK, f"You cannot run multiples instances at this time." + return HTTPStatus.OK, f"You cannot run multiples instances at this time." try: firebase_manager.update_server_running_state(user_id, name, True) except Exception as e: diff --git a/server_mc_manager.py b/server_mc_manager.py index 810433f..38a49ef 100644 --- a/server_mc_manager.py +++ b/server_mc_manager.py @@ -21,7 +21,7 @@ class MinecraftServerManager: self.offline_ports: list[int] = [] def start_server(self, server_directory: str, port: int, user_id: str, server_name: str, - version: str, jar_file='server.jar', memory_size='4G') -> Union[int, None]: + version: str, jar_file: str = 'server.jar', memory_size: str ='4G', modded: bool = False) -> Union[int, None]: if port in self.servers: return None @@ -38,6 +38,8 @@ class MinecraftServerManager: java: str = f"/usr/lib/jvm/java-{get_sdk_version(version)}-openjdk/bin/java" command = f"{java} -Xmx{memory_size} {reg_flags} -jar {jar_file} --nogui" + if modded: + command = "./start.sh" process = subprocess.Popen(shlex.split(command), cwd=server_directory, stdin=subprocess.PIPE) #TODO: Track process behavior and stderr, while excepting Advanced Terminal features not to be avail.