mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-18 00:47:42 +01:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: 8fa15382b [Auto] Updated Upstream (CraftBukkit) 732b2f6b5 [CI-SKIP] [Auto] Rebuild Patches c5a39ffa2 Add BlockPreDispenseEvent (#5075) 8aeb4c9c3 Correctly skip pathfinder ticks for inactive entities (#5085) 0e420049c Fix console spam when removing chests in water 56b7935bb Add PlayerChangeBeaconEffectEvent 2eda45c34 added Wither API 97d0c571b Added Vanilla Entity Tags fccac282a fix NPE in getDisplayNameComponent 24e140372 Configurable max leash distance Tuinity Changes: d3ee22224 Merge dev/lighting
86 lines
5.2 KiB
Diff
86 lines
5.2 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/PacketPlayInKeepAlive.java b/src/main/java/net/minecraft/server/PacketPlayInKeepAlive.java
|
|
index 8e93f1540ba5f995489c1fbcec70d10b011cd9c3..470f92c4fb0919d052b19acff8dff533724fbcc1 100644
|
|
--- a/src/main/java/net/minecraft/server/PacketPlayInKeepAlive.java
|
|
+++ b/src/main/java/net/minecraft/server/PacketPlayInKeepAlive.java
|
|
@@ -22,6 +22,7 @@ public class PacketPlayInKeepAlive implements Packet<PacketListenerPlayIn> {
|
|
packetdataserializer.writeLong(this.a);
|
|
}
|
|
|
|
+ public long getId() { return b(); } // Purpur - OBFHELPER
|
|
public long b() {
|
|
return this.a;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
index e833447073585ff97f8ab3a95caea8866fcc24e2..fdd517290a0b306dff9c0fffadc424b59b8504f3 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
@@ -84,6 +84,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
private long lastKeepAlive = SystemUtils.getMonotonicMillis(); private void setLastPing(long lastPing) { this.lastKeepAlive = lastPing;}; private long getLastPing() { return this.lastKeepAlive;}; // Paper - OBFHELPER
|
|
private boolean awaitingKeepAlive; private void setPendingPing(boolean isPending) { this.awaitingKeepAlive = isPending;}; private boolean isPendingPing() { return this.awaitingKeepAlive;}; // Paper - OBFHELPER
|
|
private long h; private void setKeepAliveID(long keepAliveID) { this.h = keepAliveID;}; private long getKeepAliveID() {return this.h; }; // Paper - OBFHELPER
|
|
+ private java.util.List<Long> keepAlives = new java.util.ArrayList<>(); // Purpur
|
|
// CraftBukkit start - multithreaded fields
|
|
private volatile int chatThrottle;
|
|
private static final AtomicIntegerFieldUpdater chatSpamField = AtomicIntegerFieldUpdater.newUpdater(PlayerConnection.class, "chatThrottle");
|
|
@@ -218,6 +219,21 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
long currentTime = SystemUtils.getMonotonicMillis();
|
|
long elapsedTime = currentTime - this.getLastPing();
|
|
|
|
+ // Purpur start
|
|
+ if (net.pl3x.purpur.PurpurConfig.useAlternateKeepAlive) {
|
|
+ if (elapsedTime >= 1000L) { // 1 second
|
|
+ if (!processedDisconnect && keepAlives.size() > KEEPALIVE_LIMIT) {
|
|
+ PlayerConnection.LOGGER.warn("{} was kicked due to keepalive timeout!", player.getName());
|
|
+ disconnect(new ChatMessage("disconnect.timeout"));
|
|
+ } else {
|
|
+ setLastPing(currentTime); // hijack this field for 1 second intervals
|
|
+ keepAlives.add(currentTime); // currentTime is ID
|
|
+ sendPacket(new PacketPlayOutKeepAlive(currentTime));
|
|
+ }
|
|
+ }
|
|
+ } else
|
|
+ // Purpur end
|
|
+
|
|
if (this.isPendingPing()) {
|
|
if (!this.processedDisconnect && elapsedTime >= KEEPALIVE_LIMIT) { // check keepalive limit, don't fire if already disconnected
|
|
PlayerConnection.LOGGER.warn("{} was kicked due to keepalive timeout!", this.player.getName()); // more info
|
|
@@ -2882,6 +2898,16 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
|
|
@Override
|
|
public void a(PacketPlayInKeepAlive packetplayinkeepalive) {
|
|
+ // Purpur start
|
|
+ if (net.pl3x.purpur.PurpurConfig.useAlternateKeepAlive) {
|
|
+ long id = packetplayinkeepalive.getId();
|
|
+ if (keepAlives.size() > 0 && keepAlives.contains(id)) {
|
|
+ int ping = (int) (SystemUtils.getMonotonicMillis() - id);
|
|
+ player.ping = (player.ping * 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.awaitingKeepAlive && packetplayinkeepalive.b() == this.h) {
|
|
int i = (int) (SystemUtils.getMonotonicMillis() - this.lastKeepAlive);
|
|
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
|
index a34ed978596f1a466b0b48e7db92ac4f1345a996..9593ac057ef5b79fb54501d7cce1e69e49102918 100644
|
|
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
|
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
|
@@ -155,6 +155,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;
|