diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoder.kt b/protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoder.kt index 5e4fe156..888eb07c 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoder.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoder.kt @@ -78,6 +78,7 @@ public class Js5ResponseDecoder : ByteToMessageDecoder() { data.writeBytes(input, blockLen) if (!last && input.readUnsignedByte().toInt() != 0xFF) { + reset() throw DecoderException("Invalid block trailer") } } @@ -90,8 +91,19 @@ public class Js5ResponseDecoder : ByteToMessageDecoder() { } } + override fun channelInactive(ctx: ChannelHandlerContext) { + super.channelInactive(ctx) + reset() + } + override fun handlerRemoved0(ctx: ChannelHandlerContext?) { + reset() + } + + private fun reset() { data.release() data = Unpooled.EMPTY_BUFFER + + state = State.READ_HEADER } }