Upstream: merge (#2105)

Upstream: merge

Co-authored-by: null <54878589+Justinmcnabb@users.noreply.github.com>
Co-authored-by: Adam <Adam@sigterm.info>
This commit is contained in:
Owain van Brakel
2019-12-11 05:16:46 +01:00
committed by GitHub
5 changed files with 37 additions and 21 deletions

View File

@@ -39,7 +39,7 @@ enum Tree
{ {
REGULAR_TREE(null, TREE, TREE_1277, TREE_1278, TREE_1279, TREE_1280), REGULAR_TREE(null, TREE, TREE_1277, TREE_1278, TREE_1279, TREE_1280),
OAK_TREE(Duration.ofMillis(8500), ObjectID.OAK_TREE, OAK_TREE_4540, OAK_10820), OAK_TREE(Duration.ofMillis(8500), ObjectID.OAK_TREE, OAK_TREE_4540, OAK_10820),
WILLOW_TREE(Duration.ofMillis(8500), WILLOW, WILLOW_10833, WILLOW_10831), WILLOW_TREE(Duration.ofMillis(8500), WILLOW, WILLOW_10829, WILLOW_10831, WILLOW_10833),
MAPLE_TREE(Duration.ofSeconds(35), ObjectID.MAPLE_TREE, MAPLE_TREE_10832, MAPLE_TREE_36681), MAPLE_TREE(Duration.ofSeconds(35), ObjectID.MAPLE_TREE, MAPLE_TREE_10832, MAPLE_TREE_36681),
TEAK_TREE(Duration.ofMillis(8500), TEAK, TEAK_36686), TEAK_TREE(Duration.ofMillis(8500), TEAK, TEAK_36686),
MAHOGANY_TREE(Duration.ofMillis(8500), MAHOGANY, MAHOGANY_36688), MAHOGANY_TREE(Duration.ofMillis(8500), MAHOGANY, MAHOGANY_36688),

View File

@@ -33,10 +33,12 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.Map;
import java.util.function.Supplier; import java.util.function.Supplier;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.runelite.client.RuneLite; import net.runelite.client.RuneLite;
import net.runelite.client.ui.RuneLiteSplashScreen; import net.runelite.client.ui.RuneLiteSplashScreen;
import net.runelite.http.api.worlds.World;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
@Slf4j @Slf4j
@@ -45,11 +47,11 @@ public class ClientLoader implements Supplier<Applet>
private static final String CONFIG_URL = "http://oldschool.runescape.com/jav_config.ws"; private static final String CONFIG_URL = "http://oldschool.runescape.com/jav_config.ws";
private static final String BACKUP_CONFIG_URL = "https://raw.githubusercontent.com/open-osrs/hosting/master/jav_config.ws"; private static final String BACKUP_CONFIG_URL = "https://raw.githubusercontent.com/open-osrs/hosting/master/jav_config.ws";
private static final int NUM_ATTEMPTS = 6; private static final int NUM_ATTEMPTS = 10;
private final ClientUpdateCheckMode updateCheckMode; private final ClientUpdateCheckMode updateCheckMode;
private Object client = null; private Object client = null;
private HostSupplier hostSupplier = new HostSupplier(); private WorldSupplier worldSupplier = new WorldSupplier();
private RSConfig config; private RSConfig config;
public ClientLoader(ClientUpdateCheckMode updateCheckMode) public ClientLoader(ClientUpdateCheckMode updateCheckMode)
@@ -129,7 +131,7 @@ public class ClientLoader implements Supplier<Applet>
catch (IOException e) catch (IOException e)
{ {
log.info("Failed to get jav_config from host \"{}\" ({})", url.host(), e.getMessage()); 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(); url = url.newBuilder().host(host).build();
err = e; err = e;
} }
@@ -141,14 +143,19 @@ public class ClientLoader implements Supplier<Applet>
{ {
RSConfig backupConfig = ClientConfigLoader.fetch(HttpUrl.parse(BACKUP_CONFIG_URL)); RSConfig backupConfig = ClientConfigLoader.fetch(HttpUrl.parse(BACKUP_CONFIG_URL));
if (Strings.isNullOrEmpty(backupConfig.getCodeBase()) || Strings.isNullOrEmpty(backupConfig.getInitialJar()) || Strings.isNullOrEmpty(backupConfig.getInitialClass())) if (Strings.isNullOrEmpty(backupConfig.getCodeBase()) || Strings.isNullOrEmpty(backupConfig.getInitialJar())
|| Strings.isNullOrEmpty(backupConfig.getInitialClass()) || Strings.isNullOrEmpty(backupConfig.getRuneLiteWorldParam()))
{ {
throw new IOException("Invalid or missing jav_config"); throw new IOException("Invalid or missing jav_config");
} }
// Randomize the codebase // Randomize the codebase
String codebase = hostSupplier.get(); World world = worldSupplier.get();
backupConfig.setCodebase("http://" + codebase + "/"); 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; config = backupConfig;
} }
catch (IOException ex) catch (IOException ex)

View File

@@ -54,4 +54,9 @@ class RSConfig
{ {
return classLoaderProperties.get("initial_class").replace(".class", ""); return classLoaderProperties.get("initial_class").replace(".class", "");
} }
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; import net.runelite.http.api.worlds.WorldType;
@Slf4j @Slf4j
class HostSupplier implements Supplier<String> class WorldSupplier implements Supplier<World>
{ {
private final Random random = new Random(System.nanoTime()); private final Random random = new Random(System.nanoTime());
private Queue<String> hosts = new ArrayDeque<>(); private Queue<World> worlds = new ArrayDeque<>();
@Override @Override
public String get() public World get()
{ {
if (!hosts.isEmpty()) if (!worlds.isEmpty())
{ {
return hosts.poll(); return worlds.poll();
} }
try try
{ {
List<String> newHosts = new WorldClient(RuneLiteAPI.CLIENT) List<World> newWorlds = new WorldClient(RuneLiteAPI.CLIENT)
.lookupWorlds() .lookupWorlds()
.getWorlds() .getWorlds()
.stream() .stream()
.filter(w -> w.getTypes().isEmpty() || EnumSet.of(WorldType.MEMBERS).equals(w.getTypes())) .filter(w -> w.getTypes().isEmpty() || EnumSet.of(WorldType.MEMBERS).equals(w.getTypes()))
.map(World::getAddress)
.collect(Collectors.toList()); .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) catch (IOException e)
{ {
log.warn("Unable to retrieve world list", 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();
} }
} }

View File

@@ -52,7 +52,7 @@ public class MessagePanel extends JPanel
private final JLabel titleLabel = new JLabel("Welcome to OpenOSRS"); private final JLabel titleLabel = new JLabel("Welcome to OpenOSRS");
private final JLabel messageArea; private final JLabel messageArea;
private final JLabel barLabel = new JLabel("Connecting with gameserver (try 1/6)"); private final JLabel barLabel = new JLabel("Connecting with gameserver (try 1/10)");
private final JProgressBar bar = new JProgressBar(0, 100); private final JProgressBar bar = new JProgressBar(0, 100);
@Getter(AccessLevel.NONE) @Getter(AccessLevel.NONE)