diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index 0080285e..7378c9de 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -130,24 +130,33 @@ class Helpers: "Chrome/104.0.0.0 Safari/537.36" ), } - target_win = 'https://minecraft.azureedge.net/bin-win/[^"]*' - target_linux = 'https://minecraft.azureedge.net/bin-linux/[^"]*' - + target_win = 'https://www.minecraft.net/bedrockdedicatedserver/bin-win/[^"]*' + target_linux = ( + 'https://www.minecraft.net/bedrockdedicatedserver/bin-linux/[^"]*' + ) try: # Get minecraft server download page # (hopefully the don't change the structure) download_page = get(url, headers=headers, timeout=1) - + download_page.raise_for_status() # Search for our string targets - win_download_url = re.search(target_win, download_page.text).group(0) - linux_download_url = re.search(target_linux, download_page.text).group(0) + win_search_result = re.search(target_win, download_page.text) + linux_search_result = re.search(target_linux, download_page.text) + if win_search_result is None or linux_search_result is None: + raise RuntimeError( + "Could not determine download URL from minecraft.net." + ) + win_download_url = win_search_result.group(0) + linux_download_url = linux_search_result.group(0) + print(win_download_url, linux_download_url) if os.name == "nt": return win_download_url return linux_download_url except Exception as e: logger.error(f"Unable to resolve remote bedrock download url! \n{e}") + raise e return False def get_execution_java(self, value, execution_command): diff --git a/app/classes/shared/import_helper.py b/app/classes/shared/import_helper.py index 030feb56..d0063409 100644 --- a/app/classes/shared/import_helper.py +++ b/app/classes/shared/import_helper.py @@ -217,15 +217,16 @@ class ImportHelpers: FileHelpers.del_dirs(temp_dir) def download_bedrock_server(self, path, new_id): + bedrock_url = Helpers.get_latest_bedrock_url() download_thread = threading.Thread( target=self.download_threaded_bedrock_server, daemon=True, - args=(path, new_id), + args=(path, new_id, bedrock_url), name=f"{new_id}_download", ) download_thread.start() - def download_threaded_bedrock_server(self, path, new_id): + def download_threaded_bedrock_server(self, path, new_id, bedrock_url): """ Downloads the latest Bedrock server, unzips it, sets necessary permissions. @@ -236,10 +237,8 @@ class ImportHelpers: This method handles exceptions and logs errors for each step of the process. """ try: - bedrock_url = Helpers.get_latest_bedrock_url() if bedrock_url: file_path = os.path.join(path, "bedrock_server.zip") - success = FileHelpers.ssl_get_file( bedrock_url, path, "bedrock_server.zip" ) @@ -263,6 +262,7 @@ class ImportHelpers: logger.critical( f"Failed to download bedrock executable during server creation! \n{e}" ) + raise e ServersController.finish_import(new_id) server_users = PermissionsServers.get_server_user_list(new_id) diff --git a/app/classes/web/routes/api/servers/index.py b/app/classes/web/routes/api/servers/index.py index ca551326..dac580e8 100644 --- a/app/classes/web/routes/api/servers/index.py +++ b/app/classes/web/routes/api/servers/index.py @@ -725,7 +725,19 @@ class ApiServersIndexHandler(BaseApiHandler): 405, {"status": "error", "error": "DATA CONSTRAINT FAILED"} ) return - new_server_id = self.controller.create_api_server(data, user["user_id"]) + try: + new_server_id = self.controller.create_api_server(data, user["user_id"]) + except Exception as e: + self.controller.servers.stats.record_stats() + + self.finish_json( + 200, + { + "status": "error", + "error": "Could not create server", + "error_data": str(e), + }, + ) self.controller.servers.stats.record_stats() diff --git a/app/frontend/templates/server/bedrock_wizard.html b/app/frontend/templates/server/bedrock_wizard.html index 7c4789f7..e046bcf3 100644 --- a/app/frontend/templates/server/bedrock_wizard.html +++ b/app/frontend/templates/server/bedrock_wizard.html @@ -624,7 +624,9 @@ if (responseData.status === "ok") { window.location.href = '/panel/dashboard'; } else { - + // Close the "be patient..." dialogue box + $('.bootbox-close-button').click(); + // Alert the user that there was an issue. bootbox.alert({ title: responseData.error, message: responseData.error_data @@ -783,4 +785,4 @@ -{% end %} \ No newline at end of file +{% end %}