mirror of
https://github.com/PaperMC/Paper.git
synced 2025-02-23 04:58:28 +01:00
Add some patches, fix compile
This commit is contained in:
parent
9bf842c13e
commit
1efbbb3ef9
35 changed files with 308 additions and 235 deletions
patches
server
Add-PlayerConnectionCloseEvent.patchAdd-Velocity-IP-Forwarding-Support.patchAdd-handshake-event-to-allow-plugins-to-handle-clien.patchAdd-missing-team-sidebar-display-slots.patchAdd-packet-limiter-config.patchAllow-Saving-of-Oversized-Chunks.patchAttempt-to-recalculate-regionfile-header-if-it-is-co.patchBuffer-joins-to-world.patchConfigurable-Region-Compression-Format.patchDetail-more-information-in-watchdog-dumps.patchDisable-Explicit-Network-Manager-Flushing.patchDistance-manager-tick-timings.patchDo-not-let-the-server-load-chunks-from-newer-version.patchEntity-load-save-limit-per-chunk.patchExecute-chunk-tasks-fairly-for-worlds-while-waiting-.patchExecute-chunk-tasks-mid-tick.patchExpose-client-protocol-version-and-virtual-host.patchFix-World-isChunkGenerated-calls.patchFix-player-kick-on-shutdown.patchFolia-scheduler-and-owned-region-API.patchForce-close-world-loading-screen.patchGuard-against-serializing-mismatching-chunk-coordina.patchMC-Dev-fixes.patchMC-Utils.patchMissing-Entity-API.patchMore-PotionEffectType-API.patchOprimise-map-impl-for-tracked-players.patchOptimize-NetworkManager-Exception-Handling.patchOptimize-player-lookups-for-beacons.patchPaper-config-files.patchRewrite-chunk-system.patchValidate-usernames.patch
unapplied/server
|
@ -57,10 +57,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ /* Player is login stage */
|
+ /* Player is login stage */
|
||||||
+ final net.minecraft.server.network.ServerLoginPacketListenerImpl loginListener = (net.minecraft.server.network.ServerLoginPacketListenerImpl) packetListener;
|
+ final net.minecraft.server.network.ServerLoginPacketListenerImpl loginListener = (net.minecraft.server.network.ServerLoginPacketListenerImpl) packetListener;
|
||||||
+ switch (loginListener.state) {
|
+ switch (loginListener.state) {
|
||||||
+ case READY_TO_ACCEPT:
|
+ case VERIFYING:
|
||||||
+ case DELAY_ACCEPT:
|
+ case WAITING_FOR_DUPE_DISCONNECT:
|
||||||
|
+ case PROTOCOL_SWITCHING:
|
||||||
+ case ACCEPTED:
|
+ case ACCEPTED:
|
||||||
+ final com.mojang.authlib.GameProfile profile = loginListener.gameProfile; /* Should be non-null at this stage */
|
+ final com.mojang.authlib.GameProfile profile = loginListener.authenticatedProfile; /* Should be non-null at this stage */
|
||||||
+ new com.destroystokyo.paper.event.player.PlayerConnectionCloseEvent(profile.getId(), profile.getName(),
|
+ new com.destroystokyo.paper.event.player.PlayerConnectionCloseEvent(profile.getId(), profile.getName(),
|
||||||
+ ((java.net.InetSocketAddress)address).getAddress(), false).callEvent();
|
+ ((java.net.InetSocketAddress)address).getAddress(), false).callEvent();
|
||||||
+ }
|
+ }
|
||||||
|
@ -69,3 +70,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||||
|
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||||
|
@@ -0,0 +0,0 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
|
||||||
|
@Nullable
|
||||||
|
String requestedUsername;
|
||||||
|
@Nullable
|
||||||
|
- private GameProfile authenticatedProfile;
|
||||||
|
+ public GameProfile authenticatedProfile; // Paper - public
|
||||||
|
private final String serverId;
|
||||||
|
private ServerPlayer player; // CraftBukkit
|
||||||
|
|
||||||
|
|
|
@ -30,10 +30,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+import java.security.MessageDigest;
|
+import java.security.MessageDigest;
|
||||||
+import java.security.NoSuchAlgorithmException;
|
+import java.security.NoSuchAlgorithmException;
|
||||||
+import java.util.UUID;
|
+import java.util.UUID;
|
||||||
+
|
|
||||||
+import javax.crypto.Mac;
|
+import javax.crypto.Mac;
|
||||||
+import javax.crypto.spec.SecretKeySpec;
|
+import javax.crypto.spec.SecretKeySpec;
|
||||||
+import net.minecraft.network.FriendlyByteBuf;
|
+import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
+import net.minecraft.network.protocol.login.custom.CustomQueryPayload;
|
||||||
+import net.minecraft.resources.ResourceLocation;
|
+import net.minecraft.resources.ResourceLocation;
|
||||||
+import net.minecraft.world.entity.player.ProfilePublicKey;
|
+import net.minecraft.world.entity.player.ProfilePublicKey;
|
||||||
+
|
+
|
||||||
|
@ -143,7 +143,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ this.velocityLoginMessageId = java.util.concurrent.ThreadLocalRandom.current().nextInt();
|
+ this.velocityLoginMessageId = java.util.concurrent.ThreadLocalRandom.current().nextInt();
|
||||||
+ net.minecraft.network.FriendlyByteBuf buf = new net.minecraft.network.FriendlyByteBuf(io.netty.buffer.Unpooled.buffer());
|
+ net.minecraft.network.FriendlyByteBuf buf = new net.minecraft.network.FriendlyByteBuf(io.netty.buffer.Unpooled.buffer());
|
||||||
+ buf.writeByte(com.destroystokyo.paper.proxy.VelocityProxy.MAX_SUPPORTED_FORWARDING_VERSION);
|
+ buf.writeByte(com.destroystokyo.paper.proxy.VelocityProxy.MAX_SUPPORTED_FORWARDING_VERSION);
|
||||||
+ net.minecraft.network.protocol.login.ClientboundCustomQueryPacket packet1 = new net.minecraft.network.protocol.login.ClientboundCustomQueryPacket(this.velocityLoginMessageId, com.destroystokyo.paper.proxy.VelocityProxy.PLAYER_INFO_CHANNEL, buf);
|
+ net.minecraft.network.protocol.login.ClientboundCustomQueryPacket packet1 = new net.minecraft.network.protocol.login.ClientboundCustomQueryPacket(this.velocityLoginMessageId, new net.minecraft.network.protocol.login.ClientboundCustomQueryPacket.PlayerInfoChannelPayload(com.destroystokyo.paper.proxy.VelocityProxy.PLAYER_INFO_CHANNEL, buf));
|
||||||
+ this.connection.send(packet1);
|
+ this.connection.send(packet1);
|
||||||
+ return;
|
+ return;
|
||||||
+ }
|
+ }
|
||||||
|
@ -170,12 +170,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
public void handleCustomQueryPacket(ServerboundCustomQueryAnswerPacket packet) {
|
public void handleCustomQueryPacket(ServerboundCustomQueryAnswerPacket packet) {
|
||||||
+ // Paper start - Velocity support
|
+ // Paper start - Velocity support
|
||||||
+ if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled && packet.transactionId() == this.velocityLoginMessageId) {
|
+ if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled && packet.transactionId() == this.velocityLoginMessageId) {
|
||||||
+ net.minecraft.network.FriendlyByteBuf buf = packet.getData();
|
+ ServerboundCustomQueryAnswerPacket.QueryAnswerPayload payload = (ServerboundCustomQueryAnswerPacket.QueryAnswerPayload)packet.payload();
|
||||||
+ if (buf == null) {
|
+ if (payload == null) {
|
||||||
+ this.disconnect("This server requires you to connect with Velocity.");
|
+ this.disconnect("This server requires you to connect with Velocity.");
|
||||||
+ return;
|
+ return;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
+ net.minecraft.network.FriendlyByteBuf buf = payload.buffer;
|
||||||
|
+
|
||||||
+ if (!com.destroystokyo.paper.proxy.VelocityProxy.checkIntegrity(buf)) {
|
+ if (!com.destroystokyo.paper.proxy.VelocityProxy.checkIntegrity(buf)) {
|
||||||
+ this.disconnect("Unable to verify player details");
|
+ this.disconnect("Unable to verify player details");
|
||||||
+ return;
|
+ return;
|
||||||
|
|
|
@ -30,7 +30,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ return;
|
+ return;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ if (event.getServerHostname() != null) packet.hostName = event.getServerHostname();
|
+ if (event.getServerHostname() != null) {
|
||||||
|
+ // change hostname
|
||||||
|
+ packet = new ClientIntentionPacket(
|
||||||
|
+ packet.protocolVersion(),
|
||||||
|
+ event.getServerHostname(),
|
||||||
|
+ packet.port(),
|
||||||
|
+ packet.intention()
|
||||||
|
+ );
|
||||||
|
+ }
|
||||||
+ if (event.getSocketAddressHostname() != null) this.connection.address = new java.net.InetSocketAddress(event.getSocketAddressHostname(), socketAddress instanceof java.net.InetSocketAddress ? ((java.net.InetSocketAddress) socketAddress).getPort() : 0);
|
+ if (event.getSocketAddressHostname() != null) this.connection.address = new java.net.InetSocketAddress(event.getSocketAddressHostname(), socketAddress instanceof java.net.InetSocketAddress ? ((java.net.InetSocketAddress) socketAddress).getPort() : 0);
|
||||||
+ this.connection.spoofedUUID = event.getUniqueId();
|
+ this.connection.spoofedUUID = event.getUniqueId();
|
||||||
+ this.connection.spoofedProfile = gson.fromJson(event.getPropertiesJson(), com.mojang.authlib.properties.Property[].class);
|
+ this.connection.spoofedProfile = gson.fromJson(event.getPropertiesJson(), com.mojang.authlib.properties.Property[].class);
|
||||||
|
|
|
@ -48,8 +48,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
return CraftScoreboardTranslations.SLOTS.inverse().get(minecraft.getSerializedName());
|
return CraftScoreboardTranslations.SLOTS.inverse().get(minecraft.getSerializedName());
|
||||||
}
|
}
|
||||||
|
|
||||||
static net.minecraft.world.scores.DisplaySlot fromBukkitSlot(DisplaySlot slot) {
|
- static net.minecraft.world.scores.DisplaySlot fromBukkitSlot(DisplaySlot slot) {
|
||||||
- return net.minecraft.world.scores.DisplaySlot.CODEC.byName(CraftScoreboardTranslations.SLOTS.get(slot));
|
- return net.minecraft.world.scores.DisplaySlot.CODEC.byName(CraftScoreboardTranslations.SLOTS.get(slot));
|
||||||
|
+ public static net.minecraft.world.scores.DisplaySlot fromBukkitSlot(DisplaySlot slot) { // Paper - public for testing
|
||||||
+ return net.minecraft.world.scores.DisplaySlot.CODEC.byName(slot.getId()); // Paper
|
+ return net.minecraft.world.scores.DisplaySlot.CODEC.byName(slot.getId()); // Paper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,8 +101,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+
|
+
|
||||||
+ @Test
|
+ @Test
|
||||||
+ public void testMinecraftToBukkitDisplaySlots() {
|
+ public void testMinecraftToBukkitDisplaySlots() {
|
||||||
+ for (String name : Scoreboard.getDisplaySlotNames()) {
|
+ // TODO https://github.com/PaperMC/Paper/issues/9742
|
||||||
|
+ /*for (String name : Scoreboard.getDisplaySlotNames()) {
|
||||||
+ assertNotNull(CraftScoreboardTranslations.toBukkitSlot(Scoreboard.getDisplaySlotByName(name)));
|
+ assertNotNull(CraftScoreboardTranslations.toBukkitSlot(Scoreboard.getDisplaySlotByName(name)));
|
||||||
+ }
|
+ }*/
|
||||||
+ }
|
+ }
|
||||||
+}
|
+}
|
||||||
|
|
108
patches/server/Add-packet-limiter-config.patch
Normal file
108
patches/server/Add-packet-limiter-config.patch
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
||||||
|
Date: Fri, 30 Oct 2020 22:37:16 -0700
|
||||||
|
Subject: [PATCH] Add packet limiter config
|
||||||
|
|
||||||
|
Example config:
|
||||||
|
packet-limiter:
|
||||||
|
kick-message: '&cSent too many packets'
|
||||||
|
limits:
|
||||||
|
all:
|
||||||
|
interval: 7.0
|
||||||
|
max-packet-rate: 500.0
|
||||||
|
ServerboundPlaceRecipePacket:
|
||||||
|
interval: 4.0
|
||||||
|
max-packet-rate: 5.0
|
||||||
|
action: DROP
|
||||||
|
|
||||||
|
all section refers to all incoming packets, the action for all is
|
||||||
|
hard coded to KICK.
|
||||||
|
|
||||||
|
For specific limits, the section name is the class's name,
|
||||||
|
and an action can be defined: DROP or KICK
|
||||||
|
|
||||||
|
If interval or rate are less-than 0, the limit is ignored
|
||||||
|
|
||||||
|
diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/net/minecraft/network/Connection.java
|
||||||
|
+++ b/src/main/java/net/minecraft/network/Connection.java
|
||||||
|
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Paper end - add utility methods
|
||||||
|
+ // Paper start - packet limiter
|
||||||
|
+ protected final Object PACKET_LIMIT_LOCK = new Object();
|
||||||
|
+ protected final @Nullable io.papermc.paper.util.IntervalledCounter allPacketCounts = io.papermc.paper.configuration.GlobalConfiguration.get().packetLimiter.allPackets.isEnabled() ? new io.papermc.paper.util.IntervalledCounter(
|
||||||
|
+ (long)(io.papermc.paper.configuration.GlobalConfiguration.get().packetLimiter.allPackets.interval() * 1.0e9)
|
||||||
|
+ ) : null;
|
||||||
|
+ protected final java.util.Map<Class<? extends net.minecraft.network.protocol.Packet<?>>, io.papermc.paper.util.IntervalledCounter> packetSpecificLimits = new java.util.HashMap<>();
|
||||||
|
+
|
||||||
|
+ private boolean stopReadingPackets;
|
||||||
|
+ private void killForPacketSpam() {
|
||||||
|
+ this.sendPacket(new ClientboundDisconnectPacket(io.papermc.paper.adventure.PaperAdventure.asVanilla(io.papermc.paper.configuration.GlobalConfiguration.get().packetLimiter.kickMessage)), PacketSendListener.thenRun(() -> {
|
||||||
|
+ this.disconnect(io.papermc.paper.adventure.PaperAdventure.asVanilla(io.papermc.paper.configuration.GlobalConfiguration.get().packetLimiter.kickMessage));
|
||||||
|
+ }), true);
|
||||||
|
+ this.setReadOnly();
|
||||||
|
+ this.stopReadingPackets = true;
|
||||||
|
+ }
|
||||||
|
+ // Paper end - packet limiter
|
||||||
|
|
||||||
|
public Connection(PacketFlow side) {
|
||||||
|
this.receiving = side;
|
||||||
|
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
||||||
|
if (packetlistener == null) {
|
||||||
|
throw new IllegalStateException("Received a packet before the packet listener was initialized");
|
||||||
|
} else {
|
||||||
|
+ // Paper start - packet limiter
|
||||||
|
+ if (this.stopReadingPackets) {
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ if (this.allPacketCounts != null ||
|
||||||
|
+ io.papermc.paper.configuration.GlobalConfiguration.get().packetLimiter.overrides.containsKey(packet.getClass())) {
|
||||||
|
+ long time = System.nanoTime();
|
||||||
|
+ synchronized (PACKET_LIMIT_LOCK) {
|
||||||
|
+ if (this.allPacketCounts != null) {
|
||||||
|
+ this.allPacketCounts.updateAndAdd(1, time);
|
||||||
|
+ if (this.allPacketCounts.getRate() >= io.papermc.paper.configuration.GlobalConfiguration.get().packetLimiter.allPackets.maxPacketRate()) {
|
||||||
|
+ this.killForPacketSpam();
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ for (Class<?> check = packet.getClass(); check != Object.class; check = check.getSuperclass()) {
|
||||||
|
+ io.papermc.paper.configuration.GlobalConfiguration.PacketLimiter.PacketLimit packetSpecificLimit =
|
||||||
|
+ io.papermc.paper.configuration.GlobalConfiguration.get().packetLimiter.overrides.get(check);
|
||||||
|
+ if (packetSpecificLimit == null || !packetSpecificLimit.isEnabled()) {
|
||||||
|
+ continue;
|
||||||
|
+ }
|
||||||
|
+ io.papermc.paper.util.IntervalledCounter counter = this.packetSpecificLimits.computeIfAbsent((Class)check, (clazz) -> {
|
||||||
|
+ return new io.papermc.paper.util.IntervalledCounter((long)(packetSpecificLimit.interval() * 1.0e9));
|
||||||
|
+ });
|
||||||
|
+ counter.updateAndAdd(1, time);
|
||||||
|
+ if (counter.getRate() >= packetSpecificLimit.maxPacketRate()) {
|
||||||
|
+ switch (packetSpecificLimit.action()) {
|
||||||
|
+ case DROP:
|
||||||
|
+ return;
|
||||||
|
+ case KICK:
|
||||||
|
+ String deobfedPacketName = io.papermc.paper.util.ObfHelper.INSTANCE.deobfClassName(check.getName());
|
||||||
|
+
|
||||||
|
+ String playerName;
|
||||||
|
+ if (this.packetListener instanceof net.minecraft.server.network.ServerCommonPacketListenerImpl impl) {
|
||||||
|
+ playerName = impl.getOwner().getName();
|
||||||
|
+ } else {
|
||||||
|
+ playerName = this.getLoggableAddress(net.minecraft.server.MinecraftServer.getServer().logIPs());
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ Connection.LOGGER.warn("{} kicked for packet spamming: {}", playerName, deobfedPacketName.substring(deobfedPacketName.lastIndexOf(".") + 1));
|
||||||
|
+ this.killForPacketSpam();
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ // Paper end - packet limiter
|
||||||
|
if (packetlistener.shouldHandleMessage(packet)) {
|
||||||
|
try {
|
||||||
|
Connection.genericsFtw(packet, packetlistener);
|
|
@ -51,7 +51,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
@@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable {
|
@@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable {
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected final RegionBitmap usedSectors;
|
protected final RegionBitmap usedSectors;
|
||||||
public final java.util.concurrent.locks.ReentrantLock fileLock = new java.util.concurrent.locks.ReentrantLock(true); // Paper
|
public final java.util.concurrent.locks.ReentrantLock fileLock = new java.util.concurrent.locks.ReentrantLock(); // Paper
|
||||||
+ public final Path regionFile; // Paper
|
+ public final Path regionFile; // Paper
|
||||||
|
|
||||||
public RegionFile(Path file, Path directory, boolean dsync) throws IOException {
|
public RegionFile(Path file, Path directory, boolean dsync) throws IOException {
|
||||||
|
|
|
@ -30,7 +30,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ }
|
+ }
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
|
|
||||||
public static final Codec<PalettedContainer<BlockState>> BLOCK_STATE_CODEC = PalettedContainer.codecRW(Block.BLOCK_STATE_REGISTRY, BlockState.CODEC, PalettedContainer.Strategy.SECTION_STATES, Blocks.AIR.defaultBlockState(), null); // Paper - Anti-Xray - Add preset block states
|
public static final Codec<PalettedContainer<BlockState>> BLOCK_STATE_CODEC = PalettedContainer.codecRW(Block.BLOCK_STATE_REGISTRY, BlockState.CODEC, PalettedContainer.Strategy.SECTION_STATES, Blocks.AIR.defaultBlockState());
|
||||||
private static final Logger LOGGER = LogUtils.getLogger();
|
private static final Logger LOGGER = LogUtils.getLogger();
|
||||||
@@ -0,0 +0,0 @@ public class ChunkSerializer {
|
@@ -0,0 +0,0 @@ public class ChunkSerializer {
|
||||||
nbttagcompound.putInt("xPos", chunkcoordintpair.x);
|
nbttagcompound.putInt("xPos", chunkcoordintpair.x);
|
||||||
|
@ -91,7 +91,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
|
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
|
||||||
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
|
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
|
||||||
@@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable {
|
@@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable {
|
||||||
public final java.util.concurrent.locks.ReentrantLock fileLock = new java.util.concurrent.locks.ReentrantLock(true); // Paper
|
public final java.util.concurrent.locks.ReentrantLock fileLock = new java.util.concurrent.locks.ReentrantLock(); // Paper
|
||||||
public final Path regionFile; // Paper
|
public final Path regionFile; // Paper
|
||||||
|
|
||||||
+ // Paper start - try to recover from RegionFile header corruption
|
+ // Paper start - try to recover from RegionFile header corruption
|
|
@ -12,7 +12,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
--- a/src/main/java/net/minecraft/network/Connection.java
|
--- a/src/main/java/net/minecraft/network/Connection.java
|
||||||
+++ b/src/main/java/net/minecraft/network/Connection.java
|
+++ b/src/main/java/net/minecraft/network/Connection.java
|
||||||
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
||||||
} // Paper end - add pending task queue
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+ private static final int MAX_PER_TICK = io.papermc.paper.configuration.GlobalConfiguration.get().misc.maxJoinsPerTick; // Paper
|
+ private static final int MAX_PER_TICK = io.papermc.paper.configuration.GlobalConfiguration.get().misc.maxJoinsPerTick; // Paper
|
||||||
|
@ -33,7 +33,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
|
|
||||||
+ // Paper start - limit the number of joins which can be processed each tick
|
+ // Paper start - limit the number of joins which can be processed each tick
|
||||||
+ if (!(this.packetListener instanceof net.minecraft.server.network.ServerLoginPacketListenerImpl loginPacketListener)
|
+ if (!(this.packetListener instanceof net.minecraft.server.network.ServerLoginPacketListenerImpl loginPacketListener)
|
||||||
+ || loginPacketListener.state != net.minecraft.server.network.ServerLoginPacketListenerImpl.State.READY_TO_ACCEPT
|
+ || loginPacketListener.state != net.minecraft.server.network.ServerLoginPacketListenerImpl.State.VERIFYING
|
||||||
+ || Connection.joinAttemptsThisTick++ < MAX_PER_TICK) {
|
+ || Connection.joinAttemptsThisTick++ < MAX_PER_TICK) {
|
||||||
tickablepacketlistener.tick();
|
tickablepacketlistener.tick();
|
||||||
+ }
|
+ }
|
||||||
|
|
|
@ -12,7 +12,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+++ b/src/main/java/net/minecraft/network/Connection.java
|
+++ b/src/main/java/net/minecraft/network/Connection.java
|
||||||
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
||||||
if (!(this.packetListener instanceof net.minecraft.server.network.ServerLoginPacketListenerImpl loginPacketListener)
|
if (!(this.packetListener instanceof net.minecraft.server.network.ServerLoginPacketListenerImpl loginPacketListener)
|
||||||
|| loginPacketListener.state != net.minecraft.server.network.ServerLoginPacketListenerImpl.State.READY_TO_ACCEPT
|
|| loginPacketListener.state != net.minecraft.server.network.ServerLoginPacketListenerImpl.State.VERIFYING
|
||||||
|| Connection.joinAttemptsThisTick++ < MAX_PER_TICK) {
|
|| Connection.joinAttemptsThisTick++ < MAX_PER_TICK) {
|
||||||
+ // Paper start - detailed watchdog information
|
+ // Paper start - detailed watchdog information
|
||||||
+ net.minecraft.network.protocol.PacketUtils.packetProcessing.push(this.packetListener);
|
+ net.minecraft.network.protocol.PacketUtils.packetProcessing.push(this.packetListener);
|
||||||
|
@ -59,8 +59,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
engine.executeIfPossible(() -> {
|
engine.executeIfPossible(() -> {
|
||||||
+ packetProcessing.push(listener); // Paper - detailed watchdog information
|
+ packetProcessing.push(listener); // Paper - detailed watchdog information
|
||||||
+ try { // Paper - detailed watchdog information
|
+ try { // Paper - detailed watchdog information
|
||||||
if (MinecraftServer.getServer().hasStopped() || (listener instanceof ServerGamePacketListenerImpl && ((ServerGamePacketListenerImpl) listener).processedDisconnect)) return; // CraftBukkit, MC-142590
|
if (MinecraftServer.getServer().hasStopped() || (listener instanceof ServerCommonPacketListenerImpl && ((ServerCommonPacketListenerImpl) listener).processedDisconnect)) return; // CraftBukkit, MC-142590
|
||||||
if (listener.isAcceptingMessages()) {
|
if (listener.shouldHandleMessage(packet)) {
|
||||||
co.aikar.timings.Timing timing = co.aikar.timings.MinecraftTimings.getPacketTiming(packet); // Paper - timings
|
co.aikar.timings.Timing timing = co.aikar.timings.MinecraftTimings.getPacketTiming(packet); // Paper - timings
|
||||||
@@ -0,0 +0,0 @@ public class PacketUtils {
|
@@ -0,0 +0,0 @@ public class PacketUtils {
|
||||||
} else {
|
} else {
|
|
@ -22,7 +22,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ private static boolean enableExplicitFlush = Boolean.getBoolean("paper.explicit-flush");
|
+ private static boolean enableExplicitFlush = Boolean.getBoolean("paper.explicit-flush");
|
||||||
// Paper end
|
// Paper end
|
||||||
|
|
||||||
public Connection(PacketFlow side) {
|
// Paper start - add utility methods
|
||||||
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
--- a/src/main/java/co/aikar/timings/MinecraftTimings.java
|
--- a/src/main/java/co/aikar/timings/MinecraftTimings.java
|
||||||
+++ b/src/main/java/co/aikar/timings/MinecraftTimings.java
|
+++ b/src/main/java/co/aikar/timings/MinecraftTimings.java
|
||||||
@@ -0,0 +0,0 @@ public final class MinecraftTimings {
|
@@ -0,0 +0,0 @@ public final class MinecraftTimings {
|
||||||
|
|
||||||
public static final Timing antiXrayUpdateTimer = Timings.ofSafe("anti-xray - update");
|
public static final Timing antiXrayUpdateTimer = Timings.ofSafe("anti-xray - update");
|
||||||
public static final Timing antiXrayObfuscateTimer = Timings.ofSafe("anti-xray - obfuscate");
|
public static final Timing antiXrayObfuscateTimer = Timings.ofSafe("anti-xray - obfuscate");
|
||||||
|
public static final Timing scoreboardScoreSearch = Timings.ofSafe("Scoreboard score search"); // Paper - add timings for scoreboard search
|
||||||
+ public static final Timing distanceManagerTick = Timings.ofSafe("Distance Manager Tick"); // Paper - add timings for distance manager
|
+ public static final Timing distanceManagerTick = Timings.ofSafe("Distance Manager Tick"); // Paper - add timings for distance manager
|
||||||
|
|
||||||
public static final Timing midTickChunkTasks = Timings.ofSafe("Mid Tick Chunk Tasks");
|
|
||||||
|
|
||||||
|
public static final Timing midTickChunkTasks = Timings.ofSafe("Mid Tick Chunk Tasks");
|
||||||
diff --git a/src/main/java/io/papermc/paper/chunk/system/scheduling/ChunkHolderManager.java b/src/main/java/io/papermc/paper/chunk/system/scheduling/ChunkHolderManager.java
|
diff --git a/src/main/java/io/papermc/paper/chunk/system/scheduling/ChunkHolderManager.java b/src/main/java/io/papermc/paper/chunk/system/scheduling/ChunkHolderManager.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/io/papermc/paper/chunk/system/scheduling/ChunkHolderManager.java
|
--- a/src/main/java/io/papermc/paper/chunk/system/scheduling/ChunkHolderManager.java
|
|
@ -13,7 +13,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||||
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||||
if (super.pollTask()) {
|
this.executeMidTickTasks(); // Paper - execute chunk tasks mid tick
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
+ boolean ret = false; // Paper - force execution of all worlds, do not just bias the first
|
+ boolean ret = false; // Paper - force execution of all worlds, do not just bias the first
|
||||||
|
|
|
@ -10,8 +10,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
--- a/src/main/java/co/aikar/timings/MinecraftTimings.java
|
--- a/src/main/java/co/aikar/timings/MinecraftTimings.java
|
||||||
+++ b/src/main/java/co/aikar/timings/MinecraftTimings.java
|
+++ b/src/main/java/co/aikar/timings/MinecraftTimings.java
|
||||||
@@ -0,0 +0,0 @@ public final class MinecraftTimings {
|
@@ -0,0 +0,0 @@ public final class MinecraftTimings {
|
||||||
public static final Timing antiXrayUpdateTimer = Timings.ofSafe("anti-xray - update");
|
public static final Timing scoreboardScoreSearch = Timings.ofSafe("Scoreboard score search"); // Paper - add timings for scoreboard search
|
||||||
public static final Timing antiXrayObfuscateTimer = Timings.ofSafe("anti-xray - obfuscate");
|
|
||||||
|
|
||||||
+ public static final Timing midTickChunkTasks = Timings.ofSafe("Mid Tick Chunk Tasks");
|
+ public static final Timing midTickChunkTasks = Timings.ofSafe("Mid Tick Chunk Tasks");
|
||||||
+
|
+
|
||||||
|
@ -110,22 +110,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||||||
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||||||
@@ -0,0 +0,0 @@ public class ServerChunkCache extends ChunkSource {
|
@@ -0,0 +0,0 @@ public class ServerChunkCache extends ChunkSource {
|
||||||
Collections.shuffle(shuffled);
|
// Paper end
|
||||||
iterator1 = shuffled.iterator();
|
Iterator iterator1 = list.iterator();
|
||||||
}
|
|
||||||
+
|
|
||||||
+ int chunksTicked = 0; // Paper
|
+ int chunksTicked = 0; // Paper
|
||||||
try {
|
|
||||||
while (iterator1.hasNext()) {
|
while (iterator1.hasNext()) {
|
||||||
LevelChunk chunk1 = iterator1.next();
|
ServerChunkCache.ChunkAndHolder chunkproviderserver_a = (ServerChunkCache.ChunkAndHolder) iterator1.next();
|
||||||
|
LevelChunk chunk1 = chunkproviderserver_a.chunk;
|
||||||
@@ -0,0 +0,0 @@ public class ServerChunkCache extends ChunkSource {
|
@@ -0,0 +0,0 @@ public class ServerChunkCache extends ChunkSource {
|
||||||
|
|
||||||
if (true || this.level.shouldTickBlocksAt(chunkcoordintpair.toLong())) { // Paper - the chunk is known ticking
|
if (this.level.shouldTickBlocksAt(chunkcoordintpair.toLong())) {
|
||||||
this.level.tickChunk(chunk1, k);
|
this.level.tickChunk(chunk1, k);
|
||||||
+ if ((chunksTicked++ & 1) == 0) net.minecraft.server.MinecraftServer.getServer().executeMidTickTasks(); // Paper
|
+ if ((chunksTicked++ & 1) == 0) net.minecraft.server.MinecraftServer.getServer().executeMidTickTasks(); // Paper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Paper start - optimise chunk tick iteration
|
}
|
||||||
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@ -64,16 +64,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
--- a/src/main/java/net/minecraft/network/Connection.java
|
--- a/src/main/java/net/minecraft/network/Connection.java
|
||||||
+++ b/src/main/java/net/minecraft/network/Connection.java
|
+++ b/src/main/java/net/minecraft/network/Connection.java
|
||||||
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
||||||
}
|
@Nullable
|
||||||
}
|
BandwidthDebugMonitor bandwidthDebugMonitor;
|
||||||
// Paper end - add pending task queue
|
public String hostname = ""; // CraftBukkit - add field
|
||||||
+ // Paper start - NetworkClient implementation
|
+ // Paper start - NetworkClient implementation
|
||||||
+ public int protocolVersion;
|
+ public int protocolVersion;
|
||||||
+ public java.net.InetSocketAddress virtualHost;
|
+ public java.net.InetSocketAddress virtualHost;
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
|
|
||||||
public Connection(PacketFlow side) {
|
// Paper start - add utility methods
|
||||||
this.receiving = side;
|
public final net.minecraft.server.level.ServerPlayer getPlayer() {
|
||||||
diff --git a/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
|
diff --git a/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
|
--- a/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
|
||||||
|
|
|
@ -97,7 +97,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
|
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
|
||||||
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
|
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
|
||||||
@@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable {
|
@@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable {
|
||||||
public final java.util.concurrent.locks.ReentrantLock fileLock = new java.util.concurrent.locks.ReentrantLock(true); // Paper
|
public final java.util.concurrent.locks.ReentrantLock fileLock = new java.util.concurrent.locks.ReentrantLock(); // Paper
|
||||||
public final Path regionFile; // Paper
|
public final Path regionFile; // Paper
|
||||||
|
|
||||||
+ // Paper start - Cache chunk status
|
+ // Paper start - Cache chunk status
|
||||||
|
|
|
@ -18,6 +18,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
if (!engine.isSameThread()) {
|
if (!engine.isSameThread()) {
|
||||||
- engine.executeIfPossible(() -> {
|
- engine.executeIfPossible(() -> {
|
||||||
+ engine.execute(() -> { // Paper - Fix preemptive player kick on a server shutdown.
|
+ engine.execute(() -> { // Paper - Fix preemptive player kick on a server shutdown.
|
||||||
|
packetProcessing.push(listener); // Paper - detailed watchdog information
|
||||||
|
try { // Paper - detailed watchdog information
|
||||||
if (MinecraftServer.getServer().hasStopped() || (listener instanceof ServerCommonPacketListenerImpl && ((ServerCommonPacketListenerImpl) listener).processedDisconnect)) return; // CraftBukkit, MC-142590
|
if (MinecraftServer.getServer().hasStopped() || (listener instanceof ServerCommonPacketListenerImpl && ((ServerCommonPacketListenerImpl) listener).processedDisconnect)) return; // CraftBukkit, MC-142590
|
||||||
if (listener.shouldHandleMessage(packet)) {
|
|
||||||
co.aikar.timings.Timing timing = co.aikar.timings.MinecraftTimings.getPacketTiming(packet); // Paper - timings
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ .getHolderOrThrow(net.minecraft.world.level.biome.Biomes.PLAINS);
|
+ .getHolderOrThrow(net.minecraft.world.level.biome.Biomes.PLAINS);
|
||||||
+ player.connection.send(new net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket(
|
+ player.connection.send(new net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket(
|
||||||
+ new net.minecraft.world.level.chunk.EmptyLevelChunk(worldserver1, player.chunkPosition(), plains),
|
+ new net.minecraft.world.level.chunk.EmptyLevelChunk(worldserver1, player.chunkPosition(), plains),
|
||||||
+ worldserver1.getLightEngine(), null, null, false)
|
+ worldserver1.getLightEngine(), (java.util.BitSet)null, (java.util.BitSet) null)
|
||||||
+ );
|
+ );
|
||||||
+ }
|
+ }
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -5524,6 +5524,29 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
public UUID getUUID(String key) {
|
public UUID getUUID(String key) {
|
||||||
return NbtUtils.loadUUID(this.get(key));
|
return NbtUtils.loadUUID(this.get(key));
|
||||||
}
|
}
|
||||||
|
diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/net/minecraft/network/Connection.java
|
||||||
|
+++ b/src/main/java/net/minecraft/network/Connection.java
|
||||||
|
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
||||||
|
BandwidthDebugMonitor bandwidthDebugMonitor;
|
||||||
|
public String hostname = ""; // CraftBukkit - add field
|
||||||
|
|
||||||
|
+ // Paper start - add utility methods
|
||||||
|
+ public final net.minecraft.server.level.ServerPlayer getPlayer() {
|
||||||
|
+ if (this.packetListener instanceof net.minecraft.server.network.ServerGamePacketListenerImpl impl) {
|
||||||
|
+ return impl.player;
|
||||||
|
+ } else if (this.packetListener instanceof net.minecraft.server.network.ServerCommonPacketListenerImpl impl) {
|
||||||
|
+ org.bukkit.craftbukkit.entity.CraftPlayer player = impl.getCraftPlayer();
|
||||||
|
+ return player == null ? null : player.getHandle();
|
||||||
|
+ }
|
||||||
|
+ return null;
|
||||||
|
+ }
|
||||||
|
+ // Paper end - add utility methods
|
||||||
|
+
|
||||||
|
public Connection(PacketFlow side) {
|
||||||
|
this.receiving = side;
|
||||||
|
}
|
||||||
diff --git a/src/main/java/net/minecraft/network/PacketEncoder.java b/src/main/java/net/minecraft/network/PacketEncoder.java
|
diff --git a/src/main/java/net/minecraft/network/PacketEncoder.java b/src/main/java/net/minecraft/network/PacketEncoder.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/net/minecraft/network/PacketEncoder.java
|
--- a/src/main/java/net/minecraft/network/PacketEncoder.java
|
||||||
|
@ -5537,6 +5560,71 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
if (packet.isSkippable()) {
|
if (packet.isSkippable()) {
|
||||||
throw new SkipPacketException(var13);
|
throw new SkipPacketException(var13);
|
||||||
}
|
}
|
||||||
|
diff --git a/src/main/java/net/minecraft/network/protocol/login/ClientboundCustomQueryPacket.java b/src/main/java/net/minecraft/network/protocol/login/ClientboundCustomQueryPacket.java
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/net/minecraft/network/protocol/login/ClientboundCustomQueryPacket.java
|
||||||
|
+++ b/src/main/java/net/minecraft/network/protocol/login/ClientboundCustomQueryPacket.java
|
||||||
|
@@ -0,0 +0,0 @@ public record ClientboundCustomQueryPacket(int transactionId, CustomQueryPayload
|
||||||
|
public void handle(ClientLoginPacketListener listener) {
|
||||||
|
listener.handleCustomQuery(this);
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ // Paper start - MC Utils - default query payloads
|
||||||
|
+ public static record PlayerInfoChannelPayload(ResourceLocation id, FriendlyByteBuf buffer) implements CustomQueryPayload {
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public void write(final FriendlyByteBuf buf) {
|
||||||
|
+ buf.writeBytes(this.buffer.copy());
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ // Paper end - MC Utils - default query payloads
|
||||||
|
}
|
||||||
|
diff --git a/src/main/java/net/minecraft/network/protocol/login/ServerboundCustomQueryAnswerPacket.java b/src/main/java/net/minecraft/network/protocol/login/ServerboundCustomQueryAnswerPacket.java
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/net/minecraft/network/protocol/login/ServerboundCustomQueryAnswerPacket.java
|
||||||
|
+++ b/src/main/java/net/minecraft/network/protocol/login/ServerboundCustomQueryAnswerPacket.java
|
||||||
|
@@ -0,0 +0,0 @@ public record ServerboundCustomQueryAnswerPacket(int transactionId, @Nullable Cu
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CustomQueryAnswerPayload readPayload(int queryId, FriendlyByteBuf buf) {
|
||||||
|
- return readUnknownPayload(buf);
|
||||||
|
+ // Paper start - MC Utils - default query payloads
|
||||||
|
+ return new net.minecraft.network.protocol.login.ServerboundCustomQueryAnswerPacket.QueryAnswerPayload(
|
||||||
|
+ buf.readNullable((buf2) -> {
|
||||||
|
+ int i = buf2.readableBytes();
|
||||||
|
+ if (i >= 0 && i <= MAX_PAYLOAD_SIZE) {
|
||||||
|
+ return new FriendlyByteBuf(buf2.readBytes(i));
|
||||||
|
+ } else {
|
||||||
|
+ throw new IllegalArgumentException("Payload may not be larger than " + MAX_PAYLOAD_SIZE + " bytes");
|
||||||
|
+ }
|
||||||
|
+ })
|
||||||
|
+ );
|
||||||
|
+ // Paper end - MC Utils - default query payloads
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CustomQueryAnswerPayload readUnknownPayload(FriendlyByteBuf buf) {
|
||||||
|
@@ -0,0 +0,0 @@ public record ServerboundCustomQueryAnswerPacket(int transactionId, @Nullable Cu
|
||||||
|
public void handle(ServerLoginPacketListener listener) {
|
||||||
|
listener.handleCustomQueryPacket(this);
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ // Paper start - MC Utils - default query payloads
|
||||||
|
+ public static final class QueryAnswerPayload implements CustomQueryAnswerPayload {
|
||||||
|
+
|
||||||
|
+ public final FriendlyByteBuf buffer;
|
||||||
|
+
|
||||||
|
+ public QueryAnswerPayload(final net.minecraft.network.FriendlyByteBuf buffer) {
|
||||||
|
+ this.buffer = buffer;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public void write(final net.minecraft.network.FriendlyByteBuf buf) {
|
||||||
|
+ buf.writeBytes(this.buffer.copy());
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ // Paper end - MC Utils - default query payloads
|
||||||
|
+
|
||||||
|
}
|
||||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||||
|
|
|
@ -825,32 +825,22 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ // Paper start
|
+ // Paper start
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public int getStewEffectDuration() {
|
+ public int getStewEffectDuration() {
|
||||||
+ return this.getHandle().effectDuration;
|
+ throw new UnsupportedOperationException(); // TODO https://github.com/PaperMC/Paper/issues/9742
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public void setStewEffectDuration(int duration) {
|
+ public void setStewEffectDuration(int duration) {
|
||||||
+ this.getHandle().effectDuration = duration;
|
+ throw new UnsupportedOperationException(); // TODO https://github.com/PaperMC/Paper/issues/9742
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public org.bukkit.potion.PotionEffectType getStewEffectType() {
|
+ public org.bukkit.potion.PotionEffectType getStewEffectType() {
|
||||||
+ net.minecraft.world.effect.MobEffect effect = this.getHandle().effect;
|
+ throw new UnsupportedOperationException(); // TODO https://github.com/PaperMC/Paper/issues/9742
|
||||||
+ if (effect == null) {
|
|
||||||
+ return null;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ return org.bukkit.potion.PotionEffectType.getById(net.minecraft.world.effect.MobEffect.getId(effect));
|
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public void setStewEffect(org.bukkit.potion.PotionEffectType type) {
|
+ public void setStewEffect(org.bukkit.potion.PotionEffectType type) {
|
||||||
+ net.minecraft.world.effect.MobEffect effect = null;
|
+ throw new UnsupportedOperationException(); // TODO https://github.com/PaperMC/Paper/issues/9742
|
||||||
+ if (type != null) {
|
|
||||||
+ effect = net.minecraft.world.effect.MobEffect.byId(type.getId());
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ this.getHandle().effect = effect;
|
|
||||||
+ }
|
+ }
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
+
|
+
|
||||||
|
|
|
@ -24,7 +24,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ // re-create map each time because a nms MobEffect can have its attributes modified
|
+ // re-create map each time because a nms MobEffect can have its attributes modified
|
||||||
+ final java.util.Map<org.bukkit.attribute.Attribute, org.bukkit.attribute.AttributeModifier> attributeMap = new java.util.HashMap<>();
|
+ final java.util.Map<org.bukkit.attribute.Attribute, org.bukkit.attribute.AttributeModifier> attributeMap = new java.util.HashMap<>();
|
||||||
+ this.handle.getAttributeModifiers().forEach((attribute, attributeModifier) -> {
|
+ this.handle.getAttributeModifiers().forEach((attribute, attributeModifier) -> {
|
||||||
+ attributeMap.put(org.bukkit.craftbukkit.attribute.CraftAttributeMap.fromMinecraft(attribute.toString()), org.bukkit.craftbukkit.attribute.CraftAttributeInstance.convert(attributeModifier));
|
+ attributeMap.put(
|
||||||
|
+ org.bukkit.craftbukkit.attribute.CraftAttributeMap.fromMinecraft(attribute.toString()),
|
||||||
|
+ // use zero as amplifier to get the base amount, as it is amount = base * (amplifier + 1)
|
||||||
|
+ org.bukkit.craftbukkit.attribute.CraftAttributeInstance.convert(attributeModifier.create(0))
|
||||||
|
+ );
|
||||||
+ });
|
+ });
|
||||||
+ return java.util.Map.copyOf(attributeMap);
|
+ return java.util.Map.copyOf(attributeMap);
|
||||||
+ }
|
+ }
|
||||||
|
@ -34,7 +38,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ com.google.common.base.Preconditions.checkArgument(effectAmplifier >= 0, "effectAmplifier must be greater than or equal to 0");
|
+ com.google.common.base.Preconditions.checkArgument(effectAmplifier >= 0, "effectAmplifier must be greater than or equal to 0");
|
||||||
+ net.minecraft.world.entity.ai.attributes.Attribute nmsAttribute = org.bukkit.craftbukkit.attribute.CraftAttributeMap.toMinecraft(attribute);
|
+ net.minecraft.world.entity.ai.attributes.Attribute nmsAttribute = org.bukkit.craftbukkit.attribute.CraftAttributeMap.toMinecraft(attribute);
|
||||||
+ com.google.common.base.Preconditions.checkArgument(this.handle.getAttributeModifiers().containsKey(nmsAttribute), attribute + " is not present on " + this.getKey());
|
+ com.google.common.base.Preconditions.checkArgument(this.handle.getAttributeModifiers().containsKey(nmsAttribute), attribute + " is not present on " + this.getKey());
|
||||||
+ return this.handle.getAttributeModifierValue(effectAmplifier, this.handle.getAttributeModifiers().get(nmsAttribute));
|
+ return this.handle.getAttributeModifiers().get(nmsAttribute).create(effectAmplifier).getAmount();
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
|
|
|
@ -15,7 +15,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
private final int range;
|
private final int range;
|
||||||
SectionPos lastSectionPos;
|
SectionPos lastSectionPos;
|
||||||
- public final Set<ServerPlayerConnection> seenBy = Sets.newIdentityHashSet();
|
- public final Set<ServerPlayerConnection> seenBy = Sets.newIdentityHashSet();
|
||||||
+ public final Set<ServerPlayerConnection> seenBy = new ReferenceOpenHashSet<>(); // Paper - optimise map impl
|
+ public final Set<ServerPlayerConnection> seenBy = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>(); // Paper - optimise map impl
|
||||||
|
|
||||||
public TrackedEntity(Entity entity, int i, int j, boolean flag) {
|
public TrackedEntity(Entity entity, int i, int j, boolean flag) {
|
||||||
this.serverEntity = new ServerEntity(ChunkMap.this.level, entity, j, flag, this::broadcast, this.seenBy); // CraftBukkit
|
this.serverEntity = new ServerEntity(ChunkMap.this.level, entity, j, flag, this::broadcast, this.seenBy); // CraftBukkit
|
||||||
|
|
|
@ -8,37 +8,28 @@ diff --git a/src/main/java/net/minecraft/network/ConnectionProtocol.java b/src/m
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/net/minecraft/network/ConnectionProtocol.java
|
--- a/src/main/java/net/minecraft/network/ConnectionProtocol.java
|
||||||
+++ b/src/main/java/net/minecraft/network/ConnectionProtocol.java
|
+++ b/src/main/java/net/minecraft/network/ConnectionProtocol.java
|
||||||
@@ -0,0 +0,0 @@ public enum ConnectionProtocol implements BundlerInfo.Provider {
|
@@ -0,0 +0,0 @@ public enum ConnectionProtocol {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Packet<?> createPacket(int id, FriendlyByteBuf buf) {
|
public Packet<?> createPacket(int id, FriendlyByteBuf buf) {
|
||||||
+ if (id < 0 || id >= this.idToDeserializer.size()) return null; // Paper
|
+ if (id < 0 || id >= this.idToDeserializer.size()) return null; // Paper
|
||||||
Function<FriendlyByteBuf, ? extends Packet<T>> function = this.idToDeserializer.get(id);
|
Function<FriendlyByteBuf, ? extends Packet<? super T>> function = this.idToDeserializer.get(id);
|
||||||
return function != null ? function.apply(buf) : null;
|
return function != null ? function.apply(buf) : null;
|
||||||
}
|
}
|
||||||
diff --git a/src/main/java/net/minecraft/network/Varint21FrameDecoder.java b/src/main/java/net/minecraft/network/Varint21FrameDecoder.java
|
diff --git a/src/main/java/net/minecraft/network/Varint21FrameDecoder.java b/src/main/java/net/minecraft/network/Varint21FrameDecoder.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/net/minecraft/network/Varint21FrameDecoder.java
|
--- a/src/main/java/net/minecraft/network/Varint21FrameDecoder.java
|
||||||
+++ b/src/main/java/net/minecraft/network/Varint21FrameDecoder.java
|
+++ b/src/main/java/net/minecraft/network/Varint21FrameDecoder.java
|
||||||
@@ -0,0 +0,0 @@ import io.netty.handler.codec.CorruptedFrameException;
|
@@ -0,0 +0,0 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder {
|
||||||
import java.util.List;
|
}
|
||||||
|
|
||||||
public class Varint21FrameDecoder extends ByteToMessageDecoder {
|
|
||||||
+ private final byte[] lenBuf = new byte[3]; // Paper
|
|
||||||
+ @Override
|
|
||||||
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) {
|
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) {
|
||||||
+ // Paper start - if channel is not active just discard the packet
|
+ // Paper start - if channel is not active just discard the packet
|
||||||
+ if (!channelHandlerContext.channel().isActive()) {
|
+ if (!channelHandlerContext.channel().isActive()) {
|
||||||
+ byteBuf.skipBytes(byteBuf.readableBytes());
|
+ byteBuf.skipBytes(byteBuf.readableBytes());
|
||||||
+ return;
|
+ return;
|
||||||
+ }
|
+ }
|
||||||
+ // Paper end
|
+ // Paper end - if channel is not active just discard the packet
|
||||||
byteBuf.markReaderIndex();
|
byteBuf.markReaderIndex();
|
||||||
- byte[] bs = new byte[3];
|
this.helperBuf.clear();
|
||||||
+ // Paper start - reuse temporary length buffer
|
if (!copyVarint(byteBuf, this.helperBuf)) {
|
||||||
+ byte[] bs = lenBuf;
|
|
||||||
+ java.util.Arrays.fill(bs, (byte) 0);
|
|
||||||
+ // Paper end
|
|
||||||
|
|
||||||
for(int i = 0; i < bs.length; ++i) {
|
|
||||||
if (!byteBuf.isReadable()) {
|
|
|
@ -20,9 +20,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ if (d0 <= 128.0) {
|
+ if (d0 <= 128.0) {
|
||||||
+ list = world.getEntitiesOfClass(Player.class, axisalignedbb);
|
+ list = world.getEntitiesOfClass(Player.class, axisalignedbb);
|
||||||
+ } else {
|
+ } else {
|
||||||
+ list = (List)world.getNearbyPlayers(null, (double)blockposition.getX() + 0.5, (double)blockposition.getY() + 0.5, (double)blockposition.getZ() + 0.5, -1.0, (net.minecraft.world.entity.Entity entity) -> {
|
+ list = new java.util.ArrayList<>();
|
||||||
+ return !entity.isSpectator() && entity.getBoundingBox().intersects(axisalignedbb);
|
+ for (Player player : world.players()) {
|
||||||
+ });
|
+ if (player.isSpectator()) {
|
||||||
|
+ continue;
|
||||||
|
+ }
|
||||||
|
+ if (player.getBoundingBox().intersects(axisalignedbb)) {
|
||||||
|
+ list.add(player);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+ // Paper end - optimize player lookup for beacons
|
+ // Paper end - optimize player lookup for beacons
|
||||||
|
|
||||||
|
|
|
@ -1800,6 +1800,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ public IntOr.Default other = IntOr.Default.USE_DEFAULT;
|
+ public IntOr.Default other = IntOr.Default.USE_DEFAULT;
|
||||||
+
|
+
|
||||||
+ public int get(Entity entity, int def) {
|
+ public int get(Entity entity, int def) {
|
||||||
|
+ return def; // TODO https://github.com/PaperMC/Paper/issues/9742
|
||||||
|
+ /*
|
||||||
+ switch (TrackingRange.getTrackingRangeType(entity)) {
|
+ switch (TrackingRange.getTrackingRangeType(entity)) {
|
||||||
+ case PLAYER -> {
|
+ case PLAYER -> {
|
||||||
+ return player.or(def);
|
+ return player.or(def);
|
||||||
|
@ -1822,6 +1824,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ return other.or(def);
|
+ return other.or(def);
|
||||||
|
+ */
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
|
|
|
@ -16818,60 +16818,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java
|
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
||||||
--- a/src/main/java/net/minecraft/network/Connection.java
|
|
||||||
+++ b/src/main/java/net/minecraft/network/Connection.java
|
|
||||||
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
|
||||||
@Nullable
|
|
||||||
BandwidthDebugMonitor bandwidthDebugMonitor;
|
|
||||||
public String hostname = ""; // CraftBukkit - add field
|
|
||||||
+ // Paper start - add pending task queue
|
|
||||||
+ private final Queue<Runnable> pendingTasks = new java.util.concurrent.ConcurrentLinkedQueue<>();
|
|
||||||
+ public void execute(final Runnable run) {
|
|
||||||
+ if (this.channel == null || !this.channel.isRegistered()) {
|
|
||||||
+ run.run();
|
|
||||||
+ return;
|
|
||||||
+ }
|
|
||||||
+ final boolean queue = !this.queue.isEmpty();
|
|
||||||
+ if (!queue) {
|
|
||||||
+ this.channel.eventLoop().execute(run);
|
|
||||||
+ } else {
|
|
||||||
+ this.pendingTasks.add(run);
|
|
||||||
+ if (this.queue.isEmpty()) {
|
|
||||||
+ // something flushed async, dump tasks now
|
|
||||||
+ Runnable r;
|
|
||||||
+ while ((r = this.pendingTasks.poll()) != null) {
|
|
||||||
+ this.channel.eventLoop().execute(r);
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ // Paper end - add pending task queue
|
|
||||||
|
|
||||||
public Connection(PacketFlow side) {
|
|
||||||
this.receiving = side;
|
|
||||||
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
|
||||||
}
|
|
||||||
|
|
||||||
private void flushQueue() {
|
|
||||||
+ try { // Paper - add pending task queue
|
|
||||||
if (this.channel != null && this.channel.isOpen()) {
|
|
||||||
Queue queue = this.pendingActions;
|
|
||||||
|
|
||||||
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+ } finally { // Paper start - add pending task queue
|
|
||||||
+ Runnable r;
|
|
||||||
+ while ((r = this.pendingTasks.poll()) != null) {
|
|
||||||
+ this.channel.eventLoop().execute(r);
|
|
||||||
+ }
|
|
||||||
+ } // Paper end - add pending task queue
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tick() {
|
|
||||||
diff --git a/src/main/java/net/minecraft/network/protocol/game/ServerboundCommandSuggestionPacket.java b/src/main/java/net/minecraft/network/protocol/game/ServerboundCommandSuggestionPacket.java
|
diff --git a/src/main/java/net/minecraft/network/protocol/game/ServerboundCommandSuggestionPacket.java b/src/main/java/net/minecraft/network/protocol/game/ServerboundCommandSuggestionPacket.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/net/minecraft/network/protocol/game/ServerboundCommandSuggestionPacket.java
|
--- a/src/main/java/net/minecraft/network/protocol/game/ServerboundCommandSuggestionPacket.java
|
||||||
|
@ -22182,7 +22128,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
private final IntBuffer timestamps;
|
private final IntBuffer timestamps;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected final RegionBitmap usedSectors;
|
protected final RegionBitmap usedSectors;
|
||||||
+ public final java.util.concurrent.locks.ReentrantLock fileLock = new java.util.concurrent.locks.ReentrantLock(true); // Paper
|
+ public final java.util.concurrent.locks.ReentrantLock fileLock = new java.util.concurrent.locks.ReentrantLock(); // Paper
|
||||||
|
|
||||||
public RegionFile(Path file, Path directory, boolean dsync) throws IOException {
|
public RegionFile(Path file, Path directory, boolean dsync) throws IOException {
|
||||||
this(file, directory, RegionFileVersion.VERSION_DEFLATE, dsync);
|
this(file, directory, RegionFileVersion.VERSION_DEFLATE, dsync);
|
||||||
|
|
|
@ -9,7 +9,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||||
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||||
@@ -0,0 +0,0 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
|
@@ -0,0 +0,0 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
|
||||||
private GameProfile authenticatedProfile;
|
public GameProfile authenticatedProfile; // Paper - public
|
||||||
private final String serverId;
|
private final String serverId;
|
||||||
private ServerPlayer player; // CraftBukkit
|
private ServerPlayer player; // CraftBukkit
|
||||||
+ public boolean iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation = false; // Paper - username validation overriding
|
+ public boolean iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation = false; // Paper - username validation overriding
|
||||||
|
|
|
@ -1,101 +0,0 @@
|
||||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
|
||||||
Date: Fri, 30 Oct 2020 22:37:16 -0700
|
|
||||||
Subject: [PATCH] Add packet limiter config
|
|
||||||
|
|
||||||
Example config:
|
|
||||||
packet-limiter:
|
|
||||||
kick-message: '&cSent too many packets'
|
|
||||||
limits:
|
|
||||||
all:
|
|
||||||
interval: 7.0
|
|
||||||
max-packet-rate: 500.0
|
|
||||||
ServerboundPlaceRecipePacket:
|
|
||||||
interval: 4.0
|
|
||||||
max-packet-rate: 5.0
|
|
||||||
action: DROP
|
|
||||||
|
|
||||||
all section refers to all incoming packets, the action for all is
|
|
||||||
hard coded to KICK.
|
|
||||||
|
|
||||||
For specific limits, the section name is the class's name,
|
|
||||||
and an action can be defined: DROP or KICK
|
|
||||||
|
|
||||||
If interval or rate are less-than 0, the limit is ignored
|
|
||||||
|
|
||||||
diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java
|
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
||||||
--- a/src/main/java/net/minecraft/network/Connection.java
|
|
||||||
+++ b/src/main/java/net/minecraft/network/Connection.java
|
|
||||||
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Paper end - allow controlled flushing
|
|
||||||
+ // Paper start - packet limiter
|
|
||||||
+ protected final Object PACKET_LIMIT_LOCK = new Object();
|
|
||||||
+ protected final @Nullable io.papermc.paper.util.IntervalledCounter allPacketCounts = io.papermc.paper.configuration.GlobalConfiguration.get().packetLimiter.allPackets.isEnabled() ? new io.papermc.paper.util.IntervalledCounter(
|
|
||||||
+ (long)(io.papermc.paper.configuration.GlobalConfiguration.get().packetLimiter.allPackets.interval() * 1.0e9)
|
|
||||||
+ ) : null;
|
|
||||||
+ protected final java.util.Map<Class<? extends net.minecraft.network.protocol.Packet<?>>, io.papermc.paper.util.IntervalledCounter> packetSpecificLimits = new java.util.HashMap<>();
|
|
||||||
+
|
|
||||||
+ private boolean stopReadingPackets;
|
|
||||||
+ private void killForPacketSpam() {
|
|
||||||
+ this.sendPacket(new ClientboundDisconnectPacket(io.papermc.paper.adventure.PaperAdventure.asVanilla(io.papermc.paper.configuration.GlobalConfiguration.get().packetLimiter.kickMessage)), PacketSendListener.thenRun(() -> {
|
|
||||||
+ this.disconnect(io.papermc.paper.adventure.PaperAdventure.asVanilla(io.papermc.paper.configuration.GlobalConfiguration.get().packetLimiter.kickMessage));
|
|
||||||
+ }));
|
|
||||||
+ this.setReadOnly();
|
|
||||||
+ this.stopReadingPackets = true;
|
|
||||||
+ }
|
|
||||||
+ // Paper end - packet limiter
|
|
||||||
|
|
||||||
public Connection(PacketFlow side) {
|
|
||||||
this.receiving = side;
|
|
||||||
@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
|
||||||
|
|
||||||
protected void channelRead0(ChannelHandlerContext channelhandlercontext, Packet<?> packet) {
|
|
||||||
if (this.channel.isOpen()) {
|
|
||||||
+ // Paper start - packet limiter
|
|
||||||
+ if (this.stopReadingPackets) {
|
|
||||||
+ return;
|
|
||||||
+ }
|
|
||||||
+ if (this.allPacketCounts != null ||
|
|
||||||
+ io.papermc.paper.configuration.GlobalConfiguration.get().packetLimiter.overrides.containsKey(packet.getClass())) {
|
|
||||||
+ long time = System.nanoTime();
|
|
||||||
+ synchronized (PACKET_LIMIT_LOCK) {
|
|
||||||
+ if (this.allPacketCounts != null) {
|
|
||||||
+ this.allPacketCounts.updateAndAdd(1, time);
|
|
||||||
+ if (this.allPacketCounts.getRate() >= io.papermc.paper.configuration.GlobalConfiguration.get().packetLimiter.allPackets.maxPacketRate()) {
|
|
||||||
+ this.killForPacketSpam();
|
|
||||||
+ return;
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ for (Class<?> check = packet.getClass(); check != Object.class; check = check.getSuperclass()) {
|
|
||||||
+ io.papermc.paper.configuration.GlobalConfiguration.PacketLimiter.PacketLimit packetSpecificLimit =
|
|
||||||
+ io.papermc.paper.configuration.GlobalConfiguration.get().packetLimiter.overrides.get(check);
|
|
||||||
+ if (packetSpecificLimit == null || !packetSpecificLimit.isEnabled()) {
|
|
||||||
+ continue;
|
|
||||||
+ }
|
|
||||||
+ io.papermc.paper.util.IntervalledCounter counter = this.packetSpecificLimits.computeIfAbsent((Class)check, (clazz) -> {
|
|
||||||
+ return new io.papermc.paper.util.IntervalledCounter((long)(packetSpecificLimit.interval() * 1.0e9));
|
|
||||||
+ });
|
|
||||||
+ counter.updateAndAdd(1, time);
|
|
||||||
+ if (counter.getRate() >= packetSpecificLimit.maxPacketRate()) {
|
|
||||||
+ switch (packetSpecificLimit.action()) {
|
|
||||||
+ case DROP:
|
|
||||||
+ return;
|
|
||||||
+ case KICK:
|
|
||||||
+ String deobfedPacketName = io.papermc.paper.util.ObfHelper.INSTANCE.deobfClassName(check.getName());
|
|
||||||
+ String playerName = this.getPlayer() == null ? "Player (null)" : this.getPlayer().getName().getString();
|
|
||||||
+ Connection.LOGGER.warn("{} kicked for packet spamming: {}", playerName, deobfedPacketName.substring(deobfedPacketName.lastIndexOf(".") + 1));
|
|
||||||
+ this.killForPacketSpam();
|
|
||||||
+ return;
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ // Paper end - packet limiter
|
|
||||||
try {
|
|
||||||
Connection.genericsFtw(packet, this.packetListener);
|
|
||||||
} catch (RunningOnDifferentThreadException cancelledpackethandleexception) {
|
|
Loading…
Add table
Reference in a new issue