3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Return the magic-3 loop again... :(

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-01-01 10:14:15 -05:00
Ursprung a15c8ecc2b
Commit c14ceb315d
2 geänderte Dateien mit 24 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -30,7 +30,6 @@ public class MinecraftCompressDecoder extends MessageToMessageDecoder<ByteBuf> {
if (claimedUncompressedSize == 0) {
// Strip the now-useless uncompressed size, this message is already uncompressed.
out.add(in.retainedSlice());
in.skipBytes(in.readableBytes());
return;
}

Datei anzeigen

@ -4,22 +4,38 @@ import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.CorruptedFrameException;
import java.util.List;
public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
while (in.isReadable()) {
int ri = in.readerIndex();
int packetLength = ProtocolUtils.readVarInt(in);
read_lens: while (in.isReadable()) {
int origReaderIndex = in.readerIndex();
for (int i = 0; i < 3; i++) {
if (!in.isReadable()) {
in.readerIndex(origReaderIndex);
return;
}
if (in.readableBytes() >= packetLength) {
out.add(in.readBytes(packetLength));
} else {
in.readerIndex(ri);
break;
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);
if (in.readableBytes() >= packetLength) {
out.add(in.readBytes(packetLength));
continue read_lens;
} else {
in.readerIndex(origReaderIndex);
return;
}
}
}
throw new CorruptedFrameException("VarInt too big");
}
}
}