mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: 8fe5611 Fix Player#playerListName nullability annotation (#6089) 8827886 Add back linking to Adventure Javadoc (#6088) 6ea4da4 AbstractSkeleton should extend RangedEntity (#6087) a831634 add Optimize Light Engine patch (#5863) 56fd1a2 Update to Minecraft 1.17.1 (#6097) f8d6cbd Deobfuscate stacktraces in sync load info (#6103) Tuinity Changes: 5065deb Make CollisionContext initialisation lazy 388bdf5 Optimise ActivationRange#activateEntities again 2310a94 Update to 1.17.1
74 lines
4.3 KiB
Diff
74 lines
4.3 KiB
Diff
From 0000000000000000000000000000000000000000 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
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
index 4525f732c12411641f77410255d3ef6a5afdc268..58cd2fdf616f450e7906e90dc9725f1067c13052 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -228,6 +228,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
|
|
private long keepAliveTime = Util.getMillis();
|
|
private boolean keepAlivePending;
|
|
private long keepAliveChallenge;
|
|
+ private java.util.List<Long> keepAlives = new java.util.ArrayList<>(); // Purpur
|
|
// CraftBukkit start - multithreaded fields
|
|
private AtomicInteger chatSpamTickCount = new AtomicInteger();
|
|
private final java.util.concurrent.atomic.AtomicInteger tabSpamLimiter = new java.util.concurrent.atomic.AtomicInteger(); // Paper - configurable tab spam limits
|
|
@@ -358,6 +359,21 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
|
|
long currentTime = Util.getMillis();
|
|
long elapsedTime = currentTime - this.keepAliveTime;
|
|
|
|
+ // Purpur start
|
|
+ if (net.pl3x.purpur.PurpurConfig.useAlternateKeepAlive) {
|
|
+ if (elapsedTime >= 1000L) { // 1 second
|
|
+ if (!processedDisconnect && keepAlives.size() > KEEPALIVE_LIMIT) {
|
|
+ LOGGER.warn("{} was kicked due to keepalive timeout!", player.getName());
|
|
+ disconnect(new TranslatableComponent("disconnect.timeout"));
|
|
+ } else {
|
|
+ keepAliveTime = currentTime; // hijack this field for 1 second intervals
|
|
+ keepAlives.add(currentTime); // currentTime is ID
|
|
+ send(new ClientboundKeepAlivePacket(currentTime));
|
|
+ }
|
|
+ }
|
|
+ } else
|
|
+ // Purpur end
|
|
+
|
|
if (this.keepAlivePending) {
|
|
if (!this.processedDisconnect && elapsedTime >= KEEPALIVE_LIMIT) { // check keepalive limit, don't fire if already disconnected
|
|
ServerGamePacketListenerImpl.LOGGER.warn("{} was kicked due to keepalive timeout!", this.player.getScoreboardName()); // more info
|
|
@@ -3069,6 +3085,16 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
|
|
|
|
@Override
|
|
public void handleKeepAlive(ServerboundKeepAlivePacket packet) {
|
|
+ // Purpur start
|
|
+ if (net.pl3x.purpur.PurpurConfig.useAlternateKeepAlive) {
|
|
+ long id = packet.getId();
|
|
+ if (keepAlives.size() > 0 && keepAlives.contains(id)) {
|
|
+ int ping = (int) (Util.getMillis() - id);
|
|
+ player.latency = (player.latency * 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.keepAlivePending && packet.getId() == this.keepAliveChallenge) {
|
|
int i = (int) (Util.getMillis() - this.keepAliveTime);
|
|
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
|
index 2697188c7e18cf5ae11e6e96a3dab95192470ac1..32520a38274224361a24c3b2fdc92af65a0164da 100644
|
|
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
|
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
|
@@ -184,6 +184,11 @@ public class PurpurConfig {
|
|
laggingThreshold = getDouble("settings.lagging-threshold", laggingThreshold);
|
|
}
|
|
|
|
+ public static boolean useAlternateKeepAlive = false;
|
|
+ private static void useAlternateKeepAlive() {
|
|
+ useAlternateKeepAlive = getBoolean("settings.use-alternate-keepalive", useAlternateKeepAlive);
|
|
+ }
|
|
+
|
|
public static boolean barrelSixRows = false;
|
|
public static boolean enderChestSixRows = false;
|
|
public static boolean enderChestPermissionRows = false;
|