From c8c1f301c05f3ec2228b24c7ea941cb8a11f9cba Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 1 Mar 2022 18:31:38 -0500 Subject: [PATCH] Fix server importing for bedrock that's not a zip --- app/classes/minecraft/stats.py | 25 +++++++++++++++++-- app/classes/shared/main_controller.py | 19 ++++++++++---- .../panel/parts/server_controls_list.html | 2 +- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/app/classes/minecraft/stats.py b/app/classes/minecraft/stats.py index da5b725e..a775c2aa 100644 --- a/app/classes/minecraft/stats.py +++ b/app/classes/minecraft/stats.py @@ -305,8 +305,30 @@ class Stats: def get_raw_server_stats(self, server_id): + try: + self.controller.get_server_obj(server_id) + except: + return { 'id': server_id, + 'started': False, + 'running': False, + 'cpu': 0, + 'mem': 0, + "mem_percent": 0, + 'world_name': None, + 'world_size': None, + 'server_port': None, + 'int_ping_results': False, + 'online': False, + 'max': False, + 'players': False, + 'desc': False, + 'version': False, + 'icon': False} + server_stats = {} server = self.controller.get_server_obj(server_id) + if not server: + return {} server_dt = servers_helper.get_server_data_by_id(server_id) @@ -314,8 +336,7 @@ class Stats: # get our server object, settings and data dictionaries server_obj = self.controller.get_server_obj(server_id) - if server_obj: - server_obj.reload_server_settings() + server_obj.reload_server_settings() server_settings = self.controller.get_server_settings(server_id) server_data = self.controller.get_server_data(server_id) diff --git a/app/classes/shared/main_controller.py b/app/classes/shared/main_controller.py index 3f87b77b..288eb610 100644 --- a/app/classes/shared/main_controller.py +++ b/app/classes/shared/main_controller.py @@ -1,9 +1,9 @@ import os import pathlib +import shutil import time import logging import tempfile -from distutils import dir_util from typing import Union from peewee import DoesNotExist @@ -329,7 +329,10 @@ class Controller: helper.ensure_dir_exists(new_server_dir) helper.ensure_dir_exists(backup_path) server_path = helper.get_os_understandable_path(server_path) - dir_util.copy_tree(server_path, new_server_dir) + try: + file_helper.copy_dir(server_path, new_server_dir, True) + except shutil.Error as ex: + logger.error(f"Server import failed with error: {ex}") has_properties = False for item in os.listdir(new_server_dir): @@ -418,7 +421,10 @@ class Controller: helper.ensure_dir_exists(new_server_dir) helper.ensure_dir_exists(backup_path) server_path = helper.get_os_understandable_path(server_path) - dir_util.copy_tree(server_path, new_server_dir) + try: + file_helper.copy_dir(server_path, new_server_dir, True) + except shutil.Error as ex: + logger.error(f"Server import failed with error: {ex}") has_properties = False for item in os.listdir(new_server_dir): @@ -443,7 +449,8 @@ class Controller: new_id = self.register_server(server_name, server_id, new_server_dir, backup_path, server_command, server_exe, server_log_file, server_stop, port, server_type='minecraft-bedrock') - os.chmod(full_jar_path, 2775) + if os.name != "nt": + os.chmod(full_jar_path, 2775) return new_id def import_bedrock_zip_server(self, server_name: str, zip_path: str, server_exe: str, port: int): @@ -491,7 +498,9 @@ class Controller: new_id = self.register_server(server_name, server_id, new_server_dir, backup_path, server_command, server_exe, server_log_file, server_stop, port, server_type='minecraft-bedrock') - os.chmod(full_jar_path, 2775) + if os.name != "nt": + os.chmod(full_jar_path, 2775) + return new_id #************************************************************************************************ diff --git a/app/frontend/templates/panel/parts/server_controls_list.html b/app/frontend/templates/panel/parts/server_controls_list.html index 34c6f0a7..a232f022 100644 --- a/app/frontend/templates/panel/parts/server_controls_list.html +++ b/app/frontend/templates/panel/parts/server_controls_list.html @@ -36,7 +36,7 @@ {{ translate('serverDetails', 'config', data['lang']) }} {% end %} - {% if data['permissions']['Players'] in data['user_permissions'] %} + {% if data['permissions']['Players'] in data['user_permissions'] and data['server_data']['type'] != 'minecraft-bedrock' %}