Skip to content

Commit

Permalink
Fix keepalive logic resetting counter
Browse files Browse the repository at this point in the history
This would of actually arised in the client being kicked due to sending
bad keepalive packets due to the erronious extra sending of keepalives too
  • Loading branch information
electronicboy committed Dec 26, 2024
1 parent 3331805 commit c9a904e
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
}
}

@@ -88,30 +_,117 @@
@@ -88,30 +_,119 @@
public void handlePong(ServerboundPongPacket packet) {
}

Expand Down Expand Up @@ -208,15 +208,16 @@
Profiler.get().push("keepAlive");
long millis = Util.getMillis();
- if (!this.isSingleplayerOwner() && millis - this.keepAliveTime >= 15000L) {
- if (this.keepAlivePending) {
- this.disconnect(TIMEOUT_DISCONNECTION_MESSAGE);
+ // Paper start - give clients a longer time to respond to pings as per pre 1.12.2 timings
+ // This should effectively place the keepalive handling back to "as it was" before 1.12.2
+ final long elapsedTime = millis - this.keepAliveTime;
+ if (!this.isSingleplayerOwner() && elapsedTime >= 15000L) { // use vanilla's 15000L between keep alive packets
+ if (this.keepAlivePending && !this.processedDisconnect && elapsedTime >= KEEPALIVE_LIMIT) { // check keepalive limit, don't fire if already disconnected
if (this.keepAlivePending) {
- this.disconnect(TIMEOUT_DISCONNECTION_MESSAGE);
+ if (!this.processedDisconnect && elapsedTime >= KEEPALIVE_LIMIT) { // check keepalive limit, don't fire if already disconnected
+ this.disconnect(TIMEOUT_DISCONNECTION_MESSAGE, org.bukkit.event.player.PlayerKickEvent.Cause.TIMEOUT); // Paper - kick event cause
+ }
+ // Paper end - give clients a longer time to respond to pings as per pre 1.12.2 timings
+ this.disconnect(TIMEOUT_DISCONNECTION_MESSAGE, org.bukkit.event.player.PlayerKickEvent.Cause.TIMEOUT); // Paper - kick event cause
} else if (this.checkIfClosed(millis)) {
this.keepAlivePending = true;
this.keepAliveTime = millis;
Expand Down

0 comments on commit c9a904e

Please sign in to comment.