-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gale: Use gale's keepalive instead of Purpur's
- Loading branch information
1 parent
1a7b4db
commit 63ac30a
Showing
20 changed files
with
132 additions
and
81 deletions.
There are no files selected for viewing
73 changes: 0 additions & 73 deletions
73
patches/server/0025-Purpur-Alternative-Keepalive-Handling.patch
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
124 changes: 124 additions & 0 deletions
124
patches/server/0043-Gale-Send-multiple-keep-alive-packets.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Martijn Muijsers <martijnmuijsers@live.nl> | ||
Date: Wed, 30 Nov 2022 00:43:42 +0100 | ||
Subject: [PATCH] Gale: Send multiple keep-alive packets | ||
|
||
Original license: MIT | ||
Original project: https://github.com/GaleMC/Gale | ||
|
||
This patch is based on the following patch: | ||
"Alternative Keepalive Handling" | ||
By: William Blake Galbreath <blake.galbreath@gmail.com> | ||
As part of: Purpur (https://github.com/PurpurMC/Purpur) | ||
Licensed under: MIT (https://opensource.org/licenses/MIT) | ||
|
||
* Purpur copyright * | ||
|
||
MIT License | ||
|
||
Copyright (c) 2019-2022 PurpurMC | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java | ||
index 785e07549c15a9355ff45187ad7faf83bc31ade5..80c41496614b28abd947182bfd895e6d75914d2d 100644 | ||
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java | ||
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java | ||
@@ -9,6 +9,8 @@ import com.mojang.datafixers.util.Pair; | ||
import com.mojang.logging.LogUtils; | ||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap.Entry; | ||
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; | ||
+import it.unimi.dsi.fastutil.longs.LongArrayList; | ||
+import it.unimi.dsi.fastutil.longs.LongList; | ||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; | ||
import it.unimi.dsi.fastutil.objects.ObjectIterator; | ||
import java.time.Instant; | ||
@@ -261,6 +263,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic | ||
private long keepAliveTime = Util.getMillis(); | ||
private boolean keepAlivePending; | ||
private long keepAliveChallenge; | ||
+ private LongList keepAlives = new LongArrayList(); // Gale - Purpur - send multiple keep-alive packets | ||
// CraftBukkit start - multithreaded fields | ||
private final AtomicInteger chatSpamTickCount = new AtomicInteger(); | ||
private final java.util.concurrent.atomic.AtomicInteger tabSpamLimiter = new java.util.concurrent.atomic.AtomicInteger(); // Paper - configurable tab spam limits | ||
@@ -297,7 +300,10 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic | ||
private final SignedMessageChain.Decoder signedMessageDecoder; | ||
private final LastSeenMessagesValidator lastSeenMessagesValidator; | ||
private final FutureChain chatMessageChain; | ||
- private static final long KEEPALIVE_LIMIT = Long.getLong("paper.playerconnection.keepalive", 30) * 1000; // Paper - provide property to set keepalive limit | ||
+ // Gale start - Purpur - send multiple keep-alive packets | ||
+ private static final long KEEPALIVE_LIMIT_IN_SECONDS = Long.getLong("paper.playerconnection.keepalive", 30); // Paper - provide property to set keepalive limit | ||
+ private static final long KEEPALIVE_LIMIT = KEEPALIVE_LIMIT_IN_SECONDS * 1000; | ||
+ // Gale end - Purpur - send multiple keep-alive packets | ||
private static final int MAX_SIGN_LINE_LENGTH = Integer.getInteger("Paper.maxSignLength", 80); // Paper | ||
|
||
private String clientBrandName = null; // Paper - Brand name | ||
@@ -408,6 +414,21 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic | ||
long currentTime = Util.getMillis(); | ||
long elapsedTime = currentTime - this.keepAliveTime; | ||
|
||
+ // Gale start - Purpur - send multiple keep-alive packets | ||
+ if (LeafConfig.sendMultipleKeepalive) { | ||
+ if (elapsedTime >= 1000L) { // 1 second | ||
+ if (!this.processedDisconnect && this.keepAlives.size() >= KEEPALIVE_LIMIT_IN_SECONDS) { | ||
+ LOGGER.warn("{} was kicked due to keepalive timeout!", this.player.getName()); | ||
+ disconnect(Component.translatable("disconnect.timeout"), org.bukkit.event.player.PlayerKickEvent.Cause.TIMEOUT); | ||
+ } else { | ||
+ this.keepAliveTime = currentTime; // hijack this field for 1 second intervals | ||
+ this.keepAlives.add(currentTime); // currentTime is ID | ||
+ send(new ClientboundKeepAlivePacket(currentTime)); | ||
+ } | ||
+ } | ||
+ } else | ||
+ // Gale end - Purpur - send multiple keep-alive packets | ||
+ | ||
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 | ||
@@ -3608,6 +3629,16 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic | ||
|
||
@Override | ||
public void handleKeepAlive(ServerboundKeepAlivePacket packet) { | ||
+ // Gale start - Purpur - send multiple keep-alive packets | ||
+ if (LeafConfig.sendMultipleKeepalive) { | ||
+ long id = packet.getId(); | ||
+ if (!this.keepAlives.isEmpty() && this.keepAlives.contains(id)) { | ||
+ int ping = (int) (Util.getMillis() - id); | ||
+ this.player.latency = (this.player.latency * 3 + ping) / 4; | ||
+ this.keepAlives.clear(); // We got a valid response, let's roll with it and forget the rest | ||
+ } | ||
+ } else | ||
+ // Gale end - Purpur - send multiple keep-alive packets | ||
//PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel()); // 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/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java | ||
index 8de8900f4523b484b090ac4602a4edf8ee121f9d..b1a4768b31fd4ae32d0b8f1b4d983b18042be9de 100644 | ||
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java | ||
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java | ||
@@ -286,7 +286,9 @@ public class LeafConfig { | ||
} | ||
|
||
public static boolean kickForOutOfOrderChat = true; | ||
+ public static boolean sendMultipleKeepalive = true; | ||
private static void networkSettings() { | ||
kickForOutOfOrderChat = getBoolean("settings.network.kick-for-out-of-order-chat", kickForOutOfOrderChat); | ||
+ sendMultipleKeepalive = getBoolean("settings.network.send-multiple-keepalive", sendMultipleKeepalive); | ||
} | ||
} |