mirror of
https://github.com/Nan1t/NanoLimbo.git
synced 2025-07-13 05:00:14 +02:00
Fixed warning about unsipported version
This commit is contained in:
parent
73f1045a76
commit
1e4b4389d5
@ -101,6 +101,7 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
|
||||
if (packet instanceof PacketHandshake) {
|
||||
PacketHandshake handshake = (PacketHandshake) packet;
|
||||
clientVersion = handshake.getVersion();
|
||||
|
||||
updateStateAndVersion(handshake.getNextState(), clientVersion);
|
||||
|
||||
Logger.debug("Pinged from %s [%s]", address, clientVersion.toString());
|
||||
@ -134,8 +135,8 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
if (clientVersion.equals(Version.UNDEFINED)) {
|
||||
disconnectLogin("Incompatible client version");
|
||||
if (!clientVersion.isSupported()) {
|
||||
disconnectLogin("Unsupported client version");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ public class PacketDecoder extends MessageToMessageDecoder<ByteBuf> {
|
||||
|
||||
if (packet != null) {
|
||||
try {
|
||||
Logger.debug("Received packet %s", packet.toString());
|
||||
packet.decode(msg, version);
|
||||
} catch (Exception e) {
|
||||
Logger.warning("Cannot decode packet 0x%s: %s", Integer.toHexString(packetId), e.getMessage());
|
||||
|
@ -47,6 +47,8 @@ public class ByteMessage extends ByteBuf {
|
||||
}
|
||||
}
|
||||
|
||||
buf.readBytes(maxRead);
|
||||
|
||||
throw new IllegalArgumentException("Cannot read VarInt");
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package ru.nanit.limbo.protocol.packets;
|
||||
|
||||
import ru.nanit.limbo.protocol.ByteMessage;
|
||||
import ru.nanit.limbo.protocol.Packet;
|
||||
import ru.nanit.limbo.protocol.PacketIn;
|
||||
import ru.nanit.limbo.protocol.registry.State;
|
||||
import ru.nanit.limbo.protocol.registry.Version;
|
||||
@ -31,7 +30,12 @@ public class PacketHandshake implements PacketIn {
|
||||
|
||||
@Override
|
||||
public void decode(ByteMessage msg, Version version) {
|
||||
this.version = Version.of(msg.readVarInt());
|
||||
try {
|
||||
this.version = Version.of(msg.readVarInt());
|
||||
} catch (IllegalArgumentException e) {
|
||||
this.version = Version.UNDEFINED;
|
||||
}
|
||||
|
||||
this.host = msg.readString();
|
||||
this.port = msg.readUnsignedShort();
|
||||
this.nextState = State.getById(msg.readVarInt());
|
||||
|
@ -172,7 +172,7 @@ public enum State {
|
||||
private final Map<Version, PacketRegistry> registry = new HashMap<>();
|
||||
|
||||
public PacketRegistry getRegistry(Version version) {
|
||||
return registry.get(version);
|
||||
return registry.getOrDefault(version, registry.get(getMin()));
|
||||
}
|
||||
|
||||
public void register(Supplier<?> packet, Mapping... mappings) {
|
||||
|
@ -83,14 +83,14 @@ public enum Version {
|
||||
return this.protocolNumber <= another.protocolNumber;
|
||||
}
|
||||
|
||||
public boolean between(Version min, Version max) {
|
||||
return this.protocolNumber > min.protocolNumber && this.protocolNumber < max.protocolNumber;
|
||||
}
|
||||
|
||||
public boolean fromTo(Version min, Version max) {
|
||||
return this.protocolNumber >= min.protocolNumber && this.protocolNumber <= max.protocolNumber;
|
||||
}
|
||||
|
||||
public boolean isSupported() {
|
||||
return this != UNDEFINED;
|
||||
}
|
||||
|
||||
public static Version getMin() {
|
||||
return V1_8;
|
||||
}
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user