mirror of
https://github.com/hubHarmony/servii-backend.git
synced 2024-11-17 21:40:31 +00:00
[+] Server deletion safety
Errors are correctly logged in firebase. User can't break the website anymore. Signed-off-by: Charles Le Maux <charles.le-maux@epitech.eu>
This commit is contained in:
parent
87a242f131
commit
fa9ba6d3e0
@ -107,6 +107,11 @@ def server_create(user: UserRecord, name: str, version: str, framework: str = "p
|
||||
|
||||
def server_delete(name: str, user: UserRecord) -> tuple[HTTPStatus, str or None]:
|
||||
user_id = user.uid
|
||||
try:
|
||||
port: int = firebase_manager.get_server_port(user_id)
|
||||
mc_manager.stop_server_forcefully(port)
|
||||
except Exception as e:
|
||||
file_manager.log_error(type(e).__name__, str(e)+f" error when stopping server {name}")
|
||||
server_path: str = f"users/{user_id}/{name}"
|
||||
try:
|
||||
firebase_manager.delete_server(user_id, name)
|
||||
|
@ -18,7 +18,7 @@ class MinecraftServerManager:
|
||||
if port in self.servers:
|
||||
return None
|
||||
|
||||
command = f"{java_executable} -Xmx{memory_size} -Xms{memory_size} -jar {jar_file} > /dev/null"
|
||||
command = f"{java_executable} -Xmx{memory_size} -Xms{memory_size} -jar {jar_file} --nogui > /dev/null"
|
||||
process = subprocess.Popen(shlex.split(command), cwd=server_directory, stdin=subprocess.PIPE)
|
||||
|
||||
self.servers_count = len(self.servers) + 1
|
||||
@ -45,12 +45,12 @@ class MinecraftServerManager:
|
||||
del self.servers[port]
|
||||
return True
|
||||
|
||||
def stop_server_forcefully(self, server_id) -> bool:
|
||||
if server_id not in self.servers:
|
||||
def stop_server_forcefully(self, port) -> bool:
|
||||
if port not in self.servers:
|
||||
return False
|
||||
process = self.servers[server_id]['process']
|
||||
process = self.servers[port]['process']
|
||||
process.terminate()
|
||||
del self.servers[server_id]
|
||||
del self.servers[port]
|
||||
return True
|
||||
|
||||
def get_servers(self):
|
||||
|
Loading…
Reference in New Issue
Block a user