mirror of
https://github.com/Dreeam-qwq/Gale.git
synced 2025-12-19 14:59:29 +00:00
Updated to latest commit in Paper 1.20.6 branch. This update didn't include backport from latest Gale branch, we recommend to use 1.21.1, or update to 1.21.3 later
169 lines
9.6 KiB
Diff
169 lines
9.6 KiB
Diff
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] Send multiple keep-alive packets
|
|
|
|
License: MIT (https://opensource.org/licenses/MIT)
|
|
Gale - https://galemc.org
|
|
|
|
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/ServerCommonPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
index 652ae75254d78fff02d68cbb747eaee4c3f35a1a..2a7de95242c80e2df86ef11538a315664617d3f0 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
@@ -4,6 +4,9 @@ import com.mojang.authlib.GameProfile;
|
|
import com.mojang.logging.LogUtils;
|
|
import java.util.Objects;
|
|
import javax.annotation.Nullable;
|
|
+
|
|
+import it.unimi.dsi.fastutil.longs.LongArrayList;
|
|
+import it.unimi.dsi.fastutil.longs.LongList;
|
|
import net.minecraft.ChatFormatting;
|
|
import net.minecraft.CrashReport;
|
|
import net.minecraft.CrashReportCategory;
|
|
@@ -30,6 +33,7 @@ import net.minecraft.server.level.ClientInformation;
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
import net.minecraft.util.VisibleForDebug;
|
|
import net.minecraft.util.thread.BlockableEventLoop;
|
|
+import org.galemc.gale.configuration.GaleGlobalConfiguration;
|
|
import org.slf4j.Logger;
|
|
|
|
// CraftBukkit start
|
|
@@ -73,10 +77,14 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
private long keepAliveChallenge;
|
|
private long closedListenerTime;
|
|
private boolean closed = false;
|
|
+ private LongList keepAlives = new LongArrayList(); // Gale - Purpur - send multiple keep-alive packets
|
|
private int latency;
|
|
private volatile boolean suspendFlushingOnServerThread = false;
|
|
public final java.util.Map<java.util.UUID, net.kyori.adventure.resource.ResourcePackCallback> packCallbacks = new java.util.concurrent.ConcurrentHashMap<>(); // Paper - adventure resource pack callbacks
|
|
- 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
|
|
protected static final ResourceLocation MINECRAFT_BRAND = new ResourceLocation("brand"); // Paper - Brand support
|
|
|
|
public ServerCommonPacketListenerImpl(MinecraftServer minecraftserver, Connection networkmanager, CommonListenerCookie commonlistenercookie, ServerPlayer player) { // CraftBukkit
|
|
@@ -124,6 +132,16 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
@Override
|
|
public void handleKeepAlive(ServerboundKeepAlivePacket packet) {
|
|
//PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); // CraftBukkit // Paper - handle ServerboundKeepAlivePacket async
|
|
+ // Gale start - Purpur - send multiple keep-alive packets
|
|
+ if (GaleGlobalConfiguration.get().misc.keepalive.sendMultiple) {
|
|
+ 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;
|
|
+ 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
|
|
if (this.keepAlivePending && packet.getId() == this.keepAliveChallenge) {
|
|
int i = (int) (Util.getMillis() - this.keepAliveTime);
|
|
|
|
@@ -136,6 +154,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
});
|
|
// Paper end - This needs to be handled on the main thread for plugins
|
|
}
|
|
+ } // Gale - Purpur - send multiple keep-alive packets
|
|
|
|
}
|
|
|
|
@@ -251,6 +270,21 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
long currentTime = Util.getMillis();
|
|
long elapsedTime = currentTime - this.keepAliveTime;
|
|
|
|
+ // Gale start - Purpur - send multiple keep-alive packets
|
|
+ if (GaleGlobalConfiguration.get().misc.keepalive.sendMultiple) {
|
|
+ if (elapsedTime >= 1000L) { // 1 second
|
|
+ if (this.keepAlivePending && !this.processedDisconnect && this.keepAlives.size() >= KEEPALIVE_LIMIT_IN_SECONDS) {
|
|
+ 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(currentTime)) {
|
|
+ this.keepAlivePending = true;
|
|
+ this.keepAliveTime = currentTime; // hijack this field for 1 second intervals
|
|
+ this.keepAlives.add(currentTime); // currentTime is ID
|
|
+ this.send(new ClientboundKeepAlivePacket(currentTime));
|
|
+ }
|
|
+ }
|
|
+ } else {
|
|
+ // Gale end - Purpur - send multiple keep-alive packets
|
|
if (!this.isSingleplayerOwner() && elapsedTime >= 15000L) { // Paper - use vanilla's 15000L between keep alive packets
|
|
if (this.keepAlivePending && !this.processedDisconnect && elapsedTime >= KEEPALIVE_LIMIT) { // Paper - check keepalive limit, don't fire if already disconnected
|
|
this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE, org.bukkit.event.player.PlayerKickEvent.Cause.TIMEOUT); // Paper - kick event cause
|
|
@@ -261,6 +295,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
this.send(new ClientboundKeepAlivePacket(this.keepAliveChallenge));
|
|
}
|
|
}
|
|
+ } // Gale - Purpur - send multiple keep-alive packets
|
|
// Paper end - give clients a longer time to respond to pings as per pre 1.12.2 timings
|
|
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
index e0fdbef351b92e3f34369943356a38053a83ee5d..13bd2c1a3b3d1b4728faa02c0d7a1b70d3777334 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.brigadier.suggestion.Suggestions;
|
|
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.net.SocketAddress;
|
|
@@ -3465,6 +3467,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
}
|
|
|
|
@Override
|
|
+
|
|
public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) {
|
|
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
|
// CraftBukkit start
|
|
diff --git a/src/main/java/org/galemc/gale/configuration/GaleGlobalConfiguration.java b/src/main/java/org/galemc/gale/configuration/GaleGlobalConfiguration.java
|
|
index b2aa32662335c4d64ac87320fcfb334784d89ec5..4650c69295adcc780f00d8d098cf939931147828 100644
|
|
--- a/src/main/java/org/galemc/gale/configuration/GaleGlobalConfiguration.java
|
|
+++ b/src/main/java/org/galemc/gale/configuration/GaleGlobalConfiguration.java
|
|
@@ -88,6 +88,11 @@ public class GaleGlobalConfiguration extends ConfigurationPart {
|
|
|
|
}
|
|
|
|
+ public Keepalive keepalive;
|
|
+ public class Keepalive extends ConfigurationPart {
|
|
+ public boolean sendMultiple = true; // Gale - Purpur - send multiple keep-alive packets
|
|
+ }
|
|
+
|
|
}
|
|
|
|
public LogToConsole logToConsole;
|