aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);