diff options
author | Travis Watkins <amaranth@ubuntu.com> | 2014-01-28 14:52:16 -0600 |
---|---|---|
committer | Travis Watkins <amaranth@ubuntu.com> | 2014-01-28 14:54:53 -0600 |
commit | 6e6ad530e720a85f3f209bd8ca2ca40f9982211c (patch) | |
tree | 0cb0071d20d59c08ed04f59575662887b0e73cc7 /src/main/java | |
parent | 516a02b8bb5010ee720a2d955b8ee4297e6f9095 (diff) | |
download | craftbukkit-6e6ad530e720a85f3f209bd8ca2ca40f9982211c.tar craftbukkit-6e6ad530e720a85f3f209bd8ca2ca40f9982211c.tar.gz craftbukkit-6e6ad530e720a85f3f209bd8ca2ca40f9982211c.tar.lz craftbukkit-6e6ad530e720a85f3f209bd8ca2ca40f9982211c.tar.xz craftbukkit-6e6ad530e720a85f3f209bd8ca2ca40f9982211c.zip |
Readd connection throttle
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/net/minecraft/server/HandshakeListener.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/main/java/net/minecraft/server/HandshakeListener.java b/src/main/java/net/minecraft/server/HandshakeListener.java index b7f67758..a02c83f7 100644 --- a/src/main/java/net/minecraft/server/HandshakeListener.java +++ b/src/main/java/net/minecraft/server/HandshakeListener.java @@ -2,8 +2,18 @@ package net.minecraft.server; import net.minecraft.util.io.netty.util.concurrent.GenericFutureListener; +// CraftBukkit start +import java.net.InetAddress; +import java.util.HashMap; +// CraftBukkit end + public class HandshakeListener implements PacketHandshakingInListener { + // CraftBukkit start + private static final HashMap<InetAddress, Long> throttleTracker = new HashMap<InetAddress, Long>(); + private static int throttleCounter = 0; + // CraftBukkit end + private final MinecraftServer a; private final NetworkManager b; @@ -18,6 +28,41 @@ public class HandshakeListener implements PacketHandshakingInListener { this.b.a(EnumProtocol.LOGIN); ChatComponentText chatcomponenttext; + // CraftBukkit start + try { + long currentTime = System.currentTimeMillis(); + long connectionThrottle = MinecraftServer.getServer().server.getConnectionThrottle(); + InetAddress address = ((java.net.InetSocketAddress) this.b.getSocketAddress()).getAddress(); + + synchronized (throttleTracker) { + if (throttleTracker.containsKey(address) && !"127.0.0.1".equals(address.getHostAddress()) && currentTime - throttleTracker.get(address) < connectionThrottle) { + throttleTracker.put(address, currentTime); + chatcomponenttext = new ChatComponentText("Connection throttled! Please wait before reconnecting."); + this.b.handle(new PacketLoginOutDisconnect(chatcomponenttext), new GenericFutureListener[0]); + this.b.a(chatcomponenttext); // Should be close + return; + } + + throttleTracker.put(address, currentTime); + throttleCounter++; + if (throttleCounter > 200) { + throttleCounter = 0; + + // Cleanup stale entries + java.util.Iterator iter = throttleTracker.entrySet().iterator(); + while (iter.hasNext()) { + java.util.Map.Entry<InetAddress, Long> entry = (java.util.Map.Entry) iter.next(); + if (entry.getValue() > connectionThrottle) { + iter.remove(); + } + } + } + } + } catch (Throwable t) { + org.apache.logging.log4j.LogManager.getLogger().error("Failed to check connection throttle", t); + } + // CraftBukkit end + if (packethandshakinginsetprotocol.d() > 4) { chatcomponenttext = new ChatComponentText("Outdated server! I\'m still on 1.7.2"); this.b.handle(new PacketLoginOutDisconnect(chatcomponenttext), new GenericFutureListener[0]); |