Configurable keep alive send and response time

This commit is contained in:
Sotr
2018-06-09 01:52:22 +08:00
parent 0df5736280
commit 6def0ae38d
3 changed files with 15 additions and 3 deletions

View File

@@ -177,4 +177,14 @@ public class AkarinGlobalConfig {
private static void timeUpdateInterval() {
timeUpdateInterval = getSeconds(getString("core.world-time-update-interval", "1s"));
}
public static int keepAliveSendInterval;
private static void keepAliveSendInterval() {
keepAliveSendInterval = getSeconds(getString("core.keep-alive-packet-send-interval", "15s"));
}
public static int keepAliveTimeout;
private static void keepAliveTimeout() {
keepAliveTimeout = getSeconds(getString("core.keep-alive-response-timeout", "30s"));
}
}

View File

@@ -46,14 +46,14 @@ public class AkarinSlackScheduler extends Thread {
long elapsedTime = currentTime - conn.getLastPing();
if (conn.isPendingPing()) {
// We're pending a ping from the client
if (!conn.processedDisconnect && elapsedTime >= PlayerConnection.KEEPALIVE_LIMIT) { // check keepalive limit, don't fire if already disconnected
if (!conn.processedDisconnect && elapsedTime >= AkarinGlobalConfig.keepAliveTimeout * 1000L) { // check keepalive limit, don't fire if already disconnected
Akari.callbackQueue.add(() -> {
Akari.logger.warn("{} was kicked due to keepalive timeout!", conn.player.getName()); // more info
conn.disconnect("disconnect.timeout");
});
}
} else {
if (elapsedTime >= 15000L) { // 15 seconds
if (elapsedTime >= AkarinGlobalConfig.keepAliveSendInterval * 1000L) { // 15 seconds default
conn.setPendingPing(true);
conn.setLastPing(currentTime);
conn.setKeepAliveID(currentTime);

View File

@@ -2,6 +2,8 @@ package net.minecraft.server;
import com.google.common.primitives.Doubles;
import com.google.common.primitives.Floats;
import io.akarin.server.core.AkarinGlobalConfig;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import java.io.IOException;
@@ -106,7 +108,7 @@ public class PlayerConnection implements PacketListenerPlayIn, ITickable {
private int receivedMovePackets;
private int processedMovePackets;
private AutoRecipe H = new AutoRecipe();
public static final long KEEPALIVE_LIMIT = Long.getLong("paper.playerconnection.keepalive", 30) * 1000; // Paper - provide property to set keepalive limit // Akarin
private static final long KEEPALIVE_LIMIT = /*Long.getLong("paper.playerconnection.keepalive", 30)*/ AkarinGlobalConfig.keepAliveTimeout * 1000; // Paper - provide property to set keepalive limit // Akarin - more accessible - keep for compatibility
public PlayerConnection(MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayer entityplayer) {
this.minecraftServer = minecraftserver;