Merge pull request #666 from HexRealm/updatecheckservice-fix
Use the address returned by the worldlist api instead of building our own
This commit is contained in:
@@ -32,10 +32,12 @@ import java.net.InetAddress;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import net.runelite.http.api.RuneLiteAPI;
|
import net.runelite.http.api.RuneLiteAPI;
|
||||||
|
import net.runelite.http.api.worlds.World;
|
||||||
import net.runelite.http.api.worlds.WorldResult;
|
import net.runelite.http.api.worlds.WorldResult;
|
||||||
import net.runelite.http.service.worlds.WorldsService;
|
import net.runelite.http.service.worlds.WorldsService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -51,7 +53,6 @@ public class UpdateCheckService
|
|||||||
private static final Logger logger = LoggerFactory.getLogger(UpdateCheckService.class);
|
private static final Logger logger = LoggerFactory.getLogger(UpdateCheckService.class);
|
||||||
|
|
||||||
private static final int PORT = 43594;
|
private static final int PORT = 43594;
|
||||||
private static final int WORLD_OFFSET = 300;
|
|
||||||
private static final byte HANDSHAKE_TYPE = 15;
|
private static final byte HANDSHAKE_TYPE = 15;
|
||||||
|
|
||||||
private static final int RESPONSE_OK = 0;
|
private static final int RESPONSE_OK = 0;
|
||||||
@@ -74,8 +75,8 @@ public class UpdateCheckService
|
|||||||
|
|
||||||
private boolean checkUpdate()
|
private boolean checkUpdate()
|
||||||
{
|
{
|
||||||
int nextWorld = randomWorld();
|
World nextWorld = randomWorld();
|
||||||
if (nextWorld == -1)
|
if (nextWorld == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -83,7 +84,7 @@ public class UpdateCheckService
|
|||||||
InetAddress address;
|
InetAddress address;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String url = "oldschool" + nextWorld + ".runescape.com";
|
String url = nextWorld.getAddress();
|
||||||
address = InetAddress.getByName(url);
|
address = InetAddress.getByName(url);
|
||||||
}
|
}
|
||||||
catch (UnknownHostException ex)
|
catch (UnknownHostException ex)
|
||||||
@@ -122,20 +123,19 @@ public class UpdateCheckService
|
|||||||
return false; // no update
|
return false; // no update
|
||||||
}
|
}
|
||||||
|
|
||||||
private int randomWorld()
|
private World randomWorld()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
WorldResult worlds = worldsService.listWorlds();
|
WorldResult worldResult = worldsService.listWorlds();
|
||||||
int size = worlds.getWorlds().size();
|
List<World> worlds = worldResult.getWorlds();
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
int worldNumber = worlds.getWorlds().get(rand.nextInt(size)).getId();
|
return worlds.get(rand.nextInt(worlds.size()));
|
||||||
return worldNumber - WORLD_OFFSET;
|
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
logger.warn(null, ex);
|
logger.warn(null, ex);
|
||||||
return -1;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user