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

Merge pull request #167 from creeper123123321/master

Don't use ByteBuf, fix varint with 0 ending
Dieser Commit ist enthalten in:
Andrew Steinborn 2019-01-13 11:31:13 -05:00 committet von GitHub
Commit 67591900e6
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -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,38 +15,32 @@ 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()) {
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 (packetLength == 0) {
return;
}
if (in.readableBytes() < packetLength) {
in.readerIndex(origReaderIndex);
return;
}
byte read = in.readByte();
lenBuf.setByte(i, read);
if (read > 0) {
// Make sure reader index of length buffer is returned to the beginning
lenBuf.readerIndex(0);
int packetLength = ProtocolUtils.readVarInt(lenBuf);
if (packetLength == 0) {
return;
}
if (in.readableBytes() < packetLength) {
in.readerIndex(origReaderIndex);
return;
}
out.add(in.readRetainedSlice(packetLength));
return;
}
out.add(in.readRetainedSlice(packetLength));
return;
}
throw new CorruptedFrameException("VarInt too big");
} finally {
lenBuf.release();
}
throw new CorruptedFrameException("VarInt too big");
}
}