From 340e1b23d60f507f9b09ea4fe0e8a7689df5fca5 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 27 Sep 2021 00:37:58 -0400 Subject: [PATCH] Fix none vhost forwarding with legacy Forge. --- .../backend/VelocityServerConnection.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java index 75578e95e..9fca54963 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java @@ -160,8 +160,11 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, PlayerInfoForwarding forwardingMode = server.getConfiguration().getPlayerInfoForwardingMode(); // Initiate the handshake. - InetSocketAddress destAddress = registeredServer.getServerInfo().getAddress(); ProtocolVersion protocolVersion = proxyPlayer.getConnection().getProtocolVersion(); + String playerVhost = proxyPlayer.getVirtualHost() + .orElseGet(() -> registeredServer.getServerInfo().getAddress()) + .getHostString(); + Handshake handshake = new Handshake(); handshake.setNextStatus(StateRegistry.LOGIN_ID); handshake.setProtocolVersion(protocolVersion); @@ -171,13 +174,12 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, byte[] secret = server.getConfiguration().getForwardingSecret(); handshake.setServerAddress(createBungeeGuardForwardingAddress(secret)); } else if (proxyPlayer.getConnection().getType() == ConnectionTypes.LEGACY_FORGE) { - handshake.setServerAddress(destAddress.getHostString() + HANDSHAKE_HOSTNAME_TOKEN); + handshake.setServerAddress(playerVhost + HANDSHAKE_HOSTNAME_TOKEN); } else { - handshake.setServerAddress(proxyPlayer.getVirtualHost() - .orElseGet(() -> registeredServer.getServerInfo().getAddress()) - .getHostString()); + handshake.setServerAddress(playerVhost); } - handshake.setPort(destAddress.getPort()); + + handshake.setPort(registeredServer.getServerInfo().getAddress().getPort()); mc.delayedWrite(handshake); mc.setProtocolVersion(protocolVersion);