client loader: fix incorrect applet world when using fallback config

This commit is contained in:
Adam
2019-12-05 13:49:59 -05:00
parent 3f8331fbd5
commit 5494249636
3 changed files with 34 additions and 18 deletions

View File

@@ -50,6 +50,7 @@ import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.function.Supplier;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
@@ -64,6 +65,7 @@ import static net.runelite.client.rs.ClientUpdateCheckMode.VANILLA;
import net.runelite.client.ui.FatalErrorDialog;
import net.runelite.client.ui.SplashScreen;
import net.runelite.http.api.RuneLiteAPI;
import net.runelite.http.api.worlds.World;
import okhttp3.HttpUrl;
import okhttp3.Request;
import okhttp3.Response;
@@ -80,7 +82,7 @@ public class ClientLoader implements Supplier<Applet>
private ClientUpdateCheckMode updateCheckMode;
private Object client = null;
private HostSupplier hostSupplier = new HostSupplier();
private WorldSupplier worldSupplier = new WorldSupplier();
private RSConfig config;
public ClientLoader(ClientUpdateCheckMode updateCheckMode)
@@ -173,7 +175,7 @@ public class ClientLoader implements Supplier<Applet>
catch (IOException e)
{
log.info("Failed to get jav_config from host \"{}\" ({})", url.host(), e.getMessage());
String host = hostSupplier.get();
String host = worldSupplier.get().getAddress();
url = url.newBuilder().host(host).build();
err = e;
}
@@ -190,14 +192,19 @@ public class ClientLoader implements Supplier<Applet>
throw new IOException("Invalid or missing jav_config");
}
if (Strings.isNullOrEmpty(backupConfig.getRuneLiteGamepack()))
if (Strings.isNullOrEmpty(backupConfig.getRuneLiteGamepack()) || Strings.isNullOrEmpty(backupConfig.getRuneLiteWorldParam()))
{
throw new IOException("Backup config does not have RuneLite gamepack url");
}
// Randomize the codebase
String codebase = hostSupplier.get();
backupConfig.setCodebase("http://" + codebase + "/");
World world = worldSupplier.get();
backupConfig.setCodebase("http://" + world.getAddress() + "/");
// Update the world applet parameter
Map<String, String> appletProperties = backupConfig.getAppletProperties();
appletProperties.put(backupConfig.getRuneLiteWorldParam(), Integer.toString(world.getId()));
config = backupConfig;
}
catch (IOException ex)
@@ -347,7 +354,7 @@ public class ClientLoader implements Supplier<Applet>
throw e;
}
url = url.newBuilder().host(hostSupplier.get()).build();
url = url.newBuilder().host(worldSupplier.get().getAddress()).build();
}
}
}

View File

@@ -59,4 +59,9 @@ class RSConfig
{
return classLoaderProperties.get("runelite.gamepack");
}
String getRuneLiteWorldParam()
{
return classLoaderProperties.get("runelite.worldparam");
}
}

View File

@@ -40,43 +40,47 @@ import net.runelite.http.api.worlds.WorldClient;
import net.runelite.http.api.worlds.WorldType;
@Slf4j
class HostSupplier implements Supplier<String>
class WorldSupplier implements Supplier<World>
{
private final Random random = new Random(System.nanoTime());
private Queue<String> hosts = new ArrayDeque<>();
private Queue<World> worlds = new ArrayDeque<>();
@Override
public String get()
public World get()
{
if (!hosts.isEmpty())
if (!worlds.isEmpty())
{
return hosts.poll();
return worlds.poll();
}
try
{
List<String> newHosts = new WorldClient(RuneLiteAPI.CLIENT)
List<World> newWorlds = new WorldClient(RuneLiteAPI.CLIENT)
.lookupWorlds()
.getWorlds()
.stream()
.filter(w -> w.getTypes().isEmpty() || EnumSet.of(WorldType.MEMBERS).equals(w.getTypes()))
.map(World::getAddress)
.collect(Collectors.toList());
Collections.shuffle(newHosts, random);
Collections.shuffle(newWorlds, random);
hosts.addAll(newHosts.subList(0, 16));
worlds.addAll(newWorlds.subList(0, 16));
}
catch (IOException e)
{
log.warn("Unable to retrieve world list", e);
}
while (hosts.size() < 2)
while (worlds.size() < 2)
{
hosts.add("oldschool" + (random.nextInt(50) + 1) + ".runescape.COM");
int id = random.nextInt(50) + 1;
World world = World.builder()
.id(300 + id) // worlds start at 300
.address("oldschool" + id + ".runescape.COM")
.build();
worlds.add(world);
}
return hosts.poll();
return worlds.poll();
}
}