3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 16:12:42 +01:00

Allow base protocols to set client version (#4029)

Dieser Commit ist enthalten in:
EnZaXD 2024-07-20 09:15:15 +02:00 committet von GitHub
Ursprung 5ec30ef18a
Commit f2f0be0581
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
2 geänderte Dateien mit 20 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -28,6 +28,17 @@ import com.viaversion.viaversion.api.platform.providers.Provider;
@FunctionalInterface
public interface VersionProvider extends Provider {
/**
* Optionally allows platforms to specify the client version of a user. This is needed when the platform supports
* connecting other version types then {@link VersionType#RELEASE} to the server.
*
* @param connection connection
* @return client protocol version, or null if handshake packet should be used
*/
default ProtocolVersion getClientProtocol(UserConnection connection) {
return null;
}
/**
* Returns the closest server protocol version to the user's protocol version.
* On non-proxy servers, this returns the actual server version.

Datei anzeigen

@ -61,15 +61,21 @@ public class BaseProtocol extends AbstractProtocol<BaseClientboundPacket, BaseCl
wrapper.passthrough(Types.UNSIGNED_SHORT); // Server Port
int state = wrapper.passthrough(Types.VAR_INT);
ProtocolInfo info = wrapper.user().getProtocolInfo();
info.setProtocolVersion(ProtocolVersion.getProtocol(protocolVersion));
// Ensure the server has a version provider
VersionProvider versionProvider = Via.getManager().getProviders().get(VersionProvider.class);
// Ensure the server has a version provider
if (versionProvider == null) {
wrapper.user().setActive(false);
return;
}
ProtocolInfo info = wrapper.user().getProtocolInfo();
ProtocolVersion clientVersion = versionProvider.getClientProtocol(wrapper.user());
if (clientVersion != null) {
info.setProtocolVersion(clientVersion);
} else {
info.setProtocolVersion(ProtocolVersion.getProtocol(protocolVersion));
}
// Choose the pipe
ProtocolVersion serverProtocol;
try {