From 1ddfbbe420b66a1440053e2011b310ab2a4d40e2 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Sun, 27 Dec 2020 21:31:53 +0100 Subject: [PATCH] unity packethandler --- .../proxy/unity/UnityCommunicator.java | 17 +++++++++++++++-- .../packethandler/unity/UnityPacketHandler.java | 5 ++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/G-Earth/src/main/java/gearth/protocol/connection/proxy/unity/UnityCommunicator.java b/G-Earth/src/main/java/gearth/protocol/connection/proxy/unity/UnityCommunicator.java index db837cd..b95181b 100644 --- a/G-Earth/src/main/java/gearth/protocol/connection/proxy/unity/UnityCommunicator.java +++ b/G-Earth/src/main/java/gearth/protocol/connection/proxy/unity/UnityCommunicator.java @@ -13,6 +13,7 @@ import gearth.protocol.packethandler.unity.UnityPacketHandler; import javax.websocket.*; import javax.websocket.server.ServerEndpoint; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; @ServerEndpoint(value = "/packethandler") @@ -23,7 +24,9 @@ public class UnityCommunicator { private final HConnection hConnection; private final ProxyProvider proxyProvider; - HProxy hProxy = null; + private HProxy hProxy = null; + private String allowedSession = null; + private String revision = null; public UnityCommunicator(HProxySetter proxySetter, HStateSetter stateSetter, HConnection hConnection, ProxyProvider proxyProvider) { this.proxySetter = proxySetter; @@ -40,6 +43,16 @@ public class UnityCommunicator { @OnMessage public void onMessage(byte[] b, Session session) throws IOException { + if (allowedSession != null && !session.getId().equals(allowedSession)) { + return; + } + + if (revision == null) { + revision = new String(b, StandardCharsets.ISO_8859_1); + allowedSession = session.getId(); + return; + } + byte[] packet = Arrays.copyOfRange(b, 1, b.length); if (hProxy == null && b[0] == 1) { @@ -50,7 +63,7 @@ public class UnityCommunicator { hProxy.verifyProxy( new UnityPacketHandler(hConnection.getExtensionHandler(), hConnection.getTrafficObservables(), session, HMessage.Direction.TOCLIENT), new UnityPacketHandler(hConnection.getExtensionHandler(), hConnection.getTrafficObservables(), session, HMessage.Direction.TOSERVER), - hotelVersion + revision ); proxySetter.setProxy(hProxy); stateSetter.setState(HState.CONNECTED); diff --git a/G-Earth/src/main/java/gearth/protocol/packethandler/unity/UnityPacketHandler.java b/G-Earth/src/main/java/gearth/protocol/packethandler/unity/UnityPacketHandler.java index 2555e21..de7a44d 100644 --- a/G-Earth/src/main/java/gearth/protocol/packethandler/unity/UnityPacketHandler.java +++ b/G-Earth/src/main/java/gearth/protocol/packethandler/unity/UnityPacketHandler.java @@ -46,7 +46,10 @@ public class UnityPacketHandler extends PacketHandler { OnHMessageHandled afterExtensionIntercept = hMessage1 -> { notifyListeners(2, hMessage1); - sendToStream(hMessage1.getPacket().toBytes()); + + if (!hMessage1.isBlocked()) { + sendToStream(hMessage1.getPacket().toBytes()); + } }; notifyListeners(0, hMessage);