diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java index 196430311..9de51453d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java @@ -73,10 +73,10 @@ public class LoginSessionHandler implements MinecraftSessionHandler { public boolean handle(LoginPluginMessage packet) { MinecraftConnection mc = serverConn.ensureConnected(); VelocityConfiguration configuration = server.getConfiguration(); - if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && packet - .getChannel().equals(VelocityConstants.VELOCITY_IP_FORWARDING_CHANNEL)) { + if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN + && packet.getChannel().equals(VelocityConstants.VELOCITY_IP_FORWARDING_CHANNEL)) { ByteBuf forwardingData = createForwardingData(configuration.getForwardingSecret(), - cleanRemoteAddress(serverConn.getPlayer().getRemoteAddress()), + serverConn.getPlayerRemoteAddressAsString(), serverConn.getPlayer().getGameProfile()); LoginPluginResponse response = new LoginPluginResponse(packet.getId(), true, forwardingData); mc.write(response); @@ -145,16 +145,6 @@ public class LoginSessionHandler implements MinecraftSessionHandler { } } - private static String cleanRemoteAddress(InetSocketAddress address) { - String addressString = address.getAddress().getHostAddress(); - int ipv6ScopeIdx = addressString.indexOf('%'); - if (ipv6ScopeIdx == -1) { - return addressString; - } else { - return addressString.substring(0, ipv6ScopeIdx); - } - } - private static ByteBuf createForwardingData(byte[] hmacSecret, String address, GameProfile profile) { ByteBuf forwarded = Unpooled.buffer(2048); 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 0c2dc6005..ed5fd7c3f 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 @@ -113,6 +113,16 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, return result; } + String getPlayerRemoteAddressAsString() { + final String addr = proxyPlayer.getRemoteAddress().getAddress().getHostAddress(); + int ipv6ScopeIdx = addr.indexOf('%'); + if (ipv6ScopeIdx == -1) { + return addr; + } else { + return addr.substring(0, ipv6ScopeIdx); + } + } + private String createLegacyForwardingAddress(UnaryOperator> propertiesTransform) { // BungeeCord IP forwarding is simply a special injection after the "address" in the handshake, // separated by \0 (the null byte). In order, you send the original host, the player's IP, their @@ -122,7 +132,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, .orElseGet(() -> registeredServer.getServerInfo().getAddress()) .getHostString()) .append('\0') - .append(proxyPlayer.getRemoteAddress().getAddress().getHostAddress()) + .append(getPlayerRemoteAddressAsString()) .append('\0') .append(proxyPlayer.getGameProfile().getUndashedId()) .append('\0');