Skip to content

Commit 62ba2c4

Browse files
committed
Update "Improve keepalive ping system"
1 parent 7bc4f89 commit 62ba2c4

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

paper-server/patches/features_unapplied/0025-Improve-keepalive-ping-system.patch renamed to paper-server/patches/features/0025-Improve-keepalive-ping-system.patch

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,22 @@ index 0000000000000000000000000000000000000000..4a2520f554c2ee74faf86d7c93baccf0
8585
+ }
8686
+}
8787
diff --git a/net/minecraft/server/network/CommonListenerCookie.java b/net/minecraft/server/network/CommonListenerCookie.java
88-
index 21d50675bfe90c2276890779eb23de58ac915b9a..7be34e37562875313b8e43357921b5fec5079d7a 100644
88+
index d87a00ee3cd04ce25dbe46ae6b386b7f0799102c..ace440c2b82a6368aa27a85ff433ba2cbc8f39a5 100644
8989
--- a/net/minecraft/server/network/CommonListenerCookie.java
9090
+++ b/net/minecraft/server/network/CommonListenerCookie.java
9191
@@ -3,8 +3,8 @@ package net.minecraft.server.network;
9292
import com.mojang.authlib.GameProfile;
9393
import net.minecraft.server.level.ClientInformation;
9494

95-
-public record CommonListenerCookie(GameProfile gameProfile, int latency, ClientInformation clientInformation, boolean transferred, @javax.annotation.Nullable String brandName, java.util.Set<String> channels) { // Paper
96-
+public record CommonListenerCookie(GameProfile gameProfile, int latency, ClientInformation clientInformation, boolean transferred, @javax.annotation.Nullable String brandName, java.util.Set<String> channels, io.papermc.paper.util.KeepAlive keepAlive) { // Paper
97-
public static CommonListenerCookie createInitial(GameProfile gameProfile, boolean transferred) {
95+
-public record CommonListenerCookie(GameProfile gameProfile, int latency, ClientInformation clientInformation, boolean transferred, @org.jspecify.annotations.Nullable String brandName, java.util.Set<String> channels) { // Paper
96+
+public record CommonListenerCookie(GameProfile gameProfile, int latency, ClientInformation clientInformation, boolean transferred, @org.jspecify.annotations.Nullable String brandName, java.util.Set<String> channels, io.papermc.paper.util.KeepAlive keepAlive) { // Paper // Paper
97+
public static CommonListenerCookie createInitial(final GameProfile gameProfile, final boolean transferred) {
9898
- return new CommonListenerCookie(gameProfile, 0, ClientInformation.createDefault(), transferred, null, new java.util.HashSet<>()); // Paper
99-
+ return new CommonListenerCookie(gameProfile, 0, ClientInformation.createDefault(), transferred, null, new java.util.HashSet<>(), new io.papermc.paper.util.KeepAlive()); // Paper
99+
+ return new CommonListenerCookie(gameProfile, 0, ClientInformation.createDefault(), transferred, null, new java.util.HashSet<>(), new io.papermc.paper.util.KeepAlive()); // Paper // Paper
100100
}
101101
}
102102
diff --git a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
103-
index 079ab378920c0e52ef4e42ef20b37bd389f40870..b8a4b4cc02a2fc6b70f4b840796eed501aad6239 100644
103+
index f54d99c59bbca7fb5e0615f8fee9c3f6fbffa18a..d9b6f3826e2126d339e926afed782f6d0e890508 100644
104104
--- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
105105
+++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
106106
@@ -39,12 +39,13 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
@@ -122,7 +122,7 @@ index 079ab378920c0e52ef4e42ef20b37bd389f40870..b8a4b4cc02a2fc6b70f4b840796eed50
122122
// CraftBukkit start
123123
public final org.bukkit.craftbukkit.CraftServer cserver;
124124
@@ -61,13 +62,14 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
125-
public ServerCommonPacketListenerImpl(MinecraftServer server, Connection connection, CommonListenerCookie cookie) {
125+
public ServerCommonPacketListenerImpl(final MinecraftServer server, final Connection connection, final CommonListenerCookie cookie) {
126126
this.server = server;
127127
this.connection = connection;
128128
- this.keepAliveTime = Util.getMillis();
@@ -140,10 +140,10 @@ index 079ab378920c0e52ef4e42ef20b37bd389f40870..b8a4b4cc02a2fc6b70f4b840796eed50
140140
@@ -100,13 +102,41 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
141141

142142
@Override
143-
public void handleKeepAlive(ServerboundKeepAlivePacket packet) {
143+
public void handleKeepAlive(final ServerboundKeepAlivePacket packet) {
144144
- if (this.keepAlivePending && packet.getId() == this.keepAliveChallenge) {
145-
- int i = (int)(Util.getMillis() - this.keepAliveTime);
146-
- this.latency = (this.latency * 3 + i) / 4;
145+
- int time = (int)(Util.getMillis() - this.keepAliveTime);
146+
- this.latency = (this.latency * 3 + time) / 4;
147147
- this.keepAlivePending = false;
148148
- } else if (!this.isSingleplayerOwner()) {
149149
- this.disconnectAsync(TIMEOUT_DISCONNECTION_MESSAGE, io.papermc.paper.connection.DisconnectionReason.TIMEOUT); // Paper - add proper async disconnect
@@ -188,29 +188,29 @@ index 079ab378920c0e52ef4e42ef20b37bd389f40870..b8a4b4cc02a2fc6b70f4b840796eed50
188188
@@ -233,20 +263,23 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
189189
protected void keepConnectionAlive() {
190190
Profiler.get().push("keepAlive");
191-
long millis = Util.getMillis();
191+
long now = Util.getMillis();
192192
- // Paper start - give clients a longer time to respond to pings as per pre 1.12.2 timings
193193
- // This should effectively place the keepalive handling back to "as it was" before 1.12.2
194-
- final long elapsedTime = millis - this.keepAliveTime;
194+
- final long elapsedTime = now - this.keepAliveTime;
195195
- if (!this.isSingleplayerOwner() && elapsedTime >= 15000L) { // use vanilla's 15000L between keep alive packets
196196
- if (this.keepAlivePending) {
197197
- if (!this.processedDisconnect && elapsedTime >= KEEPALIVE_LIMIT) { // check keepalive limit, don't fire if already disconnected
198198
- this.disconnect(TIMEOUT_DISCONNECTION_MESSAGE, io.papermc.paper.connection.DisconnectionReason.TIMEOUT); // Paper - kick event cause
199199
- }
200200
- // Paper end - give clients a longer time to respond to pings as per pre 1.12.2 timings
201-
- } else if (this.checkIfClosed(millis)) {
201+
- } else if (this.checkIfClosed(now)) {
202202
- this.keepAlivePending = true;
203-
- this.keepAliveTime = millis;
204-
- this.keepAliveChallenge = millis;
203+
- this.keepAliveTime = now;
204+
- this.keepAliveChallenge = now;
205205
- this.send(new ClientboundKeepAlivePacket(this.keepAliveChallenge));
206206
+ // Paper start - improve keepalives
207-
+ if (this.checkIfClosed(millis) && !this.processedDisconnect) {
207+
+ if (this.checkIfClosed(now) && !this.processedDisconnect) {
208208
+ long currTime = System.nanoTime();
209209
+
210210
+ if ((currTime - this.keepAlive.lastKeepAliveTx) >= java.util.concurrent.TimeUnit.SECONDS.toNanos(1L)) {
211211
+ this.keepAlive.lastKeepAliveTx = currTime;
212212
+
213-
+ io.papermc.paper.util.KeepAlive.PendingKeepAlive pka = new io.papermc.paper.util.KeepAlive.PendingKeepAlive(currTime, millis);
213+
+ io.papermc.paper.util.KeepAlive.PendingKeepAlive pka = new io.papermc.paper.util.KeepAlive.PendingKeepAlive(currTime, now);
214214
+ this.keepAlive.pendingKeepAlives.add(pka);
215215
+ this.send(new ClientboundKeepAlivePacket(pka.challengeId()));
216216
+ }
@@ -223,11 +223,11 @@ index 079ab378920c0e52ef4e42ef20b37bd389f40870..b8a4b4cc02a2fc6b70f4b840796eed50
223223
}
224224
}
225225

226-
@@ -427,6 +460,6 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
226+
@@ -424,6 +457,6 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
227227
}
228228

229-
protected CommonListenerCookie createCookie(ClientInformation clientInformation) {
229+
protected CommonListenerCookie createCookie(final ClientInformation clientInformation) {
230230
- return new CommonListenerCookie(this.playerProfile(), this.latency, clientInformation, this.transferred, this.playerBrand, this.pluginMessagerChannels); // Paper
231-
+ return new CommonListenerCookie(this.playerProfile(), this.latency, clientInformation, this.transferred, this.playerBrand, this.pluginMessagerChannels, this.keepAlive); // Paper
231+
+ return new CommonListenerCookie(this.playerProfile(), this.latency, clientInformation, this.transferred, this.playerBrand, this.pluginMessagerChannels, this.keepAlive); // Paper // Paper
232232
}
233233
}

0 commit comments

Comments
 (0)