mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 08:50:52 +01:00
Merge pull request #22 from ArachisH/development-extensionsReceiveCachedMessagesPath
Appended the path of the cached habbo messages file to the CONNECTIONSTART packet
This commit is contained in:
commit
75e92d4a3b
@ -18,7 +18,7 @@ public class Cacher {
|
|||||||
|
|
||||||
private static final String DEFAULT_CACHE_FILENAME = "cache.json";
|
private static final String DEFAULT_CACHE_FILENAME = "cache.json";
|
||||||
|
|
||||||
private static String getCacheDir() {
|
public static String getCacheDir() {
|
||||||
File GEarthDir = null;
|
File GEarthDir = null;
|
||||||
try {
|
try {
|
||||||
GEarthDir = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile();
|
GEarthDir = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParentFile();
|
||||||
|
@ -2,16 +2,13 @@ package gearth.misc.harble_api;
|
|||||||
|
|
||||||
import gearth.misc.Cacher;
|
import gearth.misc.Cacher;
|
||||||
import gearth.protocol.HMessage;
|
import gearth.protocol.HMessage;
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import sun.misc.Cache;
|
|
||||||
|
|
||||||
import javax.print.attribute.standard.Destination;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Jonas on 10/11/2018.
|
* Created by Jonas on 10/11/2018.
|
||||||
@ -33,24 +30,29 @@ public class HarbleAPI {
|
|||||||
this.name = (name == null || name.equals("null") ? null : name);
|
this.name = (name == null || name.equals("null") ? null : name);
|
||||||
this.structure = (structure == null || structure.equals("null") ? null : structure);
|
this.structure = (structure == null || structure.equals("null") ? null : structure);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeaderId() {
|
public int getHeaderId() {
|
||||||
return headerId;
|
return headerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HMessage.Side getDestination() {
|
public HMessage.Side getDestination() {
|
||||||
return destination;
|
return destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHash() {
|
public String getHash() {
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStructure() {
|
public String getStructure() {
|
||||||
return structure;
|
return structure;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String s = (headerId+": " + "["+hash+"]["+name+"]["+ structure+"]");
|
String s = (headerId + ": " + "[" + hash + "][" + name + "][" + structure + "]");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,9 +67,11 @@ public class HarbleAPI {
|
|||||||
private Map<String, HarbleMessage> nameToMessage_outgoing = new HashMap<>();
|
private Map<String, HarbleMessage> nameToMessage_outgoing = new HashMap<>();
|
||||||
|
|
||||||
private boolean success = false;
|
private boolean success = false;
|
||||||
|
private String cachedMessagesPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cache file must be generated first within G-Earth, inb4 20 extensions requesting it at the same time
|
* cache file must be generated first within G-Earth, inb4 20 extensions requesting it at the same time
|
||||||
|
*
|
||||||
* @param hotelversion
|
* @param hotelversion
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -79,10 +83,12 @@ public class HarbleAPI {
|
|||||||
return wannabe;
|
return wannabe;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HarbleAPI (String hotelversion) {
|
public HarbleAPI(String hotelversion) {
|
||||||
if (Cacher.cacheFileExists(HarbleAPIFetcher.CACHE_PREFIX + hotelversion)) {
|
String possibleCachedMessagesPath = HarbleAPIFetcher.CACHE_PREFIX + hotelversion;
|
||||||
JSONObject object = Cacher.getCacheContents(HarbleAPIFetcher.CACHE_PREFIX + hotelversion);
|
if (Cacher.cacheFileExists(possibleCachedMessagesPath)) {
|
||||||
|
JSONObject object = Cacher.getCacheContents(possibleCachedMessagesPath);
|
||||||
success = true;
|
success = true;
|
||||||
|
cachedMessagesPath = possibleCachedMessagesPath;
|
||||||
parse(object);
|
parse(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,8 +97,7 @@ public class HarbleAPI {
|
|||||||
String name;
|
String name;
|
||||||
try {
|
try {
|
||||||
name = object.getString("Name");
|
name = object.getString("Name");
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
name = null;
|
name = null;
|
||||||
}
|
}
|
||||||
String hash = object.getString("Hash");
|
String hash = object.getString("Hash");
|
||||||
@ -101,8 +106,7 @@ public class HarbleAPI {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
structure = object.getString("Structure");
|
structure = object.getString("Structure");
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
structure = null;
|
structure = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,6 +136,7 @@ public class HarbleAPI {
|
|||||||
nameToMessag.put(message.getName(), message);
|
nameToMessag.put(message.getName(), message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parse(JSONObject object) {
|
private void parse(JSONObject object) {
|
||||||
try {
|
try {
|
||||||
JSONObject incoming = object.getJSONObject("Incoming");
|
JSONObject incoming = object.getJSONObject("Incoming");
|
||||||
@ -142,8 +147,7 @@ public class HarbleAPI {
|
|||||||
try {
|
try {
|
||||||
JSONObject inMsg = incoming.getJSONObject(key);
|
JSONObject inMsg = incoming.getJSONObject(key);
|
||||||
addMessage(HMessage.Side.TOCLIENT, inMsg, key);
|
addMessage(HMessage.Side.TOCLIENT, inMsg, key);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch( Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,12 +155,11 @@ public class HarbleAPI {
|
|||||||
try {
|
try {
|
||||||
JSONObject outMsg = outgoing.getJSONObject(key);
|
JSONObject outMsg = outgoing.getJSONObject(key);
|
||||||
addMessage(HMessage.Side.TOSERVER, outMsg, key);
|
addMessage(HMessage.Side.TOSERVER, outMsg, key);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch( Exception e) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
} catch (Exception e) {
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,6 +173,7 @@ public class HarbleAPI {
|
|||||||
|
|
||||||
return headerIdToMessage.get(headerId);
|
return headerIdToMessage.get(headerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<HarbleMessage> getHarbleMessagesFromHash(HMessage.Side side, String hash) {
|
public List<HarbleMessage> getHarbleMessagesFromHash(HMessage.Side side, String hash) {
|
||||||
Map<String, List<HarbleMessage>> hashToMessage =
|
Map<String, List<HarbleMessage>> hashToMessage =
|
||||||
(side == HMessage.Side.TOSERVER
|
(side == HMessage.Side.TOSERVER
|
||||||
@ -179,6 +183,7 @@ public class HarbleAPI {
|
|||||||
List<HarbleMessage> result = hashToMessage.get(hash);
|
List<HarbleMessage> result = hashToMessage.get(hash);
|
||||||
return result == null ? new ArrayList<>() : result;
|
return result == null ? new ArrayList<>() : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HarbleMessage getHarbleMessageFromName(HMessage.Side side, String name) {
|
public HarbleMessage getHarbleMessageFromName(HMessage.Side side, String name) {
|
||||||
Map<String, HarbleMessage> nameToMessage =
|
Map<String, HarbleMessage> nameToMessage =
|
||||||
(side == HMessage.Side.TOSERVER
|
(side == HMessage.Side.TOSERVER
|
||||||
@ -188,5 +193,11 @@ public class HarbleAPI {
|
|||||||
return nameToMessage.get(name);
|
return nameToMessage.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
if (Cacher.cacheFileExists(cachedMessagesPath)) {
|
||||||
|
return Cacher.getCacheDir() + File.separator + cachedMessagesPath;
|
||||||
|
}
|
||||||
|
return super.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,6 +158,7 @@ public class Extensions extends SubForm {
|
|||||||
.appendString(getHConnection().getDomain())
|
.appendString(getHConnection().getDomain())
|
||||||
.appendInt(getHConnection().getPort())
|
.appendInt(getHConnection().getPort())
|
||||||
.appendString(getHConnection().getHotelVersion())
|
.appendString(getHConnection().getHotelVersion())
|
||||||
|
.appendString(HarbleAPIFetcher.HARBLEAPI.toString())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -294,6 +295,7 @@ public class Extensions extends SubForm {
|
|||||||
.appendString(getHConnection().getDomain())
|
.appendString(getHConnection().getDomain())
|
||||||
.appendInt(getHConnection().getPort())
|
.appendInt(getHConnection().getPort())
|
||||||
.appendString(getHConnection().getHotelVersion())
|
.appendString(getHConnection().getHotelVersion())
|
||||||
|
.appendString(HarbleAPIFetcher.HARBLEAPI.toString())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user