mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2025-01-17 20:41:53 +01:00
Improved version auto detect
This commit is contained in:
parent
825c825dc0
commit
3c46a0355c
@ -21,6 +21,7 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
|||||||
import net.lenni0451.mcping.MCPing;
|
import net.lenni0451.mcping.MCPing;
|
||||||
import net.lenni0451.mcping.pings.sockets.impl.factories.SocketChannelSocketFactory;
|
import net.lenni0451.mcping.pings.sockets.impl.factories.SocketChannelSocketFactory;
|
||||||
import net.lenni0451.mcping.responses.MCPingResponse;
|
import net.lenni0451.mcping.responses.MCPingResponse;
|
||||||
|
import net.raphimc.vialoader.util.ProtocolVersionList;
|
||||||
|
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
|
|
||||||
@ -51,7 +52,14 @@ public class ProtocolVersionDetector {
|
|||||||
if (ProtocolVersion.isRegistered(response.version.protocol)) { // If the protocol is registered, we can use it
|
if (ProtocolVersion.isRegistered(response.version.protocol)) { // If the protocol is registered, we can use it
|
||||||
return ProtocolVersion.getProtocol(response.version.protocol);
|
return ProtocolVersion.getProtocol(response.version.protocol);
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Unsupported protocol version: " + response.version.protocol);
|
for (ProtocolVersion protocolVersion : ProtocolVersionList.getProtocolsNewToOld()) {
|
||||||
|
for (String version : protocolVersion.getIncludedVersions()) {
|
||||||
|
if (response.version.name.contains(version)) {
|
||||||
|
return protocolVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new RuntimeException("Unable to detect the server version\nServer sent an invalid protocol id: " + response.version.protocol + " (" + response.version.name + "§r)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user