servii-backend/generic_executor.py

47 lines
1.6 KiB
Python
Raw Normal View History

2024-06-14 21:33:55 +00:00
from server_mc_manager import MinecraftServerManager
import file_manager
mc_manager: MinecraftServerManager = MinecraftServerManager()
2024-06-20 16:57:04 +00:00
def account_create(port: str) -> bool:
file_manager.create_folder("users/" + port)
def server_create(port: str, name: str, version: str) -> bool:
2024-06-14 21:33:55 +00:00
server_path: str = f"users/{port}/{name}"
2024-06-20 16:57:04 +00:00
server_template_path: str = "servers/paper/" + version
2024-06-14 21:33:55 +00:00
file_manager.create_folder(server_path)
file_manager.copy_folder_contents(server_template_path, server_path)
2024-06-15 04:18:57 +00:00
file_manager.copy_folder_contents("servers/shared", server_path)
2024-06-20 16:57:04 +00:00
file_manager.update_server_property(server_path + "/server.properties", "server-port", port)
2024-06-14 21:33:55 +00:00
2024-06-20 16:57:04 +00:00
def server_delete(port: str, name: str) -> bool:
2024-06-14 21:33:55 +00:00
server_path: str = f"users/{port}/{name}"
file_manager.delete_non_empty_folder(server_path)
2024-06-20 16:57:04 +00:00
def account_delete(port: str) -> bool:
file_manager.delete_non_empty_folder("users/" + port)
def server_run(port: str, name: str) -> bool:
2024-06-14 21:33:55 +00:00
server_id = mc_manager.start_server(f"users/{port}/{name}")
mc_manager.servers[server_id]['port'] = int(port)
2024-06-20 16:57:04 +00:00
def server_stop(port: str, name: str) -> bool:
2024-06-14 21:33:55 +00:00
server_id = mc_manager.get_server_id_by_port(int(port))
mc_manager.stop_server(server_id)
2024-06-20 16:57:04 +00:00
def update_property(port: str, name: str, prop: str, value: str) -> bool:
2024-06-14 21:33:55 +00:00
property_file_path: str = f"users/{port}/{name}/server.properties"
file_manager.update_server_property(property_file_path, prop, value)
2024-06-20 16:57:04 +00:00
def run_command(port: str, command: str) -> bool:
2024-06-14 21:33:55 +00:00
server_id = mc_manager.get_server_id_by_port(int(port))
2024-06-20 16:57:04 +00:00
mc_manager.execute_server_command(server_id, command)