[+] generic_executor type safety /2

This commit is contained in:
Charles Le Maux 2024-06-15 06:18:57 +02:00
parent a08cb54e06
commit 5d9cf5ae5e
7 changed files with 12 additions and 12 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
/server/
/servers/
/users/
unit_test.py
!*.py

View File

@ -11,7 +11,7 @@
Email: <input type="text" id="accountEmail"><br>
Port: <input type="number" id="accountPort"><br>
Name: <input type="text" id="serverName"><br>
Version: <input type="number" id="serverVersion"><br>
Version: <input type="text" id="serverVersion"><br>
<button type="button" class="actionButton" data-action="AccountCreate">Create Account</button>
<button type="button" class="actionButton" data-action="AccountDelete">Delete Account</button>
<button type="button" class="actionButton" data-action="ServerCreate">Create Server</button>

View File

@ -3,35 +3,36 @@ import file_manager
mc_manager: MinecraftServerManager = MinecraftServerManager()
def AccountCreate(port) -> bool:
def AccountCreate(port : str) -> bool:
file_manager.create_folder("users/"+port)
def ServerCreate(port, name, version) -> bool:
def ServerCreate(port : str, name : str, version : str) -> bool:
server_path: str = f"users/{port}/{name}"
server_template_path: str = "servers/"+version
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 ServerDelete(port, name) -> bool:
def ServerDelete(port : str, name : str) -> bool:
server_path: str = f"users/{port}/{name}"
file_manager.delete_non_empty_folder(server_path)
def AccountDelete(port) -> bool:
def AccountDelete(port : str) -> bool:
file_manager.delete_non_empty_folder("users/"+port)
def ServerRun(port, name) -> bool:
def ServerRun(port : str, name : str) -> bool:
server_id = mc_manager.start_server(f"users/{port}/{name}")
mc_manager.servers[server_id]['port'] = int(port)
def ServerStop(port, name) -> bool:
def ServerStop(port : str, name : str) -> 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:
def UpdateProperty(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 RunCommand(port, command) -> bool:
def RunCommand(port : str, command : str) -> bool:
server_id = mc_manager.get_server_id_by_port(int(port))
mc_manager.execute_server_command(server_id, command)

View File

@ -22,7 +22,6 @@ class MinecraftServerManager:
def execute_server_command(self, server_id, command):
if server_id in self.servers:
process = self.servers[server_id]['process']
#process.communicate(input=(command + "\n").encode())
process.stdin.write(command.encode() + b'\n')
print(f"Server {server_id} executed command : {command}")
else: