use of net.runelite.http.api.worlds.World in project runelite by runelite.
the class XpTrackerPlugin method onGameStateChanged.
@Subscribe
public void onGameStateChanged(GameStateChanged event) {
if (event.getGameState() == GameState.LOGGED_IN) {
// LOGGED_IN is triggered between region changes too.
// Check that the username changed or the world type changed.
World world = worlds.findWorld(client.getWorld());
if (world == null) {
log.warn("Logged into nonexistent world {}?", client.getWorld());
return;
}
XpWorldType type = worldSetToType(world.getTypes());
if (!Objects.equals(client.getUsername(), lastUsername) || lastWorldType != type) {
// Reset
log.debug("World change: {} -> {}, {} -> {}", lastUsername, client.getUsername(), lastWorldType, type);
lastUsername = client.getUsername();
lastWorldType = type;
xpPanel.resetAllInfoBoxes();
}
} else if (event.getGameState() == GameState.LOGIN_SCREEN) {
Player local = client.getLocalPlayer();
String username = local != null ? local.getName() : null;
if (username != null) {
log.debug("Submitting xp track for {}", username);
executor.submit(() -> {
try {
xpClient.update(username);
} catch (IOException ex) {
log.warn("error submitting xp track", ex);
}
});
}
}
}
use of net.runelite.http.api.worlds.World in project runelite by runelite.
the class WorldsService method listWorlds.
@RequestMapping
public WorldResult listWorlds() throws IOException {
Request okrequest = new Request.Builder().url(url).build();
byte[] b;
try (Response okresponse = RuneLiteAPI.CLIENT.newCall(okrequest).execute()) {
b = okresponse.body().bytes();
}
List<World> worlds = new ArrayList<>();
ByteBuffer buf = ByteBuffer.wrap(b);
int length = buf.getInt();
buf.limit(length + 4);
int num = buf.getShort() & 0xFFFF;
for (int i = 0; i < num; ++i) {
final World.WorldBuilder worldBuilder = World.builder().id(buf.getShort() & 0xFFFF).types(getTypes(buf.getInt())).address(readString(buf)).activity(readString(buf)).location(buf.get() & 0xFF).players(buf.getShort() & 0xFFFF);
worlds.add(worldBuilder.build());
}
WorldResult result = new WorldResult();
result.setWorlds(worlds);
return result;
}
use of net.runelite.http.api.worlds.World in project runelite by runelite.
the class WorldsServiceTest method testListWorlds.
@Test
public void testListWorlds() throws Exception {
WorldsService worlds = new WorldsService();
worlds.setUrl(server.url("/"));
WorldResult worldResult = worlds.listWorlds();
assertEquals(82, worldResult.getWorlds().size());
World world = worldResult.findWorld(385);
assertNotNull(world);
assertTrue(world.getTypes().contains(WorldType.SKILL_TOTAL));
}
use of net.runelite.http.api.worlds.World in project runelite by runelite.
the class UpdateCheckService method checkUpdate.
private boolean checkUpdate() {
World nextWorld = randomWorld();
if (nextWorld == null) {
return false;
}
InetAddress address;
try {
String url = nextWorld.getAddress();
address = InetAddress.getByName(url);
} catch (UnknownHostException ex) {
logger.warn(null, ex);
return false;
}
try (Socket socket = new Socket(address, PORT)) {
ByteBuffer buffer = ByteBuffer.allocate(5);
buffer.put(HANDSHAKE_TYPE);
buffer.putInt(RuneLiteAPI.getRsVersion());
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
os.write(buffer.array());
int reply = is.read();
if (reply == RESPONSE_OUTDATED) {
return true;
}
if (reply != RESPONSE_OK) {
logger.debug("Non-ok response for handshake: {}", reply);
}
} catch (IOException ex) {
logger.warn(null, ex);
}
// no update
return false;
}
use of net.runelite.http.api.worlds.World in project runelite by runelite.
the class UpdateCheckService method randomWorld.
private World randomWorld() {
try {
WorldResult worldResult = worldsService.listWorlds();
List<World> worlds = worldResult.getWorlds();
Random rand = new Random();
return worlds.get(rand.nextInt(worlds.size()));
} catch (IOException ex) {
logger.warn(null, ex);
return null;
}
}
Aggregations