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