From cd7a3ab2b2aac5b4491fafea189e78f769b192e5 Mon Sep 17 00:00:00 2001 From: Mystiflow Date: Sat, 25 Jan 2020 11:16:02 +1100 Subject: [PATCH] #2758: Improve server list ping response where remote ping failed --- .../bungee/connection/InitialHandler.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) 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 a53b113c1..71f6a5ba5 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 @@ -208,6 +208,15 @@ public class InitialHandler extends PacketHandler implements PendingConnection return pos == -1 ? str : str.substring( 0, pos ); } + private ServerPing getPingInfo(String motd, int protocol) + { + return new ServerPing( + new ServerPing.Protocol( bungee.getName() + " " + bungee.getGameVersion(), protocol ), + new ServerPing.Players( listener.getMaxPlayers(), bungee.getOnlineCount(), null ), + motd, BungeeCord.getInstance().config.getFaviconObject() + ); + } + @Override public void handle(StatusRequest statusRequest) throws Exception { @@ -215,6 +224,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection ServerInfo forced = AbstractReconnectHandler.getForcedHost( this ); final String motd = ( forced != null ) ? forced.getMotd() : listener.getMotd(); + final int protocol = ( ProtocolConstants.SUPPORTED_VERSION_IDS.contains( handshake.getProtocolVersion() ) ) ? handshake.getProtocolVersion() : bungee.getProtocolVersion(); Callback pingBack = new Callback() { @@ -223,8 +233,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection { if ( error != null ) { - result = new ServerPing(); - result.setDescription( bungee.getTranslation( "ping_cannot_connect" ) ); + result = getPingInfo( bungee.getTranslation( "ping_cannot_connect" ), protocol ); bungee.getLogger().log( Level.WARNING, "Error pinging remote server", error ); } @@ -251,12 +260,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection ( (BungeeServerInfo) forced ).ping( pingBack, handshake.getProtocolVersion() ); } else { - int protocol = ( ProtocolConstants.SUPPORTED_VERSION_IDS.contains( handshake.getProtocolVersion() ) ) ? handshake.getProtocolVersion() : bungee.getProtocolVersion(); - pingBack.done( new ServerPing( - new ServerPing.Protocol( bungee.getName() + " " + bungee.getGameVersion(), protocol ), - new ServerPing.Players( listener.getMaxPlayers(), bungee.getOnlineCount(), null ), - motd, BungeeCord.getInstance().config.getFaviconObject() ), - null ); + pingBack.done( getPingInfo( motd, protocol ), null ); } thisState = State.PING;