From 1cd3e4218245b77ac5ba8d83b97c589be327e88c Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 24 Apr 2016 22:18:23 +1000 Subject: [PATCH] #1841: Fix disabled throttle and improve code. --- proxy/src/main/java/net/md_5/bungee/BungeeCord.java | 5 ++++- proxy/src/main/java/net/md_5/bungee/ConnectionThrottle.java | 2 +- .../main/java/net/md_5/bungee/connection/InitialHandler.java | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index e97ee538..1189ac69 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -270,7 +270,10 @@ public class BungeeCord extends ProxyServer pluginManager.enablePlugins(); - connectionThrottle = new ConnectionThrottle( config.getThrottle() ); + if ( config.getThrottle() > 0 ) + { + connectionThrottle = new ConnectionThrottle( config.getThrottle() ); + } startListeners(); saveThread.scheduleAtFixedRate( new TimerTask() diff --git a/proxy/src/main/java/net/md_5/bungee/ConnectionThrottle.java b/proxy/src/main/java/net/md_5/bungee/ConnectionThrottle.java index a2690b77..8f366724 100644 --- a/proxy/src/main/java/net/md_5/bungee/ConnectionThrottle.java +++ b/proxy/src/main/java/net/md_5/bungee/ConnectionThrottle.java @@ -13,7 +13,7 @@ public class ConnectionThrottle public ConnectionThrottle(int throttleTime) { - this.throttleTime = throttleTime; + this.throttleTime = throttleTime; this.throttle = CacheBuilder.newBuilder() .concurrencyLevel( Runtime.getRuntime().availableProcessors() ) .initialCapacity( 100 ) diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java index 6579121b..729aeafb 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java @@ -296,7 +296,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection thisState = State.USERNAME; ch.setProtocol( Protocol.LOGIN ); - if ( bungee.getConnectionThrottle().throttle( ( (InetSocketAddress) ch.getHandle().remoteAddress() ).getAddress() ) ) + if ( bungee.getConnectionThrottle() != null && bungee.getConnectionThrottle().throttle( getAddress().getAddress() ) ) { disconnect( bungee.getTranslation( "join_throttle_kick", TimeUnit.MILLISECONDS.toSeconds( bungee.getConfig().getThrottle() ) ) ); }