packet expression things

This commit is contained in:
sirjonasxx 2020-10-04 17:28:18 +02:00
parent 1d1831cc94
commit 1f58290393
2 changed files with 28 additions and 8 deletions

View File

@ -537,25 +537,44 @@ public class HPacket implements StringifyAble {
isEdited = edited; isEdited = edited;
} }
public String toExpression(HMessage.Direction direction) { private String getHarbleStructure(HMessage.Direction direction) {
if (isCorrupted()) return "";
HarbleAPI.HarbleMessage msg; HarbleAPI.HarbleMessage msg;
if (HarbleAPIFetcher.HARBLEAPI != null && if (HarbleAPIFetcher.HARBLEAPI != null &&
((msg = HarbleAPIFetcher.HARBLEAPI.getHarbleMessageFromHeaderId(direction, headerId())) != null)) { ((msg = HarbleAPIFetcher.HARBLEAPI.getHarbleMessageFromHeaderId(direction, headerId())) != null)) {
if (msg.getStructure() != null) { if (msg.getStructure() != null && structureEquals(msg.getStructure())) {
return PacketStringUtils.toExpressionFromGivenStructure(this, 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 * returns "" if not found or not sure enough
* dont hate on the coding quality in this function, its pretty effective.
*/ */
public String toExpression() { public String toExpression() {
if (isCorrupted()) return ""; 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); return PacketStringUtils.predictedExpression(this);
} }

View File

@ -8,6 +8,7 @@ import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
/** /**
* Created by Jonas on 21/06/18. * Created by Jonas on 21/06/18.
@ -224,7 +225,7 @@ public class NetworkExtension extends GEarthExtension {
public void packetToStringResponse(String string, String expression) { public void packetToStringResponse(String string, String expression) {
HPacket packet = new HPacket(NetworkExtensionInfo.OUTGOING_MESSAGES_IDS.PACKETTOSTRING_RESPONSE); HPacket packet = new HPacket(NetworkExtensionInfo.OUTGOING_MESSAGES_IDS.PACKETTOSTRING_RESPONSE);
packet.appendLongString(string); packet.appendLongString(string);
packet.appendLongString(expression); packet.appendLongString(expression, StandardCharsets.UTF_8);
sendMessage(packet); sendMessage(packet);
} }