From c2405a882cff5c65196018c0dae215e71247b68c Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 12 Oct 2024 22:16:37 -0400 Subject: [PATCH] Added fallback URLs for server list --- core/src/mindustry/Vars.java | 4 ++-- core/src/mindustry/ui/dialogs/JoinDialog.java | 20 +++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/core/src/mindustry/Vars.java b/core/src/mindustry/Vars.java index 2eb0e16ca5..c838f55c15 100644 --- a/core/src/mindustry/Vars.java +++ b/core/src/mindustry/Vars.java @@ -72,9 +72,9 @@ public class Vars implements Loadable{ /** URL the links to the wiki's modding guide.*/ public static final String modGuideURL = "https://mindustrygame.github.io/wiki/modding/1-modding/"; /** URL to the JSON file containing all the BE servers. Only queried in BE. */ - public static final String serverJsonBeURL = "https://raw.githubusercontent.com/Anuken/MindustryServerList/master/servers_be.json"; + public static final String[] serverJsonBeURLs = {"https://raw.githubusercontent.com/Anuken/MindustryServerList/master/servers_be.json", "https://cdn.jsdelivr.net/gh/anuken/mindustryserverlist/servers_be.json"}; /** URL to the JSON file containing all the stable servers. */ - public static final String serverJsonURL = "https://raw.githubusercontent.com/Anuken/MindustryServerList/master/servers_v8.json"; + public static final String[] serverJsonURLs = {"https://raw.githubusercontent.com/Anuken/MindustryServerList/master/servers_v8.json", "https://cdn.jsdelivr.net/gh/anuken/mindustryserverlist/servers_v8.json"}; /** URL of the github issue report template.*/ public static final String reportIssueURL = "https://github.com/Anuken/Mindustry/issues/new?labels=bug&template=bug_report.md"; /** list of built-in servers.*/ diff --git a/core/src/mindustry/ui/dialogs/JoinDialog.java b/core/src/mindustry/ui/dialogs/JoinDialog.java index b0912c7b9c..f6e4191c7b 100644 --- a/core/src/mindustry/ui/dialogs/JoinDialog.java +++ b/core/src/mindustry/ui/dialogs/JoinDialog.java @@ -631,12 +631,24 @@ public class JoinDialog extends BaseDialog{ Core.settings.remove("server-list"); } - var url = Version.type.equals("bleeding-edge") || Vars.forceBeServers ? serverJsonBeURL : serverJsonURL; - Log.info("Fetching community servers at @", url); + var urls = Version.type.equals("bleeding-edge") || Vars.forceBeServers ? serverJsonBeURLs : serverJsonURLs; + + fetchServers(urls, 0); + } + + private void fetchServers(String[] urls, int index){ + if(index >= urls.length) return; //get servers - Http.get(url) - .error(t -> Log.err("Failed to fetch community servers", t)) + Http.get(urls[index]) + .error(t -> { + if(index < urls.length - 1){ + //attempt fetching from the next URL upon failure + fetchServers(urls, index + 1); + }else{ + Log.err("Failed to fetch community servers", t); + } + }) .submit(result -> { Jval val = Jval.read(result.getResultAsString()); Seq servers = new Seq<>();