Scissors/patches/server/0029-Block-server-side-chunkbans.patch

194 lines
9.7 KiB
Diff
Raw Normal View History

2022-07-28 03:57:50 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ayunami2000 <spwilliamsiam@gmail.com>
Date: Fri, 17 Jun 2022 15:28:43 -0500
Subject: [PATCH] Block server side chunkbans
diff --git a/src/main/java/net/minecraft/network/PacketEncoder.java b/src/main/java/net/minecraft/network/PacketEncoder.java
2022-12-11 06:16:06 +00:00
index 5fce1177e7198d791d4ab1c64b394c5b1c145782..25d483a4792cf159ff691521cd32382d0f7fe931 100644
2022-07-28 03:57:50 +00:00
--- a/src/main/java/net/minecraft/network/PacketEncoder.java
+++ b/src/main/java/net/minecraft/network/PacketEncoder.java
@@ -6,9 +6,18 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import io.papermc.paper.adventure.PaperAdventure; // Paper
import java.io.IOException;
+import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketFlow;
+import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
+import net.minecraft.network.protocol.game.ClientboundContainerSetContentPacket;
+import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
+import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData;
+import net.minecraft.network.protocol.game.ClientboundMapItemDataPacket;
+import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
+import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
import net.minecraft.util.profiling.jfr.JvmProfiler;
+import net.minecraft.world.item.ItemStack;
import org.slf4j.Logger;
public class PacketEncoder extends MessageToByteEncoder<Packet<?>> {
@@ -41,30 +50,101 @@ public class PacketEncoder extends MessageToByteEncoder<Packet<?>> {
packet.write(friendlyByteBuf);
int j = friendlyByteBuf.writerIndex() - i;
if (j > 8388608) {
- throw new IllegalArgumentException("Packet too big (is " + j + ", should be less than 8388608): " + packet);
+ // Scissors start
+ noKicking(friendlyByteBuf, packet, integer, channelHandlerContext);
+ // Scissors end
} else {
int k = channelHandlerContext.channel().attr(Connection.ATTRIBUTE_PROTOCOL).get().getId();
JvmProfiler.INSTANCE.onPacketSent(k, integer, channelHandlerContext.channel().remoteAddress(), j);
}
} catch (Throwable var10) {
- LOGGER.error("Packet encoding of packet ID {} threw (skippable? {})", integer, packet.isSkippable(), var10); // Paper - Give proper error message
- if (packet.isSkippable()) {
- throw new SkipPacketException(var10);
- } else {
- throw var10;
- }
+ noKicking(friendlyByteBuf, packet, integer, channelHandlerContext);
}
// Paper start
int packetLength = friendlyByteBuf.readableBytes();
if (packetLength > MAX_PACKET_SIZE) {
- throw new PacketTooLargeException(packet, packetLength);
+ // Scissors start
+ friendlyByteBuf.clear();
+ noKicking(friendlyByteBuf, packet, integer, channelHandlerContext);
+ packetLength = friendlyByteBuf.readableBytes();
+ if (packetLength > MAX_PACKET_SIZE) {
+ friendlyByteBuf.clear();
+ }
+ // Scissors end
}
// Paper end
}
}
}
+ // Scissors start
+ private static void noKicking(FriendlyByteBuf friendlyByteBuf, Packet packet, Integer integer, ChannelHandlerContext channelHandlerContext)
+ {
+ friendlyByteBuf.clear();
+ friendlyByteBuf.writeVarInt(integer);
+ friendlyByteBuf.adventure$locale = channelHandlerContext.channel().attr(PaperAdventure.LOCALE_ATTRIBUTE).get(); // Paper
+ boolean didIt = true;
+ if (packet instanceof ClientboundBlockEntityDataPacket blockEntityDataPacket)
+ {
+ packet = new ClientboundBlockEntityDataPacket(blockEntityDataPacket.getPos(), blockEntityDataPacket.getType(), new CompoundTag());
+ }
+ else if (packet instanceof ClientboundLevelChunkPacketData chunkPacket)
+ {
+ chunkPacket.clearNBT();
+ }
+ else if (packet instanceof ClientboundSetEntityDataPacket entityDataPacket)
+ {
2022-12-11 06:16:06 +00:00
+ friendlyByteBuf.writeVarInt(entityDataPacket.id());
2022-07-28 03:57:50 +00:00
+ friendlyByteBuf.writeByte(255);
+ didIt = false;//prevent default packet writing
+ }
+ else if (packet instanceof ClientboundContainerSetContentPacket containerSetContentPacket)
+ {
+ containerSetContentPacket.clearNBT();
+ }
+ else if (packet instanceof ClientboundSetEquipmentPacket setEquipmentPacket)
+ {
+ friendlyByteBuf.writeVarInt(setEquipmentPacket.getEntity());
+ didIt = false; //prevent default
+ }
+ else if (packet instanceof ClientboundContainerSetSlotPacket containerSetSlotPacket)
+ {
+ friendlyByteBuf.writeByte(containerSetSlotPacket.getContainerId());
+ friendlyByteBuf.writeVarInt(containerSetSlotPacket.getStateId());
+ friendlyByteBuf.writeShort(containerSetSlotPacket.getSlot());
+ friendlyByteBuf.writeItem(ItemStack.EMPTY);
+ didIt = false; //prevent default
+ }
+ else if (packet instanceof ClientboundMapItemDataPacket mapItemDataPacket)
+ {
+ packet = new ClientboundMapItemDataPacket(mapItemDataPacket.getMapId(), mapItemDataPacket.getScale(), mapItemDataPacket.isLocked(), null, null);
+ }
+ else
+ {
+ didIt = false;
+ LOGGER.info(packet.getClass().getName() + " overflowed/errored and was not caught!!");
+ }
+ if (didIt)
+ {
+ try
+ {
+ int i = friendlyByteBuf.writerIndex();
+ packet.write(friendlyByteBuf);
+ int j = friendlyByteBuf.writerIndex() - i;
+ if (j > 8388608)
+ {
+ friendlyByteBuf.clear();
+ }
+ }
+ catch (Throwable var69)
+ {
+ friendlyByteBuf.clear();
+ }
+ }
+ }
+ // Scissors end
+
// Paper start
private static int MAX_PACKET_SIZE = 2097152;
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundBlockEntityDataPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundBlockEntityDataPacket.java
2022-12-11 06:04:11 +00:00
index 3944852921335c78a04a9dc301882ab5b152b1ed..0d88828bc0bbd68328da4d0e7d3b880006d2c775 100644
2022-07-28 03:57:50 +00:00
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundBlockEntityDataPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundBlockEntityDataPacket.java
@@ -24,7 +24,8 @@ public class ClientboundBlockEntityDataPacket implements Packet<ClientGamePacket
return create(blockEntity, BlockEntity::getUpdateTag);
}
- private ClientboundBlockEntityDataPacket(BlockPos pos, BlockEntityType<?> blockEntityType, CompoundTag nbt) {
+ // Scissors - make this public
+ public ClientboundBlockEntityDataPacket(BlockPos pos, BlockEntityType<?> blockEntityType, CompoundTag nbt) {
this.pos = pos;
this.type = blockEntityType;
this.tag = nbt.isEmpty() ? null : nbt;
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
index dbd8b9b09b82c1b75e8be9dc7416d9f0863c8c87..24e0f4ee1dc9b5a46ed063e087d4b7bcd2a7fe46 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundContainerSetContentPacket.java
@@ -10,7 +10,15 @@ public class ClientboundContainerSetContentPacket implements Packet<ClientGamePa
private final int containerId;
private final int stateId;
private final List<ItemStack> items;
- private final ItemStack carriedItem;
+ private ItemStack carriedItem; // Scissors - removed "final"
+
+ // Scissors start
+ public void clearNBT()
+ {
+ this.items.clear();
+ this.carriedItem = ItemStack.EMPTY;
+ }
+ // Scissors end
public ClientboundContainerSetContentPacket(int syncId, int revision, NonNullList<ItemStack> contents, ItemStack cursorStack) {
this.containerId = syncId;
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
2022-12-11 06:04:11 +00:00
index f3fa2678796c33f3a408a02a1995ad117eac9169..c8dd976240aa4f640bb2d223d472f81fdd8dcf7c 100644
2022-07-28 03:57:50 +00:00
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
@@ -33,6 +33,14 @@ public class ClientboundLevelChunkPacketData {
}
// Paper end
+ // Scissors start
+ public void clearNBT()
+ {
+ this.blockEntitiesData.clear();
+ this.extraPackets.clear();
+ }
+ // Scissors end
+
// Paper start - Anti-Xray - Add chunk packet info
@Deprecated @io.papermc.paper.annotation.DoNotUse public ClientboundLevelChunkPacketData(LevelChunk chunk) { this(chunk, null); }
public ClientboundLevelChunkPacketData(LevelChunk chunk, com.destroystokyo.paper.antixray.ChunkPacketInfo<net.minecraft.world.level.block.state.BlockState> chunkPacketInfo) {