From 1f58290393a614e0511b27dbc7bd476b39004575 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Sun, 4 Oct 2020 17:28:18 +0200 Subject: [PATCH] packet expression things --- .../main/java/gearth/protocol/HPacket.java | 33 +++++++++++++++---- .../network/NetworkExtension.java | 3 +- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/G-Earth/src/main/java/gearth/protocol/HPacket.java b/G-Earth/src/main/java/gearth/protocol/HPacket.java index 5412bd1..40f05e1 100644 --- a/G-Earth/src/main/java/gearth/protocol/HPacket.java +++ b/G-Earth/src/main/java/gearth/protocol/HPacket.java @@ -537,25 +537,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); } diff --git a/G-Earth/src/main/java/gearth/services/extensionhandler/extensions/implementations/network/NetworkExtension.java b/G-Earth/src/main/java/gearth/services/extensionhandler/extensions/implementations/network/NetworkExtension.java index 2539d1c..af4600c 100644 --- a/G-Earth/src/main/java/gearth/services/extensionhandler/extensions/implementations/network/NetworkExtension.java +++ b/G-Earth/src/main/java/gearth/services/extensionhandler/extensions/implementations/network/NetworkExtension.java @@ -8,6 +8,7 @@ import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.net.Socket; +import java.nio.charset.StandardCharsets; /** * Created by Jonas on 21/06/18. @@ -224,7 +225,7 @@ public class NetworkExtension extends GEarthExtension { public void packetToStringResponse(String string, String expression) { HPacket packet = new HPacket(NetworkExtensionInfo.OUTGOING_MESSAGES_IDS.PACKETTOSTRING_RESPONSE); packet.appendLongString(string); - packet.appendLongString(expression); + packet.appendLongString(expression, StandardCharsets.UTF_8); sendMessage(packet); }