try to fix spam part 2

This commit is contained in:
creeper123123321 2021-03-13 17:08:49 -03:00
parent 22d07a7ea7
commit d376b4ae4f
3 changed files with 25 additions and 24 deletions

View File

@ -42,7 +42,7 @@ class CompressionCodec(val threshold: Int) : MessageToMessageCodec<ByteBuf, Byte
@Throws(Exception::class) @Throws(Exception::class)
override fun decode(ctx: ChannelHandlerContext, input: ByteBuf, out: MutableList<Any>) { override fun decode(ctx: ChannelHandlerContext, input: ByteBuf, out: MutableList<Any>) {
if (input.isReadable) { if (!input.isReadable || !ctx.channel().isActive) return
val outLength = Type.VAR_INT.readPrimitive(input) val outLength = Type.VAR_INT.readPrimitive(input)
if (outLength == 0) { if (outLength == 0) {
out.add(input.retain()) out.add(input.retain())
@ -70,6 +70,5 @@ class CompressionCodec(val threshold: Int) : MessageToMessageCodec<ByteBuf, Byte
output.release() output.release()
} }
} }
}
} }

View File

@ -7,6 +7,7 @@ import javax.crypto.Cipher
class CryptoCodec(val cipherDecode: Cipher, var cipherEncode: Cipher) : MessageToMessageCodec<ByteBuf, ByteBuf>() { class CryptoCodec(val cipherDecode: Cipher, var cipherEncode: Cipher) : MessageToMessageCodec<ByteBuf, ByteBuf>() {
override fun decode(ctx: ChannelHandlerContext, msg: ByteBuf, out: MutableList<Any>) { override fun decode(ctx: ChannelHandlerContext, msg: ByteBuf, out: MutableList<Any>) {
if (!ctx.channel().isActive) return
val i = msg.readerIndex() val i = msg.readerIndex()
val size = msg.readableBytes() val size = msg.readableBytes()
msg.writerIndex(i + cipherDecode.update(msg.nioBuffer(), msg.nioBuffer(i, cipherDecode.getOutputSize(size)))) msg.writerIndex(i + cipherDecode.update(msg.nioBuffer(), msg.nioBuffer(i, cipherDecode.getOutputSize(size))))

View File

@ -9,6 +9,7 @@ import us.myles.ViaVersion.exception.CancelEncoderException
class ViaCodec(val info: UserConnection) : MessageToMessageCodec<ByteBuf, ByteBuf>() { class ViaCodec(val info: UserConnection) : MessageToMessageCodec<ByteBuf, ByteBuf>() {
override fun decode(ctx: ChannelHandlerContext, bytebuf: ByteBuf, out: MutableList<Any>) { override fun decode(ctx: ChannelHandlerContext, bytebuf: ByteBuf, out: MutableList<Any>) {
if (!ctx.channel().isActive) return
if (!info.checkIncomingPacket()) throw CancelDecoderException.generate(null) if (!info.checkIncomingPacket()) throw CancelDecoderException.generate(null)
if (!info.shouldTransformPacket()) { if (!info.shouldTransformPacket()) {
out.add(bytebuf.retain()) out.add(bytebuf.retain())