geforkt von Mirrors/Velocity
Return the magic-3 loop again... :(
Dieser Commit ist enthalten in:
Ursprung
a15c8ecc2b
Commit
c14ceb315d
@ -30,7 +30,6 @@ public class MinecraftCompressDecoder extends MessageToMessageDecoder<ByteBuf> {
|
|||||||
if (claimedUncompressedSize == 0) {
|
if (claimedUncompressedSize == 0) {
|
||||||
// Strip the now-useless uncompressed size, this message is already uncompressed.
|
// Strip the now-useless uncompressed size, this message is already uncompressed.
|
||||||
out.add(in.retainedSlice());
|
out.add(in.retainedSlice());
|
||||||
in.skipBytes(in.readableBytes());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,22 +4,38 @@ import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||||
|
import io.netty.handler.codec.CorruptedFrameException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
|
public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||||
while (in.isReadable()) {
|
read_lens: while (in.isReadable()) {
|
||||||
int ri = in.readerIndex();
|
int origReaderIndex = in.readerIndex();
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
if (!in.isReadable()) {
|
||||||
|
in.readerIndex(origReaderIndex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte read = in.readByte();
|
||||||
|
if (read >= 0) {
|
||||||
|
// Make sure reader index of length buffer is returned to the beginning
|
||||||
|
in.readerIndex(origReaderIndex);
|
||||||
int packetLength = ProtocolUtils.readVarInt(in);
|
int packetLength = ProtocolUtils.readVarInt(in);
|
||||||
|
|
||||||
if (in.readableBytes() >= packetLength) {
|
if (in.readableBytes() >= packetLength) {
|
||||||
out.add(in.readBytes(packetLength));
|
out.add(in.readBytes(packetLength));
|
||||||
|
continue read_lens;
|
||||||
} else {
|
} else {
|
||||||
in.readerIndex(ri);
|
in.readerIndex(origReaderIndex);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new CorruptedFrameException("VarInt too big");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren