#2758: Improve server list ping response where remote ping failed

This commit is contained in:
Mystiflow 2020-01-25 11:16:02 +11:00 committed by md_5
parent 0a4b9b4984
commit cd7a3ab2b2

View File

@ -208,6 +208,15 @@ public class InitialHandler extends PacketHandler implements PendingConnection
return pos == -1 ? str : str.substring( 0, pos ); 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 @Override
public void handle(StatusRequest statusRequest) throws Exception public void handle(StatusRequest statusRequest) throws Exception
{ {
@ -215,6 +224,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
ServerInfo forced = AbstractReconnectHandler.getForcedHost( this ); ServerInfo forced = AbstractReconnectHandler.getForcedHost( this );
final String motd = ( forced != null ) ? forced.getMotd() : listener.getMotd(); final String motd = ( forced != null ) ? forced.getMotd() : listener.getMotd();
final int protocol = ( ProtocolConstants.SUPPORTED_VERSION_IDS.contains( handshake.getProtocolVersion() ) ) ? handshake.getProtocolVersion() : bungee.getProtocolVersion();
Callback<ServerPing> pingBack = new Callback<ServerPing>() Callback<ServerPing> pingBack = new Callback<ServerPing>()
{ {
@ -223,8 +233,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
{ {
if ( error != null ) if ( error != null )
{ {
result = new ServerPing(); result = getPingInfo( bungee.getTranslation( "ping_cannot_connect" ), protocol );
result.setDescription( bungee.getTranslation( "ping_cannot_connect" ) );
bungee.getLogger().log( Level.WARNING, "Error pinging remote server", error ); 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() ); ( (BungeeServerInfo) forced ).ping( pingBack, handshake.getProtocolVersion() );
} else } else
{ {
int protocol = ( ProtocolConstants.SUPPORTED_VERSION_IDS.contains( handshake.getProtocolVersion() ) ) ? handshake.getProtocolVersion() : bungee.getProtocolVersion(); pingBack.done( getPingInfo( motd, protocol ), null );
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 );
} }
thisState = State.PING; thisState = State.PING;