From 2b631c9adc1ddf8408888ad7f43b98f5dacee14b Mon Sep 17 00:00:00 2001 From: acrylic-style Date: Sat, 27 Aug 2022 23:16:07 +0900 Subject: [PATCH] Log error when a packet has extra data --- .../azipluginmessaging/api/protocol/Protocol.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/api/src/main/java/net/azisaba/azipluginmessaging/api/protocol/Protocol.java b/api/src/main/java/net/azisaba/azipluginmessaging/api/protocol/Protocol.java index d5c6dd3..11567aa 100644 --- a/api/src/main/java/net/azisaba/azipluginmessaging/api/protocol/Protocol.java +++ b/api/src/main/java/net/azisaba/azipluginmessaging/api/protocol/Protocol.java @@ -227,6 +227,12 @@ public static void handleProxySide(ServerConnection server, byte[] rawData) { ProxyMessageHandler handler = (ProxyMessageHandler) protocol.getHandler(); Message message = handler.read(server, in); Objects.requireNonNull(message, "handler.read(in) returned null"); + if (in.available() > 0) { + Logger.getCurrentLogger().error( + "Received extra data after message {} from server connection {}: {} of {} bytes remaining", + message, server, in.available(), data.length); + //throw new RuntimeException("Received extra data after message " + message + " from server connection " + server + ": " + in.available() + " of " + data.length + " bytes remaining"); + } handler.handle(server, message); } catch (Exception | AssertionError e) { Logger.getCurrentLogger().warn("Failed to handle plugin message from " + server, e); @@ -274,6 +280,12 @@ public static void handleServerSide(@NotNull PacketSender sender, byte[] rawData ServerMessageHandler handler = (ServerMessageHandler) protocol.getHandler(); Message message = handler.read(in); Objects.requireNonNull(message, "handler.read(in) returned null"); + if (in.available() > 0) { + Logger.getCurrentLogger().error( + "Received extra data after message {} from {}: {} of {} bytes remaining", + message, sender, in.available(), data.length); + //throw new RuntimeException("Received extra data after message " + message + " from " + sender + ": " + in.available() + " of " + data.length + " bytes remaining"); + } handler.handle(sender, message); } catch (Exception | AssertionError e) { Logger.getCurrentLogger().warn("Failed to handle plugin message from " + sender, e);