From d67acd7bc9de429d90b244d75308dc6746a9edbf Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 15 Sep 2013 07:29:22 +1000 Subject: [PATCH] Add functionality to replicate #336 --- .../md_5/bungee/api/config/ListenerInfo.java | 5 ++ .../net/md_5/bungee/config/Configuration.java | 3 -- .../net/md_5/bungee/config/YamlConfig.java | 3 +- .../bungee/connection/InitialHandler.java | 46 +++++++++++-------- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/config/ListenerInfo.java b/api/src/main/java/net/md_5/bungee/api/config/ListenerInfo.java index 1ec6d5c2..8eea1adf 100644 --- a/api/src/main/java/net/md_5/bungee/api/config/ListenerInfo.java +++ b/api/src/main/java/net/md_5/bungee/api/config/ListenerInfo.java @@ -56,4 +56,9 @@ public class ListenerInfo * Whether to set the local address when connecting to servers. */ private final boolean setLocalAddress; + /** + * Whether to pass the ping through when we can reliably get the target + * server (force default server). + */ + private final boolean pingPassthrough; } 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 5b93a904..b1b8b816 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 @@ -11,9 +11,6 @@ import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ConfigurationAdapter; import net.md_5.bungee.api.config.ListenerInfo; import net.md_5.bungee.api.config.ServerInfo; -import net.md_5.bungee.tab.GlobalPing; -import net.md_5.bungee.tab.Global; -import net.md_5.bungee.tab.ServerUnique; import net.md_5.bungee.util.CaseInsensitiveMap; import net.md_5.bungee.util.CaseInsensitiveSet; diff --git a/proxy/src/main/java/net/md_5/bungee/config/YamlConfig.java b/proxy/src/main/java/net/md_5/bungee/config/YamlConfig.java index e88970d6..89d248dd 100644 --- a/proxy/src/main/java/net/md_5/bungee/config/YamlConfig.java +++ b/proxy/src/main/java/net/md_5/bungee/config/YamlConfig.java @@ -213,8 +213,9 @@ public class YamlConfig implements ConfigurationAdapter value = DefaultTabList.GLOBAL_PING; } boolean setLocalAddress = get( "bind_local_address", true, val ); + boolean pingPassthrough = get( "ping_passthrough", false, val ); - ListenerInfo info = new ListenerInfo( address, motd, maxPlayers, tabListSize, defaultServer, fallbackServer, forceDefault, forced, value.clazz, setLocalAddress ); + ListenerInfo info = new ListenerInfo( address, motd, maxPlayers, tabListSize, defaultServer, fallbackServer, forceDefault, forced, value.clazz, setLocalAddress, pingPassthrough ); ret.add( info ); } 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 a01d3fd8..9b10346a 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 @@ -133,31 +133,37 @@ public class InitialHandler extends PacketHandler implements PendingConnection private void respondToPing() { - try + ServerInfo forced = AbstractReconnectManager.getForcedHost( this ); + final String motd = ( forced != null ) ? forced.getMotd() : listener.getMotd(); + + Callback pingBack = new Callback() { - ServerInfo forced = AbstractReconnectManager.getForcedHost( this ); - String motd = listener.getMotd(); - if ( forced != null ) + @Override + public void done(ServerPing result, Throwable error) { - motd = forced.getMotd(); + if ( error != null ) + { + result = new ServerPing( (byte) -1, "-1", "Error pinging remote server: " + Util.exception( error ), -1, -1 ); + } + result = bungee.getPluginManager().callEvent( new ProxyPingEvent( InitialHandler.this, result ) ).getResponse(); + + String kickMessage = ChatColor.DARK_BLUE + + "\00" + result.getProtocolVersion() + + "\00" + result.getGameVersion() + + "\00" + result.getMotd() + + "\00" + result.getCurrentPlayers() + + "\00" + result.getMaxPlayers(); + BungeeCord.getInstance().getConnectionThrottle().unthrottle( getAddress().getAddress() ); + disconnect( kickMessage ); } + }; - ServerPing response = new ServerPing( bungee.getProtocolVersion(), bungee.getGameVersion(), - motd, bungee.getOnlineCount(), listener.getMaxPlayers() ); - - response = bungee.getPluginManager().callEvent( new ProxyPingEvent( InitialHandler.this, response ) ).getResponse(); - - String kickMessage = ChatColor.DARK_BLUE - + "\00" + response.getProtocolVersion() - + "\00" + response.getGameVersion() - + "\00" + response.getMotd() - + "\00" + response.getCurrentPlayers() - + "\00" + response.getMaxPlayers(); - BungeeCord.getInstance().getConnectionThrottle().unthrottle( getAddress().getAddress() ); - disconnect( kickMessage ); - } catch ( Throwable t ) + if ( forced != null && listener.isPingPassthrough() ) { - t.printStackTrace(); + forced.ping( pingBack ); + } else + { + pingBack.done( new ServerPing( bungee.getProtocolVersion(), bungee.getGameVersion(), motd, bungee.getOnlineCount(), listener.getMaxPlayers() ), null ); } }