From b2d9e11217f2440808e8e6baddafa0595e47365d Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 6 Aug 2020 07:42:42 -0400 Subject: [PATCH 1/3] Fix packet decode logging not giving useful errors See #349 for context --- .../velocitypowered/proxy/connection/MinecraftConnection.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java index c3212d09e..e99ddf212 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -157,9 +157,9 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { logger.error("{}: read timed out", association); } else { boolean isQuietDecoderException = cause instanceof QuietDecoderException; - boolean willLogQuietDecoderException = isQuietDecoderException + boolean willLogQuietDecoderException = MinecraftDecoder.DEBUG || (isQuietDecoderException && !(sessionHandler instanceof LoginSessionHandler) - && !(sessionHandler instanceof HandshakeSessionHandler); + && !(sessionHandler instanceof HandshakeSessionHandler)); if (willLogQuietDecoderException) { logger.error("{}: exception encountered in {}", association, sessionHandler, cause); } else if (isQuietDecoderException) { From 6cec09974a99b06b083cf019bad4f489b10e1380 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 6 Aug 2020 11:09:11 -0400 Subject: [PATCH 2/3] Properly fix debug logging --- .../proxy/connection/MinecraftConnection.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java index e99ddf212..70de89673 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -157,12 +157,12 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { logger.error("{}: read timed out", association); } else { boolean isQuietDecoderException = cause instanceof QuietDecoderException; - boolean willLogQuietDecoderException = MinecraftDecoder.DEBUG || (isQuietDecoderException - && !(sessionHandler instanceof LoginSessionHandler) + boolean willLogQuietDecoderException = !isQuietDecoderException + || (!(sessionHandler instanceof LoginSessionHandler) && !(sessionHandler instanceof HandshakeSessionHandler)); if (willLogQuietDecoderException) { logger.error("{}: exception encountered in {}", association, sessionHandler, cause); - } else if (isQuietDecoderException) { + } else { knownDisconnect = true; } } From 5cceebdffc1c3c076ee444ce4ce75bf8a6c4cca9 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 6 Aug 2020 15:13:22 -0400 Subject: [PATCH 3/3] Read PlayerListItem display names according to the protocol version. Fixes #349 --- .../proxy/protocol/packet/PlayerListItem.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItem.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItem.java index d0717bf43..c21a513e9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItem.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/PlayerListItem.java @@ -58,7 +58,7 @@ public class PlayerListItem implements MinecraftPacket { item.setProperties(ProtocolUtils.readProperties(buf)); item.setGameMode(ProtocolUtils.readVarInt(buf)); item.setLatency(ProtocolUtils.readVarInt(buf)); - item.setDisplayName(readOptionalComponent(buf)); + item.setDisplayName(readOptionalComponent(buf, version)); break; case UPDATE_GAMEMODE: item.setGameMode(ProtocolUtils.readVarInt(buf)); @@ -67,7 +67,7 @@ public class PlayerListItem implements MinecraftPacket { item.setLatency(ProtocolUtils.readVarInt(buf)); break; case UPDATE_DISPLAY_NAME: - item.setDisplayName(readOptionalComponent(buf)); + item.setDisplayName(readOptionalComponent(buf, version)); break; case REMOVE_PLAYER: //Do nothing, all that is needed is the uuid @@ -85,9 +85,10 @@ public class PlayerListItem implements MinecraftPacket { } } - private static @Nullable Component readOptionalComponent(ByteBuf buf) { + private static @Nullable Component readOptionalComponent(ByteBuf buf, ProtocolVersion version) { if (buf.readBoolean()) { - return GsonComponentSerializer.gson().deserialize(ProtocolUtils.readString(buf)); + return ProtocolUtils.getJsonChatSerializer(version) + .deserialize(ProtocolUtils.readString(buf)); } return null; }