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:
Ursprung
a15c8ecc2b
Commit
c14ceb315d
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
read_lens: while (in.isReadable()) {
|
||||
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);
|
||||
|
||||
if (in.readableBytes() >= packetLength) {
|
||||
out.add(in.readBytes(packetLength));
|
||||
continue read_lens;
|
||||
} else {
|
||||
in.readerIndex(ri);
|
||||
break;
|
||||
in.readerIndex(origReaderIndex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new CorruptedFrameException("VarInt too big");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren