diff --git a/api/src/main/java/com/velocitypowered/api/proxy/InboundConnection.java b/api/src/main/java/com/velocitypowered/api/proxy/InboundConnection.java index 224abbd6e..1b16e9e14 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/InboundConnection.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/InboundConnection.java @@ -26,11 +26,20 @@ public interface InboundConnection { /** * Returns the hostname that the user entered into the client, if applicable. - * + *
+ * This is partially processed, including removing a trailing dot, and discarding data after a null byte. + * @return the hostname from the client */ Optional getVirtualHost(); + /** + * Returns the raw hostname that the client sent, if applicable. + * + * @return the raw hostname from the client + */ + Optional getRawVirtualHost(); + /** * Determine whether or not the player remains online. * diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/AuthSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/AuthSessionHandler.java index ac02bcf76..6165a8467 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/AuthSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/AuthSessionHandler.java @@ -96,7 +96,7 @@ public class AuthSessionHandler implements MinecraftSessionHandler { // Initiate a regular connection and move over to it. ConnectedPlayer player = new ConnectedPlayer(server, profileEvent.getGameProfile(), - mcConnection, inbound.getVirtualHost().orElse(null), onlineMode, + mcConnection, inbound.getVirtualHost().orElse(null), inbound.getRawVirtualHost().orElse(null), onlineMode, inbound.getIdentifiedKey()); this.connectedPlayer = player; if (!server.canRegisterConnection(player)) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 2b22fc7bc..46c3d63d2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -155,6 +155,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, */ private final MinecraftConnection connection; private final @Nullable InetSocketAddress virtualHost; + private final @Nullable String rawVirtualHost; private GameProfile profile; private PermissionFunction permissionFunction; private int tryIndex = 0; @@ -191,12 +192,13 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, private final ChatBuilderFactory chatBuilderFactory; ConnectedPlayer(VelocityServer server, GameProfile profile, MinecraftConnection connection, - @Nullable InetSocketAddress virtualHost, boolean onlineMode, + @Nullable InetSocketAddress virtualHost, @Nullable String rawVirtualHost, boolean onlineMode, @Nullable IdentifiedKey playerKey) { this.server = server; this.profile = profile; this.connection = connection; this.virtualHost = virtualHost; + this.rawVirtualHost = rawVirtualHost; this.permissionFunction = PermissionFunction.ALWAYS_UNDEFINED; this.connectionPhase = connection.getType().getInitialClientPhase(); this.onlineMode = onlineMode; @@ -356,6 +358,11 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, return Optional.ofNullable(virtualHost); } + @Override + public Optional getRawVirtualHost() { + return Optional.ofNullable(rawVirtualHost); + } + void setPermissionFunction(PermissionFunction permissionFunction) { this.permissionFunction = permissionFunction; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java index fae6533db..f31e08126 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java @@ -243,6 +243,11 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { return Optional.ofNullable(ping.getVhost()); } + @Override + public Optional getRawVirtualHost() { + return getVirtualHost().map(InetSocketAddress::getHostName); + } + @Override public boolean isActive() { return !connection.isClosed(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java index 2441e2ac5..7b9183745 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java @@ -63,6 +63,11 @@ public final class InitialInboundConnection implements VelocityInboundConnection return Optional.of(InetSocketAddress.createUnresolved(cleanedAddress, handshake.getPort())); } + @Override + public Optional getRawVirtualHost() { + return Optional.of(handshake.getServerAddress()); + } + @Override public boolean isActive() { return connection.getChannel().isActive(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginInboundConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginInboundConnection.java index 837376f95..18596e4e6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginInboundConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginInboundConnection.java @@ -71,6 +71,11 @@ public class LoginInboundConnection implements LoginPhaseConnection, KeyIdentifi return delegate.getVirtualHost(); } + @Override + public Optional getRawVirtualHost() { + return delegate.getRawVirtualHost(); + } + @Override public boolean isActive() { return delegate.isActive();