Add functionality to replicate #336

This commit is contained in:
md_5 2013-09-15 07:29:22 +10:00
parent 702f434db1
commit d67acd7bc9
4 changed files with 33 additions and 24 deletions

View File

@ -56,4 +56,9 @@ public class ListenerInfo
* Whether to set the local address when connecting to servers. * Whether to set the local address when connecting to servers.
*/ */
private final boolean setLocalAddress; 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;
} }

View File

@ -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.ConfigurationAdapter;
import net.md_5.bungee.api.config.ListenerInfo; import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.config.ServerInfo; 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.CaseInsensitiveMap;
import net.md_5.bungee.util.CaseInsensitiveSet; import net.md_5.bungee.util.CaseInsensitiveSet;

View File

@ -213,8 +213,9 @@ public class YamlConfig implements ConfigurationAdapter
value = DefaultTabList.GLOBAL_PING; value = DefaultTabList.GLOBAL_PING;
} }
boolean setLocalAddress = get( "bind_local_address", true, val ); 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 ); ret.add( info );
} }

View File

@ -133,31 +133,37 @@ public class InitialHandler extends PacketHandler implements PendingConnection
private void respondToPing() private void respondToPing()
{ {
try ServerInfo forced = AbstractReconnectManager.getForcedHost( this );
final String motd = ( forced != null ) ? forced.getMotd() : listener.getMotd();
Callback<ServerPing> pingBack = new Callback<ServerPing>()
{ {
ServerInfo forced = AbstractReconnectManager.getForcedHost( this ); @Override
String motd = listener.getMotd(); public void done(ServerPing result, Throwable error)
if ( forced != null )
{ {
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(), if ( forced != null && listener.isPingPassthrough() )
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 )
{ {
t.printStackTrace(); forced.ping( pingBack );
} else
{
pingBack.done( new ServerPing( bungee.getProtocolVersion(), bungee.getGameVersion(), motd, bungee.getOnlineCount(), listener.getMaxPlayers() ), null );
} }
} }