3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-16 21:10:30 +01:00

Fix IPv6 scope issue in legacy forwarding too

Dieser Commit ist enthalten in:
Andrew Steinborn 2021-09-01 07:14:38 -04:00
Ursprung 484687522d
Commit 0097359a99
2 geänderte Dateien mit 14 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -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);

Datei anzeigen

@ -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<List<Property>> 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');