update [Fix Incorrect Collision Behavior for Block Shape] to [Configurable collision behavior] fix chunk reload detector 20250604 23:22:57 UTC+8: use BLOCK_SHAPE_VANILLA as default instead of PAPER
68 lines
4.2 KiB
Diff
68 lines
4.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MrHua269 <wangxyper@163.com>
|
|
Date: Sun, 12 Jan 2025 11:43:15 +0800
|
|
Subject: [PATCH] Purpur: Use alternative keep alive
|
|
|
|
As part of: Purpur (https://github.com/PurpurMC/Purpur/blob/09f547de09fc5d886f18f6d99ff389289766ec9d/purpur-server/minecraft-patches/sources/net/minecraft/server/network/ServerCommonPacketListenerImpl.java.patch)
|
|
Licensed under: MIT (https://github.com/PurpurMC/Purpur/blob/09f547de09fc5d886f18f6d99ff389289766ec9d/LICENSE)
|
|
|
|
diff --git a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
index 8bc92e45099007fa2120184916c4cdca98a6a452..50ddb37511074b01749a7c60b1d639ec67b3644c 100644
|
|
--- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
@@ -41,6 +41,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
private long keepAliveChallenge;
|
|
private long closedListenerTime;
|
|
private boolean closed = false;
|
|
+ private it.unimi.dsi.fastutil.longs.LongList keepAlives = new it.unimi.dsi.fastutil.longs.LongArrayList(); // Purpur
|
|
private int latency;
|
|
private volatile boolean suspendFlushingOnServerThread = false;
|
|
// CraftBukkit start
|
|
@@ -130,6 +131,16 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
|
|
@Override
|
|
public void handleKeepAlive(ServerboundKeepAlivePacket packet) {
|
|
+ // Purpur start
|
|
+ if (me.earthme.luminol.config.modules.optimizations.PurpurAlternativeKeepaliveConfig.useAlternateKeepAlive) {
|
|
+ if (this.keepAlivePending && !keepAlives.isEmpty() && keepAlives.contains(packet.getId())) {
|
|
+ int ping = (int) (Util.getMillis() - packet.getId());
|
|
+ this.latency = (this.latency * 3 + ping) / 4;
|
|
+ this.keepAlivePending = false;
|
|
+ keepAlives.clear(); // we got a valid response, lets roll with it and forget the rest
|
|
+ }
|
|
+ } else
|
|
+ // Purpur end
|
|
if (this.keepAlivePending && packet.getId() == this.keepAliveChallenge) {
|
|
int i = (int)(Util.getMillis() - this.keepAliveTime);
|
|
this.latency = (this.latency * 3 + i) / 4;
|
|
@@ -254,6 +265,21 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
// 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;
|
|
+ // Purpur start
|
|
+ if (me.earthme.luminol.config.modules.optimizations.PurpurAlternativeKeepaliveConfig.useAlternateKeepAlive) {
|
|
+ if (elapsedTime >= 1000L) { // 1 second
|
|
+ if (this.keepAlivePending && !this.processedDisconnect && keepAlives.size() * 1000L >= KEEPALIVE_LIMIT) {
|
|
+ LOGGER.warn("{} was kicked due to keepalive timeout!", this.player.getScoreboardName());
|
|
+ this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE, org.bukkit.event.player.PlayerKickEvent.Cause.TIMEOUT);
|
|
+ } else if (this.checkIfClosed(millis)) {
|
|
+ this.keepAlivePending = true;
|
|
+ this.keepAliveTime = millis; // hijack this field for 1 second intervals
|
|
+ this.keepAlives.add(millis); // currentTime is ID
|
|
+ this.send(new ClientboundKeepAlivePacket(millis));
|
|
+ }
|
|
+ }
|
|
+ } else {
|
|
+
|
|
if (!this.isSingleplayerOwner() && elapsedTime >= 15000L) { // use vanilla's 15000L between keep alive packets
|
|
if (this.keepAlivePending) {
|
|
if (!this.processedDisconnect && elapsedTime >= KEEPALIVE_LIMIT) { // check keepalive limit, don't fire if already disconnected
|
|
@@ -267,6 +293,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
this.send(new ClientboundKeepAlivePacket(this.keepAliveChallenge));
|
|
}
|
|
}
|
|
+ } // Purpur end
|
|
|
|
Profiler.get().pop();
|
|
}
|