mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-05 18:22:03 +01:00
#3241: Support ping passthrough for legacy pings
This commit is contained in:
parent
e151a6cf92
commit
d221e52929
@ -28,18 +28,13 @@ public abstract class AbstractReconnectHandler implements ReconnectHandler
|
||||
|
||||
public static ServerInfo getForcedHost(PendingConnection con)
|
||||
{
|
||||
if ( con.getVirtualHost() == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String forced = con.getListener().getForcedHosts().get( con.getVirtualHost().getHostString() );
|
||||
String forced = ( con.getVirtualHost() == null ) ? null : con.getListener().getForcedHosts().get( con.getVirtualHost().getHostString() );
|
||||
|
||||
if ( forced == null && con.getListener().isForceDefault() )
|
||||
{
|
||||
forced = con.getListener().getDefaultServer();
|
||||
}
|
||||
return ProxyServer.getInstance().getServerInfo( forced );
|
||||
return ( forced == null ) ? null : ProxyServer.getInstance().getServerInfo( forced );
|
||||
}
|
||||
|
||||
protected abstract ServerInfo getStoredServer(ProxiedPlayer player);
|
||||
|
@ -25,7 +25,6 @@ import net.md_5.bungee.Util;
|
||||
import net.md_5.bungee.api.AbstractReconnectHandler;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
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.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
@ -175,44 +174,65 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
this.legacy = true;
|
||||
final boolean v1_5 = ping.isV1_5();
|
||||
|
||||
ServerPing legacy = new ServerPing( new ServerPing.Protocol( bungee.getName() + " " + bungee.getGameVersion(), bungee.getProtocolVersion() ),
|
||||
new ServerPing.Players( listener.getMaxPlayers(), bungee.getOnlineCount(), null ),
|
||||
new TextComponent( TextComponent.fromLegacyText( listener.getMotd() ) ), (Favicon) null );
|
||||
ServerInfo forced = AbstractReconnectHandler.getForcedHost( this );
|
||||
final String motd = ( forced != null ) ? forced.getMotd() : listener.getMotd();
|
||||
final int protocol = bungee.getProtocolVersion();
|
||||
|
||||
Callback<ProxyPingEvent> callback = new Callback<ProxyPingEvent>()
|
||||
Callback<ServerPing> pingBack = new Callback<ServerPing>()
|
||||
{
|
||||
@Override
|
||||
public void done(ProxyPingEvent result, Throwable error)
|
||||
public void done(ServerPing result, Throwable error)
|
||||
{
|
||||
if ( ch.isClosed() )
|
||||
if ( error != null )
|
||||
{
|
||||
return;
|
||||
result = getPingInfo( bungee.getTranslation( "ping_cannot_connect" ), protocol );
|
||||
bungee.getLogger().log( Level.WARNING, "Error pinging remote server", error );
|
||||
}
|
||||
|
||||
ServerPing legacy = result.getResponse();
|
||||
String kickMessage;
|
||||
|
||||
if ( v1_5 )
|
||||
Callback<ProxyPingEvent> callback = new Callback<ProxyPingEvent>()
|
||||
{
|
||||
kickMessage = ChatColor.DARK_BLUE
|
||||
+ "\00" + 127
|
||||
+ '\00' + legacy.getVersion().getName()
|
||||
+ '\00' + getFirstLine( legacy.getDescription() )
|
||||
+ '\00' + legacy.getPlayers().getOnline()
|
||||
+ '\00' + legacy.getPlayers().getMax();
|
||||
} else
|
||||
{
|
||||
// Clients <= 1.3 don't support colored motds because the color char is used as delimiter
|
||||
kickMessage = ChatColor.stripColor( getFirstLine( legacy.getDescription() ) )
|
||||
+ '\u00a7' + legacy.getPlayers().getOnline()
|
||||
+ '\u00a7' + legacy.getPlayers().getMax();
|
||||
}
|
||||
@Override
|
||||
public void done(ProxyPingEvent result, Throwable error)
|
||||
{
|
||||
if ( ch.isClosed() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ch.close( kickMessage );
|
||||
ServerPing legacy = result.getResponse();
|
||||
String kickMessage;
|
||||
|
||||
if ( v1_5 )
|
||||
{
|
||||
kickMessage = ChatColor.DARK_BLUE
|
||||
+ "\00" + 127
|
||||
+ '\00' + legacy.getVersion().getName()
|
||||
+ '\00' + getFirstLine( legacy.getDescription() )
|
||||
+ '\00' + legacy.getPlayers().getOnline()
|
||||
+ '\00' + legacy.getPlayers().getMax();
|
||||
} else
|
||||
{
|
||||
// Clients <= 1.3 don't support colored motds because the color char is used as delimiter
|
||||
kickMessage = ChatColor.stripColor( getFirstLine( legacy.getDescription() ) )
|
||||
+ '\u00a7' + legacy.getPlayers().getOnline()
|
||||
+ '\u00a7' + legacy.getPlayers().getMax();
|
||||
}
|
||||
|
||||
ch.close( kickMessage );
|
||||
}
|
||||
};
|
||||
|
||||
bungee.getPluginManager().callEvent( new ProxyPingEvent( InitialHandler.this, result, callback ) );
|
||||
}
|
||||
};
|
||||
|
||||
bungee.getPluginManager().callEvent( new ProxyPingEvent( this, legacy, 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)
|
||||
|
Loading…
Reference in New Issue
Block a user