mirror of
https://github.com/hubHarmony/servii-backend.git
synced 2024-11-17 21:40:31 +00:00
[+] Light modloader support
[+] Light modloader support
This commit is contained in:
commit
ba53890e60
@ -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]]:
|
||||
@ -199,7 +199,6 @@ def server_create(user: UserRecord, name: str, version: str, framework: str = "p
|
||||
return HTTPStatus.NOT_FOUND, f"You haven't associated a subdomain yet."
|
||||
if firebase_manager.server_name_taken(user_id, name):
|
||||
return HTTPStatus.CONFLICT, f"Server name '{name}' already in use."
|
||||
firebase_manager.create_server(user_id, name, version, port, framework)
|
||||
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)
|
||||
@ -208,6 +207,7 @@ def server_create(user: UserRecord, name: str, version: str, framework: str = "p
|
||||
file_manager.update_server_property(prop_path, "query.port", port)
|
||||
file_manager.update_server_property(prop_path, "enable-query", "true")
|
||||
file_manager.log_action(user_id, name, "ServerCreate")
|
||||
firebase_manager.create_server(user_id, name, version, port, framework)
|
||||
return HTTPStatus.CREATED, f"Successfully created server '{name}'."
|
||||
except Exception as e:
|
||||
file_manager.log_error(type(e).__name__, str(e))
|
||||
@ -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:
|
||||
@ -299,7 +304,7 @@ def update_property(uid: str, name: str, prop: str, value: str) -> tuple[HTTPSta
|
||||
def update_properties(user: UserRecord, name: str, props: list[tuple[str, str]]) -> tuple[HTTPStatus, Union[str, None]]:
|
||||
errors: list[str] = []
|
||||
for prop, value in props:
|
||||
if prop not in MinecraftServerManager.allowed_properties:
|
||||
if prop not in mc_manager.allowed_properties:
|
||||
return HTTPStatus.FORBIDDEN, f"Property '{prop}' not allowed."
|
||||
status, message = update_property(uid=user.uid, name=name, prop=prop, value=value)
|
||||
if status != HTTPStatus.OK:
|
||||
|
@ -21,7 +21,8 @@ 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 +39,9 @@ class MinecraftServerManager:
|
||||
java: str = f"/usr/lib/jvm/java-{get_sdk_version(version)}-openjdk-amd64/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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user