3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-16 21:10:30 +01:00

Fix Brigadier command node redirect serialization (#565)

Dieser Commit ist enthalten in:
Andrew Steinborn 2021-08-24 13:58:13 -04:00
Ursprung 321f1306f3
Commit 1b069fc611
3 geänderte Dateien mit 22 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -44,17 +44,24 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
if (varintEnd == -1) {
// We tried to go beyond the end of the buffer. This is probably a good sign that the
// buffer was too short to hold a proper varint.
if (reader.getResult() == DecodeResult.RUN_OF_ZEROES) {
// Special case where the entire packet is just a run of zeroes. We ignore them all.
in.clear();
}
return;
}
if (reader.getResult() == DecodeResult.SUCCESS) {
if (reader.getResult() == DecodeResult.RUN_OF_ZEROES) {
// this will return to the point where the next varint starts
in.readerIndex(varintEnd);
} else if (reader.getResult() == DecodeResult.SUCCESS) {
int readVarint = reader.getReadVarint();
int bytesRead = reader.getBytesRead();
if (readVarint < 0) {
in.clear();
throw BAD_LENGTH_CACHED;
} else if (readVarint == 0) {
// skip over the empty packet and ignore it
// skip over the empty packet(s) and ignore it
in.readerIndex(varintEnd + 1);
} else {
int minimumRead = bytesRead + readVarint;

Datei anzeigen

@ -27,6 +27,14 @@ class VarintByteDecoder implements ByteProcessor {
@Override
public boolean process(byte k) {
if (k == 0 && bytesRead == 0) {
// tentatively say it's invalid, but there's a possibility of redemption
result = DecodeResult.RUN_OF_ZEROES;
return true;
}
if (result == DecodeResult.RUN_OF_ZEROES) {
return false;
}
readVarint |= (k & 0x7F) << bytesRead++ * 7;
if (bytesRead > 3) {
result = DecodeResult.TOO_BIG;
@ -54,6 +62,7 @@ class VarintByteDecoder implements ByteProcessor {
public enum DecodeResult {
SUCCESS,
TOO_SHORT,
TOO_BIG
TOO_BIG,
RUN_OF_ZEROES
}
}

Datei anzeigen

@ -122,6 +122,9 @@ public class AvailableCommands implements MinecraftPacket {
if (!idMappings.containsKey(child)) {
idMappings.put(child, idMappings.size());
childrenQueue.addAll(child.getChildren());
if (child.getRedirect() != null) {
childrenQueue.add(child.getRedirect());
}
}
}