Skip to content

Commit

Permalink
Added fallback URLs for server list
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuken committed Oct 13, 2024
1 parent 3545ed1 commit c2405a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions core/src/mindustry/Vars.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*/
Expand Down
20 changes: 16 additions & 4 deletions core/src/mindustry/ui/dialogs/JoinDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -631,12 +631,24 @@ private void loadServers(){
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<ServerGroup> servers = new Seq<>();
Expand Down

0 comments on commit c2405a8

Please sign in to comment.