Added fallback URLs for server list

This commit is contained in:
Anuken
2024-10-12 22:16:37 -04:00
parent 3545ed100c
commit c2405a882c
2 changed files with 18 additions and 6 deletions

View File

@@ -72,9 +72,9 @@ public class Vars implements Loadable{
/** URL the links to the wiki's modding guide.*/ /** URL the links to the wiki's modding guide.*/
public static final String modGuideURL = "https://mindustrygame.github.io/wiki/modding/1-modding/"; 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. */ /** 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. */ /** 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.*/ /** 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"; public static final String reportIssueURL = "https://github.com/Anuken/Mindustry/issues/new?labels=bug&template=bug_report.md";
/** list of built-in servers.*/ /** list of built-in servers.*/

View File

@@ -631,12 +631,24 @@ public class JoinDialog extends BaseDialog{
Core.settings.remove("server-list"); Core.settings.remove("server-list");
} }
var url = Version.type.equals("bleeding-edge") || Vars.forceBeServers ? serverJsonBeURL : serverJsonURL; var urls = Version.type.equals("bleeding-edge") || Vars.forceBeServers ? serverJsonBeURLs : serverJsonURLs;
Log.info("Fetching community servers at @", url);
fetchServers(urls, 0);
}
private void fetchServers(String[] urls, int index){
if(index >= urls.length) return;
//get servers //get servers
Http.get(url) Http.get(urls[index])
.error(t -> Log.err("Failed to fetch community servers", t)) .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 -> { .submit(result -> {
Jval val = Jval.read(result.getResultAsString()); Jval val = Jval.read(result.getResultAsString());
Seq<ServerGroup> servers = new Seq<>(); Seq<ServerGroup> servers = new Seq<>();