From e7e337bea1c7b582087006c316ca4d7b96e0328f Mon Sep 17 00:00:00 2001 From: luukas Date: Mon, 16 May 2022 18:16:04 +0300 Subject: [PATCH] Improve the start_server function --- app/classes/shared/server.py | 38 +++++++++++++----------------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index af0073cf..73f22705 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -261,27 +261,18 @@ class Server: # Checks for eula. Creates one if none detected. # If EULA is detected and not set to true we offer to set it true. + e_flag = False if Helpers.check_file_exists(os.path.join(self.settings["path"], "eula.txt")): - f = open( + with open( os.path.join(self.settings["path"], "eula.txt"), "r", encoding="utf-8" - ) - line = f.readline().lower() - if line == "eula=true": - e_flag = True - - elif line == "eula = true": - e_flag = True - - elif line == "eula= true": - e_flag = True - - elif line == "eula =true": - e_flag = True - - else: - e_flag = False - else: - e_flag = False + ) as f: + line = f.readline().lower() + e_flag = line in [ + "eula=true", + "eula = true", + "eula= true", + "eula =true", + ] if not e_flag: if user_id: @@ -293,9 +284,7 @@ class Server: "Autostart failed due to EULA being false. " "Agree not sent due to auto start." ) - return False return False - f.close() if Helpers.is_os_windows(): logger.info("Windows Detected") else: @@ -307,15 +296,16 @@ class Server: # checks to make sure file is openable (downloaded) and exists. try: - f = open( + with open( os.path.join( self.server_path, HelperServers.get_server_data_by_id(self.server_id)["executable"], ), "r", encoding="utf-8", - ) - f.close() + ): + # Can open the file + pass except: if user_id: