upstream: merge

upstream: merge
This commit is contained in:
xKylee
2019-12-07 00:22:32 +00:00
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),
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),
TEAK_TREE(Duration.ofMillis(8500), TEAK, TEAK_36686),
MAHOGANY_TREE(Duration.ofMillis(8500), MAHOGANY, MAHOGANY_36688),

View File

@@ -33,10 +33,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Map;
import java.util.function.Supplier;
import lombok.extern.slf4j.Slf4j;
import net.runelite.client.RuneLite;
import net.runelite.client.ui.RuneLiteSplashScreen;
import net.runelite.http.api.worlds.World;
import okhttp3.HttpUrl;
@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 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 Object client = null;
private HostSupplier hostSupplier = new HostSupplier();
private WorldSupplier worldSupplier = new WorldSupplier();
private RSConfig config;
public ClientLoader(ClientUpdateCheckMode updateCheckMode)
@@ -129,7 +131,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;
}
@@ -141,14 +143,19 @@ public class ClientLoader implements Supplier<Applet>
{
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");
}
// 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)
@@ -215,4 +222,4 @@ public class ClientLoader implements Supplier<Applet>
rs.setStub(new RSAppletStub(config));
return rs;
}
}
}

View File

@@ -54,4 +54,9 @@ class RSConfig
{
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;
@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();
}
}

View File

@@ -52,7 +52,7 @@ public class MessagePanel extends JPanel
private final JLabel titleLabel = new JLabel("Welcome to OpenOSRS");
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);
@Getter(AccessLevel.NONE)