diff --git a/paper-server/patches/features/0024-Improve-keepalive-ping-system.patch b/paper-server/patches/features/0024-Improve-keepalive-ping-system.patch index f046496ff6a4..7c9ffecdb454 100644 --- a/paper-server/patches/features/0024-Improve-keepalive-ping-system.patch +++ b/paper-server/patches/features/0024-Improve-keepalive-ping-system.patch @@ -13,10 +13,10 @@ average over the last 5 seconds of keepalive transactions. diff --git a/io/papermc/paper/util/KeepAlive.java b/io/papermc/paper/util/KeepAlive.java new file mode 100644 -index 0000000000000000000000000000000000000000..4a2520f554c2ee74faf86d7c93baccf0f391a6b3 +index 0000000000000000000000000000000000000000..66d6af2833d76af28fbeb2ce70c194a559572460 --- /dev/null +++ b/io/papermc/paper/util/KeepAlive.java -@@ -0,0 +1,67 @@ +@@ -0,0 +1,84 @@ +package io.papermc.paper.util; + +public class KeepAlive { @@ -34,6 +34,14 @@ index 0000000000000000000000000000000000000000..4a2520f554c2ee74faf86d7c93baccf0 + public final PingCalculator pingCalculator1m = new PingCalculator(java.util.concurrent.TimeUnit.MINUTES.toNanos(1L)); + public final PingCalculator pingCalculator5s = new PingCalculator(java.util.concurrent.TimeUnit.SECONDS.toNanos(5L)); + ++ public KeepAlive copyForListenerHandoff() { ++ KeepAlive copy = new KeepAlive(); ++ copy.lastKeepAliveTx = this.lastKeepAliveTx; ++ copy.pingCalculator1m.copyFrom(this.pingCalculator1m); ++ copy.pingCalculator5s.copyFrom(this.pingCalculator5s); ++ return copy; ++ } ++ + public static final class PingCalculator { + + private final long intervalNS; @@ -47,6 +55,15 @@ index 0000000000000000000000000000000000000000..4a2520f554c2ee74faf86d7c93baccf0 + this.intervalNS = intervalNS; + } + ++ private void copyFrom(PingCalculator other) { ++ for (KeepAliveResponse response : other.responses) { ++ this.responses.add(response); ++ } ++ this.timeSumNS = other.timeSumNS; ++ this.timeSumCount = other.timeSumCount; ++ this.lastAverageNS = other.lastAverageNS; ++ } ++ + public void update(KeepAliveResponse response) { + long currTime = response.txTimeNS; + @@ -100,7 +117,7 @@ index 21d50675bfe90c2276890779eb23de58ac915b9a..7be34e37562875313b8e43357921b5fe } } diff --git a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java -index 079ab378920c0e52ef4e42ef20b37bd389f40870..b8a4b4cc02a2fc6b70f4b840796eed501aad6239 100644 +index 079ab378920c0e52ef4e42ef20b37bd389f40870..dc9020f210c21a626c948d013cc6c972cbc093f3 100644 --- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java +++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java @@ -39,12 +39,13 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack @@ -223,11 +240,19 @@ index 079ab378920c0e52ef4e42ef20b37bd389f40870..b8a4b4cc02a2fc6b70f4b840796eed50 } } -@@ -427,6 +460,6 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack +@@ -427,6 +460,14 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack } protected CommonListenerCookie createCookie(ClientInformation clientInformation) { - return new CommonListenerCookie(this.playerProfile(), this.latency, clientInformation, this.transferred, this.playerBrand, this.pluginMessagerChannels); // Paper -+ return new CommonListenerCookie(this.playerProfile(), this.latency, clientInformation, this.transferred, this.playerBrand, this.pluginMessagerChannels, this.keepAlive); // Paper ++ return new CommonListenerCookie( ++ this.playerProfile(), ++ this.latency, ++ clientInformation, ++ this.transferred, ++ this.playerBrand, ++ this.pluginMessagerChannels, ++ this.keepAlive.copyForListenerHandoff() ++ ); // Paper - listener handoff should reset pending keepalive expectations } }