Potential fix for true IP for floodgate players

This commit is contained in:
Lixfel
2025-01-04 21:25:32 +01:00
parent a3490b801e
commit 088965df59
@@ -20,6 +20,7 @@
package de.steamwar.velocitycore.listeners;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.DisconnectEvent;
import com.velocitypowered.api.event.connection.PreLoginEvent;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.proxy.connection.MinecraftConnection;
@@ -32,21 +33,32 @@ import de.steamwar.velocitycore.mods.Hostname;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
public class IPSanitizer extends BasicListener {
private static final Reflection.Field<MinecraftConnection, SocketAddress> remoteAddress = new Reflection.Field<>(MinecraftConnection.class, "remoteAddress");
private static final Map<UUID, InetAddress> trueAddress = new HashMap<>(); // Will likely slightly leak over time
public static InetAddress getTrueAddress(Player player) {
return ((InetSocketAddress) ((ConnectedPlayer)player).getConnection().getChannel().remoteAddress()).getAddress();
return trueAddress.getOrDefault(player.getUniqueId(), ((InetSocketAddress) ((ConnectedPlayer)player).getConnection().getChannel().remoteAddress()).getAddress());
}
private final InetSocketAddress sanitized = new InetSocketAddress("127.127.127.127", 25565);
private static final Reflection.Field<MinecraftConnection, SocketAddress> remoteAddress = new Reflection.Field<>(MinecraftConnection.class, "remoteAddress");
private static final InetSocketAddress sanitized = new InetSocketAddress("127.127.127.127", 25565);
@Subscribe
public void loginEvent(PreLoginEvent e) {
VelocityCore.getLogger().log(Level.INFO, "%s has logged in with user name %s".formatted(e.getConnection().getRemoteAddress(), e.getUsername()));
InetSocketAddress address = e.getConnection().getRemoteAddress();
VelocityCore.getLogger().log(Level.INFO, "%s has logged in with user name %s".formatted(address, e.getUsername()));
trueAddress.put(e.getUniqueId(), address.getAddress());
remoteAddress.set(Hostname.getInitialInboundConnection((LoginInboundConnection) e.getConnection()).getConnection(), sanitized);
}
@Subscribe
public void disconnectEvent(DisconnectEvent e) {
trueAddress.remove(e.getPlayer().getUniqueId());
}
}