13
0
geforkt von Mirrors/Velocity

Don't use ByteBuf, fix varint with 0 ending

Dieser Commit ist enthalten in:
creeper123123321 2019-01-13 08:57:54 -02:00
Ursprung 027fcf3825
Commit 7d6fa11a83
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0AC57D54786721D1

Datei anzeigen

@ -2,11 +2,9 @@ package com.velocitypowered.proxy.protocol.netty;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
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 io.netty.handler.codec.CorruptedFrameException;
import java.util.Arrays;
import java.util.List; import java.util.List;
public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder { public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
@ -17,38 +15,32 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
return; return;
} }
ByteBuf lenBuf = ctx.alloc().buffer(3).writeZero(3);
int origReaderIndex = in.readerIndex(); int origReaderIndex = in.readerIndex();
try { for (int i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++) { if (!in.isReadable()) {
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); in.readerIndex(origReaderIndex);
return; return;
} }
byte read = in.readByte(); out.add(in.readRetainedSlice(packetLength));
lenBuf.setByte(i, read); return;
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;
}
} }
throw new CorruptedFrameException("VarInt too big");
} finally {
lenBuf.release();
} }
throw new CorruptedFrameException("VarInt too big");
} }
} }