geforkt von Mirrors/Velocity
Don't use ByteBuf, fix varint with 0 ending
Dieser Commit ist enthalten in:
Ursprung
027fcf3825
Commit
7d6fa11a83
@ -2,11 +2,9 @@ package com.velocitypowered.proxy.protocol.netty;
|
||||
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
import io.netty.handler.codec.CorruptedFrameException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
|
||||
@ -17,9 +15,7 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
|
||||
return;
|
||||
}
|
||||
|
||||
ByteBuf lenBuf = ctx.alloc().buffer(3).writeZero(3);
|
||||
int origReaderIndex = in.readerIndex();
|
||||
try {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (!in.isReadable()) {
|
||||
in.readerIndex(origReaderIndex);
|
||||
@ -27,11 +23,10 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
|
||||
}
|
||||
|
||||
byte read = in.readByte();
|
||||
lenBuf.setByte(i, read);
|
||||
if (read > 0) {
|
||||
if (read >= 0) {
|
||||
// Make sure reader index of length buffer is returned to the beginning
|
||||
lenBuf.readerIndex(0);
|
||||
int packetLength = ProtocolUtils.readVarInt(lenBuf);
|
||||
in.readerIndex(origReaderIndex);
|
||||
int packetLength = ProtocolUtils.readVarInt(in);
|
||||
if (packetLength == 0) {
|
||||
return;
|
||||
}
|
||||
@ -47,8 +42,5 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
|
||||
}
|
||||
|
||||
throw new CorruptedFrameException("VarInt too big");
|
||||
} finally {
|
||||
lenBuf.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren