geforkt von Mirrors/Velocity
Merge pull request #167 from creeper123123321/master
Don't use ByteBuf, fix varint with 0 ending
Dieser Commit ist enthalten in:
Commit
67591900e6
@ -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,9 +15,7 @@ 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);
|
in.readerIndex(origReaderIndex);
|
||||||
@ -27,11 +23,10 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
byte read = in.readByte();
|
byte read = in.readByte();
|
||||||
lenBuf.setByte(i, read);
|
if (read >= 0) {
|
||||||
if (read > 0) {
|
|
||||||
// Make sure reader index of length buffer is returned to the beginning
|
// Make sure reader index of length buffer is returned to the beginning
|
||||||
lenBuf.readerIndex(0);
|
in.readerIndex(origReaderIndex);
|
||||||
int packetLength = ProtocolUtils.readVarInt(lenBuf);
|
int packetLength = ProtocolUtils.readVarInt(in);
|
||||||
if (packetLength == 0) {
|
if (packetLength == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -47,8 +42,5 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
throw new CorruptedFrameException("VarInt too big");
|
throw new CorruptedFrameException("VarInt too big");
|
||||||
} finally {
|
|
||||||
lenBuf.release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren