mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-01 08:10:00 +01:00
Allow base protocols to set client version (#4029)
This commit is contained in:
parent
5ec30ef18a
commit
f2f0be0581
@ -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.
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user