From 5d9cf5ae5e3b22e3aba54e730dd1357754a67765 Mon Sep 17 00:00:00 2001 From: Charles Le Maux Date: Sat, 15 Jun 2024 06:18:57 +0200 Subject: [PATCH 1/2] [+] generic_executor type safety /2 --- .gitignore | 2 +- __pycache__/file_manager.cpython-312.pyc | Bin 3153 -> 4178 bytes __pycache__/generic_executor.cpython-312.pyc | Bin 2777 -> 3092 bytes __pycache__/server_mc_manager.cpython-312.pyc | Bin 3512 -> 3515 bytes api_sender.html | 2 +- generic_executor.py | 19 +++++++++--------- server_mc_manager.py | 1 - 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 37dbd19..31ed2f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/server/ +/servers/ /users/ unit_test.py !*.py diff --git a/__pycache__/file_manager.cpython-312.pyc b/__pycache__/file_manager.cpython-312.pyc index dc76a390a3390e0c6acbc49b591167c1663cae8a..5fda88f3097e9abfd5f233150b531326ad99b313 100644 GIT binary patch delta 1641 zcmah}O>7%Q7@b+K|9=viv`q!3ZfXb)YFwpN<%$p*6!idYL=#R%VY~K@?Ty#FtC@9D zM-C1mQVWViBLgibDo%+aB&3`wA*zUq9*|IeT2yUwf(zULOI6zw-)wA?hy!c+?Kd;u zeDn6ro7wEyiuL^z4hIlCKit)F86QHw@kZ-$HG_t-)EBMgks^GJ(=H{XxE63)RKki# z+&MvUFSyel#j}9YUd0ROQ+$Aa#Sa)z0)RmhQi8=-5TdvOzeMB@UU@9xvOSq{v8YfBllHyH>@k!tRXKCL4wqN2+*9SR55$@i{yJh@EH#t>CeQ+ZGIFdo`6=ib`$K zl&ym8R+-b7GE_Yw*uk8kDTGSSn5fGo!uTq&*t6G?1*1fg1=(aqa+K5s++9;oWaMm- z=t?rDYD6l@x|}C;z^vGvd16Vjrb*L;GS$!-?SwM?TiF``^Jph}^sDrj>E+;d^z<*m z{PlOg6Yh9#d+&sAhwoYmM*#(cA_mWRMRRXhuMEj8x^%MDHE zxrTBWOy#QzqiD6+2YEFooInY2?EI{c5z0R{xz8ND{3-Z1UIzFazl|`bfhNJqbNFLe zavFVsZ(xiT10t%RZ(K8&a+OvPm`@luNh8p(y)6}axmawTcEJ0Yzc!R7I=N!f;n`!& z42fKU?PUW)nvsA_lHr{P5!S_yh4Ujjnw!R9&w-O9cNVOyiJB zV;uNpMEU8kJu2gelJ@b2J8PJgK^la({(KA#re*iyvl7RpK delta 616 zcmZWm&ubJh7)@p-+1VL)TlLUYw60pIi&Q}b6>7bRC)=f+NRP`CU{w=cVcDCtFqf*E9e{gKVn zP;apZ>kX_sj^V05DwEW3$V!m%zdmz9rV{<+MIOm)SXM{QPU86xmue!sB;UN?&FZVw zw+ma|9E6h>{JDE?|BCRRS+G*T$cd??=o+&z-jgE94NsH}0*>1~)-8tBb;A;c0(~=h zPwV<~aGG7j&F181aE{V&5*~Z#AivQ(!)_zr)|<`WoAracY!_IvVB-V(a7^;Bv~8g^<+Jqe QbRneYcl7e?3D0)>3%TK$&;S4c diff --git a/__pycache__/generic_executor.cpython-312.pyc b/__pycache__/generic_executor.cpython-312.pyc index cf68c6bcf6cfca16c60beba66a1241973046d3a9..6008a221f9b1e91854d7859a855c736f08dc30c5 100644 GIT binary patch delta 934 zcmZ8e%}Z2K6o2P^-1jjbI*q1fl#DtylwUR2Fq?{u7#D34gcixnyl0Be2ltuaP#Mu5 zpxhR2im8>+BBe#HLTJ&#O@ai?wp|oFm{zvwocGki3-A2y`JLbWoqNyw*8aS+eL zBwX-$etMEg(sxP@mtVo8`E|Ab%CfCFY+AM1Gxe@+tBz*t_!;;SZ`daC#t}~(vn}LI zp9{{0Ft?6r!pMb=aS`OgM_d$pv^af1Bg<~ZV#F`T4w^Ij1ai?OITc_1IH0N33SU_L z@if9Uyu1q-y7#Y&8YIlwfkM7G=ag;n8pdM{wVW?G4Smt!?rf!8RK%v<275x0pNL60 z4z`$+2d`;0G_cu2>8*krTp%q;Dg8D#ala2kwW#ZGvKXr7s}BD!cW3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edd..af29aae 100644 --- a/api_sender.html +++ b/api_sender.html @@ -11,7 +11,7 @@ Email:
Port:
Name:
- Version:
+ Version:
diff --git a/generic_executor.py b/generic_executor.py index fd14749..ec9e23a 100644 --- a/generic_executor.py +++ b/generic_executor.py @@ -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) \ No newline at end of file diff --git a/server_mc_manager.py b/server_mc_manager.py index aa4a4da..914fc42 100644 --- a/server_mc_manager.py +++ b/server_mc_manager.py @@ -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: From 7147cc9b88eff1c5c64ea5ea5fa85d8a2581ce6c Mon Sep 17 00:00:00 2001 From: Charles Le Maux Date: Sat, 15 Jun 2024 06:20:33 +0200 Subject: [PATCH 2/2] [+] generic_executor type safety /2 --- file_manager.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/file_manager.py b/file_manager.py index 7d6e160..663f4a9 100644 --- a/file_manager.py +++ b/file_manager.py @@ -2,6 +2,17 @@ import os import shutil import re +supported_versions = ["bukkit", "paper", "spigot"] + +def get_all_versions(folder_path="servers/paper"): + return [name for name in os.listdir(folder_path) if os.path.isdir(os.path.join(folder_path, name))] + +def version_exists(version, framework = "paper")->bool: + if framework not in supported_versions: + return False + folder_names = get_all_versions("servers/"+framework) + return any(version in name for name in folder_names) + def create_folder(path): os.makedirs(path, exist_ok=True)