From d5cc4529b00ae93b60549a177cc4128a3f029ca3 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 21 Dec 2022 21:55:21 -0500 Subject: [PATCH 1/5] Add try/except for not finding run file --- app/classes/shared/server.py | 83 +++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index ccc50f70..421e1568 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -587,47 +587,52 @@ class ServerInstance: # We need to grab the exact forge version number. # We know we can find it here in the run.sh/bat script. - run_file_path = "" - if self.helper.is_os_windows(): - run_file_path = os.path.join(server_obj.path, "run.bat") - else: - run_file_path = os.path.join(server_obj.path, "run.sh") + try: + run_file_path = "" + if self.helper.is_os_windows(): + run_file_path = os.path.join(server_obj.path, "run.bat") + else: + run_file_path = os.path.join(server_obj.path, "run.sh") - if Helpers.check_file_perms(run_file_path) and os.path.isfile( - run_file_path - ): - run_file = open(run_file_path, "r", encoding="utf-8") - run_file_text = run_file.read() - else: - Console.error( - "ERROR ! Forge install can't read the scripts files." - " Aborting ..." + if Helpers.check_file_perms(run_file_path) and os.path.isfile( + run_file_path + ): + run_file = open(run_file_path, "r", encoding="utf-8") + run_file_text = run_file.read() + else: + Console.error( + "ERROR ! Forge install can't read the scripts files." + " Aborting ..." + ) + return + + # We get the server command parameters from forge script + server_command = re.findall( + r"java @([a-zA-Z0-9_\.]+)" + r" @([a-z.\/\-]+)([0-9.\-]+)\/\b([a-z_0-9]+\.txt)\b( .{2,4})?", + run_file_text, + )[0] + + version = server_command[2] + executable_path = f"{server_command[1]}{server_command[2]}/" + + # Let's set the proper server executable + server_obj.executable = os.path.join( + f"{executable_path}forge-{version}-server.jar" ) - return - - # We get the server command parameters from forge script - server_command = re.findall( - r"java @([a-zA-Z0-9_\.]+)" - r" @([a-z.\/\-]+)([0-9.\-]+)\/\b([a-z_0-9]+\.txt)\b( .{2,4})?", - run_file_text, - )[0] - - version = server_command[2] - executable_path = f"{server_command[1]}{server_command[2]}/" - - # Let's set the proper server executable - server_obj.executable = os.path.join( - f"{executable_path}forge-{version}-server.jar" - ) - # Now lets set up the new run command. - # This is based off the run.sh/bat that - # Forge uses in 1.16 and < - execution_command = ( - f"java @{server_command[0]}" - f" @{executable_path}{server_command[3]} nogui {server_command[4]}" - ) - server_obj.execution_command = execution_command - Console.debug("SUCCESS! Forge install completed") + # Now lets set up the new run command. + # This is based off the run.sh/bat that + # Forge uses in 1.17 and < + execution_command = ( + f"java @{server_command[0]}" + f" @{executable_path}{server_command[3]} nogui" + " {server_command[4]}" + ) + server_obj.execution_command = execution_command + Console.debug("SUCCESS! Forge install completed") + except: + logger.debug("Could not find run file.") + # TODO Use regex to get version and rebuild simple execution # We'll update the server with the new information now. HelperServers.update_server(server_obj) From 9dac0b5d85532fa4c312fe653319fdb7dac156c7 Mon Sep 17 00:00:00 2001 From: Silversthorn Date: Thu, 22 Dec 2022 19:32:56 +0100 Subject: [PATCH 2/5] Adding Forge Installer Compaptibility with old versions --- app/classes/shared/server.py | 122 ++++++++++++++++++++++++----------- 1 file changed, 84 insertions(+), 38 deletions(-) diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index 421e1568..86afa1cf 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -10,6 +10,7 @@ import logging.config import subprocess import html import urllib.request +import glob # TZLocal is set as a hidden import on win pipeline from tzlocal import get_localzone @@ -580,7 +581,7 @@ class ServerInstance: # Process has exited. Lets do some work to setup the new # run command. # Let's grab the server object we're going to update. - server_obj = HelperServers.get_server_obj(self.server_id) + server_obj: Servers = HelperServers.get_server_obj(self.server_id) # The forge install is done so we can delete that install file. os.remove(os.path.join(server_obj.path, server_obj.executable)) @@ -588,48 +589,93 @@ class ServerInstance: # We need to grab the exact forge version number. # We know we can find it here in the run.sh/bat script. try: - run_file_path = "" - if self.helper.is_os_windows(): - run_file_path = os.path.join(server_obj.path, "run.bat") - else: - run_file_path = os.path.join(server_obj.path, "run.sh") - if Helpers.check_file_perms(run_file_path) and os.path.isfile( - run_file_path - ): - run_file = open(run_file_path, "r", encoding="utf-8") - run_file_text = run_file.read() - else: - Console.error( - "ERROR ! Forge install can't read the scripts files." - " Aborting ..." + # Getting the forge version from the executable command + version = re.findall( + r"forge-([0-9\.]+)((?:)|(?:-([0-9\.]+)-[a-zA-Z]+)).jar", + server_obj.execution_command, + ) + version_param = version[0][0].split(".") + version_major = int(version_param[0]) + version_minor = int(version_param[1]) + + # Checking which version we are with + if version_major <= 1 and version_minor < 17: + # OLD VERSION < 1.17 + + # Retrieving the executable jar filename + file_path = glob.glob( + f"{server_obj.path}/forge-{version[0][0]}*.jar" + )[0] + file_name = re.findall( + r"(forge[-0-9.]+.jar)", + file_path, + )[0] + + # Let's set the proper server executable + server_obj.executable = os.path.join(file_name) + + # Get memory values + memory_values = re.findall( + r"-Xms([A-Z0-9\.]+) -Xmx([A-Z0-9\.]+)", + server_obj.execution_command, ) - return - # We get the server command parameters from forge script - server_command = re.findall( - r"java @([a-zA-Z0-9_\.]+)" - r" @([a-z.\/\-]+)([0-9.\-]+)\/\b([a-z_0-9]+\.txt)\b( .{2,4})?", - run_file_text, - )[0] + # Now lets set up the new run command. + # This is based off the run.sh/bat that + # Forge uses in 1.17 and < + execution_command = ( + f"java -Xms{memory_values[0][0]} -Xmx{memory_values[0][1]}" + f' -jar "{file_name}" nogui' + ) + server_obj.execution_command = execution_command + Console.debug("SUCCESS! Forge install completed") - version = server_command[2] - executable_path = f"{server_command[1]}{server_command[2]}/" + else: + # NEW VERSION >= 1.17 - # Let's set the proper server executable - server_obj.executable = os.path.join( - f"{executable_path}forge-{version}-server.jar" - ) - # Now lets set up the new run command. - # This is based off the run.sh/bat that - # Forge uses in 1.17 and < - execution_command = ( - f"java @{server_command[0]}" - f" @{executable_path}{server_command[3]} nogui" - " {server_command[4]}" - ) - server_obj.execution_command = execution_command - Console.debug("SUCCESS! Forge install completed") + run_file_path = "" + if self.helper.is_os_windows(): + run_file_path = os.path.join(server_obj.path, "run.bat") + else: + run_file_path = os.path.join(server_obj.path, "run.sh") + + if Helpers.check_file_perms(run_file_path) and os.path.isfile( + run_file_path + ): + run_file = open(run_file_path, "r", encoding="utf-8") + run_file_text = run_file.read() + else: + Console.error( + "ERROR ! Forge install can't read the scripts files." + " Aborting ..." + ) + return + + # We get the server command parameters from forge script + server_command = re.findall( + r"java @([a-zA-Z0-9_\.]+)" + r" @([a-z.\/\-]+)([0-9.\-]+)\/\b([a-z_0-9]+\.txt)\b( .{2,4})?", + run_file_text, + )[0] + + version = server_command[2] + executable_path = f"{server_command[1]}{server_command[2]}/" + + # Let's set the proper server executable + server_obj.executable = os.path.join( + f"{executable_path}forge-{version}-server.jar" + ) + # Now lets set up the new run command. + # This is based off the run.sh/bat that + # Forge uses in 1.17 and < + execution_command = ( + f"java @{server_command[0]}" + f" @{executable_path}{server_command[3]} nogui" + " {server_command[4]}" + ) + server_obj.execution_command = execution_command + Console.debug("SUCCESS! Forge install completed") except: logger.debug("Could not find run file.") # TODO Use regex to get version and rebuild simple execution From ddaac250606a1dc2a90dfaa29af8e33165c4f65e Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 23 Dec 2022 20:14:41 -0500 Subject: [PATCH 3/5] Run forge installer for all versions of forge --- app/classes/minecraft/serverjars.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/classes/minecraft/serverjars.py b/app/classes/minecraft/serverjars.py index a656944b..3ecfdb8f 100644 --- a/app/classes/minecraft/serverjars.py +++ b/app/classes/minecraft/serverjars.py @@ -192,7 +192,7 @@ class ServerJars: with open(path, "wb") as output: shutil.copyfileobj(r.raw, output) # If this is the newer forge version we will run the installer - if server == "forge" and int(version.split(".")[1]) > 15: + if server == "forge": ServersController.finish_import(server_id, True) else: ServersController.finish_import(server_id) From c80d357f13a1ed23c6d19e3b37aa81461149172a Mon Sep 17 00:00:00 2001 From: Zedifus Date: Mon, 2 Jan 2023 20:59:29 +0000 Subject: [PATCH 4/5] Fix CodeQuality, line length --- app/classes/shared/server.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index 86afa1cf..745d840d 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -655,7 +655,8 @@ class ServerInstance: # We get the server command parameters from forge script server_command = re.findall( r"java @([a-zA-Z0-9_\.]+)" - r" @([a-z.\/\-]+)([0-9.\-]+)\/\b([a-z_0-9]+\.txt)\b( .{2,4})?", + r" @([a-z.\/\-]+)([0-9.\-]+)" + r"\/\b([a-z_0-9]+\.txt)\b( .{2,4})?", run_file_text, )[0] From d4d8fa21d5cf014648b8bd6fe74c2e7a5b05f25e Mon Sep 17 00:00:00 2001 From: Zedifus Date: Mon, 2 Jan 2023 21:01:46 +0000 Subject: [PATCH 5/5] Update changelog !515 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a61a3c7b..cb023634 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ TBD - Fix root dir selection in Upload Zip Import ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/508)) - Fix stats error on mac M1 chips ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/512)) - Fix window path escape on java override ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/513)) +- Fix Forge import stalling on 1.17 Forge servers ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/515)) ### Tweaks - Make server directories non-configurable ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/511)) - Add popover to server port to detail it's purpose ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/514))