From 4e94c278da99d26a9fa8739ac951d5ffddd42447 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 13 Sep 2015 09:28:21 +1000 Subject: [PATCH] [#1567] Let BungeeCord dictate the network compression threshold. --- .../java/net/md_5/bungee/conf/Configuration.java | 2 ++ .../net/md_5/bungee/connection/InitialHandler.java | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java index c44a26d0..97e00039 100644 --- a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java +++ b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java @@ -52,6 +52,7 @@ public class Configuration implements ProxyConfig private int throttle = 4000; private boolean ipForward; private Favicon favicon; + private int compressionThreshold = 256; public void load() { @@ -77,6 +78,7 @@ public class Configuration implements ProxyConfig playerLimit = adapter.getInt( "player_limit", playerLimit ); throttle = adapter.getInt( "connection_throttle", throttle ); ipForward = adapter.getBoolean( "ip_forward", ipForward ); + compressionThreshold = adapter.getInt( "network_compression_threshold", compressionThreshold ); disabledCommands = new CaseInsensitiveSet( (Collection) adapter.getList( "disabled_commands", Arrays.asList( "disabledcommandhere" ) ) ); 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 d252f7e2..c13d2e62 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 @@ -433,7 +433,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection // TODO See #1218 oldID.disconnect( bungee.getTranslation( "already_connected" ) ); } - } else { + } else + { // In offline mode the existing user stays and we kick the new one ProxiedPlayer oldName = bungee.getPlayer( getName() ); if ( oldName != null ) @@ -473,6 +474,10 @@ public class InitialHandler extends PacketHandler implements PendingConnection { if ( ch.getHandle().isActive() ) { + UserConnection userCon = new UserConnection( bungee, ch, getName(), InitialHandler.this ); + userCon.setCompressionThreshold( BungeeCord.getInstance().config.getCompressionThreshold() ); + userCon.init(); + if ( getVersion() >= ProtocolConstants.MINECRAFT_1_7_6 ) { unsafe.sendPacket( new LoginSuccess( getUniqueId().toString(), getName() ) ); // With dashes in between @@ -482,9 +487,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection } ch.setProtocol( Protocol.GAME ); - UserConnection userCon = new UserConnection( bungee, ch, getName(), InitialHandler.this ); - userCon.init(); - ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new UpstreamBridge( bungee, userCon ) ); bungee.getPluginManager().callEvent( new PostLoginEvent( userCon ) ); ServerInfo server; @@ -535,7 +537,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection @Override public void run() { - if (thisState != State.STATUS && thisState != State.PING) + if ( thisState != State.STATUS && thisState != State.PING ) { unsafe().sendPacket( new Kick( ComponentSerializer.toString( reason ) ) ); }