mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 04:56:29 +00:00
8c5b837e05
Firstly, the old methods all routed to the CompletableFuture method. However, the CF method could not guarantee that if the caller was off-main that the future would be "completed" on-main. Since the callback methods used the CF one, this meant that the callback methods did not guarantee that the callbacks were to be called on the main thread. Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb) so that the methods with the callback are guaranteed to invoke the callback on the main thread. The CF behavior remains unchanged; it may still appear to complete on main if invoked off-main. Secondly, remove the scheduleOnMain invocation in the async chunk completion. This unnecessarily delays the callback by 1 tick. Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which will load chunks within an area. This method is provided as a helper as keeping all chunks loaded within an area can be complicated to implement for plugins (due to the lacking ticket API), and is already implemented internally anyways. Fourthly, remove the ticket addition that occured with getChunkAt and getChunkAtAsync. The ticket addition may delay the unloading of the chunk unnecessarily. It also fixes a very rare timing bug where the future/callback would be completed after the chunk unloads.
41 lines
2.1 KiB
Diff
41 lines
2.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Shane Freeder <theboyetronic@gmail.com>
|
|
Date: Wed, 19 Aug 2020 05:05:54 +0100
|
|
Subject: [PATCH] Buffer joins to world
|
|
|
|
This patch buffers the number of logins which will attempt to join
|
|
the world per tick, this attempts to reduce the impact that join floods
|
|
has on the server
|
|
|
|
diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java
|
|
index 38947f40864f3661df2eb4baa0aef5740b82f9d9..134810ac91d828d67759cd1ed56f11b71e292917 100644
|
|
--- a/src/main/java/net/minecraft/network/Connection.java
|
|
+++ b/src/main/java/net/minecraft/network/Connection.java
|
|
@@ -445,12 +445,26 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
|
}
|
|
}
|
|
|
|
+ private static final int MAX_PER_TICK = io.papermc.paper.configuration.GlobalConfiguration.get().misc.maxJoinsPerTick; // Paper - Buffer joins to world
|
|
+ private static int joinAttemptsThisTick; // Paper - Buffer joins to world
|
|
+ private static int currTick; // Paper - Buffer joins to world
|
|
public void tick() {
|
|
this.flushQueue();
|
|
+ // Paper start - Buffer joins to world
|
|
+ if (Connection.currTick != net.minecraft.server.MinecraftServer.currentTick) {
|
|
+ Connection.currTick = net.minecraft.server.MinecraftServer.currentTick;
|
|
+ Connection.joinAttemptsThisTick = 0;
|
|
+ }
|
|
+ // Paper end - Buffer joins to world
|
|
PacketListener packetlistener = this.packetListener;
|
|
|
|
if (packetlistener instanceof TickablePacketListener tickablepacketlistener) {
|
|
+ // Paper start - Buffer joins to world
|
|
+ if (!(this.packetListener instanceof net.minecraft.server.network.ServerLoginPacketListenerImpl loginPacketListener)
|
|
+ || loginPacketListener.state != net.minecraft.server.network.ServerLoginPacketListenerImpl.State.VERIFYING
|
|
+ || Connection.joinAttemptsThisTick++ < MAX_PER_TICK) {
|
|
tickablepacketlistener.tick();
|
|
+ } // Paper end - Buffer joins to world
|
|
}
|
|
|
|
if (!this.isConnected() && !this.disconnectionHandled) {
|