From 849e416c8d972511b57b164e22db9ab5f0ade918 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Wed, 1 Sep 2021 07:14:38 -0400 Subject: [PATCH] Fix IPv6 scope issue in legacy forwarding too --- .../connection/backend/LoginSessionHandler.java | 16 +++------------- .../backend/VelocityServerConnection.java | 12 +++++++++++- 2 files changed, 14 insertions(+), 14 deletions(-) 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 9f408310f..3bf611258 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');