project: Add xtea base, Fix session base
This commit is contained in:
@@ -24,11 +24,8 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.cache.util;
|
package net.runelite.cache.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import net.runelite.http.api.xtea.XteaClient;
|
|
||||||
import net.runelite.http.api.xtea.XteaKey;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -40,23 +37,7 @@ public class XteaKeyManager
|
|||||||
|
|
||||||
public void loadKeys()
|
public void loadKeys()
|
||||||
{
|
{
|
||||||
XteaClient xteaClient = new XteaClient();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for (XteaKey key : xteaClient.get())
|
|
||||||
{
|
|
||||||
keys.put(key.getRegion(), key.getKeys());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
// happens on release when it is not deployed yet
|
|
||||||
logger.debug("unable to load xtea keys", ex);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Loaded {} keys", keys.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] getKeys(int region)
|
public int[] getKeys(int region)
|
||||||
|
|||||||
@@ -65,7 +65,8 @@ public class RuneLiteAPI
|
|||||||
private static final String STATICBASE = "https://static.runelite.net";
|
private static final String STATICBASE = "https://static.runelite.net";
|
||||||
|
|
||||||
private static final String OPENOSRS_BASE = /*"https://api.openosrs.com*/ "https://api.runelitepl.us";
|
private static final String OPENOSRS_BASE = /*"https://api.openosrs.com*/ "https://api.runelitepl.us";
|
||||||
private static final String OPENOSRS_SESSION = "http://www.openosrs.dev/session";
|
private static final String OPENOSRS_SESSION = "http://session.openosrs.dev";
|
||||||
|
private static final String OPENOSRS_XTEA = "http://xtea.openosrs.dev";
|
||||||
private static final String MAVEN_METADATA = "http://repo.runelite.net/net/runelite/runelite-parent/maven-metadata.xml";
|
private static final String MAVEN_METADATA = "http://repo.runelite.net/net/runelite/runelite-parent/maven-metadata.xml";
|
||||||
|
|
||||||
private static final Properties properties = new Properties();
|
private static final Properties properties = new Properties();
|
||||||
@@ -121,6 +122,11 @@ public class RuneLiteAPI
|
|||||||
return HttpUrl.parse(OPENOSRS_SESSION);
|
return HttpUrl.parse(OPENOSRS_SESSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HttpUrl getXteaBase()
|
||||||
|
{
|
||||||
|
return HttpUrl.parse(OPENOSRS_XTEA);
|
||||||
|
}
|
||||||
|
|
||||||
public static HttpUrl getApiBase()
|
public static HttpUrl getApiBase()
|
||||||
{
|
{
|
||||||
final String prop = System.getProperty("runelite.http-service.url");
|
final String prop = System.getProperty("runelite.http-service.url");
|
||||||
|
|||||||
@@ -29,14 +29,12 @@ import com.google.gson.reflect.TypeToken;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.List;
|
import java.util.HashMap;
|
||||||
import net.runelite.http.api.RuneLiteAPI;
|
import net.runelite.http.api.RuneLiteAPI;
|
||||||
import static net.runelite.http.api.RuneLiteAPI.JSON;
|
|
||||||
import okhttp3.Call;
|
import okhttp3.Call;
|
||||||
import okhttp3.Callback;
|
import okhttp3.Callback;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.RequestBody;
|
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -45,19 +43,19 @@ public class XteaClient
|
|||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(XteaClient.class);
|
private static final Logger logger = LoggerFactory.getLogger(XteaClient.class);
|
||||||
|
|
||||||
public void submit(XteaRequest xteaRequest)
|
public void submit(int region, int[] keys)
|
||||||
{
|
{
|
||||||
String json = RuneLiteAPI.GSON.toJson(xteaRequest);
|
|
||||||
|
|
||||||
HttpUrl url = RuneLiteAPI.getOpenOSRSApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getXteaBase().newBuilder()
|
||||||
.addPathSegment("xtea")
|
.addPathSegment("submit")
|
||||||
|
.addQueryParameter("region", String.valueOf(region))
|
||||||
|
.addQueryParameter("key1", String.valueOf(keys[0]))
|
||||||
|
.addQueryParameter("key2", String.valueOf(keys[1]))
|
||||||
|
.addQueryParameter("key3", String.valueOf(keys[2]))
|
||||||
|
.addQueryParameter("key4", String.valueOf(keys[3]))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
logger.debug("Built URI: {}", url);
|
|
||||||
|
|
||||||
RequestBody body = RequestBody.Companion.create(json, JSON);
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.post(body)
|
|
||||||
.url(url)
|
.url(url)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@@ -87,10 +85,10 @@ public class XteaClient
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<XteaKey> get() throws IOException
|
public HashMap<Integer, int[]> get() throws IOException
|
||||||
{
|
{
|
||||||
HttpUrl url = RuneLiteAPI.getOpenOSRSApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getXteaBase().newBuilder()
|
||||||
.addPathSegment("xtea")
|
.addPathSegment("get")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
@@ -101,7 +99,7 @@ public class XteaClient
|
|||||||
{
|
{
|
||||||
InputStream in = response.body().byteStream();
|
InputStream in = response.body().byteStream();
|
||||||
// CHECKSTYLE:OFF
|
// CHECKSTYLE:OFF
|
||||||
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), new TypeToken<List<XteaKey>>() {}.getType());
|
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), new TypeToken<HashMap<Integer, Integer[]>>() {}.getType());
|
||||||
// CHECKSTYLE:ON
|
// CHECKSTYLE:ON
|
||||||
}
|
}
|
||||||
catch (JsonParseException ex)
|
catch (JsonParseException ex)
|
||||||
@@ -109,26 +107,4 @@ public class XteaClient
|
|||||||
throw new IOException(ex);
|
throw new IOException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public XteaKey get(int region) throws IOException
|
|
||||||
{
|
|
||||||
HttpUrl url = RuneLiteAPI.getOpenOSRSApiBase().newBuilder()
|
|
||||||
.addPathSegment("xtea")
|
|
||||||
.addPathSegment(Integer.toString(region))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
|
||||||
.url(url)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
|
||||||
{
|
|
||||||
InputStream in = response.body().byteStream();
|
|
||||||
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), XteaKey.class);
|
|
||||||
}
|
|
||||||
catch (JsonParseException ex)
|
|
||||||
{
|
|
||||||
throw new IOException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,18 +24,17 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.xtea;
|
package net.runelite.client.plugins.xtea;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.io.IOException;
|
||||||
import java.util.Set;
|
import java.util.HashMap;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.GameState;
|
import net.runelite.api.GameState;
|
||||||
import net.runelite.api.events.GameStateChanged;
|
import net.runelite.api.events.GameStateChanged;
|
||||||
|
import net.runelite.client.eventbus.Subscribe;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
import net.runelite.http.api.xtea.XteaClient;
|
import net.runelite.http.api.xtea.XteaClient;
|
||||||
import net.runelite.http.api.xtea.XteaKey;
|
|
||||||
import net.runelite.http.api.xtea.XteaRequest;
|
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Xtea",
|
name = "Xtea",
|
||||||
@@ -46,13 +45,22 @@ public class XteaPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
private final XteaClient xteaClient = new XteaClient();
|
private final XteaClient xteaClient = new XteaClient();
|
||||||
|
|
||||||
private final Set<Integer> sentRegions = new HashSet<>();
|
private HashMap<Integer, int[]> xteas;
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
xteas = xteaClient.get();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
// todo re-enable when we have our server back up.
|
@Subscribe
|
||||||
// @Subscribe
|
|
||||||
private void onGameStateChanged(GameStateChanged gameStateChanged)
|
private void onGameStateChanged(GameStateChanged gameStateChanged)
|
||||||
{
|
{
|
||||||
if (gameStateChanged.getGameState() != GameState.LOGGED_IN)
|
if (gameStateChanged.getGameState() != GameState.LOGGED_IN)
|
||||||
@@ -60,24 +68,20 @@ public class XteaPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int revision = client.getRevision();
|
|
||||||
int[] regions = client.getMapRegions();
|
int[] regions = client.getMapRegions();
|
||||||
int[][] xteaKeys = client.getXteaKeys();
|
int[][] xteaKeys = client.getXteaKeys();
|
||||||
|
|
||||||
XteaRequest xteaRequest = new XteaRequest();
|
|
||||||
xteaRequest.setRevision(revision);
|
|
||||||
|
|
||||||
for (int idx = 0; idx < regions.length; ++idx)
|
for (int idx = 0; idx < regions.length; ++idx)
|
||||||
{
|
{
|
||||||
int region = regions[idx];
|
int region = regions[idx];
|
||||||
int[] keys = xteaKeys[idx];
|
int[] keys = xteaKeys[idx];
|
||||||
|
|
||||||
if (sentRegions.contains(region))
|
if (xteas.get(region) != null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sentRegions.add(region);
|
xteas.put(region, keys);
|
||||||
|
|
||||||
log.debug("Region {} keys {}, {}, {}, {}", region, keys[0], keys[1], keys[2], keys[3]);
|
log.debug("Region {} keys {}, {}, {}, {}", region, keys[0], keys[1], keys[2], keys[3]);
|
||||||
|
|
||||||
@@ -87,17 +91,7 @@ public class XteaPlugin extends Plugin
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
XteaKey xteaKey = new XteaKey();
|
xteaClient.submit(region, keys);
|
||||||
xteaKey.setRegion(region);
|
|
||||||
xteaKey.setKeys(keys);
|
|
||||||
xteaRequest.addKey(xteaKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xteaRequest.getKeys().isEmpty())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
xteaClient.submit(xteaRequest);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user