aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide
diff options
context:
space:
mode:
authorsyeyoung <42869671+cyoung06@users.noreply.github.com>2020-12-09 12:56:43 +0900
committersyeyoung <42869671+cyoung06@users.noreply.github.com>2020-12-09 12:56:43 +0900
commitb03a04dc1e11900e9013fd83fe77e7ecbb07019a (patch)
tree208bd6bca2f6a14301bf0c976617fd5c02756b5a /src/main/java/kr/syeyoung/dungeonsguide
parentd165e145f7066bd46e2a0b2b0fd0752ba7156cae (diff)
downloadSkyblock-Dungeons-Guide-b03a04dc1e11900e9013fd83fe77e7ecbb07019a.tar.gz
Skyblock-Dungeons-Guide-b03a04dc1e11900e9013fd83fe77e7ecbb07019a.tar.bz2
Skyblock-Dungeons-Guide-b03a04dc1e11900e9013fd83fe77e7ecbb07019a.zip
more hacky stuff
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide')
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/customurl/DGURLConnection.java22
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java6
2 files changed, 19 insertions, 9 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/customurl/DGURLConnection.java b/src/main/java/kr/syeyoung/dungeonsguide/customurl/DGURLConnection.java
index 404ccdb4..fac39796 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/customurl/DGURLConnection.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/customurl/DGURLConnection.java
@@ -23,13 +23,15 @@ public class DGURLConnection extends URLConnection {
protected DGURLConnection(URL url) {
super(url);
- try {
- connect();
- } catch (IOException e) {
- e.printStackTrace();
- }
}
+ @Override
+ public void setUseCaches(boolean b) {
+ checkExist = !b;
+ }
+ private boolean checkExist = false;
+ private boolean exists= false;
+
@SneakyThrows
@Override
public void connect() throws IOException {
@@ -49,10 +51,16 @@ public class DGURLConnection extends URLConnection {
HttpURLConnection huc = (HttpURLConnection) new URL(DOMAIN+"resource/resource?class="+ URLEncoder.encode(url.getPath().substring(1))).openConnection();
huc.setRequestProperty("User-Agent", "DungeonsGuide/1.0");
huc.setRequestProperty("Content-Type", "application/json");
+ huc.setRequestMethod(checkExist ? "HEAD" : "GET");
huc.setRequestProperty("Authorization", (url.getUserInfo() == null && classLoader) ? DungeonsGuideMain.getDungeonsGuideMain().getAuthenticator().getToken() : url.getUserInfo());
huc.setDoInput(true);
huc.setDoOutput(true);
+ exists = huc.getResponseCode() != 404;
+ if (checkExist) {
+ return;
+ }
+
InputStream inputStream = huc.getInputStream();
byte[] bytes = new byte[4];
inputStream.read(bytes);
@@ -75,6 +83,7 @@ public class DGURLConnection extends URLConnection {
cipher.init(Cipher.DECRYPT_MODE,keySpec,ivSpec);
CipherInputStream cipherInputStream = new CipherInputStream(inputStream, cipher);
+ cipherInputStream.read(bytes);
int length = ((bytes[0] & 0xFF) << 24) |
((bytes[1] & 0xFF) << 16) |
((bytes[2] & 0xFF) << 8 ) |
@@ -87,7 +96,7 @@ public class DGURLConnection extends URLConnection {
while ( (read = cipherInputStream.read(buffer)) != -1 ) {
totalLen += read;
byteStream.write(buffer, 0, read);
- if (totalLen >= length) break;;
+ if (totalLen >= length) break;
}
} catch (Exception ignored) {}
byte[] byte1 = byteStream.toByteArray();
@@ -101,6 +110,7 @@ public class DGURLConnection extends URLConnection {
@Override
public InputStream getInputStream() throws IOException {
+ if (!connected) connect();
return inputStream;
}
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java
index b5bc69ea..f27d1b2f 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/dungeon/roomfinder/DungeonRoomInfoRegistry.java
@@ -69,10 +69,10 @@ public class DungeonRoomInfoRegistry {
registered.clear();
shapeMap.clear();
uuidMap.clear();
- URL url = new URL("dungeonsguide://"+DungeonsGuideMain.getDungeonsGuideMain().getAuthenticator().getToken()+"@/roomdatas/data.txt");
+ URL url = new URL("dungeonsguide://"+DungeonsGuideMain.getDungeonsGuideMain().getAuthenticator().getToken()+"@/roomdata/datas.txt");
List<String> lines = IOUtils.readLines(url.openConnection().getInputStream());
- for (String name : lines) {
- if (name.endsWith(".roomdata")) continue;
+ for (String name : lines) {
+ if (!name.endsWith(".roomdata")) continue;
try {
InputStream fis = new URL("dungeonsguide://"+DungeonsGuideMain.getDungeonsGuideMain().getAuthenticator().getToken()+"@/"+name).openStream();
ObjectInputStream ois = new ObjectInputStream(fis);