From eefd1bade55cf23ef26931d6d8d0762273c24c3d Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Sun, 3 Jan 2021 02:44:05 +0100 Subject: [PATCH] stuff --- .../proxy/unity/UnityCommunicator.java | 15 +++----- .../unity/UnityPacketHandler.java | 34 ++++++++----------- 2 files changed, 18 insertions(+), 31 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 8ee90bf..985239b 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 @@ -38,10 +38,8 @@ public class UnityCommunicator { session.setMaxBinaryMessageBufferSize(1024 * 1024 * 10); } - private int lastType = 2; // 0 = incoming, 1 = outgoing, 2 = expect new - @OnMessage - public void onMessage(byte[] b, boolean isLast, Session session) throws IOException { + public void onMessage(byte[] b, Session session) throws IOException { if (allowedSession != null && !session.getId().equals(allowedSession)) { return; } @@ -49,15 +47,12 @@ public class UnityCommunicator { if (revision == null) { revision = new String(b, StandardCharsets.ISO_8859_1); allowedSession = session.getId(); - if (!isLast) { - System.out.println("this is bad"); - } return; } - byte[] packet = lastType == 2 ? Arrays.copyOfRange(b, 1, b.length) : b; + byte[] packet = Arrays.copyOfRange(b, 1, b.length); if (hProxy == null && b[0] == 1) { HPacket maybe = new HPacket(packet); @@ -74,13 +69,11 @@ public class UnityCommunicator { } - if (hProxy != null && ((lastType == 2 && b[0] == 0) || lastType == 0)) { + if (hProxy != null && b[0] == 0) { hProxy.getInHandler().act(packet); - lastType = isLast ? 2 : 0; } - else if (hProxy != null && ((lastType == 2 && b[0] == 1) || lastType == 1)) { + else if (hProxy != null && b[0] == 1) { hProxy.getOutHandler().act(packet); - lastType = isLast ? 2 : 1; } else { proxyProvider.abort(); 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 266fb80..5f3030d 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 @@ -25,34 +25,28 @@ public class UnityPacketHandler extends PacketHandler { @Override public void sendToStream(byte[] buffer) { - synchronized (session) { - byte[] prefix = new byte[]{(direction == HMessage.Direction.TOCLIENT ? ((byte)0) : ((byte)1))}; - byte[] combined = ByteArrayUtils.combineByteArrays(prefix, buffer); + byte[] prefix = new byte[]{(direction == HMessage.Direction.TOCLIENT ? ((byte)0) : ((byte)1))}; + byte[] combined = ByteArrayUtils.combineByteArrays(prefix, buffer); - session.getAsyncRemote().sendBinary(ByteBuffer.wrap(combined)); - } + session.getAsyncRemote().sendBinary(ByteBuffer.wrap(combined)); } @Override public void act(byte[] buffer) throws IOException { - HPacket[] packets = payloadBuffer.pushAndReceive(buffer); + HMessage hMessage = new HMessage(new HPacket(buffer), direction, currentIndex); - for (HPacket hPacket : packets) { - HMessage hMessage = new HMessage(hPacket, direction, currentIndex); + OnHMessageHandled afterExtensionIntercept = hMessage1 -> { + notifyListeners(2, hMessage1); - OnHMessageHandled afterExtensionIntercept = hMessage1 -> { - notifyListeners(2, hMessage1); + if (!hMessage1.isBlocked()) { + sendToStream(hMessage1.getPacket().toBytes()); + } + }; - if (!hMessage1.isBlocked()) { - sendToStream(hMessage1.getPacket().toBytes()); - } - }; + notifyListeners(0, hMessage); + notifyListeners(1, hMessage); + extensionHandler.handle(hMessage, afterExtensionIntercept); - notifyListeners(0, hMessage); - notifyListeners(1, hMessage); - extensionHandler.handle(hMessage, afterExtensionIntercept); - - currentIndex++; - } + currentIndex++; } }