From 9349ea84bbd9429e62b1162fa41e7bd7faea3196 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 22 Dec 2021 15:46:18 -0500 Subject: [PATCH] cache: remove http-api dependency This was only for the xtea client, which we don't use anymore anyway. Instead allow XteaKeyManager to read from an input stream. --- cache/pom.xml | 6 ---- .../runelite/cache/region/RegionLoader.java | 1 - .../java/net/runelite/cache/util/XteaKey.java | 34 +++++++++++++++++++ .../runelite/cache/util/XteaKeyManager.java | 30 +++++++--------- .../net/runelite/cache/MapDumperTest.java | 2 -- 5 files changed, 47 insertions(+), 26 deletions(-) create mode 100644 cache/src/main/java/net/runelite/cache/util/XteaKey.java diff --git a/cache/pom.xml b/cache/pom.xml index 8ed326415b..4b42efcf78 100644 --- a/cache/pom.xml +++ b/cache/pom.xml @@ -42,12 +42,6 @@ - - net.runelite - http-api - ${project.version} - - com.google.guava guava diff --git a/cache/src/main/java/net/runelite/cache/region/RegionLoader.java b/cache/src/main/java/net/runelite/cache/region/RegionLoader.java index a15e25a868..21f4868a9a 100644 --- a/cache/src/main/java/net/runelite/cache/region/RegionLoader.java +++ b/cache/src/main/java/net/runelite/cache/region/RegionLoader.java @@ -60,7 +60,6 @@ public class RegionLoader this.store = store; index = store.getIndex(IndexType.MAPS); keyManager = new XteaKeyManager(); - keyManager.loadKeys(); } public void loadRegions() throws IOException diff --git a/cache/src/main/java/net/runelite/cache/util/XteaKey.java b/cache/src/main/java/net/runelite/cache/util/XteaKey.java new file mode 100644 index 0000000000..888c6e7eeb --- /dev/null +++ b/cache/src/main/java/net/runelite/cache/util/XteaKey.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.cache.util; + +import lombok.Data; + +@Data +public class XteaKey +{ + private int region; + private int keys[]; +} diff --git a/cache/src/main/java/net/runelite/cache/util/XteaKeyManager.java b/cache/src/main/java/net/runelite/cache/util/XteaKeyManager.java index 38ba347d4b..c1c7607e9b 100644 --- a/cache/src/main/java/net/runelite/cache/util/XteaKeyManager.java +++ b/cache/src/main/java/net/runelite/cache/util/XteaKeyManager.java @@ -24,12 +24,14 @@ */ package net.runelite.cache.util; -import java.io.IOException; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.HashMap; +import java.util.List; import java.util.Map; -import net.runelite.http.api.RuneLiteAPI; -import net.runelite.http.api.xtea.XteaClient; -import net.runelite.http.api.xtea.XteaKey; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,22 +41,16 @@ public class XteaKeyManager private final Map keys = new HashMap<>(); - public void loadKeys() + public void loadKeys(InputStream in) { - XteaClient xteaClient = new XteaClient(RuneLiteAPI.CLIENT); + // CHECKSTYLE:OFF + List k = new Gson() + .fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), new TypeToken>() { }.getType()); + // CHECKSTYLE:ON - try + for (XteaKey key : k) { - 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; + keys.put(key.getRegion(), key.getKeys()); } logger.info("Loaded {} keys", keys.size()); diff --git a/cache/src/test/java/net/runelite/cache/MapDumperTest.java b/cache/src/test/java/net/runelite/cache/MapDumperTest.java index 8d1fffd7cb..b73c250e43 100644 --- a/cache/src/test/java/net/runelite/cache/MapDumperTest.java +++ b/cache/src/test/java/net/runelite/cache/MapDumperTest.java @@ -65,7 +65,6 @@ public class MapDumperTest File base = StoreLocation.LOCATION, outDir = folder.newFolder(); XteaKeyManager keyManager = new XteaKeyManager(); - keyManager.loadKeys(); try (Store store = new Store(base)) { @@ -121,7 +120,6 @@ public class MapDumperTest Storage storage = store.getStorage(); Index index = store.getIndex(IndexType.MAPS); XteaKeyManager keyManager = new XteaKeyManager(); - keyManager.loadKeys(); for (int i = 0; i < MAX_REGIONS; ++i) {