#2753: Add configurable remote ping caching
This commit is contained in:
parent
a4512e50fb
commit
636c020772
@ -56,6 +56,14 @@ public interface ProxyConfig
|
||||
*/
|
||||
boolean isLogCommands();
|
||||
|
||||
/**
|
||||
* Time in milliseconds to cache server list info from a ping request from
|
||||
* the proxy to a server.
|
||||
*
|
||||
* @return cache time
|
||||
*/
|
||||
int getRemotePingCache();
|
||||
|
||||
/**
|
||||
* Returns the player max.
|
||||
*
|
||||
|
@ -123,6 +123,18 @@ public class BungeeServerInfo implements ServerInfo
|
||||
}
|
||||
}
|
||||
|
||||
private long lastPing;
|
||||
private ServerPing cachedPing;
|
||||
|
||||
public void cachePing(ServerPing serverPing)
|
||||
{
|
||||
if ( ProxyServer.getInstance().getConfig().getRemotePingCache() > 0 )
|
||||
{
|
||||
this.cachedPing = serverPing;
|
||||
this.lastPing = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getAddress()
|
||||
{
|
||||
@ -139,6 +151,18 @@ public class BungeeServerInfo implements ServerInfo
|
||||
{
|
||||
Preconditions.checkNotNull( callback, "callback" );
|
||||
|
||||
int pingCache = ProxyServer.getInstance().getConfig().getRemotePingCache();
|
||||
if ( pingCache > 0 && cachedPing != null && ( lastPing - System.currentTimeMillis() ) > pingCache )
|
||||
{
|
||||
cachedPing = null;
|
||||
}
|
||||
|
||||
if ( cachedPing != null )
|
||||
{
|
||||
callback.done( cachedPing, null );
|
||||
return;
|
||||
}
|
||||
|
||||
ChannelFutureListener listener = new ChannelFutureListener()
|
||||
{
|
||||
@Override
|
||||
|
@ -52,6 +52,7 @@ public class Configuration implements ProxyConfig
|
||||
*/
|
||||
private boolean logCommands;
|
||||
private boolean logPings = true;
|
||||
private int remotePingCache = -1;
|
||||
private int playerLimit = -1;
|
||||
private Collection<String> disabledCommands;
|
||||
private int throttle = 4000;
|
||||
@ -85,6 +86,7 @@ public class Configuration implements ProxyConfig
|
||||
onlineMode = adapter.getBoolean( "online_mode", onlineMode );
|
||||
logCommands = adapter.getBoolean( "log_commands", logCommands );
|
||||
logPings = adapter.getBoolean( "log_pings", logPings );
|
||||
remotePingCache = adapter.getInt( "remote_ping_cache", remotePingCache );
|
||||
playerLimit = adapter.getInt( "player_limit", playerLimit );
|
||||
throttle = adapter.getInt( "connection_throttle", throttle );
|
||||
throttleLimit = adapter.getInt( "connection_throttle_limit", throttleLimit );
|
||||
|
@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.BungeeServerInfo;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
@ -65,7 +66,9 @@ public class PingHandler extends PacketHandler
|
||||
public void handle(StatusResponse statusResponse) throws Exception
|
||||
{
|
||||
Gson gson = BungeeCord.getInstance().gson;
|
||||
callback.done( gson.fromJson( statusResponse.getResponse(), ServerPing.class ), null );
|
||||
ServerPing serverPing = gson.fromJson( statusResponse.getResponse(), ServerPing.class );
|
||||
( (BungeeServerInfo) target ).cachePing( serverPing );
|
||||
callback.done( serverPing, null );
|
||||
channel.close();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user