From 7a635ffe6a3c6c597eac8e4786b649d0b86b8d1d Mon Sep 17 00:00:00 2001 From: UnfamiliarLegacy <74633542+UnfamiliarLegacy@users.noreply.github.com> Date: Fri, 26 Nov 2021 06:48:33 +0100 Subject: [PATCH] Fix outgoing packet --- .../nitro/websocket/NitroPacketHandler.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/G-Earth/src/main/java/gearth/protocol/connection/proxy/nitro/websocket/NitroPacketHandler.java b/G-Earth/src/main/java/gearth/protocol/connection/proxy/nitro/websocket/NitroPacketHandler.java index a6283e3..8ea0ee8 100644 --- a/G-Earth/src/main/java/gearth/protocol/connection/proxy/nitro/websocket/NitroPacketHandler.java +++ b/G-Earth/src/main/java/gearth/protocol/connection/proxy/nitro/websocket/NitroPacketHandler.java @@ -22,13 +22,18 @@ public class NitroPacketHandler extends PacketHandler { @Override public boolean sendToStream(byte[] buffer) { + // Required to prevent garbage buffer within the UI logger. + if (direction == HMessage.Direction.TOSERVER) { + buffer = buffer.clone(); + } + session.getSession().getAsyncRemote().sendBinary(ByteBuffer.wrap(buffer)); return true; } @Override public void act(byte[] buffer) throws IOException { - HMessage hMessage = new HMessage(new HPacket(deepCopy(buffer)), direction, currentIndex); + HMessage hMessage = new HMessage(new HPacket(buffer), direction, currentIndex); OnHMessageHandled afterExtensionIntercept = hMessage1 -> { notifyListeners(2, hMessage1); @@ -44,13 +49,4 @@ public class NitroPacketHandler extends PacketHandler { currentIndex++; } - - public static byte[] deepCopy(byte[] org) { - if (org == null) - return null; - byte[] result = new byte[org.length]; - System.arraycopy(org, 0, result, 0, org.length); - return result; - } - }