servii-backend/generic_executor.py
2024-06-20 17:57:04 +01:00

47 lines
1.6 KiB
Python

from server_mc_manager import MinecraftServerManager
import file_manager
mc_manager: MinecraftServerManager = MinecraftServerManager()
def account_create(port: str) -> bool:
file_manager.create_folder("users/" + port)
def server_create(port: str, name: str, version: str) -> bool:
server_path: str = f"users/{port}/{name}"
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 server_delete(port: str, name: str) -> bool:
server_path: str = f"users/{port}/{name}"
file_manager.delete_non_empty_folder(server_path)
def account_delete(port: str) -> bool:
file_manager.delete_non_empty_folder("users/" + port)
def server_run(port: str, name: str) -> bool:
server_id = mc_manager.start_server(f"users/{port}/{name}")
mc_manager.servers[server_id]['port'] = int(port)
def server_stop(port: str, name: str) -> bool:
server_id = mc_manager.get_server_id_by_port(int(port))
mc_manager.stop_server(server_id)
def update_property(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 run_command(port: str, command: str) -> bool:
server_id = mc_manager.get_server_id_by_port(int(port))
mc_manager.execute_server_command(server_id, command)