3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-23 23:00:35 +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) { 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;
} }

Datei anzeigen

@ -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();
int packetLength = ProtocolUtils.readVarInt(in); for (int i = 0; i < 3; i++) {
if (!in.isReadable()) {
in.readerIndex(origReaderIndex);
return;
}
if (in.readableBytes() >= packetLength) { byte read = in.readByte();
out.add(in.readBytes(packetLength)); if (read >= 0) {
} else { // Make sure reader index of length buffer is returned to the beginning
in.readerIndex(ri); in.readerIndex(origReaderIndex);
break; 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");
} }
} }
} }