Small changes
This commit is contained in:
parent
ba3cdc59cc
commit
3cec84fbe1
|
@ -9,7 +9,6 @@ import io.netty.buffer.ByteBufProcessor;
|
|||
import io.netty.handler.codec.DecoderException;
|
||||
import io.netty.handler.codec.EncoderException;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -107,36 +106,28 @@ public class PacketDataSerializer extends ByteBuf {
|
|||
}
|
||||
|
||||
public int e() {
|
||||
byte b0;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
byte b0;
|
||||
|
||||
do {
|
||||
b0 = this.readByte();
|
||||
i |= (b0 & 127) << j++ * 7;
|
||||
if (j > 5) {
|
||||
b0 = readByte();
|
||||
i |= (b0 & Byte.MAX_VALUE) << j++ * 7;
|
||||
if (j > 5)
|
||||
throw new RuntimeException("VarInt too big");
|
||||
}
|
||||
} while ((b0 & 128) == 128);
|
||||
|
||||
} while ((b0 & 0x80) == 128);
|
||||
return i;
|
||||
}
|
||||
|
||||
public long f() {
|
||||
byte b0;
|
||||
long i = 0L;
|
||||
int j = 0;
|
||||
|
||||
byte b0;
|
||||
|
||||
do {
|
||||
b0 = this.readByte();
|
||||
i |= (long) (b0 & 127) << j++ * 7;
|
||||
if (j > 10) {
|
||||
b0 = readByte();
|
||||
i |= (long) (b0 & Byte.MAX_VALUE) << j++ * 7;
|
||||
if (j > 10)
|
||||
throw new RuntimeException("VarLong too big");
|
||||
}
|
||||
} while ((b0 & 128) == 128);
|
||||
|
||||
} while ((b0 & 0x80) == 128);
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -236,44 +227,30 @@ public class PacketDataSerializer extends ByteBuf {
|
|||
|
||||
public String c(int i) {
|
||||
int j = this.e();
|
||||
|
||||
if (j > i * 4) {
|
||||
throw new DecoderException("The received encoded string buffer length is longer than maximum allowed (" + j + " > " + i * 4 + ")");
|
||||
} else if (j < 0) {
|
||||
if (j > i * 4)
|
||||
throw new DecoderException("The received encoded string buffer length is longer than maximum allowed (" + j + " > " + (i * 4) + ")");
|
||||
if (j < 0)
|
||||
throw new DecoderException("The received encoded string buffer length is less than zero! Weird string!");
|
||||
} else {
|
||||
String s = toString(readerIndex(), j, StandardCharsets.UTF_8);
|
||||
readerIndex(readerIndex() + j);
|
||||
|
||||
if (s.length() > i) {
|
||||
if (s.length() > i)
|
||||
throw new DecoderException("The received string length is longer than maximum allowed (" + j + " > " + i + ")");
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// KigPaper start
|
||||
public String readCappedString(int maxLength) {
|
||||
int toRead = this.e();
|
||||
|
||||
if (toRead > maxLength * 4) {
|
||||
throw new DecoderException("The received encoded string buffer length is longer than maximum allowed (" + toRead + " > " + maxLength * 4 + ")");
|
||||
} else if (toRead < 0) {
|
||||
if (toRead > maxLength * 4)
|
||||
throw new DecoderException("The received encoded string buffer length is longer than maximum allowed (" + toRead + " > " + (maxLength * 4) + ")");
|
||||
if (toRead < 0)
|
||||
throw new DecoderException("The received encoded string buffer length is less than zero! Weird string!");
|
||||
} else {
|
||||
int len = Math.min(toRead, maxLength);
|
||||
String s = toString(readerIndex(), len, StandardCharsets.UTF_8);
|
||||
readerIndex(readerIndex() + len);
|
||||
int remaining = toRead - len;
|
||||
if (remaining > 0) {
|
||||
this.skipBytes(remaining);
|
||||
}
|
||||
|
||||
if (s.length() > 0)
|
||||
throw new DecoderException("The received string length is longer than maximum allowed (" + toRead + " > " + maxLength + ")");
|
||||
return s;
|
||||
}
|
||||
}
|
||||
// KigPaper end
|
||||
|
||||
public PacketDataSerializer a(String s) {
|
||||
byte[] abyte = s.getBytes(Charsets.UTF_8);
|
||||
|
|
Loading…
Reference in New Issue