CavePVP-Stuff/cSpigot-master/spigot-server-Patches/0040-Improve-Network-Manager-packet-handling.patch
2023-05-01 19:59:40 +01:00

60 lines
2.7 KiB
Diff

From abcfdaa6d0fa168158fb20ace3dbba3666a158ee Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 19 Oct 2014 16:01:51 -0500
Subject: [PATCH] Improve Network Manager packet handling
Removes an unnecessary "peek at head of queue", and also makes the number of packets
processed per player per tick configurable, so larger servers can slow down incoming processing.
diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java
index 76a54037e..5a5604ca7 100644
--- a/src/main/java/net/minecraft/server/NetworkManager.java
+++ b/src/main/java/net/minecraft/server/NetworkManager.java
@@ -154,11 +154,12 @@ public class NetworkManager extends SimpleChannelInboundHandler {
private void i() {
if (this.m != null && this.m.isOpen()) {
- while (!this.l.isEmpty()) {
- QueuedPacket queuedpacket = (QueuedPacket) this.l.poll();
-
+ // PaperSpigot start - Improve Network Manager packet handling
+ QueuedPacket queuedpacket;
+ while ((queuedpacket = (QueuedPacket) this.l.poll()) != null) {
this.b(QueuedPacket.a(queuedpacket), QueuedPacket.b(queuedpacket));
}
+ // PaperSpigot end
}
}
@@ -175,8 +176,10 @@ public class NetworkManager extends SimpleChannelInboundHandler {
}
if (this.o != null) {
- for (int i = 1000; !this.k.isEmpty() && i >= 0; --i) {
- Packet packet = (Packet) this.k.poll();
+ // PaperSpigot start - Improve Network Manager packet handling - Configurable packets per player per tick processing
+ Packet packet;
+ for (int i = org.github.paperspigot.PaperSpigotConfig.maxPacketsPerPlayer; (packet = (Packet) this.k.poll()) != null && i >= 0; --i) {
+ // PaperSpigot end
// CraftBukkit start
if (!this.isConnected() || !this.m.config().isAutoRead()) {
diff --git a/src/main/java/org/github/paperspigot/PaperSpigotConfig.java b/src/main/java/org/github/paperspigot/PaperSpigotConfig.java
index 0091cbf1e..e23430bf9 100644
--- a/src/main/java/org/github/paperspigot/PaperSpigotConfig.java
+++ b/src/main/java/org/github/paperspigot/PaperSpigotConfig.java
@@ -171,4 +171,10 @@ public class PaperSpigotConfig
strengthEffectModifier = getDouble( "effect-modifiers.strength", 1.3D );
weaknessEffectModifier = getDouble( "effect-modifiers.weakness", -0.5D );
}
+
+ public static int maxPacketsPerPlayer;
+ private static void maxPacketsPerPlayer()
+ {
+ maxPacketsPerPlayer = getInt( "max-packets-per-player", 1000 );
+ }
}
--
2.13.3