Allow base protocols to set client version (#4029)

This commit is contained in:
EnZaXD 2024-07-20 09:15:15 +02:00 committed by GitHub
parent 5ec30ef18a
commit f2f0be0581
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 3 deletions

View File

@ -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.

View File

@ -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 {