mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Alternate Keepalive Handling
This commit is contained in:
@@ -80,6 +80,11 @@ use-better-mending
|
||||
* **default**: true
|
||||
* **description:** Set to true for mending enchantment to always repair the most damaged equipment first
|
||||
|
||||
use-alternate-keepalive
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
* **default**: false
|
||||
* **description:** Uses a different approach to keepalive ping timeouts. Enabling this sends a keepalive packet once per second to a player, and only kicks for timeout if none of them were responded to in 30 seconds. Responding to any of them in any order will keep the player connected. AKA, it won't kick your players because 1 packet gets dropped somewhere along the lines.
|
||||
|
||||
update-perms-on-world-change
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* **default**: false
|
||||
|
||||
95
patches/server/0067-Alternative-Keepalive-Handling.patch
Normal file
95
patches/server/0067-Alternative-Keepalive-Handling.patch
Normal file
@@ -0,0 +1,95 @@
|
||||
From baff2d4e06feec49d075f9996aaaafc0993ccc52 Mon Sep 17 00:00:00 2001
|
||||
From: William Blake Galbreath <blake.galbreath@gmail.com>
|
||||
Date: Fri, 11 Oct 2019 00:17:39 -0500
|
||||
Subject: [PATCH] Alternative Keepalive Handling
|
||||
|
||||
---
|
||||
.../server/PacketPlayInKeepAlive.java | 1 +
|
||||
.../minecraft/server/PlayerConnection.java | 28 +++++++++++++++++++
|
||||
.../java/net/pl3x/purpur/PurpurConfig.java | 5 ++++
|
||||
3 files changed, 34 insertions(+)
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/PacketPlayInKeepAlive.java b/src/main/java/net/minecraft/server/PacketPlayInKeepAlive.java
|
||||
index 8e93f1540..470f92c4f 100644
|
||||
--- a/src/main/java/net/minecraft/server/PacketPlayInKeepAlive.java
|
||||
+++ b/src/main/java/net/minecraft/server/PacketPlayInKeepAlive.java
|
||||
@@ -22,6 +22,7 @@ public class PacketPlayInKeepAlive implements Packet<PacketListenerPlayIn> {
|
||||
packetdataserializer.writeLong(this.a);
|
||||
}
|
||||
|
||||
+ public long getId() { return b(); } // Purpur - OBFHELPER
|
||||
public long b() {
|
||||
return this.a;
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||
index 6f584d515..b40bea8e8 100644
|
||||
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
||||
@@ -74,6 +74,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
||||
private long lastKeepAlive = SystemUtils.getMonotonicMillis(); private void setLastPing(long lastPing) { this.lastKeepAlive = lastPing;}; private long getLastPing() { return this.lastKeepAlive;}; // Paper - OBFHELPER
|
||||
private boolean awaitingKeepAlive; private void setPendingPing(boolean isPending) { this.awaitingKeepAlive = isPending;}; private boolean isPendingPing() { return this.awaitingKeepAlive;}; // Paper - OBFHELPER
|
||||
private long h; private void setKeepAliveID(long keepAliveID) { this.h = keepAliveID;}; private long getKeepAliveID() {return this.h; }; // Paper - OBFHELPER
|
||||
+ private java.util.List<Long> keepAlives = new java.util.ArrayList<>(); // Purpur
|
||||
// CraftBukkit start - multithreaded fields
|
||||
private volatile int chatThrottle;
|
||||
private static final AtomicIntegerFieldUpdater chatSpamField = AtomicIntegerFieldUpdater.newUpdater(PlayerConnection.class, "chatThrottle");
|
||||
@@ -242,6 +243,21 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
||||
long currentTime = SystemUtils.getMonotonicMillis();
|
||||
long elapsedTime = currentTime - this.getLastPing();
|
||||
|
||||
+ // Purpur start
|
||||
+ if (net.pl3x.purpur.PurpurConfig.useAlternateKeepAlive) {
|
||||
+ if (elapsedTime >= 1000L) { // 1 second
|
||||
+ if (!processedDisconnect && keepAlives.size() > KEEPALIVE_LIMIT) {
|
||||
+ PlayerConnection.LOGGER.warn("{} was kicked due to keepalive timeout!", player.getName());
|
||||
+ disconnect(new ChatMessage("disconnect.timeout"));
|
||||
+ } else {
|
||||
+ setLastPing(currentTime); // hijack this field for 1 second intervals
|
||||
+ keepAlives.add(currentTime); // currentTime is ID
|
||||
+ sendPacket(new PacketPlayOutKeepAlive(currentTime));
|
||||
+ }
|
||||
+ }
|
||||
+ } else
|
||||
+ // Purpur end
|
||||
+
|
||||
if (this.isPendingPing()) {
|
||||
if (!this.processedDisconnect && elapsedTime >= KEEPALIVE_LIMIT) { // check keepalive limit, don't fire if already disconnected
|
||||
PlayerConnection.LOGGER.warn("{} was kicked due to keepalive timeout!", this.player.getName()); // more info
|
||||
@@ -2652,6 +2668,18 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
||||
|
||||
@Override
|
||||
public void a(PacketPlayInKeepAlive packetplayinkeepalive) {
|
||||
+ // Purpur start
|
||||
+ if (net.pl3x.purpur.PurpurConfig.useAlternateKeepAlive) {
|
||||
+ PlayerConnectionUtils.ensureMainThread(packetplayinkeepalive, this, player.getWorldServer()); // This SHOULD be on the main thread...
|
||||
+ long id = packetplayinkeepalive.getId();
|
||||
+ if (keepAlives.size() > 0 && keepAlives.contains(id)) {
|
||||
+ int ping = (int) (SystemUtils.getMonotonicMillis() - id);
|
||||
+ player.ping = (player.ping * 3 + ping) / 4;
|
||||
+ keepAlives.clear(); // we got a valid response, lets roll with it and forget the rest
|
||||
+ }
|
||||
+ } else
|
||||
+ // Purpur end
|
||||
+
|
||||
//PlayerConnectionUtils.ensureMainThread(packetplayinkeepalive, this, this.player.getWorldServer()); // CraftBukkit // Paper - This shouldn't be on the main thread
|
||||
if (this.awaitingKeepAlive && packetplayinkeepalive.b() == this.h) {
|
||||
int i = (int) (SystemUtils.getMonotonicMillis() - this.lastKeepAlive);
|
||||
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
index f2f61f997..baa069d0c 100644
|
||||
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
@@ -167,6 +167,11 @@ public class PurpurConfig {
|
||||
useBetterMending = getBoolean("settings.use-better-mending", useBetterMending);
|
||||
}
|
||||
|
||||
+ public static boolean useAlternateKeepAlive = false;
|
||||
+ private static void useAlternateKeepAlive() {
|
||||
+ useAlternateKeepAlive = getBoolean("settings.use-alternate-keepalive", useAlternateKeepAlive);
|
||||
+ }
|
||||
+
|
||||
public static boolean updatePermissionsOnWorldChange = false;
|
||||
private static void updatePermissionsOnWorldChange() {
|
||||
updatePermissionsOnWorldChange = getBoolean("settings.update-perms-on-world-change", updatePermissionsOnWorldChange);
|
||||
--
|
||||
2.23.0.rc1
|
||||
|
||||
Reference in New Issue
Block a user