From 2ddc1e7c9622ed8629edac0ac4d690b8c47291b1 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 16 Jul 2022 19:05:00 -0400 Subject: [PATCH] Remove server.props requirement --- app/classes/controllers/servers_controller.py | 22 ------- app/classes/minecraft/server_props.py | 66 ------------------- app/classes/minecraft/stats.py | 5 -- app/classes/shared/server.py | 14 ++-- 4 files changed, 4 insertions(+), 103 deletions(-) delete mode 100644 app/classes/minecraft/server_props.py diff --git a/app/classes/controllers/servers_controller.py b/app/classes/controllers/servers_controller.py index ca59fbdc..5168695a 100644 --- a/app/classes/controllers/servers_controller.py +++ b/app/classes/controllers/servers_controller.py @@ -13,7 +13,6 @@ from app.classes.shared.console import Console from app.classes.shared.helpers import Helpers from app.classes.shared.main_models import DatabaseShortcuts -from app.classes.minecraft.server_props import ServerProps from app.classes.minecraft.stats import Stats from app.classes.models.servers import HelperServers @@ -171,18 +170,6 @@ class ServersController(metaclass=Singleton): ) continue - settings_file = os.path.join( - Helpers.get_os_understandable_path(server["path"]), "server.properties" - ) - - # if the properties file isn't there, let's warn - if not Helpers.check_file_exists(settings_file): - logger.error(f"Unable to find {settings_file}. Skipping this server.") - Console.error(f"Unable to find {settings_file}. Skipping this server.") - continue - - settings = ServerProps(settings_file) - temp_server_dict = { "server_id": server.get("server_id"), "server_data_obj": server, @@ -193,7 +180,6 @@ class ServersController(metaclass=Singleton): self.stats, self.file_helper, ), - "server_settings": settings.props, } # setup the server, do the auto start and all that jazz @@ -350,14 +336,6 @@ class ServersController(metaclass=Singleton): def get_server_friendly_name(server_id): return HelperServers.get_server_friendly_name(server_id) - def get_server_settings(self, server_id): - for server in self.servers_list: - if int(server["server_id"]) == int(server_id): - return server["server_settings"] - - logger.warning(f"Unable to find server object for server id {server_id}") - return False - def crash_detection(self, server_obj): svr = self.get_server_instance_by_id(server_obj.server_id) # start or stop crash detection depending upon user preference diff --git a/app/classes/minecraft/server_props.py b/app/classes/minecraft/server_props.py deleted file mode 100644 index cc54a148..00000000 --- a/app/classes/minecraft/server_props.py +++ /dev/null @@ -1,66 +0,0 @@ -import pprint -import os - - -class ServerProps: - def __init__(self, filepath): - self.filepath = filepath - self.props = self._parse() - - def _parse(self): - # Loads and parses the file specified in self.filepath - with open(self.filepath, encoding="utf-8") as full_path: - line = full_path.readline() - dictionary = {} - if os.path.exists(".header"): - os.remove(".header") - while line: - if "#" != line[0]: - string = line - string1 = string[: string.find("=")] - if "\n" in string: - string2 = string[string.find("=") + 1 : string.find("\n")] - else: - string2 = string[string.find("=") + 1 :] - dictionary[string1] = string2 - else: - with open(".header", "a+", encoding="utf-8") as header: - header.write(line) - line = full_path.readline() - return dictionary - - def print(self): - # Prints the properties dictionary (using pprint) - pprint.pprint(self.props) - - def get(self): - # Returns the properties dictionary - return self.props - - def update(self, key, val): - # Updates property in the properties dictionary [ update("pvp", "true") ] - # and returns boolean condition - if key in self.props.keys(): - self.props[key] = val - return True - return False - - def save(self): - # Writes to the new file - with open(self.filepath, "a+", encoding="utf-8") as f: - f.truncate(0) - with open(".header", encoding="utf-8") as header: - line = header.readline() - while line: - f.write(line) - line = header.readline() - header.close() - for key, value in self.props.items(): - f.write(key + "=" + value + "\n") - if os.path.exists(".header"): - os.remove(".header") - - @staticmethod - def cleanup(): - if os.path.exists(".header"): - os.remove(".header") diff --git a/app/classes/minecraft/stats.py b/app/classes/minecraft/stats.py index 64cbf894..ff0b092f 100644 --- a/app/classes/minecraft/stats.py +++ b/app/classes/minecraft/stats.py @@ -224,11 +224,6 @@ class Stats: logger.info(f"Getting players for server {server}") - # get our settings and data dictionaries - # server_settings = server.get('server_settings', {}) - # server_data = server.get('server_data_obj', {}) - - # TODO: search server properties file for possible override of 127.0.0.1 internal_ip = server["server_ip"] server_port = server["server_port"] diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index d1ae524c..2391b827 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -1244,7 +1244,6 @@ class ServerInstance: # process stats p_stats = Stats._try_get_process_stats(self.process, self.check_running()) - # TODO: search server properties file for possible override of 127.0.0.1 internal_ip = server["server_ip"] server_port = server["server_port"] server_name = server.get("server_name", f"ID#{server_id}") @@ -1253,7 +1252,10 @@ class ServerInstance: if HelperServers.get_server_type_by_id(server_id) == "minecraft-bedrock": int_mc_ping = ping_bedrock(internal_ip, int(server_port)) else: - int_mc_ping = ping(internal_ip, int(server_port)) + try: + int_mc_ping = ping(internal_ip, int(server_port)) + except: + int_mc_ping = False int_data = False ping_data = {} @@ -1315,11 +1317,6 @@ class ServerInstance: logger.info(f"Getting players for server {server}") - # get our settings and data dictionaries - # server_settings = server.get('server_settings', {}) - # server_data = server.get('server_data_obj', {}) - - # TODO: search server properties file for possible override of 127.0.0.1 internal_ip = server["server_ip"] server_port = server["server_port"] @@ -1377,9 +1374,6 @@ class ServerInstance: # process stats p_stats = Stats._try_get_process_stats(self.process, self.check_running()) - # TODO: search server properties file for possible override of 127.0.0.1 - # internal_ip = server['server_ip'] - # server_port = server['server_port'] internal_ip = server_dt["server_ip"] server_port = server_dt["server_port"]