From f27aa8e3ba256efb31407f6ec1193e5b710a50e3 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 31 May 2020 09:54:47 -0400 Subject: [PATCH] Handle empty packets too --- .../netty/MinecraftVarintFrameDecoder.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java index 6cf258e6b..816c25429 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java @@ -33,14 +33,17 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder { if (reader.result == DecodeResult.SUCCESS) { if (reader.readVarint < 0) { throw BAD_LENGTH_CACHED; - } - - int minimumRead = reader.bytesRead + reader.readVarint; - if (in.isReadable(minimumRead)) { - out.add(in.retainedSlice(varintEnd + 1, reader.readVarint)); - in.skipBytes(minimumRead); + } else if (reader.readVarint == 0) { + // skip over the empty packet and ignore it + in.readerIndex(varintEnd + 1); } else { - return; + int minimumRead = reader.bytesRead + reader.readVarint; + if (in.isReadable(minimumRead)) { + out.add(in.retainedSlice(varintEnd + 1, reader.readVarint)); + in.skipBytes(minimumRead); + } else { + return; + } } } else if (reader.result == DecodeResult.TOO_BIG) { throw VARINT_BIG_CACHED;