mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-24 03:05:49 +01:00
#2753: Add configurable remote ping caching
This commit is contained in:
parent
a4512e50fb
commit
636c020772
@ -56,6 +56,14 @@ public interface ProxyConfig
|
|||||||
*/
|
*/
|
||||||
boolean isLogCommands();
|
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.
|
* 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
|
@Override
|
||||||
public InetSocketAddress getAddress()
|
public InetSocketAddress getAddress()
|
||||||
{
|
{
|
||||||
@ -139,6 +151,18 @@ public class BungeeServerInfo implements ServerInfo
|
|||||||
{
|
{
|
||||||
Preconditions.checkNotNull( callback, "callback" );
|
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()
|
ChannelFutureListener listener = new ChannelFutureListener()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -52,6 +52,7 @@ public class Configuration implements ProxyConfig
|
|||||||
*/
|
*/
|
||||||
private boolean logCommands;
|
private boolean logCommands;
|
||||||
private boolean logPings = true;
|
private boolean logPings = true;
|
||||||
|
private int remotePingCache = -1;
|
||||||
private int playerLimit = -1;
|
private int playerLimit = -1;
|
||||||
private Collection<String> disabledCommands;
|
private Collection<String> disabledCommands;
|
||||||
private int throttle = 4000;
|
private int throttle = 4000;
|
||||||
@ -85,6 +86,7 @@ public class Configuration implements ProxyConfig
|
|||||||
onlineMode = adapter.getBoolean( "online_mode", onlineMode );
|
onlineMode = adapter.getBoolean( "online_mode", onlineMode );
|
||||||
logCommands = adapter.getBoolean( "log_commands", logCommands );
|
logCommands = adapter.getBoolean( "log_commands", logCommands );
|
||||||
logPings = adapter.getBoolean( "log_pings", logPings );
|
logPings = adapter.getBoolean( "log_pings", logPings );
|
||||||
|
remotePingCache = adapter.getInt( "remote_ping_cache", remotePingCache );
|
||||||
playerLimit = adapter.getInt( "player_limit", playerLimit );
|
playerLimit = adapter.getInt( "player_limit", playerLimit );
|
||||||
throttle = adapter.getInt( "connection_throttle", throttle );
|
throttle = adapter.getInt( "connection_throttle", throttle );
|
||||||
throttleLimit = adapter.getInt( "connection_throttle_limit", throttleLimit );
|
throttleLimit = adapter.getInt( "connection_throttle_limit", throttleLimit );
|
||||||
|
@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
|||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.md_5.bungee.BungeeCord;
|
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.Callback;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.ServerPing;
|
import net.md_5.bungee.api.ServerPing;
|
||||||
@ -65,7 +66,9 @@ public class PingHandler extends PacketHandler
|
|||||||
public void handle(StatusResponse statusResponse) throws Exception
|
public void handle(StatusResponse statusResponse) throws Exception
|
||||||
{
|
{
|
||||||
Gson gson = BungeeCord.getInstance().gson;
|
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();
|
channel.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user