servii-backend/generic_executor.py

37 lines
1.4 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()
def AccountCreate(port) -> bool:
file_manager.create_folder("users/"+port)
def ServerCreate(port, name, version) -> bool:
server_path: str = f"users/{port}/{name}"
server_template_path: str = "servers/"+version
file_manager.create_folder(server_path)
file_manager.copy_folder_contents(server_template_path, server_path)
file_manager.update_server_property(server_path+"/server.properties", "server-port", port)
def ServerDelete(port, name) -> bool:
server_path: str = f"users/{port}/{name}"
file_manager.delete_non_empty_folder(server_path)
def AccountDelete(port) -> bool:
file_manager.delete_non_empty_folder("users/"+port)
def ServerRun(port, name) -> bool:
server_id = mc_manager.start_server(f"users/{port}/{name}")
mc_manager.servers[server_id]['port'] = int(port)
def ServerStop(port, name) -> 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:
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:
server_id = mc_manager.get_server_id_by_port(int(port))
mc_manager.execute_server_command(server_id, command)