diff --git a/Extensions/AdminOnConnect/pom.xml b/Extensions/AdminOnConnect/pom.xml
index f7bf8a0..4343f99 100644
--- a/Extensions/AdminOnConnect/pom.xml
+++ b/Extensions/AdminOnConnect/pom.xml
@@ -13,7 +13,7 @@
G-Earth
G-Earth-Parent
- 1.1
+ 1.3
../../
@@ -106,7 +106,7 @@
G-Earth
G-Earth
- 1.0
+ 1.3
diff --git a/Extensions/BlockReplacePackets/pom.xml b/Extensions/BlockReplacePackets/pom.xml
index 813592d..55dc0ca 100644
--- a/Extensions/BlockReplacePackets/pom.xml
+++ b/Extensions/BlockReplacePackets/pom.xml
@@ -13,7 +13,7 @@
G-Earth
G-Earth-Parent
- 1.1
+ 1.3
../../
@@ -106,7 +106,7 @@
G-Earth
G-Earth
- 1.0
+ 1.3
diff --git a/G-Earth/pom.xml b/G-Earth/pom.xml
index adbc5be..80081dc 100644
--- a/G-Earth/pom.xml
+++ b/G-Earth/pom.xml
@@ -8,22 +8,21 @@
jar
- 1.1
+ 1.3
1.8
+ 9.4.35.v20201120
G-Earth
G-Earth-Parent
- 1.1
+ 1.3
-
-
org.apache.maven.plugins
@@ -36,7 +35,7 @@
true
true
lib/
- gearth.J11Main
+ gearth.Main
false
@@ -58,7 +57,7 @@
${project.build.directory}/bin
- gearth.J11Main
+ gearth.Main
@@ -86,6 +85,11 @@
+
+
+
+
+
@@ -123,6 +127,7 @@
+
@@ -152,13 +157,51 @@
com.github.tulskiy
jkeymaster
- 1.2
+ 1.3
org.slf4j
slf4j-jdk14
2.0.0-alpha0
+
+
+ org.apache.maven
+ maven-artifact
+ 3.6.3
+
+
+
+
+ javax.websocket
+ javax.websocket-api
+ 1.1
+
+
+
+ org.eclipse.jetty
+ jetty-server
+ ${jettyVersion}
+
+
+ org.eclipse.jetty.websocket
+ javax-websocket-server-impl
+ ${jettyVersion}
+
+
+ org.eclipse.jetty
+ jetty-http
+ ${jettyVersion}
+
+
+
+
+
+ G-Earth
+ G-Wasm
+ 1.0
+
+
diff --git a/G-Earth/src/main/java/gearth/J11Main.java b/G-Earth/src/main/java/gearth/J11Main.java
deleted file mode 100644
index 7fc0e6c..0000000
--- a/G-Earth/src/main/java/gearth/J11Main.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package gearth;
-
-public class J11Main {
- public static void main(String[] args) {
- Main.main(args);
- }
-}
diff --git a/G-Earth/src/main/java/gearth/Main.java b/G-Earth/src/main/java/gearth/Main.java
index ce3138f..745b1db 100644
--- a/G-Earth/src/main/java/gearth/Main.java
+++ b/G-Earth/src/main/java/gearth/Main.java
@@ -1,54 +1,53 @@
package gearth;
import gearth.misc.AdminValidator;
+import gearth.ui.GEarthController;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
-import javafx.scene.control.*;
+import javafx.scene.control.Alert;
+import javafx.scene.control.ButtonType;
+import javafx.scene.control.Hyperlink;
+import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Region;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
-import gearth.ui.GEarthController;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
// run as root issue Invalid MIT-MAGIC-COOKIE-1 key fix: https://stackoverflow.com/questions/48139447/invalid-mit-magic-cookie-1-key
public class Main extends Application {
public static Application main;
- public static String version = "1.1";
+ public static String version = "1.3";
private static String gitApi = "https://api.github.com/repos/sirjonasxx/G-Earth/releases/latest";
@Override
public void start(Stage primaryStage) throws Exception{
main = this;
- FXMLLoader loader = new FXMLLoader(getClass().getResource("/gearth/ui/G-Earth.fxml"));
+ FXMLLoader loader = new FXMLLoader(getClass().getResource("ui/G-Earth.fxml"));
Parent root = loader.load();
GEarthController companion = loader.getController();
companion.setStage(primaryStage);
- primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/gearth/G-EarthLogoSmaller.png")));
+ primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("G-EarthLogoSmaller.png")));
- // TODO fix
primaryStage.setResizable(false);
-// primaryStage.setResizable(true);
-// primaryStage.onShownProperty().addListener(e -> {
-// Platform.runLater(() -> primaryStage.setResizable(false));
-// });
- //primaryStage.initStyle(StageStyle.UNDECORATED);
primaryStage.setTitle("G-Earth " + version);
primaryStage.setScene(new Scene(root, 650, 295));
primaryStage.show();
- primaryStage.getScene().getStylesheets().add(getClass().getResource("/gearth/ui/bootstrap3.css").toExternalForm());
+ primaryStage.getScene().getStylesheets().add(getClass().getResource("ui/bootstrap3.css").toExternalForm());
primaryStage.setOnCloseRequest( event -> {
companion.exit();
@@ -58,21 +57,17 @@ public class Main extends Application {
System.exit(0);
});
- new Thread(() -> {
- if (!AdminValidator.isAdmin()) {
- Platform.runLater(() -> {
- Alert alert = new Alert(Alert.AlertType.ERROR, "G-Earth needs admin privileges in order to work properly, please restart G-Earth with admin permissions unless you know what you're doing", ButtonType.OK);
- alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
- alert.setResizable(false);
-// alert.setResizable(true);
-// alert.onShownProperty().addListener(e -> {
-// Platform.runLater(() -> alert.setResizable(false));
-// });
- alert.show();
- });
-
- }
- }).start();
+// new Thread(() -> {
+// if (!AdminValidator.isAdmin()) {
+// Platform.runLater(() -> {
+// Alert alert = new Alert(Alert.AlertType.ERROR, "G-Earth needs admin privileges in order to work properly, please restart G-Earth with admin permissions unless you know what you're doing", ButtonType.OK);
+// alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
+// alert.setResizable(false);
+// alert.show();
+// });
+//
+// }
+// }).start();
new Thread(() -> {
try {
@@ -83,7 +78,7 @@ public class Main extends Application {
if (!gitv.equals(version)) {
Platform.runLater(() -> {
String body = (String)object.get("body");
- boolean isForcedUpdate = body.contains("");
+ boolean isForcedUpdate = body.contains("(!)");
Alert alert = new Alert(isForcedUpdate ? Alert.AlertType.ERROR : Alert.AlertType.INFORMATION, "G-Earth is outdated!", ButtonType.OK);
@@ -103,11 +98,6 @@ public class Main extends Application {
webView.setPrefSize(500, 200);
alert.setResizable(false);
-// alert.setResizable(true);
-// alert.onShownProperty().addListener(e -> {
-// Platform.runLater(() -> alert.setResizable(false));
-// });
-
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alert.getDialogPane().setContent(fp);
if (isForcedUpdate) {
diff --git a/G-Earth/src/main/java/gearth/extensions/Extension.java b/G-Earth/src/main/java/gearth/extensions/Extension.java
index 5078c47..89d668f 100644
--- a/G-Earth/src/main/java/gearth/extensions/Extension.java
+++ b/G-Earth/src/main/java/gearth/extensions/Extension.java
@@ -298,7 +298,13 @@ public abstract class Extension implements IExtension {
public boolean requestFlags(FlagsCheckListener flagRequestCallback) {
if (this.flagRequestCallback != null) return false;
this.flagRequestCallback = flagRequestCallback;
- return true;
+ try {
+ writeToStream(new HPacket(NetworkExtensionInfo.INCOMING_MESSAGES_IDS.REQUESTFLAGS).toBytes());
+ return true;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
}
diff --git a/G-Earth/src/main/java/gearth/extensions/ExtensionForm.java b/G-Earth/src/main/java/gearth/extensions/ExtensionForm.java
index 983ba74..145733c 100644
--- a/G-Earth/src/main/java/gearth/extensions/ExtensionForm.java
+++ b/G-Earth/src/main/java/gearth/extensions/ExtensionForm.java
@@ -11,7 +11,7 @@ import gearth.protocol.HPacket;
public abstract class ExtensionForm implements IExtension {
volatile Extension extension;
- volatile Stage primaryStage;
+ protected volatile Stage primaryStage;
protected static void runExtensionForm(String[] args, Class extends ExtensionForm> extension) {
ExtensionFormLauncher launcher = new ExtensionFormLauncher();
diff --git a/G-Earth/src/main/java/gearth/extensions/extra/harble/HashSupport.java b/G-Earth/src/main/java/gearth/extensions/extra/harble/HashSupport.java
index 842fbc5..f507f44 100644
--- a/G-Earth/src/main/java/gearth/extensions/extra/harble/HashSupport.java
+++ b/G-Earth/src/main/java/gearth/extensions/extra/harble/HashSupport.java
@@ -6,6 +6,7 @@ import gearth.misc.harble_api.HarbleAPI;
import gearth.protocol.HMessage;
import gearth.protocol.HPacket;
+import java.io.File;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -30,7 +31,7 @@ public class HashSupport {
extension.onConnect((host, port, hotelversion, cachePath) -> {
// synchronized (lock) {
- harbleAPI = new HarbleAPI(hotelversion, cachePath);
+ harbleAPI = new HarbleAPI(new File(cachePath));
// }
});
diff --git a/G-Earth/src/main/java/gearth/extensions/parsers/HEntityUpdate.java b/G-Earth/src/main/java/gearth/extensions/parsers/HEntityUpdate.java
index 3aab58a..56d28f7 100644
--- a/G-Earth/src/main/java/gearth/extensions/parsers/HEntityUpdate.java
+++ b/G-Earth/src/main/java/gearth/extensions/parsers/HEntityUpdate.java
@@ -4,14 +4,14 @@ import gearth.protocol.HPacket;
public class HEntityUpdate {
private int index;
- private boolean isController;
+ private boolean isController = false;
private HPoint tile;
- private HPoint movingTo;
+ private HPoint movingTo = null;
- private HSign sign;
- private HStance stance;
- private HAction action;
+ private HSign sign = null;
+ private HStance stance = null;
+ private HAction action = null;
private HDirection headFacing;
private HDirection bodyFacing;
diff --git a/G-Earth/src/main/java/gearth/misc/harble_api/HarbleAPI.java b/G-Earth/src/main/java/gearth/misc/harble_api/HarbleAPI.java
index 77f75b7..8333483 100644
--- a/G-Earth/src/main/java/gearth/misc/harble_api/HarbleAPI.java
+++ b/G-Earth/src/main/java/gearth/misc/harble_api/HarbleAPI.java
@@ -71,7 +71,6 @@ public class HarbleAPI {
private boolean success = false;
private String fullPath = null;
- private String revision = null;
/**
* cache file must be generated first within G-Earth, inb4 20 extensions requesting it at the same time
@@ -92,22 +91,18 @@ public class HarbleAPI {
if (Cacher.cacheFileExists(possibleCachedMessagesPath)) {
JSONObject object = Cacher.getCacheContents(possibleCachedMessagesPath);
success = true;
- revision = hotelversion;
fullPath = Cacher.getCacheDir() + File.separator + possibleCachedMessagesPath;
parse(object);
}
}
- public HarbleAPI(String hotelversion, String path_to_file) {
-
- File f = new File(path_to_file);
+ public HarbleAPI(File f) {
if (f.exists() && !f.isDirectory()) {
try {
String contents = String.join("\n", Files.readAllLines(f.toPath()));
JSONObject object = new JSONObject(contents);
success = true;
- revision = hotelversion;
- fullPath = path_to_file;
+ fullPath = f.getAbsolutePath();
parse(object);
} catch (IOException e) {
@@ -118,15 +113,16 @@ public class HarbleAPI {
private void addMessage(HMessage.Direction direction, JSONObject object) {
String name;
- try {
- name = object.getString("Name");
- } catch (Exception e) {
- name = null;
- }
- String hash = object.getString("Hash");
- Integer headerId = object.getInt("Id");
- String structure;
+ String hash;
+ try { name = object.getString("Name"); }
+ catch (Exception e) { name = null; }
+ try { hash = object.getString("Hash"); }
+ catch (Exception e) { hash = null; }
+
+ int headerId = object.getInt("Id");
+
+ String structure;
try {
structure = object.getString("Structure");
} catch (Exception e) {
@@ -218,10 +214,6 @@ public class HarbleAPI {
return nameToMessage.get(name);
}
- public String getRevision() {
- return revision;
- }
-
public String getPath() {
if (success) {
return fullPath;
diff --git a/G-Earth/src/main/java/gearth/misc/harble_api/HarbleAPIFetcher.java b/G-Earth/src/main/java/gearth/misc/harble_api/HarbleAPIFetcher.java
index c99d942..08beed3 100644
--- a/G-Earth/src/main/java/gearth/misc/harble_api/HarbleAPIFetcher.java
+++ b/G-Earth/src/main/java/gearth/misc/harble_api/HarbleAPIFetcher.java
@@ -1,11 +1,14 @@
package gearth.misc.harble_api;
+import gearth.Main;
import gearth.misc.Cacher;
import gearth.protocol.HMessage;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
+import java.io.File;
import java.io.IOException;
+import java.net.URISyntaxException;
/**
* Created by Jonas on 10/11/2018.
@@ -36,6 +39,20 @@ public class HarbleAPIFetcher {
public static HarbleAPI HARBLEAPI = null;
public synchronized static void fetch(String hotelversion) {
+ // if unity
+ if (!(hotelversion.toLowerCase().contains("production") || hotelversion.toLowerCase().contains("release"))) {
+ try {
+ HARBLEAPI = new HarbleAPI(
+ new File(new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI())
+ .getParentFile(), "messages.json"
+ )
+ );
+ } catch (URISyntaxException e) {
+ HARBLEAPI = null;
+ }
+ return;
+ }
+
String cacheName = CACHE_PREFIX + hotelversion;
if (Cacher.cacheFileExists(cacheName)) {
diff --git a/G-Earth/src/main/java/gearth/misc/packetrepresentation/PacketStringUtils.java b/G-Earth/src/main/java/gearth/misc/packetrepresentation/PacketStringUtils.java
index 7814fc3..adbafe8 100644
--- a/G-Earth/src/main/java/gearth/misc/packetrepresentation/PacketStringUtils.java
+++ b/G-Earth/src/main/java/gearth/misc/packetrepresentation/PacketStringUtils.java
@@ -39,12 +39,18 @@ public class PacketStringUtils {
packet = replaceAll(packet, "\\{i:(-?[0-9]+)}",
m -> toString(ByteBuffer.allocate(4).putInt(Integer.parseInt(m.group(1))).array()));
+ packet = replaceAll(packet, "\\{l:(-?[0-9]+)}",
+ m -> toString(ByteBuffer.allocate(8).putLong(Integer.parseInt(m.group(1))).array()));
+
packet = replaceAll(packet, "\\{d:(-?[0-9]*\\.[0-9]*)}",
m -> toString(ByteBuffer.allocate(8).putDouble(Double.parseDouble(m.group(1))).array()));
packet = replaceAll(packet, "\\{u:([0-9]+)}",
m -> "[" + (Integer.parseInt(m.group(1))/256) + "][" + (Integer.parseInt(m.group(1)) % 256) + "]");
+ packet = replaceAll(packet, "\\{h:([0-9]+)}",
+ m -> "[" + (Integer.parseInt(m.group(1))/256) + "][" + (Integer.parseInt(m.group(1)) % 256) + "]");
+
packet = replaceAll(packet, "\\{b:([Ff]alse|[Tt]rue)}",
m -> m.group(1).toLowerCase().equals("true") ? "[1]" : "[0]");
@@ -174,7 +180,7 @@ public class PacketStringUtils {
packet.resetReadIndex();
StringBuilder builder = new StringBuilder();
- builder.append("{l}{u:").append(packet.headerId()).append("}");
+ builder.append("{l}{h:").append(packet.headerId()).append("}");
buildExpressionFromGivenStructure(packet, struct, 0, builder);
packet.setReadIndex(oldReadIndex);
@@ -196,7 +202,7 @@ public class PacketStringUtils {
}
else if (c == 'i') builder.append("{i:").append(prevInt = p.readInteger()).append('}');
else if (c == 's') builder.append("{s:\"").append(
- new String(p.readString().getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8)
+ p.readString(StandardCharsets.UTF_8)
.replace("\\", "\\\\") // \ -> \\
.replace("\"", "\\\"") // " -> \"
.replace("\r", "\\r") // CR -> \r
@@ -204,6 +210,8 @@ public class PacketStringUtils {
else if (c == 'd') builder.append("{d:").append(p.readDouble()).append('}');
else if (c == 'b') builder.append("{b:").append(p.readByte()).append('}');
else if (c == 'B') builder.append("{b:").append(p.readBoolean()).append('}');
+ else if (c == 'l') builder.append("{l:").append(p.readLong()).append('}');
+ else if (c == 'u') builder.append("{u:").append(p.readShort()).append('}');
else return;
}
}
@@ -232,16 +240,16 @@ public class PacketStringUtils {
}
public static void main(String[] args) throws InvalidPacketException {
- HPacket p1 = fromString("{l}{u:1129}{s:\"\\\\\\\\\"}{i:0}{i:0}");
+ HPacket p1 = fromString("{l}{h:1129}{s:\"\\\\\\\\\"}{i:0}{i:0}");
System.out.println(p1.toExpression());
HPacket p1_2 = fromString(p1.toExpression());
System.out.println(p1_2.toExpression());
- HPacket p2 = fromString("{l}{u:4564}{i:3}{i:0}{s:\"hi\"}{i:0}{i:1}{s:\"how\"}{i:3}{b:1}{b:2}{b:3}{i:2}{s:\"r u\"}{i:1}{b:120}{i:2}{b:true}");
+ HPacket p2 = fromString("{l}{h:4564}{i:3}{i:0}{s:\"hi\"}{i:0}{i:1}{s:\"how\"}{i:3}{b:1}{b:2}{b:3}{i:2}{s:\"r u\"}{i:1}{b:120}{i:2}{b:true}");
System.out.println(p2);
System.out.println(structureEquals(
- new HPacket("{l}{u:5}{s:\"asdas\"}"),
+ new HPacket("{l}{h:5}{s:\"asdas\"}"),
"s"
));
}
diff --git a/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/StructurePredictor.java b/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/StructurePredictor.java
index aa1f413..8216489 100644
--- a/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/StructurePredictor.java
+++ b/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/StructurePredictor.java
@@ -9,8 +9,8 @@ import java.util.List;
public class StructurePredictor {
- HPacket packet;
- String structure; // null if not found/ didnt try to find
+ private HPacket packet;
+ private String structure; // null if not found/ didnt try to find
public StructurePredictor(HPacket packet) {
this.packet = packet;
@@ -44,17 +44,12 @@ public class StructurePredictor {
while (index < packet.getBytesLength()) {
double currentLogScore = dynamic[index - 6].logScore;
for (TypeChecker typeChecker : typeCheckers) {
- if (typeChecker.canRead(index)) {
- double score = typeChecker.score(index);
- double newScore = currentLogScore + Math.log(score);
- int nextIndex = typeChecker.nextIndex(index) - 6;
- if (dynamic[nextIndex] == null || newScore > dynamic[nextIndex].logScore) {
- dynamic[nextIndex] = new SubStructure(
- index - 6,
- typeChecker.getStructCode(),
- newScore
- );
- }
+ if (!typeChecker.canRead(index)) continue;
+
+ double newScore = currentLogScore + Math.log(typeChecker.score(index));
+ int nextIndex = typeChecker.nextIndex(index) - 6;
+ if (dynamic[nextIndex] == null || newScore > dynamic[nextIndex].logScore) {
+ dynamic[nextIndex] = new SubStructure(index - 6, typeChecker.getStructCode(), newScore);
}
}
index++;
@@ -80,39 +75,4 @@ public class StructurePredictor {
public String getStructure() {
return structure;
}
-
- public static void main(String[] args) {
- HPacket[] packets = new HPacket[] {
- new HPacket("{l}{u:500}{i:20}"),
- new HPacket(4002, "test"),
- new HPacket(4002, "test", 0, true),
- new HPacket(4002, "test", "testtsd", 54452, true, false),
- new HPacket(4002, "test", 46564554, "testtsd", 54452, true, false),
- new HPacket(4002, "test", 0, 46564554, "testtsd", 54452, true, false),
- new HPacket(4002, -1, "test", 0, 46564554, "testtsd", -1, 54452, true, false),
- new HPacket(4002, -1, "test", 0, 46564554, "testtsd", -1, 54452, false, true, ""),
- new HPacket(4002, -1, "test", 0, 46564554, "testtsd", -1, 54452, false, true, ""),
- new HPacket(4002, -1, "test", 0, 46564554, "testtsd", -1, 54452, false, true, 0),
- new HPacket(4002, -1, (byte) 5, "test", 0, 46564554, "testtsd", -1, 54452, false, true, 0),
- new HPacket(4002, "", 20, 0),
- new HPacket(4002, 1),
- new HPacket(4002, 0, 0),
- new HPacket(4002, 0, 0, 42, false),
- new HPacket(4002, 0, ""),
- new HPacket("[0][0][0]F[0] [0][0][0] [0][0][0][5][0]\u0013ACH_FriendListSize5[0][0][0]U[0][0][0] [0][0][0][0][0][0][0][0][0][0][0]Z[0][0][6]social[0][0][0][0][0][13][0][0][0][2]"),
- new HPacket("[0][0][0]?[0] [0][0][0][4][0][0][0][4][0][10]ACH_Login4[0][0][0]\u000F[0][0][0]\u001C[0][0][0][0][0][0][0][0][0][0][0][2][0][0][8]identity[0][0][0][0][0]\u0014[0][0][0][0]"),
- new HPacket("[0][0][0][6]\u000Ew[0][0][0][0]"),
- new HPacket("[0][0][0]'[3] [0][5]Login[0][6]socket[0]\u000Eclient.auth_ok[0][0][0][0][0][0]"),
- new HPacket(4002, false, ""),
- new HPacket("{l}{u:145}[0][0][0]ÿÿÿÿ[0]"),
-// new HPacket("[0][0][1]p[13]1[0][0][0][12][0][10]MOUSE_ZOOM[0][0][1][0]\u0015HABBO_CLUB_OFFER_BETA[0][0][1][0]\u000EUSE_GUIDE_TOOL[0]&requirement.unfulfilled.helper_level_4[0][0]\u000FBUILDER_AT_WORK[0](requirement.unfulfilled.group_membership[0][0]\u000FCALL_ON_HELPERS[0][0][1][0]\u001FNAVIGATOR_ROOM_THUMBNAIL_CAMERA[0][0][1][0][7]CITIZEN[0][0][1][0]\u0012JUDGE_CHAT_REVIEWS[0]&requirement.unfulfilled.helper_level_6[0][0][5]TRADE[0][0][1][0][6]CAMERA[0][0][1][0]\u0014VOTE_IN_COMPETITIONS[0][0][1][0]\u0018NAVIGATOR_PHASE_TWO_2014[0][0][1]")
-
- };
-
- for (HPacket packet : packets) {
- StructurePredictor structurePredictor = new StructurePredictor(packet);
- System.out.println(structurePredictor.getStructure());
- System.out.println(structurePredictor.getExpression());
- }
- }
}
diff --git a/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/IntegerChecker.java b/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/IntegerChecker.java
index 54c9941..d34c0a3 100644
--- a/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/IntegerChecker.java
+++ b/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/IntegerChecker.java
@@ -1,6 +1,7 @@
package gearth.misc.packetrepresentation.prediction.checkers;
import gearth.protocol.HPacket;
+import gearth.services.Constants;
import java.nio.charset.StandardCharsets;
@@ -33,7 +34,7 @@ public class IntegerChecker extends TypeChecker {
}
// 4 bytes that read [0][2]xy could be a string
- if (ushortTest >= 2 && ushortTest <= 6 && StringChecker.canReadString(hPacket, index)) {
+ if (ushortTest == 2 && StringChecker.canReadString(hPacket, index)) {
return (1 - StringChecker.scoreString(hPacket.readString(index)));
}
diff --git a/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/LongChecker.java b/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/LongChecker.java
new file mode 100644
index 0000000..7cc3591
--- /dev/null
+++ b/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/LongChecker.java
@@ -0,0 +1,45 @@
+package gearth.misc.packetrepresentation.prediction.checkers;
+
+import gearth.protocol.HPacket;
+
+public class LongChecker extends TypeChecker {
+
+ private IntegerChecker integerChecker;
+
+ protected LongChecker(HPacket hPacket) {
+ super("l", hPacket);
+ integerChecker = new IntegerChecker(hPacket);
+ }
+
+ @Override
+ public boolean canRead(int index) {
+ return index >= 6 && !(index + 8 > hPacket.getBytesLength());
+ }
+
+ @Override
+ public double score(int index) {
+ int split1 = hPacket.readInteger(index);
+ int split2 = hPacket.readInteger(index + 4);
+
+ int zeros = 0;
+ for (int i = index + 4; i < index + 8; i++) {
+ zeros += hPacket.readByte(i) == 0 ? 1 : 0;
+ }
+
+ if (split2 > 256 * 256 * 3 && split1 == 0 && zeros < 2) {
+ return integerChecker.score(index) * integerChecker.score(index + 4) + 0.0000000001;
+ }
+
+ return 0;
+ }
+
+ @Override
+ Long get(int index) {
+ return hPacket.readLong(index);
+ }
+
+ @Override
+ int nextIndexSafe(int index) {
+ return index + 8;
+ }
+}
diff --git a/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/ShortChecker.java b/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/ShortChecker.java
new file mode 100644
index 0000000..d125e3b
--- /dev/null
+++ b/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/ShortChecker.java
@@ -0,0 +1,56 @@
+package gearth.misc.packetrepresentation.prediction.checkers;
+
+import gearth.protocol.HPacket;
+
+public class ShortChecker extends TypeChecker {
+
+ private BooleanChecker booleanChecker;
+ private ByteChecker byteChecker;
+
+ protected ShortChecker(HPacket hPacket) {
+ super("u", hPacket);
+ booleanChecker = new BooleanChecker(hPacket);
+ byteChecker = new ByteChecker(hPacket);
+ }
+
+ @Override
+ public boolean canRead(int index) {
+ return index >= 6 && !(index + 2 > hPacket.getBytesLength());
+ }
+
+ @Override
+ public double score(int index) {
+ short val = hPacket.readShort(index);
+
+ if (index == 6 && val == 0 && hPacket.length() == nextIndexSafe(index)) {
+ return 1;
+ }
+
+ if (val <= 0) {
+ return 0;
+ }
+
+ if (val < 1000) {
+ return 0.5;
+ }
+
+ double leftMinScore;
+ double rightMinScore;
+ if (booleanChecker.canRead(index)) leftMinScore = booleanChecker.score(index);
+ else leftMinScore = byteChecker.score(index);
+ if (booleanChecker.canRead(index+1)) rightMinScore = booleanChecker.score(index+1);
+ else rightMinScore = byteChecker.score(index+1);
+
+ return leftMinScore * rightMinScore + 0.00000001;
+ }
+
+ @Override
+ Object get(int index) {
+ return hPacket.readShort();
+ }
+
+ @Override
+ int nextIndexSafe(int index) {
+ return index + 2;
+ }
+}
diff --git a/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/TypeCheckerProducer.java b/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/TypeCheckerProducer.java
index 675699c..11255a7 100644
--- a/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/TypeCheckerProducer.java
+++ b/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/TypeCheckerProducer.java
@@ -2,18 +2,27 @@ package gearth.misc.packetrepresentation.prediction.checkers;
import gearth.protocol.HPacket;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import static gearth.services.Constants.UNITY_PACKETS;
+
public class TypeCheckerProducer {
public static List getValidators(HPacket packet) {
- return Arrays.asList(
+ List typeCheckers = new ArrayList<>(Arrays.asList(
new BooleanChecker(packet),
new ByteChecker(packet),
new IntegerChecker(packet),
- new StringChecker(packet)
- );
+ new StringChecker(packet)));
+
+ if (UNITY_PACKETS) {
+ typeCheckers.add(new LongChecker(packet));
+ typeCheckers.add(new ShortChecker(packet));
+ }
+
+ return typeCheckers;
}
}
diff --git a/G-Earth/src/main/java/gearth/protocol/HConnection.java b/G-Earth/src/main/java/gearth/protocol/HConnection.java
index 1a84a6d..97ed7d4 100644
--- a/G-Earth/src/main/java/gearth/protocol/HConnection.java
+++ b/G-Earth/src/main/java/gearth/protocol/HConnection.java
@@ -4,9 +4,10 @@ import gearth.misc.listenerpattern.Observable;
import gearth.protocol.connection.HProxy;
import gearth.protocol.connection.HState;
import gearth.protocol.connection.proxy.ProxyProvider;
+import gearth.protocol.connection.proxy.flash.FlashProxyProvider;
import gearth.protocol.connection.proxy.ProxyProviderFactory;
-import gearth.protocol.connection.proxy.unix.LinuxRawIpProxyProvider;
-import gearth.protocol.connection.proxy.windows.WindowsRawIpProxyProvider;
+import gearth.protocol.connection.proxy.flash.unix.LinuxRawIpFlashProxyProvider;
+import gearth.protocol.connection.proxy.unity.UnityProxyProvider;
import gearth.services.extensionhandler.ExtensionHandler;
import java.io.IOException;
@@ -60,6 +61,12 @@ public class HConnection {
startMITM();
}
+ public void startUnity() {
+ HConnection selff = this;
+ proxyProvider = new UnityProxyProvider(proxy -> selff.proxy = proxy, selff::setState, this);
+ startMITM();
+ }
+
private void startMITM() {
try {
if (proxyProvider != null) {
@@ -166,7 +173,7 @@ public class HConnection {
}
public boolean isRawIpMode() {
- return proxyProvider != null && proxyProvider instanceof LinuxRawIpProxyProvider;
+ return proxyProvider != null && proxyProvider instanceof LinuxRawIpFlashProxyProvider;
// WindowsRawIpProxyProvider extends LinuxRawIpProxyProvider
}
diff --git a/G-Earth/src/main/java/gearth/protocol/HPacket.java b/G-Earth/src/main/java/gearth/protocol/HPacket.java
index 1cde853..c1cfb94 100644
--- a/G-Earth/src/main/java/gearth/protocol/HPacket.java
+++ b/G-Earth/src/main/java/gearth/protocol/HPacket.java
@@ -8,6 +8,7 @@ import gearth.misc.packetrepresentation.PacketStringUtils;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.InvalidParameterException;
import java.util.Arrays;
@@ -36,7 +37,7 @@ public class HPacket implements StringifyAble {
}
public HPacket(int header) {
packetInBytes = new byte[]{0,0,0,2,0,0};
- replaceUShort(4, header);
+ replaceShort(4, (short)header);
isEdited = false;
}
public HPacket(int header, byte[] bytes) {
@@ -126,7 +127,7 @@ public class HPacket implements StringifyAble {
}
public int headerId() {
- return readUshort(4);
+ return readShort(4);
}
public int readInteger(){
@@ -180,34 +181,49 @@ public class HPacket implements StringifyAble {
return java.nio.ByteBuffer.wrap(btarray).getLong();
}
- public String readString() {
- String r = readString(readIndex);
- readIndex += (2 + r.length());
+
+ public String readString(Charset charset) {
+ String r = readString(readIndex, charset);
+ readIndex += (2 + readUshort(readIndex));
return r;
}
- public String readString(int index) {
+ public String readString(int index, Charset charset) {
int length = readUshort(index);
index+=2;
-
- return readString(index, length);
+ return readString(index, length, charset);
}
- private String readString(int index, int length) {
+ public String readString() {
+ return readString(StandardCharsets.ISO_8859_1);
+ }
+ public String readString(int index) {
+ return readString(index, StandardCharsets.ISO_8859_1);
+ }
+
+ private String readString(int index, int length, Charset charset) {
byte[] x = new byte[length];
for (int i = 0; i < x.length; i++) { x[i] = readByte(index); index++; }
- return new String(x, StandardCharsets.ISO_8859_1);
+ return new String(x, charset);
}
- public String readLongString() {
- String r = readLongString(readIndex);
- readIndex += (4 + r.length());
+
+ public String readLongString(Charset charset) {
+ String r = readLongString(readIndex, charset);
+ readIndex += (4 + readInteger(readIndex));
return r;
}
- public String readLongString(int index) {
+ public String readLongString(int index, Charset charset) {
int length = readInteger(index);
index += 4;
- return readString(index, length);
+ return readString(index, length, charset);
+ }
+
+ public String readLongString() {
+ return readLongString(StandardCharsets.ISO_8859_1);
+ }
+ public String readLongString(int index) {
+ return readLongString(index, StandardCharsets.ISO_8859_1);
}
public boolean readBoolean() {
@@ -231,6 +247,14 @@ public class HPacket implements StringifyAble {
}
return this;
}
+ public HPacket replaceLong(int index, long l) {
+ isEdited = true;
+ ByteBuffer b = ByteBuffer.allocate(8).putLong(l);
+ for (int j = 0; j < 8; j++) {
+ packetInBytes[index + j] = b.array()[j];
+ }
+ return this;
+ }
public HPacket replaceDouble(int index, double d) {
isEdited = true;
ByteBuffer b = ByteBuffer.allocate(8).putDouble(d);
@@ -267,10 +291,11 @@ public class HPacket implements StringifyAble {
packetInBytes[index + 1] = b.array()[1];
return this;
}
- public HPacket replaceString(int index, String s) {
+
+ public HPacket replaceString(int index, String s, Charset charset) {
isEdited = true;
- byte[] sbytes = s.getBytes(StandardCharsets.ISO_8859_1);
- int mover = s.length() - readUshort(index);
+ byte[] sbytes = s.getBytes(charset);
+ int mover = sbytes.length - readUshort(index);
if (mover != 0) {
byte[] newPacket = Arrays.copyOf(packetInBytes, packetInBytes.length + mover);
@@ -283,7 +308,7 @@ public class HPacket implements StringifyAble {
}
}
else {
- int i = index + 2 + s.length();
+ int i = index + 2 + sbytes.length;
while (i < newPacket.length) {
newPacket[i] = packetInBytes[i - mover];
i++;
@@ -294,13 +319,17 @@ public class HPacket implements StringifyAble {
fixLength();
}
- replaceUShort(index, s.length());
- for (int i = 0; i < s.length(); i++) {
+ replaceUShort(index, sbytes.length);
+ for (int i = 0; i < sbytes.length; i++) {
packetInBytes[index + 2 + i] = sbytes[i];
}
return this;
}
+ public HPacket replaceString(int index, String s) {
+ return replaceString(index, s, StandardCharsets.ISO_8859_1);
+ }
+
private boolean canReadString(int index) {
if (index < packetInBytes.length - 1) {
int l = readUshort(index);
@@ -394,6 +423,16 @@ public class HPacket implements StringifyAble {
fixLength();
return this;
}
+ public HPacket appendLong(long l) {
+ isEdited = true;
+ packetInBytes = Arrays.copyOf(packetInBytes, packetInBytes.length + 8);
+ ByteBuffer byteBuffer = ByteBuffer.allocate(8).putLong(l);
+ for (int j = 0; j < 8; j++) {
+ packetInBytes[packetInBytes.length - 8 + j] = byteBuffer.array()[j];
+ }
+ fixLength();
+ return this;
+ }
public HPacket appendDouble(double d) {
isEdited = true;
packetInBytes = Arrays.copyOf(packetInBytes, packetInBytes.length + 8);
@@ -445,18 +484,27 @@ public class HPacket implements StringifyAble {
fixLength();
return this;
}
+ public HPacket appendString(String s, Charset charset) {
+ isEdited = true;
+ appendUShort(s.getBytes(charset).length);
+ appendBytes(s.getBytes(charset));
+ return this;
+ }
public HPacket appendString(String s) {
+ return appendString(s, StandardCharsets.ISO_8859_1);
+ }
+
+ public HPacket appendLongString(String s, Charset charset) {
isEdited = true;
- appendUShort(s.length());
- appendBytes(s.getBytes(StandardCharsets.ISO_8859_1));
+ appendInt(s.getBytes(charset).length);
+ appendBytes(s.getBytes(charset));
return this;
}
+
public HPacket appendLongString(String s) {
- isEdited = true;
- appendInt(s.length());
- appendBytes(s.getBytes(StandardCharsets.ISO_8859_1));
- return this;
+ return appendLongString(s, StandardCharsets.ISO_8859_1);
}
+
public HPacket appendObject(Object o) throws InvalidParameterException {
isEdited = true;
@@ -472,6 +520,9 @@ public class HPacket implements StringifyAble {
else if (o instanceof Boolean) {
appendBoolean((Boolean) o);
}
+ else if (o instanceof Long) {
+ appendLong((Long) o);
+ }
else {
throw new InvalidParameterException();
}
@@ -479,20 +530,6 @@ public class HPacket implements StringifyAble {
return this;
}
-
- public HPacket removeFrom(int index) {
- return removeRange(index, packetInBytes.length - index);
- }
- public HPacket removeRange(int index, int length) {
- isEdited = true;
- for (int i = index; i < packetInBytes.length - length; i++) {
- packetInBytes[i] = packetInBytes[i + length];
- }
- packetInBytes = Arrays.copyOf(packetInBytes, packetInBytes.length - length);
- fixLength();
- return this;
- }
-
public boolean isReplaced() {
return isEdited;
}
@@ -507,25 +544,44 @@ public class HPacket implements StringifyAble {
isEdited = edited;
}
- public String toExpression(HMessage.Direction direction) {
- if (isCorrupted()) return "";
-
+ private String getHarbleStructure(HMessage.Direction direction) {
HarbleAPI.HarbleMessage msg;
if (HarbleAPIFetcher.HARBLEAPI != null &&
((msg = HarbleAPIFetcher.HARBLEAPI.getHarbleMessageFromHeaderId(direction, headerId())) != null)) {
- if (msg.getStructure() != null) {
- return PacketStringUtils.toExpressionFromGivenStructure(this, msg.getStructure());
+ if (msg.getStructure() != null && structureEquals(msg.getStructure())) {
+ return msg.getStructure();
}
}
- return toExpression();
+
+ return null;
+ }
+
+ public String toExpression(HMessage.Direction direction) {
+ if (isCorrupted()) return "";
+
+ String structure = getHarbleStructure(direction);
+ if (structure != null) {
+ return PacketStringUtils.toExpressionFromGivenStructure(this, structure);
+ }
+
+ return PacketStringUtils.predictedExpression(this);
}
/**
* returns "" if not found or not sure enough
- * dont hate on the coding quality in this function, its pretty effective.
*/
public String toExpression() {
if (isCorrupted()) return "";
+
+ String structure1 = getHarbleStructure(HMessage.Direction.TOCLIENT);
+ String structure2 = getHarbleStructure(HMessage.Direction.TOSERVER);
+ if (structure1 != null && structure2 == null) {
+ return PacketStringUtils.toExpressionFromGivenStructure(this, structure1);
+ }
+ else if (structure1 == null && structure2 != null) {
+ return PacketStringUtils.toExpressionFromGivenStructure(this, structure2);
+ }
+
return PacketStringUtils.predictedExpression(this);
}
@@ -551,7 +607,7 @@ public class HPacket implements StringifyAble {
}
public static void main(String[] args) {
- HPacket packet = new HPacket("{l}{u:4564}{i:3}{i:0}{s:\"hi\"}{i:0}{i:1}{s:\"how\"}{i:3}{b:1}{b:2}{b:3}{i:2}{s:\"r u\"}{i:1}{b:120}{i:2}{b:true}{d:1.4}");
+ HPacket packet = new HPacket("{l}{h:4564}{i:3}{i:0}{s:\"hi\"}{i:0}{i:1}{s:\"how\"}{i:3}{b:1}{b:2}{b:3}{i:2}{s:\"r u\"}{i:1}{b:120}{i:2}{b:true}{d:1.4}");
String str = PacketStringUtils.toExpressionFromGivenStructure(packet, "i(isi(b))iBd");
diff --git a/G-Earth/src/main/java/gearth/protocol/connection/HClient.java b/G-Earth/src/main/java/gearth/protocol/connection/HClient.java
new file mode 100644
index 0000000..54653c3
--- /dev/null
+++ b/G-Earth/src/main/java/gearth/protocol/connection/HClient.java
@@ -0,0 +1,6 @@
+package gearth.protocol.connection;
+
+public enum HClient {
+ UNITY,
+ FLASH
+}
diff --git a/G-Earth/src/main/java/gearth/protocol/connection/HProxy.java b/G-Earth/src/main/java/gearth/protocol/connection/HProxy.java
index b49fd5e..e5f1147 100644
--- a/G-Earth/src/main/java/gearth/protocol/connection/HProxy.java
+++ b/G-Earth/src/main/java/gearth/protocol/connection/HProxy.java
@@ -1,11 +1,13 @@
package gearth.protocol.connection;
-import gearth.protocol.packethandler.IncomingPacketHandler;
-import gearth.protocol.packethandler.OutgoingPacketHandler;
+import gearth.protocol.packethandler.PacketHandler;
import java.net.ServerSocket;
public class HProxy {
+
+ private final HClient hClient;
+
private volatile String input_domain; //string representation of the domain to intercept
private volatile String actual_domain; //dns resolved domain (ignoring hosts file)
private volatile int actual_port; //port of the server
@@ -15,13 +17,14 @@ public class HProxy {
private volatile ServerSocket proxy_server = null; //listener for the client
- private volatile IncomingPacketHandler inHandler = null; //connection with client (only initialized when verified habbo connection)
- private volatile OutgoingPacketHandler outHandler = null; //connection with server (only initialized when verified habbo connection)
+ private volatile PacketHandler inHandler = null; //connection with client (only initialized when verified habbo connection)
+ private volatile PacketHandler outHandler = null; //connection with server (only initialized when verified habbo connection)
private volatile String hotelVersion = "";
private volatile AsyncPacketSender asyncPacketSender = null;
- public HProxy(String input_domain, String actual_domain, int actual_port, int intercept_port, String intercept_host) {
+ public HProxy(HClient hClient, String input_domain, String actual_domain, int actual_port, int intercept_port, String intercept_host) {
+ this.hClient = hClient;
this.input_domain = input_domain;
this.actual_domain = actual_domain;
this.actual_port = actual_port;
@@ -33,7 +36,7 @@ public class HProxy {
this.proxy_server = socket;
}
- public void verifyProxy(IncomingPacketHandler incomingHandler, OutgoingPacketHandler outgoingHandler, String hotelVersion) {
+ public void verifyProxy(PacketHandler incomingHandler, PacketHandler outgoingHandler, String hotelVersion) {
this.inHandler = incomingHandler;
this.outHandler = outgoingHandler;
this.hotelVersion = hotelVersion;
@@ -64,11 +67,11 @@ public class HProxy {
return intercept_host;
}
- public IncomingPacketHandler getInHandler() {
+ public PacketHandler getInHandler() {
return inHandler;
}
- public OutgoingPacketHandler getOutHandler() {
+ public PacketHandler getOutHandler() {
return outHandler;
}
@@ -79,4 +82,8 @@ public class HProxy {
public AsyncPacketSender getAsyncPacketSender() {
return asyncPacketSender;
}
+
+ public HClient gethClient() {
+ return hClient;
+ }
}
diff --git a/G-Earth/src/main/java/gearth/protocol/connection/proxy/ProxyProvider.java b/G-Earth/src/main/java/gearth/protocol/connection/proxy/ProxyProvider.java
index a1faa47..c3a831d 100644
--- a/G-Earth/src/main/java/gearth/protocol/connection/proxy/ProxyProvider.java
+++ b/G-Earth/src/main/java/gearth/protocol/connection/proxy/ProxyProvider.java
@@ -1,129 +1,10 @@
package gearth.protocol.connection.proxy;
-import gearth.protocol.HConnection;
-import gearth.protocol.connection.HProxy;
-import gearth.protocol.connection.HProxySetter;
-import gearth.protocol.connection.HState;
-import gearth.protocol.connection.HStateSetter;
-import gearth.protocol.memory.Rc4Obtainer;
-import gearth.protocol.packethandler.IncomingPacketHandler;
-import gearth.protocol.packethandler.OutgoingPacketHandler;
-import gearth.protocol.packethandler.PacketHandler;
-import javafx.application.Platform;
-import javafx.scene.control.Alert;
-import javafx.scene.control.ButtonType;
-import javafx.scene.layout.Region;
-
import java.io.IOException;
-import java.net.Socket;
-import java.util.Arrays;
-import java.util.concurrent.Semaphore;
-public abstract class ProxyProvider {
+public interface ProxyProvider {
- protected final HProxySetter proxySetter;
- protected final HStateSetter stateSetter;
- protected final HConnection hConnection;
-
- private Semaphore abortSemaphore = null;
-
- public ProxyProvider(HProxySetter proxySetter, HStateSetter stateSetter, HConnection hConnection){
- this.proxySetter = proxySetter;
- this.stateSetter = stateSetter;
- this.hConnection = hConnection;
- }
-
- protected void startProxyThread(Socket client, Socket server, HProxy proxy) throws IOException, InterruptedException {
- final boolean[] datastream = new boolean[1];
- server.setTcpNoDelay(true);
- client.setTcpNoDelay(true);
-
- client.setSoTimeout(0);
- server.setSoTimeout(0);
-
- if (HConnection.DEBUG) System.out.println(server.getLocalAddress().getHostAddress() + ": " + server.getLocalPort());
- Rc4Obtainer rc4Obtainer = new Rc4Obtainer(hConnection);
-
- OutgoingPacketHandler outgoingHandler = new OutgoingPacketHandler(server.getOutputStream(), hConnection.getTrafficObservables(), hConnection.getExtensionHandler());
- IncomingPacketHandler incomingHandler = new IncomingPacketHandler(client.getOutputStream(), hConnection.getTrafficObservables(), outgoingHandler, hConnection.getExtensionHandler());
- rc4Obtainer.setPacketHandlers(outgoingHandler, incomingHandler);
-
- Semaphore abort = new Semaphore(0);
-
- outgoingHandler.addOnDatastreamConfirmedListener(hotelVersion -> {
- incomingHandler.setAsDataStream();
- proxy.verifyProxy(incomingHandler, outgoingHandler, hotelVersion);
- proxySetter.setProxy(proxy);
- datastream[0] = true;
- abortSemaphore = abort;
- onConnect();
- });
-
- handleInputStream(client, outgoingHandler, abort);
- handleInputStream(server, incomingHandler, abort);
-
- // abort can be acquired as soon as one of the sockets is closed
- abort.acquire();
- try {
- if (!server.isClosed()) server.close();
- if (!client.isClosed()) client.close();
- if (HConnection.DEBUG) System.out.println("STOP");
- if (datastream[0]) {
- onConnectEnd();
- };
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- private void handleInputStream(Socket socket, PacketHandler packetHandler, Semaphore abort) {
- new Thread(() -> {
- try {
- int readLength;
- byte[] buffer = new byte[10000];
- while (!socket.isClosed() &&
- (hConnection.getState() == HState.WAITING_FOR_CLIENT || hConnection.getState() == HState.CONNECTED) &&
- (readLength = socket.getInputStream().read(buffer)) != -1) {
- packetHandler.act(Arrays.copyOf(buffer, readLength));
- }
- }
- catch (IOException ignore) {
-// System.err.println(packetHandler instanceof IncomingPacketHandler ? "incoming" : "outgoing");
-// ignore.printStackTrace();
- } finally {
- abort.release();
- }
- }).start();
- }
-
-
- public abstract void start() throws IOException;
- public void abort() {
- if (abortSemaphore != null) {
- abortSemaphore.release();
- }
- else {
- stateSetter.setState(HState.NOT_CONNECTED);
- }
- }
-
- protected void onConnect() {
- stateSetter.setState(HState.CONNECTED);
- }
- protected void onConnectEnd() {
- proxySetter.setProxy(null);
- abortSemaphore = null;
- stateSetter.setState(HState.NOT_CONNECTED);
- }
-
- protected void showInvalidConnectionError() {
- Platform.runLater(() -> {
- Alert alert = new Alert(Alert.AlertType.ERROR, "You entered invalid connection information, G-Earth could not connect", ButtonType.OK);
- alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
- alert.setResizable(false);
- alert.show();
- });
- }
+ void start() throws IOException;
+ void abort();
}
diff --git a/G-Earth/src/main/java/gearth/protocol/connection/proxy/ProxyProviderFactory.java b/G-Earth/src/main/java/gearth/protocol/connection/proxy/ProxyProviderFactory.java
index 9cbe29e..59eecb4 100644
--- a/G-Earth/src/main/java/gearth/protocol/connection/proxy/ProxyProviderFactory.java
+++ b/G-Earth/src/main/java/gearth/protocol/connection/proxy/ProxyProviderFactory.java
@@ -5,8 +5,10 @@ import gearth.misc.OSValidator;
import gearth.protocol.HConnection;
import gearth.protocol.connection.HProxySetter;
import gearth.protocol.connection.HStateSetter;
-import gearth.protocol.connection.proxy.unix.LinuxRawIpProxyProvider;
-import gearth.protocol.connection.proxy.windows.WindowsRawIpProxyProvider;
+import gearth.protocol.connection.proxy.flash.NormalFlashProxyProvider;
+import gearth.protocol.connection.proxy.flash.FlashProxyProvider;
+import gearth.protocol.connection.proxy.flash.unix.LinuxRawIpFlashProxyProvider;
+import gearth.protocol.connection.proxy.flash.windows.WindowsRawIpFlashProxyProvider;
import javafx.application.Platform;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
@@ -67,7 +69,7 @@ public class ProxyProviderFactory {
// checks if host is a raw IP instead of a domain
// TODO support ipv6 (not only here, also in IPmapper)
- static boolean hostIsIpAddress(String host){
+ public static boolean hostIsIpAddress(String host){
for (char c : host.toCharArray()) {
if (c != '.' && (c < '0' || c > '9')) {
return false;
@@ -79,7 +81,6 @@ public class ProxyProviderFactory {
public ProxyProvider provide() {
return provide(autoDetectHosts);
}
-
public ProxyProvider provide(String domain, int port) {
List