From c2cdeac09b03691241358d106671a801dc2d6fa4 Mon Sep 17 00:00:00 2001 From: EvilSeph Date: Thu, 22 Mar 2012 08:03:24 -0400 Subject: [PATCH] Added configurable Connection Throttle. Addresses BUKKIT-1274 --- src/main/java/net/minecraft/server/NetworkAcceptThread.java | 5 ++++- src/main/java/org/bukkit/craftbukkit/CraftServer.java | 4 ++++ src/main/resources/configurations/bukkit.yml | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minecraft/server/NetworkAcceptThread.java b/src/main/java/net/minecraft/server/NetworkAcceptThread.java index 005d61bb6f..2937aee833 100644 --- a/src/main/java/net/minecraft/server/NetworkAcceptThread.java +++ b/src/main/java/net/minecraft/server/NetworkAcceptThread.java @@ -10,6 +10,8 @@ class NetworkAcceptThread extends Thread { final NetworkListenThread listenThread; + long connectionThrottle; // CraftBukkit + NetworkAcceptThread(NetworkListenThread networklistenthread, String s, MinecraftServer minecraftserver) { super(s); this.listenThread = networklistenthread; @@ -24,9 +26,10 @@ class NetworkAcceptThread extends Thread { if (socket != null) { synchronized (NetworkListenThread.getRecentConnectionAttempts(this.listenThread)) { InetAddress inetaddress = socket.getInetAddress(); + connectionThrottle = this.a.server.getConnectionThrottle(); // CraftBukkit // CraftBukkit - if (NetworkListenThread.getRecentConnectionAttempts(this.listenThread).containsKey(inetaddress) && System.currentTimeMillis() - ((Long) NetworkListenThread.getRecentConnectionAttempts(this.listenThread).get(inetaddress)).longValue() < 4000L) { + if (NetworkListenThread.getRecentConnectionAttempts(this.listenThread).containsKey(inetaddress) && System.currentTimeMillis() - ((Long) NetworkListenThread.getRecentConnectionAttempts(this.listenThread).get(inetaddress)).longValue() < connectionThrottle) { NetworkListenThread.getRecentConnectionAttempts(this.listenThread).put(inetaddress, Long.valueOf(System.currentTimeMillis())); socket.close(); continue; diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 617676a7b4..8e6bdd4131 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -424,6 +424,10 @@ public final class CraftServer implements Server { return this.configuration.getInt("settings.ping-packet-limit", 100); } + public long getConnectionThrottle() { + return this.configuration.getInt("settings.connection-throttle"); + } + public int getTicksPerAnimalSpawns() { return this.configuration.getInt("ticks-per.animal-spawns"); } diff --git a/src/main/resources/configurations/bukkit.yml b/src/main/resources/configurations/bukkit.yml index 9f89cbf711..a1ebd98a68 100644 --- a/src/main/resources/configurations/bukkit.yml +++ b/src/main/resources/configurations/bukkit.yml @@ -22,6 +22,7 @@ settings: ping-packet-limit: 100 use-exact-login-location: false plugin-profiling: false + connection-throttle: 4000 ticks-per: animal-spawns: 400 monster-spawns: 1