Readd connection throttle

Dieser Commit ist enthalten in:
Travis Watkins 2014-01-28 14:52:16 -06:00
Ursprung 516a02b8bb
Commit 6e6ad530e7

Datei anzeigen

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