использованы костыли для предотвращения "рваных" пакетоов
Пакеты иногда могут приходить не полностью, а кусками. Раньше из-за этого возникали ошибки декода пакетов, у которых данные обрывались.
This commit is contained in:
@@ -13,25 +13,31 @@ import java.util.UUID;
|
||||
@Slf4j
|
||||
public abstract class NetInputStream_p340 extends NetInputStream {
|
||||
@Override
|
||||
public int readVarInt() {
|
||||
public int readVarInt(int[] countReadBytes) {
|
||||
int numRead = 0;
|
||||
int result = 0;
|
||||
byte read;
|
||||
do {
|
||||
if ((numRead+1) > 5) {
|
||||
log.warn("VarInt is too big");
|
||||
break;
|
||||
}
|
||||
read = readByte();
|
||||
int value = (read & 0b01111111);
|
||||
result |= (value << (7 * numRead));
|
||||
|
||||
numRead++;
|
||||
if (numRead > 5) {
|
||||
log.warn("VarInt is too big");
|
||||
break;
|
||||
}
|
||||
} while ((read & 0b10000000) != 0);
|
||||
|
||||
if (countReadBytes != null && countReadBytes.length == 1) countReadBytes[0] = numRead;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readVarInt() {
|
||||
return readVarInt(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readString() {
|
||||
int size = readVarInt();
|
||||
|
||||
Reference in New Issue
Block a user