diff --git a/runelite-client/src/main/java/net/runelite/client/RuneLiteProperties.java b/runelite-client/src/main/java/net/runelite/client/RuneLiteProperties.java index a1ff15e2eb..60355dee62 100644 --- a/runelite-client/src/main/java/net/runelite/client/RuneLiteProperties.java +++ b/runelite-client/src/main/java/net/runelite/client/RuneLiteProperties.java @@ -43,6 +43,8 @@ public class RuneLiteProperties private static final String TROUBLESHOOTING_LINK = "runelite.wiki.troubleshooting.link"; private static final String BUILDING_LINK = "runelite.wiki.building.link"; private static final String DNS_CHANGE_LINK = "runelite.dnschange.link"; + private static final String JAV_CONFIG = "runelite.jav_config"; + private static final String JAV_CONFIG_BACKUP = "runelite.jav_config_backup"; private static final Properties properties = new Properties(); @@ -118,4 +120,14 @@ public class RuneLiteProperties { return properties.getProperty(DNS_CHANGE_LINK); } + + public static String getJavConfig() + { + return properties.getProperty(JAV_CONFIG); + } + + public static String getJavConfigBackup() + { + return properties.getProperty(JAV_CONFIG_BACKUP); + } } \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/rs/ClientConfigLoader.java b/runelite-client/src/main/java/net/runelite/client/rs/ClientConfigLoader.java index ed105ec830..19c612bd0e 100644 --- a/runelite-client/src/main/java/net/runelite/client/rs/ClientConfigLoader.java +++ b/runelite-client/src/main/java/net/runelite/client/rs/ClientConfigLoader.java @@ -39,16 +39,8 @@ class ClientConfigLoader { } - private static final String CONFIG_URL = "http://oldschool.runescape.com/jav_config.ws"; - - static RSConfig fetch(String host) throws IOException + static RSConfig fetch(HttpUrl url) throws IOException { - HttpUrl url = HttpUrl.parse(CONFIG_URL); - if (host != null) - { - url = url.newBuilder().host(host).build(); - } - final Request request = new Request.Builder() .url(url) .build(); diff --git a/runelite-client/src/main/java/net/runelite/client/rs/ClientLoader.java b/runelite-client/src/main/java/net/runelite/client/rs/ClientLoader.java index 6a5067561c..1dd110dc68 100644 --- a/runelite-client/src/main/java/net/runelite/client/rs/ClientLoader.java +++ b/runelite-client/src/main/java/net/runelite/client/rs/ClientLoader.java @@ -57,6 +57,7 @@ import javax.swing.SwingUtilities; import lombok.extern.slf4j.Slf4j; import net.runelite.api.Client; import net.runelite.client.RuneLite; +import net.runelite.client.RuneLiteProperties; import static net.runelite.client.rs.ClientUpdateCheckMode.AUTO; import static net.runelite.client.rs.ClientUpdateCheckMode.NONE; import static net.runelite.client.rs.ClientUpdateCheckMode.VANILLA; @@ -154,32 +155,55 @@ public class ClientLoader implements Supplier private void downloadConfig() throws IOException { - String host = null; - for (int attempt = 0; ; attempt++) + HttpUrl url = HttpUrl.parse(RuneLiteProperties.getJavConfig()); + IOException err = null; + for (int attempt = 0; attempt < NUM_ATTEMPTS; attempt++) { try { - config = ClientConfigLoader.fetch(host); + config = ClientConfigLoader.fetch(url); if (Strings.isNullOrEmpty(config.getCodeBase()) || Strings.isNullOrEmpty(config.getInitialJar()) || Strings.isNullOrEmpty(config.getInitialClass())) { throw new IOException("Invalid or missing jav_config"); } - break; + return; } catch (IOException e) { - log.info("Failed to get jav_config from host \"{}\" ({})", host, e.getMessage()); - - if (attempt >= NUM_ATTEMPTS) - { - throw e; - } - - host = hostSupplier.get(); + log.info("Failed to get jav_config from host \"{}\" ({})", url.host(), e.getMessage()); + String host = hostSupplier.get(); + url = url.newBuilder().host(host).build(); + err = e; } } + + log.info("Falling back to backup client config"); + + try + { + RSConfig backupConfig = ClientConfigLoader.fetch(HttpUrl.parse(RuneLiteProperties.getJavConfigBackup())); + + if (Strings.isNullOrEmpty(backupConfig.getCodeBase()) || Strings.isNullOrEmpty(backupConfig.getInitialJar()) || Strings.isNullOrEmpty(backupConfig.getInitialClass())) + { + throw new IOException("Invalid or missing jav_config"); + } + + if (Strings.isNullOrEmpty(backupConfig.getRuneLiteGamepack())) + { + throw new IOException("Backup config does not have RuneLite gamepack url"); + } + + // Randomize the codebase + String codebase = hostSupplier.get(); + backupConfig.setCodebase("http://" + codebase + "/"); + config = backupConfig; + } + catch (IOException ex) + { + throw err; // use error from Jagex's servers + } } private void updateVanilla() throws IOException, VerificationException @@ -217,10 +241,18 @@ public class ClientLoader implements Supplier vanilla.position(0); // Start downloading the vanilla client - - String codebase = config.getCodeBase(); - String initialJar = config.getInitialJar(); - HttpUrl url = HttpUrl.parse(codebase + initialJar); + HttpUrl url; + if (config.getRuneLiteGamepack() != null) + { + // If we are using the backup config, use our own gamepack and ignore the codebase + url = HttpUrl.parse(config.getRuneLiteGamepack()); + } + else + { + String codebase = config.getCodeBase(); + String initialJar = config.getInitialJar(); + url = HttpUrl.parse(codebase + initialJar); + } for (int attempt = 0; ; attempt++) { diff --git a/runelite-client/src/main/java/net/runelite/client/rs/RSConfig.java b/runelite-client/src/main/java/net/runelite/client/rs/RSConfig.java index e0c5539323..a9841755b9 100644 --- a/runelite-client/src/main/java/net/runelite/client/rs/RSConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/rs/RSConfig.java @@ -40,6 +40,11 @@ class RSConfig return classLoaderProperties.get("codebase"); } + void setCodebase(String codebase) + { + classLoaderProperties.put("codebase", codebase); + } + String getInitialJar() { return classLoaderProperties.get("initial_jar"); @@ -49,4 +54,9 @@ class RSConfig { return classLoaderProperties.get("initial_class").replace(".class", ""); } + + String getRuneLiteGamepack() + { + return classLoaderProperties.get("runelite.gamepack"); + } } diff --git a/runelite-client/src/main/resources/net/runelite/client/runelite.properties b/runelite-client/src/main/resources/net/runelite/client/runelite.properties index c29c1e8e39..b9ea63fae9 100644 --- a/runelite-client/src/main/resources/net/runelite/client/runelite.properties +++ b/runelite-client/src/main/resources/net/runelite/client/runelite.properties @@ -9,3 +9,5 @@ runelite.patreon.link=https://www.patreon.com/runelite runelite.wiki.troubleshooting.link=https://github.com/runelite/runelite/wiki/Troubleshooting-problems-with-the-client runelite.wiki.building.link=https://github.com/runelite/runelite/wiki/Building-with-IntelliJ-IDEA#client-failing-to-start runelite.dnschange.link=https://1.1.1.1/dns/ +runelite.jav_config=http://oldschool.runescape.com/jav_config.ws +runelite.jav_config_backup=http://static.runelite.net/jav_config.ws