From ec1de0f636b8d6a89f38b983fc1539738f970779 Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 14 Mar 2013 20:14:01 +1100 Subject: [PATCH] Add global slot limit. Fixes feature request #40 --- proxy/src/main/java/net/md_5/bungee/config/Configuration.java | 4 ++-- .../main/java/net/md_5/bungee/connection/InitialHandler.java | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/config/Configuration.java b/proxy/src/main/java/net/md_5/bungee/config/Configuration.java index ea4b0b1fb..aacff219b 100644 --- a/proxy/src/main/java/net/md_5/bungee/config/Configuration.java +++ b/proxy/src/main/java/net/md_5/bungee/config/Configuration.java @@ -48,7 +48,7 @@ public class Configuration * Should we check minecraft.net auth. */ private boolean onlineMode = true; - private int sleepTime = 1; + private int playerLimit = -1; public void load() { @@ -58,7 +58,7 @@ public class Configuration timeout = adapter.getInt( "timeout", timeout ); uuid = adapter.getString( "stats", uuid ); onlineMode = adapter.getBoolean( "online_mode", onlineMode ); - sleepTime = adapter.getInt( "sleep_time", sleepTime ); + playerLimit = adapter.getInt( "player_limit", playerLimit ); DefaultTabList tab = DefaultTabList.valueOf( adapter.getString( "tab_list", "GLOBAL_PING" ) ); if ( tab == null ) 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 6fd909f01..5020e5671 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 @@ -117,6 +117,10 @@ public class InitialHandler extends PacketHandler implements PendingConnection { Preconditions.checkState( thisState == State.HANDSHAKE, "Not expecting HANDSHAKE" ); Preconditions.checkArgument( handshake.username.length() <= 16, "Cannot have username longer than 16 characters" ); + + int limit = BungeeCord.getInstance().config.getPlayerLimit(); + Preconditions.checkState( limit <= 0 || bungee.getPlayers().size() < limit, "Server is full!" ); + this.handshake = handshake; ch.write( forgeMods ); ch.write( request = EncryptionUtil.encryptRequest() );