Add basic game config grabber/logic to check for an update. I guess this works.
This commit is contained in:
74
src/main/java/net/runelite/deob/updater/GameConfig.java
Normal file
74
src/main/java/net/runelite/deob/updater/GameConfig.java
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
package net.runelite.deob.updater;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class GameConfig
|
||||||
|
{
|
||||||
|
private static final String URL = "http://192.168.1.2/rs/jav_config.ws";
|
||||||
|
//private static final String URL = "http://oldschool.runescape.com/jav_config.ws"; // https redirects to rs3
|
||||||
|
|
||||||
|
private final Map<String, String> properties = new HashMap<>(),
|
||||||
|
appletProperties = new HashMap<>();
|
||||||
|
|
||||||
|
public void fetch() throws IOException
|
||||||
|
{
|
||||||
|
URLConnection conn = new URL(URL).openConnection();
|
||||||
|
try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())))
|
||||||
|
{
|
||||||
|
String str;
|
||||||
|
|
||||||
|
while ((str = in.readLine()) != null)
|
||||||
|
{
|
||||||
|
int idx = str.indexOf('=');
|
||||||
|
|
||||||
|
if (idx == -1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String s = str.substring(0, idx);
|
||||||
|
|
||||||
|
if (s.equals("param"))
|
||||||
|
{
|
||||||
|
str = str.substring(idx + 1);
|
||||||
|
idx = str.indexOf('=');
|
||||||
|
s = str.substring(0, idx);
|
||||||
|
|
||||||
|
appletProperties.put(s, str.substring(idx + 1));
|
||||||
|
}
|
||||||
|
else if (s.equals("msg"))
|
||||||
|
{
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
properties.put(s, str.substring(idx + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProperty(String name)
|
||||||
|
{
|
||||||
|
return properties.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getProperties()
|
||||||
|
{
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppletProperty(String name)
|
||||||
|
{
|
||||||
|
return appletProperties.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getAppletProperties()
|
||||||
|
{
|
||||||
|
return appletProperties;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package net.runelite.deob.updater;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
|
public class GameConfigUpdateDetector
|
||||||
|
{
|
||||||
|
private final GameConfig g1, g2;
|
||||||
|
|
||||||
|
public GameConfigUpdateDetector(GameConfig g1, GameConfig g2)
|
||||||
|
{
|
||||||
|
this.g1 = g1;
|
||||||
|
this.g2 = g2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasUpdated()
|
||||||
|
{
|
||||||
|
// between game updatesthe parameters are scrambled, so detect when that happens.
|
||||||
|
// normally only one parameter changes, which is some integer value (+ the world)
|
||||||
|
//
|
||||||
|
// N.B. my other idea is to compare content-length in HEAD requests for the gamepack.
|
||||||
|
// the httpd doesn't support if-match and does not etag anything, and the last-modified time
|
||||||
|
// appears to be constant NOW-1 week (it moves per request)
|
||||||
|
|
||||||
|
int differences = 0;
|
||||||
|
|
||||||
|
for (String key : g1.getProperties().keySet())
|
||||||
|
{
|
||||||
|
String value = g1.getAppletProperty(key), otherValue = g2.getAppletProperty(value);
|
||||||
|
|
||||||
|
if (!Strings.nullToEmpty(value).equals(Strings.nullToEmpty(otherValue)))
|
||||||
|
++differences;
|
||||||
|
}
|
||||||
|
|
||||||
|
return differences > 2; // random number, world
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/test/java/net/runelite/deob/updater/GameConfigTest.java
Normal file
17
src/test/java/net/runelite/deob/updater/GameConfigTest.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package net.runelite.deob.updater;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class GameConfigTest
|
||||||
|
{
|
||||||
|
@Test
|
||||||
|
public void testGetAppletProperties() throws IOException
|
||||||
|
{
|
||||||
|
GameConfig config = new GameConfig();
|
||||||
|
config.fetch();
|
||||||
|
System.out.println(config.getProperties());
|
||||||
|
System.out.println(config.getAppletProperties());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package net.runelite.deob.updater;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class GameConfigUpdateDetectorTest
|
||||||
|
{
|
||||||
|
@Test
|
||||||
|
public void testHasUpdated() throws IOException
|
||||||
|
{
|
||||||
|
GameConfig c1 = new GameConfig(), c2 = new GameConfig();
|
||||||
|
c1.fetch();
|
||||||
|
c2.fetch();
|
||||||
|
|
||||||
|
GameConfigUpdateDetector gcu = new GameConfigUpdateDetector(c1, c2);
|
||||||
|
Assert.assertFalse(gcu.hasUpdated());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user