#3241: Support ping passthrough for legacy pings

This commit is contained in:
Kevin Ludwig 2022-07-02 10:26:28 +10:00 committed by md_5
parent e151a6cf92
commit d221e52929
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 49 additions and 34 deletions

View File

@ -28,18 +28,13 @@ public abstract class AbstractReconnectHandler implements ReconnectHandler
public static ServerInfo getForcedHost(PendingConnection con) public static ServerInfo getForcedHost(PendingConnection con)
{ {
if ( con.getVirtualHost() == null ) String forced = ( con.getVirtualHost() == null ) ? null : con.getListener().getForcedHosts().get( con.getVirtualHost().getHostString() );
{
return null;
}
String forced = con.getListener().getForcedHosts().get( con.getVirtualHost().getHostString() );
if ( forced == null && con.getListener().isForceDefault() ) if ( forced == null && con.getListener().isForceDefault() )
{ {
forced = con.getListener().getDefaultServer(); forced = con.getListener().getDefaultServer();
} }
return ProxyServer.getInstance().getServerInfo( forced ); return ( forced == null ) ? null : ProxyServer.getInstance().getServerInfo( forced );
} }
protected abstract ServerInfo getStoredServer(ProxiedPlayer player); protected abstract ServerInfo getStoredServer(ProxiedPlayer player);

View File

@ -25,7 +25,6 @@ import net.md_5.bungee.Util;
import net.md_5.bungee.api.AbstractReconnectHandler; import net.md_5.bungee.api.AbstractReconnectHandler;
import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.Favicon;
import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
@ -175,9 +174,20 @@ public class InitialHandler extends PacketHandler implements PendingConnection
this.legacy = true; this.legacy = true;
final boolean v1_5 = ping.isV1_5(); final boolean v1_5 = ping.isV1_5();
ServerPing legacy = new ServerPing( new ServerPing.Protocol( bungee.getName() + " " + bungee.getGameVersion(), bungee.getProtocolVersion() ), ServerInfo forced = AbstractReconnectHandler.getForcedHost( this );
new ServerPing.Players( listener.getMaxPlayers(), bungee.getOnlineCount(), null ), final String motd = ( forced != null ) ? forced.getMotd() : listener.getMotd();
new TextComponent( TextComponent.fromLegacyText( listener.getMotd() ) ), (Favicon) null ); final int protocol = bungee.getProtocolVersion();
Callback<ServerPing> pingBack = new Callback<ServerPing>()
{
@Override
public void done(ServerPing result, Throwable error)
{
if ( error != null )
{
result = getPingInfo( bungee.getTranslation( "ping_cannot_connect" ), protocol );
bungee.getLogger().log( Level.WARNING, "Error pinging remote server", error );
}
Callback<ProxyPingEvent> callback = new Callback<ProxyPingEvent>() Callback<ProxyPingEvent> callback = new Callback<ProxyPingEvent>()
{ {
@ -212,7 +222,17 @@ public class InitialHandler extends PacketHandler implements PendingConnection
} }
}; };
bungee.getPluginManager().callEvent( new ProxyPingEvent( this, legacy, callback ) ); bungee.getPluginManager().callEvent( new ProxyPingEvent( InitialHandler.this, result, callback ) );
}
};
if ( forced != null && listener.isPingPassthrough() )
{
( (BungeeServerInfo) forced ).ping( pingBack, bungee.getProtocolVersion() );
} else
{
pingBack.done( getPingInfo( motd, protocol ), null );
}
} }
private static String getFirstLine(String str) private static String getFirstLine(String str)