mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 08:50:52 +01:00
more packet stuff
This commit is contained in:
parent
74a72d199b
commit
7030fcb9f2
@ -36,6 +36,8 @@ public abstract class Extension implements IExtension {
|
|||||||
private static final String[] FILE_FLAG = {"--filename", "-f"};
|
private static final String[] FILE_FLAG = {"--filename", "-f"};
|
||||||
private static final String[] COOKIE_FLAG = {"--auth-token", "-c"}; // don't add a cookie or filename when debugging
|
private static final String[] COOKIE_FLAG = {"--auth-token", "-c"}; // don't add a cookie or filename when debugging
|
||||||
|
|
||||||
|
protected PacketInfoManager packetInfoManager = new PacketInfoManager(new ArrayList<>()); // empty
|
||||||
|
|
||||||
private OutputStream out = null;
|
private OutputStream out = null;
|
||||||
private final Map<Integer, List<MessageListener>> incomingMessageListeners = new HashMap<>();
|
private final Map<Integer, List<MessageListener>> incomingMessageListeners = new HashMap<>();
|
||||||
private final Map<Integer, List<MessageListener>> outgoingMessageListeners = new HashMap<>();
|
private final Map<Integer, List<MessageListener>> outgoingMessageListeners = new HashMap<>();
|
||||||
@ -144,7 +146,7 @@ public abstract class Extension implements IExtension {
|
|||||||
String hotelVersion = packet.readString();
|
String hotelVersion = packet.readString();
|
||||||
String clientIdentifier = packet.readString();
|
String clientIdentifier = packet.readString();
|
||||||
HClient clientType = HClient.valueOf(packet.readString());
|
HClient clientType = HClient.valueOf(packet.readString());
|
||||||
PacketInfoManager packetInfoManager = PacketInfoManager.readFromPacket(packet);
|
packetInfoManager = PacketInfoManager.readFromPacket(packet);
|
||||||
|
|
||||||
Constants.UNITY_PACKETS = clientType == HClient.UNITY;
|
Constants.UNITY_PACKETS = clientType == HClient.UNITY;
|
||||||
onConnectionObservable.fireEvent(l -> l.onConnection(
|
onConnectionObservable.fireEvent(l -> l.onConnection(
|
||||||
@ -256,6 +258,11 @@ public abstract class Extension implements IExtension {
|
|||||||
return send(packet, HMessage.Direction.TOSERVER);
|
return send(packet, HMessage.Direction.TOSERVER);
|
||||||
}
|
}
|
||||||
private boolean send(HPacket packet, HMessage.Direction direction) {
|
private boolean send(HPacket packet, HMessage.Direction direction) {
|
||||||
|
if (packet.isCorrupted()) return false;
|
||||||
|
|
||||||
|
if (!packet.isPacketComplete()) packet.completePacket(direction, packetInfoManager);
|
||||||
|
if (!packet.isPacketComplete()) return false;
|
||||||
|
|
||||||
HPacket packet1 = new HPacket(NetworkExtensionInfo.INCOMING_MESSAGES_IDS.SENDMESSAGE);
|
HPacket packet1 = new HPacket(NetworkExtensionInfo.INCOMING_MESSAGES_IDS.SENDMESSAGE);
|
||||||
packet1.appendByte(direction == HMessage.Direction.TOCLIENT ? (byte)0 : (byte)1);
|
packet1.appendByte(direction == HMessage.Direction.TOCLIENT ? (byte)0 : (byte)1);
|
||||||
packet1.appendInt(packet.getBytesLength());
|
packet1.appendInt(packet.getBytesLength());
|
||||||
|
@ -44,6 +44,7 @@ public class HarblePacketInfoProvider extends RemotePacketInfoProvider {
|
|||||||
catch (Exception e) { hash = null; }
|
catch (Exception e) { hash = null; }
|
||||||
try { structure = object.getString("Structure");
|
try { structure = object.getString("Structure");
|
||||||
} catch (Exception e) { structure = null; }
|
} catch (Exception e) { structure = null; }
|
||||||
|
structure = (structure == null || structure.equals("")) ? null : structure;
|
||||||
|
|
||||||
int headerId;
|
int headerId;
|
||||||
try {headerId = object.getInt("Id"); }
|
try {headerId = object.getInt("Id"); }
|
||||||
|
@ -135,6 +135,14 @@ public class PacketStringUtils {
|
|||||||
packet.substring(end + 2);
|
packet.substring(end + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String[] identifier = {null};
|
||||||
|
if (!fixLengthLater && packet.startsWith("{")) {
|
||||||
|
packet = replaceAll(packet, "^\\{([^:{}]*)}", m -> {
|
||||||
|
identifier[0] = m.group(1);
|
||||||
|
return "[255][255]";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (identifier[0] != null) fixLengthLater = true;
|
||||||
|
|
||||||
if (packet.contains("{") || packet.contains("}")) {
|
if (packet.contains("{") || packet.contains("}")) {
|
||||||
throw new InvalidPacketException();
|
throw new InvalidPacketException();
|
||||||
@ -164,6 +172,9 @@ public class PacketStringUtils {
|
|||||||
if (fixLengthLater) {
|
if (fixLengthLater) {
|
||||||
hPacket.fixLength();
|
hPacket.fixLength();
|
||||||
}
|
}
|
||||||
|
if (identifier[0] != null) {
|
||||||
|
hPacket.setIdentifier(identifier[0]);
|
||||||
|
}
|
||||||
return hPacket;
|
return hPacket;
|
||||||
}
|
}
|
||||||
public static String toString(byte[] packet) {
|
public static String toString(byte[] packet) {
|
||||||
@ -255,6 +266,9 @@ public class PacketStringUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws InvalidPacketException {
|
public static void main(String[] args) throws InvalidPacketException {
|
||||||
|
HPacket zed = fromString("{test}{s:\"¥\"}{i:0}{i:0}");
|
||||||
|
System.out.println(zed);
|
||||||
|
|
||||||
HPacket p1 = fromString("{l}{h:1129}{s:\"\\\\\\\\\"}{i:0}{i:0}");
|
HPacket p1 = fromString("{l}{h:1129}{s:\"\\\\\\\\\"}{i:0}{i:0}");
|
||||||
System.out.println(p1.toExpression());
|
System.out.println(p1.toExpression());
|
||||||
HPacket p1_2 = fromString(p1.toExpression());
|
HPacket p1_2 = fromString(p1.toExpression());
|
||||||
|
@ -138,16 +138,28 @@ public class HConnection {
|
|||||||
|
|
||||||
|
|
||||||
public boolean sendToClientAsync(HPacket message) {
|
public boolean sendToClientAsync(HPacket message) {
|
||||||
if (proxy == null) {
|
if (proxy == null) return false;
|
||||||
return false;
|
|
||||||
|
if (!message.isPacketComplete()) {
|
||||||
|
PacketInfoManager packetInfoManager = getPacketInfoManager();
|
||||||
|
message.completePacket(HMessage.Direction.TOCLIENT, packetInfoManager);
|
||||||
|
|
||||||
|
if (!message.isPacketComplete()) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy.getAsyncPacketSender().sendToClientAsync(message);
|
proxy.getAsyncPacketSender().sendToClientAsync(message);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public boolean sendToServerAsync(HPacket message) {
|
public boolean sendToServerAsync(HPacket message) {
|
||||||
if (proxy == null) {
|
if (proxy == null) return false;
|
||||||
return false;
|
|
||||||
|
if (!message.isPacketComplete()) {
|
||||||
|
PacketInfoManager packetInfoManager = getPacketInfoManager();
|
||||||
|
message.completePacket(HMessage.Direction.TOSERVER, packetInfoManager);
|
||||||
|
|
||||||
|
if (!message.isPacketComplete()) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy.getAsyncPacketSender().sendToServerAsync(message);
|
proxy.getAsyncPacketSender().sendToServerAsync(message);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,13 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public class HPacket implements StringifyAble {
|
public class HPacket implements StringifyAble {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private boolean isEdited = false;
|
private boolean isEdited = false;
|
||||||
private byte[] packetInBytes;
|
private byte[] packetInBytes;
|
||||||
private int readIndex = 6;
|
private int readIndex = 6;
|
||||||
|
|
||||||
|
// if identifier != null, this is a placeholder name for the type of packet, headerId will be "-1"
|
||||||
|
private String identifier = null;
|
||||||
|
|
||||||
public HPacket(byte[] packet) {
|
public HPacket(byte[] packet) {
|
||||||
packetInBytes = packet.clone();
|
packetInBytes = packet.clone();
|
||||||
}
|
}
|
||||||
@ -30,11 +31,11 @@ public class HPacket implements StringifyAble {
|
|||||||
}
|
}
|
||||||
public HPacket(String packet) {
|
public HPacket(String packet) {
|
||||||
try {
|
try {
|
||||||
packetInBytes = PacketStringUtils.fromString(packet).packetInBytes;
|
HPacket packetFromString = PacketStringUtils.fromString(packet);
|
||||||
|
packetInBytes = packetFromString.packetInBytes;
|
||||||
|
identifier = packetFromString.identifier;
|
||||||
} catch (InvalidPacketException e) {
|
} catch (InvalidPacketException e) {
|
||||||
packetInBytes = new byte[0];
|
packetInBytes = new byte[0];
|
||||||
// will be corrupted
|
|
||||||
// e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public HPacket(int header) {
|
public HPacket(int header) {
|
||||||
@ -42,6 +43,7 @@ public class HPacket implements StringifyAble {
|
|||||||
replaceShort(4, (short)header);
|
replaceShort(4, (short)header);
|
||||||
isEdited = false;
|
isEdited = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HPacket(int header, byte[] bytes) {
|
public HPacket(int header, byte[] bytes) {
|
||||||
this(header);
|
this(header);
|
||||||
appendBytes(bytes);
|
appendBytes(bytes);
|
||||||
@ -55,14 +57,19 @@ public class HPacket implements StringifyAble {
|
|||||||
*/
|
*/
|
||||||
public HPacket(int header, Object... objects) throws InvalidParameterException {
|
public HPacket(int header, Object... objects) throws InvalidParameterException {
|
||||||
this(header);
|
this(header);
|
||||||
for (int i = 0; i < objects.length; i++) {
|
appendObjects(objects);
|
||||||
Object o = objects[i];
|
|
||||||
appendObject(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
isEdited = false;
|
isEdited = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HPacket(String identifier, Object... objects) throws InvalidParameterException {
|
||||||
|
packetInBytes = new byte[]{0,0,0,2,-1,-1};
|
||||||
|
this.identifier = identifier;
|
||||||
|
appendObjects(objects);
|
||||||
|
isEdited = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return PacketStringUtils.toString(packetInBytes);
|
return PacketStringUtils.toString(packetInBytes);
|
||||||
}
|
}
|
||||||
@ -77,6 +84,46 @@ public class HPacket implements StringifyAble {
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setIdentifier(String identifier) {
|
||||||
|
this.identifier = identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIdentifier() {
|
||||||
|
return identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void completePacket(HMessage.Direction direction, PacketInfoManager packetInfoManager) {
|
||||||
|
if (isCorrupted() || identifier == null) return;
|
||||||
|
|
||||||
|
PacketInfo packetInfo = packetInfoManager.getPacketInfoFromName(direction, identifier);
|
||||||
|
if (packetInfo == null) {
|
||||||
|
packetInfo = packetInfoManager.getPacketInfoFromHash(direction, identifier);
|
||||||
|
if (packetInfo == null) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean wasEdited = isEdited;
|
||||||
|
replaceShort(4, (short)(packetInfo.getHeaderId()));
|
||||||
|
identifier = null;
|
||||||
|
|
||||||
|
isEdited = wasEdited;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canComplete(HMessage.Direction direction, PacketInfoManager packetInfoManager) {
|
||||||
|
if (isCorrupted() || identifier == null) return false;
|
||||||
|
|
||||||
|
PacketInfo packetInfo = packetInfoManager.getPacketInfoFromName(direction, identifier);
|
||||||
|
if (packetInfo == null) {
|
||||||
|
packetInfo = packetInfoManager.getPacketInfoFromHash(direction, identifier);
|
||||||
|
return packetInfo != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPacketComplete() {
|
||||||
|
return identifier == null;
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] toBytes() {
|
public byte[] toBytes() {
|
||||||
return packetInBytes;
|
return packetInBytes;
|
||||||
}
|
}
|
||||||
@ -534,6 +581,14 @@ public class HPacket implements StringifyAble {
|
|||||||
return appendLongString(s, StandardCharsets.ISO_8859_1);
|
return appendLongString(s, StandardCharsets.ISO_8859_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HPacket appendObjects(Object... objects) {
|
||||||
|
for (Object object : objects) {
|
||||||
|
appendObject(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public HPacket appendObject(Object o) throws InvalidParameterException {
|
public HPacket appendObject(Object o) throws InvalidParameterException {
|
||||||
isEdited = true;
|
isEdited = true;
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package gearth.ui.injection;
|
package gearth.ui.injection;
|
||||||
|
|
||||||
|
import gearth.misc.packet_info.PacketInfoManager;
|
||||||
|
import gearth.protocol.HMessage;
|
||||||
import gearth.protocol.connection.HState;
|
import gearth.protocol.connection.HState;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
@ -12,7 +14,13 @@ import gearth.protocol.HConnection;
|
|||||||
import gearth.protocol.HPacket;
|
import gearth.protocol.HPacket;
|
||||||
import gearth.ui.SubForm;
|
import gearth.ui.SubForm;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class InjectionController extends SubForm {
|
public class InjectionController extends SubForm {
|
||||||
public TextArea inputPacket;
|
public TextArea inputPacket;
|
||||||
@ -95,9 +103,38 @@ public class InjectionController extends SubForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!dirty) {
|
if (!dirty) {
|
||||||
btn_sendToClient.setDisable(getHConnection().getState() != HState.CONNECTED);
|
PacketInfoManager packetInfoManager = getHConnection().getPacketInfoManager();
|
||||||
btn_sendToServer.setDisable(getHConnection().getState() != HState.CONNECTED);
|
|
||||||
|
List<String> unIdentifiedPackets = Arrays.stream(packets)
|
||||||
|
.filter(hPacket -> !hPacket.isPacketComplete())
|
||||||
|
.map(HPacket::getIdentifier).collect(Collectors.toList());
|
||||||
|
|
||||||
|
boolean canSendToClient = unIdentifiedPackets.stream().allMatch(s -> {
|
||||||
|
if (packetInfoManager == null) return false;
|
||||||
|
return packetInfoManager.getPacketInfoFromHash(HMessage.Direction.TOCLIENT, s) != null ||
|
||||||
|
packetInfoManager.getPacketInfoFromName(HMessage.Direction.TOCLIENT, s) != null;
|
||||||
|
});
|
||||||
|
boolean canSendToServer = unIdentifiedPackets.stream().allMatch(s -> {
|
||||||
|
if (packetInfoManager == null) return false;
|
||||||
|
return packetInfoManager.getPacketInfoFromHash(HMessage.Direction.TOSERVER, s) != null ||
|
||||||
|
packetInfoManager.getPacketInfoFromName(HMessage.Direction.TOSERVER, s) != null;
|
||||||
|
});
|
||||||
|
|
||||||
|
btn_sendToClient.setDisable(!canSendToClient || getHConnection().getState() != HState.CONNECTED);
|
||||||
|
btn_sendToServer.setDisable(!canSendToServer || getHConnection().getState() != HState.CONNECTED);
|
||||||
if (packets.length == 1) {
|
if (packets.length == 1) {
|
||||||
|
|
||||||
|
// complete packet to show correct headerId
|
||||||
|
if (!packets[0].isPacketComplete()) {
|
||||||
|
HPacket packet = packets[0];
|
||||||
|
if (packet.canComplete(HMessage.Direction.TOCLIENT, packetInfoManager) && !packet.canComplete(HMessage.Direction.TOSERVER, packetInfoManager)) {
|
||||||
|
packet.completePacket(HMessage.Direction.TOCLIENT, packetInfoManager);
|
||||||
|
}
|
||||||
|
else if (!packet.canComplete(HMessage.Direction.TOCLIENT, packetInfoManager) && packet.canComplete(HMessage.Direction.TOSERVER, packetInfoManager)) {
|
||||||
|
packet.completePacket(HMessage.Direction.TOSERVER, packetInfoManager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lbl_pcktInfo.setText("header (id:" + packets[0].headerId() + ", length:" +
|
lbl_pcktInfo.setText("header (id:" + packets[0].headerId() + ", length:" +
|
||||||
packets[0].length() + ")");
|
packets[0].length() + ")");
|
||||||
}
|
}
|
||||||
|
@ -72,8 +72,8 @@ public class InteractableScheduleItem extends ScheduleItem implements StringifyA
|
|||||||
.append("\t")
|
.append("\t")
|
||||||
.append(getDelayProperty().get().toString())
|
.append(getDelayProperty().get().toString())
|
||||||
.append("\t")
|
.append("\t")
|
||||||
.append(getPacketProperty().get().toString())
|
// .append(getPacketProperty().get().toString())
|
||||||
.append("\t")
|
// .append("\t")
|
||||||
.append(getDestinationProperty().get().name())
|
.append(getDestinationProperty().get().name())
|
||||||
.append("\t")
|
.append("\t")
|
||||||
.append(getPacketAsStringProperty().get());
|
.append(getPacketAsStringProperty().get());
|
||||||
@ -87,9 +87,10 @@ public class InteractableScheduleItem extends ScheduleItem implements StringifyA
|
|||||||
int index = Integer.parseInt(parts[0]);
|
int index = Integer.parseInt(parts[0]);
|
||||||
boolean paused = parts[1].equals("true");
|
boolean paused = parts[1].equals("true");
|
||||||
Interval delay = new Interval(parts[2]);
|
Interval delay = new Interval(parts[2]);
|
||||||
HPacket packet = new HPacket(parts[3]);
|
// HPacket packet = new HPacket(parts[3]);
|
||||||
HMessage.Direction direction = parts[4].equals(HMessage.Direction.TOSERVER.name()) ? HMessage.Direction.TOSERVER : HMessage.Direction.TOCLIENT;
|
HMessage.Direction direction = parts[3].equals(HMessage.Direction.TOSERVER.name()) ? HMessage.Direction.TOSERVER : HMessage.Direction.TOCLIENT;
|
||||||
String packetAsString = parts[5];
|
String packetAsString = parts[4];
|
||||||
|
HPacket packet = new HPacket(packetAsString);
|
||||||
|
|
||||||
construct(index, paused, delay, packet, direction);
|
construct(index, paused, delay, packet, direction);
|
||||||
this.packetAsStringProperty = new SimpleStringProperty(packetAsString);
|
this.packetAsStringProperty = new SimpleStringProperty(packetAsString);
|
||||||
|
Loading…
Reference in New Issue
Block a user