From 27f6ceb7a4ed65d7d04d6be7efce9cbbf5188a65 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 23 Mar 2013 11:15:11 +1100 Subject: [PATCH] BungeeCord Support - Allows BungeeCord to set the players real IP address very early in the login process, so that the BungeeCord proxy IP is never even seen by a plugin. diff --git a/src/main/java/net/minecraft/server/PendingConnection.java b/src/main/java/net/minecraft/server/PendingConnection.java index a945892..7ef9a6f 100644 --- a/src/main/java/net/minecraft/server/PendingConnection.java +++ b/src/main/java/net/minecraft/server/PendingConnection.java @@ -221,4 +221,17 @@ public class PendingConnection extends Connection { static boolean a(PendingConnection pendingconnection, boolean flag) { return pendingconnection.h = flag; } + + // Spigot start + @Override + public void a(Packet250CustomPayload pcp) { + if (pcp.tag.equals("BungeeCord") && org.bukkit.craftbukkit.Spigot.bungeeIPs.contains(getSocket().getInetAddress().getHostAddress())) { + com.google.common.io.ByteArrayDataInput in = com.google.common.io.ByteStreams.newDataInput(pcp.data); + String subTag = in.readUTF(); + if (subTag.equals("Login")) { + networkManager.setSocketAddress(new java.net.InetSocketAddress(in.readUTF(), in.readInt())); + } + } + } + // Spigot end } diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java index 5ccc7f0..cc9c3ba 100644 --- a/src/main/java/net/minecraft/server/PlayerList.java +++ b/src/main/java/net/minecraft/server/PlayerList.java @@ -293,7 +293,7 @@ public abstract class PlayerList { // depending on the outcome. EntityPlayer entity = new EntityPlayer(this.server, this.server.getWorldServer(0), s, this.server.M() ? new DemoPlayerInteractManager(this.server.getWorldServer(0)) : new PlayerInteractManager(this.server.getWorldServer(0))); Player player = entity.getBukkitEntity(); - PlayerLoginEvent event = new PlayerLoginEvent(player, hostname, pendingconnection.getSocket().getInetAddress()); + PlayerLoginEvent event = new PlayerLoginEvent(player, hostname, ((java.net.InetSocketAddress) pendingconnection.networkManager.getSocketAddress()).getAddress()); // Spigot SocketAddress socketaddress = pendingconnection.networkManager.getSocketAddress(); diff --git a/src/main/java/net/minecraft/server/ThreadLoginVerifier.java b/src/main/java/net/minecraft/server/ThreadLoginVerifier.java index fcd4136..fb4ec7b 100644 --- a/src/main/java/net/minecraft/server/ThreadLoginVerifier.java +++ b/src/main/java/net/minecraft/server/ThreadLoginVerifier.java @@ -45,11 +45,11 @@ class ThreadLoginVerifier extends Thread { return; } - AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(PendingConnection.d(this.pendingConnection), this.pendingConnection.getSocket().getInetAddress()); + AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(PendingConnection.d(this.pendingConnection), ((java.net.InetSocketAddress) this.pendingConnection.networkManager.getSocketAddress()).getAddress()); // Spigot this.server.getPluginManager().callEvent(asyncEvent); if (PlayerPreLoginEvent.getHandlerList().getRegisteredListeners().length != 0) { - final PlayerPreLoginEvent event = new PlayerPreLoginEvent(PendingConnection.d(this.pendingConnection), this.pendingConnection.getSocket().getInetAddress()); + final PlayerPreLoginEvent event = new PlayerPreLoginEvent(PendingConnection.d(this.pendingConnection), ((java.net.InetSocketAddress) this.pendingConnection.networkManager.getSocketAddress()).getAddress()); // Spigot if (asyncEvent.getResult() != PlayerPreLoginEvent.Result.ALLOWED) { event.disallow(asyncEvent.getResult(), asyncEvent.getKickMessage()); } diff --git a/src/main/java/org/bukkit/craftbukkit/Spigot.java b/src/main/java/org/bukkit/craftbukkit/Spigot.java index f25852e..b327310 100644 --- a/src/main/java/org/bukkit/craftbukkit/Spigot.java +++ b/src/main/java/org/bukkit/craftbukkit/Spigot.java @@ -54,6 +54,7 @@ public class Spigot { private static boolean filterIps; public static boolean tabPing = false; private static Metrics metrics; + public static List bungeeIPs; public static void initialize(CraftServer server, SimpleCommandMap commandMap, YamlConfiguration configuration) { commandMap.register("bukkit", new org.bukkit.craftbukkit.command.TicksPerSecondCommand("tps")); @@ -91,6 +92,7 @@ public class Spigot { } tabPing = configuration.getBoolean("settings.tab-ping", tabPing); + bungeeIPs = configuration.getStringList("settings.bungee-proxies"); if (metrics == null) { try { diff --git a/src/main/resources/configurations/bukkit.yml b/src/main/resources/configurations/bukkit.yml index eb23dae..62bf79a 100644 --- a/src/main/resources/configurations/bukkit.yml +++ b/src/main/resources/configurations/bukkit.yml @@ -37,6 +37,8 @@ settings: timeout-time: 30 restart-on-crash: false restart-script-location: /path/to/server/start.sh + bungee-proxies: + - 127.0.0.1 world-settings: default: growth-chunks-per-tick: 650 -- 1.8.2.1