3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Make Velocity's server list ping behavior more conformant.

This fixes pinging with 1.7.x and with certain ping libraries that send
the -1 protocol version.
Dieser Commit ist enthalten in:
Andrew Steinborn 2018-12-07 17:24:41 -05:00
Ursprung 811d7400c3
Commit ce6b061b79
4 geänderte Dateien mit 20 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -179,7 +179,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
@Override @Override
public ProtocolVersion getProtocolVersion() { public ProtocolVersion getProtocolVersion() {
return ProtocolVersion.UNKNOWN; return ProtocolVersion.LEGACY;
} }
} }
} }

Datei anzeigen

@ -38,9 +38,8 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
public boolean handle(StatusRequest packet) { public boolean handle(StatusRequest packet) {
VelocityConfiguration configuration = server.getConfiguration(); VelocityConfiguration configuration = server.getConfiguration();
ProtocolVersion shownVersion = ProtocolVersion.isSupported(connection.getProtocolVersion()) ? connection ProtocolVersion shownVersion = ProtocolVersion.isSupported(connection.getProtocolVersion())
.getProtocolVersion() : ? connection.getProtocolVersion() : ProtocolVersion.MAXIMUM_VERSION;
ProtocolVersion.MAXIMUM_VERSION;
ServerPing initialPing = new ServerPing( ServerPing initialPing = new ServerPing(
new ServerPing.Version(shownVersion.getProtocol(), new ServerPing.Version(shownVersion.getProtocol(),
"Velocity " + ProtocolVersion.SUPPORTED_VERSION_STRING), "Velocity " + ProtocolVersion.SUPPORTED_VERSION_STRING),

Datei anzeigen

@ -200,14 +200,18 @@ public enum StateRegistry {
public static class PacketRegistry { public static class PacketRegistry {
private static final EnumMap<ProtocolVersion, ImmutableList<ProtocolVersion>> LINKED_PROTOCOL_VERSIONS = new EnumMap(ProtocolVersion.class); private static final Map<ProtocolVersion, List<ProtocolVersion>> LINKED_PROTOCOL_VERSIONS
= new EnumMap<>(ProtocolVersion.class);
static { static {
LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_9, ImmutableList.of(MINECRAFT_1_9_1, MINECRAFT_1_9_2, MINECRAFT_1_9_4)); LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_9, ImmutableList.of(MINECRAFT_1_9_1, MINECRAFT_1_9_2,
LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_9_4, ImmutableList.of(MINECRAFT_1_10, MINECRAFT_1_11, MINECRAFT_1_11_1)); MINECRAFT_1_9_4));
LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_9_4, ImmutableList.of(MINECRAFT_1_10, MINECRAFT_1_11,
MINECRAFT_1_11_1));
LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_12, ImmutableList.of(MINECRAFT_1_12_1)); LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_12, ImmutableList.of(MINECRAFT_1_12_1));
LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_12_1, ImmutableList.of(MINECRAFT_1_12_2)); LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_12_1, ImmutableList.of(MINECRAFT_1_12_2));
LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_13, ImmutableList.of(MINECRAFT_1_13_1, MINECRAFT_1_13_2)); LINKED_PROTOCOL_VERSIONS.put(MINECRAFT_1_13, ImmutableList.of(MINECRAFT_1_13_1,
MINECRAFT_1_13_2));
} }
private final Direction direction; private final Direction direction;
@ -217,10 +221,12 @@ public enum StateRegistry {
PacketRegistry(Direction direction) { PacketRegistry(Direction direction) {
this.direction = direction; this.direction = direction;
EnumMap<ProtocolVersion, ProtocolRegistry> mutableVersions = new EnumMap(ProtocolVersion.class); Map<ProtocolVersion, ProtocolRegistry> mutableVersions = new EnumMap<>(ProtocolVersion.class);
for (ProtocolVersion version : ProtocolVersion.values()) { for (ProtocolVersion version : ProtocolVersion.values()) {
if (!version.isLegacy() && !version.isUnknown()) {
mutableVersions.put(version, new ProtocolRegistry(version)); mutableVersions.put(version, new ProtocolRegistry(version));
} }
}
this.versions = Collections.unmodifiableMap(mutableVersions); this.versions = Collections.unmodifiableMap(mutableVersions);
} }
@ -252,7 +258,7 @@ public enum StateRegistry {
} }
registry.packetClassToId.put(clazz, mapping.id); registry.packetClassToId.put(clazz, mapping.id);
ImmutableList<ProtocolVersion> linked = LINKED_PROTOCOL_VERSIONS.get(mapping.protocolVersion); List<ProtocolVersion> linked = LINKED_PROTOCOL_VERSIONS.get(mapping.protocolVersion);
if (linked != null) { if (linked != null) {
links: links:
for (int i = 0; i < linked.size(); i++) { for (int i = 0; i < linked.size(); i++) {

Datei anzeigen

@ -56,15 +56,16 @@ public class Handshake implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion ignored) {
this.protocolVersion = ProtocolVersion.getProtocolVersion(ProtocolUtils.readVarInt(buf)); int realProtocolVersion = ProtocolUtils.readVarInt(buf);
this.protocolVersion = ProtocolVersion.getProtocolVersion(realProtocolVersion);
this.serverAddress = ProtocolUtils.readString(buf); this.serverAddress = ProtocolUtils.readString(buf);
this.port = buf.readUnsignedShort(); this.port = buf.readUnsignedShort();
this.nextStatus = ProtocolUtils.readVarInt(buf); this.nextStatus = ProtocolUtils.readVarInt(buf);
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion ignored) {
ProtocolUtils.writeVarInt(buf, this.protocolVersion.getProtocol()); ProtocolUtils.writeVarInt(buf, this.protocolVersion.getProtocol());
ProtocolUtils.writeString(buf, this.serverAddress); ProtocolUtils.writeString(buf, this.serverAddress);
buf.writeShort(this.port); buf.writeShort(this.port);