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,33 +42,32 @@ class CompressionCodec(val threshold: Int) : MessageToMessageCodec<ByteBuf, Byte
@Throws(Exception::class)
override fun decode(ctx: ChannelHandlerContext, input: ByteBuf, out: MutableList<Any>) {
if (input.isReadable) {
val outLength = Type.VAR_INT.readPrimitive(input)
if (outLength == 0) {
out.add(input.retain())
return
}
if (!input.isReadable || !ctx.channel().isActive) return
val outLength = Type.VAR_INT.readPrimitive(input)
if (outLength == 0) {
out.add(input.retain())
return
}
if (outLength < threshold) {
throw DecoderException("Badly compressed packet - size of $outLength is below server threshold of $threshold")
}
if (outLength > 2097152) {
throw DecoderException("Badly compressed packet - size of $outLength is larger than protocol maximum of 2097152")
}
if (outLength < threshold) {
throw DecoderException("Badly compressed packet - size of $outLength is below server threshold of $threshold")
}
if (outLength > 2097152) {
throw DecoderException("Badly compressed packet - size of $outLength is larger than protocol maximum of 2097152")
}
inflater.setInput(input.nioBuffer())
val output = ctx.alloc().buffer(outLength, outLength)
try {
output.writerIndex(
output.writerIndex() + inflater.inflate(
output.nioBuffer(output.writerIndex(), output.writableBytes())
)
inflater.setInput(input.nioBuffer())
val output = ctx.alloc().buffer(outLength, outLength)
try {
output.writerIndex(
output.writerIndex() + inflater.inflate(
output.nioBuffer(output.writerIndex(), output.writableBytes())
)
out.add(output.retain())
} finally {
inflater.reset()
output.release()
}
)
out.add(output.retain())
} finally {
inflater.reset()
output.release()
}
}

View File

@ -7,6 +7,7 @@ import javax.crypto.Cipher
class CryptoCodec(val cipherDecode: Cipher, var cipherEncode: Cipher) : MessageToMessageCodec<ByteBuf, ByteBuf>() {
override fun decode(ctx: ChannelHandlerContext, msg: ByteBuf, out: MutableList<Any>) {
if (!ctx.channel().isActive) return
val i = msg.readerIndex()
val size = msg.readableBytes()
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>() {
override fun decode(ctx: ChannelHandlerContext, bytebuf: ByteBuf, out: MutableList<Any>) {
if (!ctx.channel().isActive) return
if (!info.checkIncomingPacket()) throw CancelDecoderException.generate(null)
if (!info.shouldTransformPacket()) {
out.add(bytebuf.retain())