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
|
2023-04-08 19:10:07 +00:00
|
|
|
index ebee957fb048da6ffcd2a5ba2ed989ed1a6634e9..889342fac2903f16846e9303631a64df6fcfc589 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
|
2023-04-08 19:10:07 +00:00
|
|
|
@@ -6,9 +6,26 @@ import io.netty.channel.ChannelHandlerContext;
|
2022-07-28 03:57:50 +00:00
|
|
|
import io.netty.handler.codec.MessageToByteEncoder;
|
|
|
|
import io.papermc.paper.adventure.PaperAdventure; // Paper
|
|
|
|
import java.io.IOException;
|
2023-04-08 19:10:07 +00:00
|
|
|
+import java.util.Collections;
|
|
|
|
+import net.minecraft.ChatFormatting;
|
|
|
|
+import net.minecraft.core.NonNullList;
|
2022-07-28 03:57:50 +00:00
|
|
|
+import net.minecraft.nbt.CompoundTag;
|
2023-04-08 19:10:07 +00:00
|
|
|
+import net.minecraft.network.chat.Component;
|
|
|
|
+import net.minecraft.network.chat.SignedMessageBody;
|
2022-07-28 03:57:50 +00:00
|
|
|
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;
|
2023-04-08 19:10:07 +00:00
|
|
|
+import net.minecraft.network.protocol.game.ClientboundDisguisedChatPacket;
|
2022-07-28 03:57:50 +00:00
|
|
|
+import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData;
|
|
|
|
+import net.minecraft.network.protocol.game.ClientboundMapItemDataPacket;
|
2023-04-08 19:10:07 +00:00
|
|
|
+import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket;
|
2022-07-28 03:57:50 +00:00
|
|
|
+import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
|
|
|
|
+import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
2023-04-08 19:10:07 +00:00
|
|
|
+import net.minecraft.network.protocol.game.ClientboundSystemChatPacket;
|
2022-07-28 03:57:50 +00:00
|
|
|
import net.minecraft.util.profiling.jfr.JvmProfiler;
|
|
|
|
+import net.minecraft.world.item.ItemStack;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
|
|
public class PacketEncoder extends MessageToByteEncoder<Packet<?>> {
|
2023-04-08 19:10:07 +00:00
|
|
|
@@ -19,6 +36,23 @@ public class PacketEncoder extends MessageToByteEncoder<Packet<?>> {
|
|
|
|
this.flow = side;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Scissors start
|
|
|
|
+ private static int tryWrite(Packet packet, FriendlyByteBuf friendlyByteBuf, ChannelHandlerContext channelHandlerContext, int i) {
|
|
|
|
+ friendlyByteBuf.writeVarInt(i);
|
|
|
|
+ friendlyByteBuf.adventure$locale = channelHandlerContext.channel().attr(PaperAdventure.LOCALE_ATTRIBUTE).get();
|
|
|
|
+
|
|
|
|
+ int j = friendlyByteBuf.writerIndex();
|
|
|
|
+ packet.write(friendlyByteBuf);
|
|
|
|
+ int k = friendlyByteBuf.writerIndex() - j;
|
|
|
|
+ int packetLength = friendlyByteBuf.readableBytes();
|
|
|
|
+ if (k > 8388608 || packetLength > MAX_PACKET_SIZE) {
|
|
|
|
+ throw new SkipPacketException(new IllegalArgumentException("Packet too big (is " + k + "): " + packet));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return k;
|
|
|
|
+ }
|
|
|
|
+ // Scissors end
|
|
|
|
+
|
|
|
|
protected void encode(ChannelHandlerContext channelHandlerContext, Packet<?> packet, ByteBuf byteBuf) throws Exception {
|
|
|
|
ConnectionProtocol connectionProtocol = channelHandlerContext.channel().attr(Connection.ATTRIBUTE_PROTOCOL).get();
|
|
|
|
if (connectionProtocol == null) {
|
|
|
|
@@ -33,38 +67,87 @@ public class PacketEncoder extends MessageToByteEncoder<Packet<?>> {
|
|
|
|
throw new IOException("Can't serialize unregistered packet");
|
|
|
|
} else {
|
|
|
|
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(byteBuf);
|
|
|
|
- friendlyByteBuf.writeVarInt(i);
|
|
|
|
- friendlyByteBuf.adventure$locale = channelHandlerContext.channel().attr(PaperAdventure.LOCALE_ATTRIBUTE).get(); // Paper
|
|
|
|
-
|
|
|
|
+ // Scissors start
|
|
|
|
+ int k;
|
|
|
|
try {
|
|
|
|
- int j = friendlyByteBuf.writerIndex();
|
|
|
|
- packet.write(friendlyByteBuf);
|
|
|
|
- int k = friendlyByteBuf.writerIndex() - j;
|
|
|
|
- if (k > 8388608) {
|
2023-03-16 03:57:35 +00:00
|
|
|
- throw new IllegalArgumentException("Packet too big (is " + k + ", should be less than 8388608): " + packet);
|
2023-04-08 19:10:07 +00:00
|
|
|
- } else {
|
|
|
|
- int l = channelHandlerContext.channel().attr(Connection.ATTRIBUTE_PROTOCOL).get().getId();
|
|
|
|
- JvmProfiler.INSTANCE.onPacketSent(l, i, channelHandlerContext.channel().remoteAddress(), k);
|
|
|
|
- }
|
|
|
|
+ k = tryWrite(packet, friendlyByteBuf, channelHandlerContext, i);
|
2022-07-28 03:57:50 +00:00
|
|
|
} catch (Throwable var10) {
|
2023-03-16 03:57:35 +00:00
|
|
|
- LOGGER.error("Packet encoding of packet ID {} threw (skippable? {})", i, packet.isSkippable(), var10); // Paper - Give proper error message
|
2022-07-28 03:57:50 +00:00
|
|
|
- if (packet.isSkippable()) {
|
|
|
|
- throw new SkipPacketException(var10);
|
|
|
|
- } else {
|
|
|
|
- throw var10;
|
2023-04-08 19:10:07 +00:00
|
|
|
+ packet = capPacket(packet, i);
|
|
|
|
+ if (packet == null) {
|
|
|
|
+ throw new SkipPacketException(new IllegalArgumentException("Packet too big: " + packet));
|
|
|
|
}
|
|
|
|
+ friendlyByteBuf.clear();
|
|
|
|
+ k = tryWrite(packet, friendlyByteBuf, channelHandlerContext, i);
|
2022-07-28 03:57:50 +00:00
|
|
|
}
|
|
|
|
|
2023-04-08 19:10:07 +00:00
|
|
|
- // Paper start
|
|
|
|
- int packetLength = friendlyByteBuf.readableBytes();
|
|
|
|
- if (packetLength > MAX_PACKET_SIZE) {
|
2022-07-28 03:57:50 +00:00
|
|
|
- throw new PacketTooLargeException(packet, packetLength);
|
2023-04-08 19:10:07 +00:00
|
|
|
- }
|
|
|
|
- // Paper end
|
|
|
|
+ int l = channelHandlerContext.channel().attr(Connection.ATTRIBUTE_PROTOCOL).get().getId();
|
|
|
|
+ JvmProfiler.INSTANCE.onPacketSent(l, i, channelHandlerContext.channel().remoteAddress(), k);
|
|
|
|
+ // Scissors end
|
2022-07-28 03:57:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Scissors start
|
2023-04-08 19:10:07 +00:00
|
|
|
+ private static Packet capPacket(Packet packet, int i)
|
2022-07-28 03:57:50 +00:00
|
|
|
+ {
|
|
|
|
+ if (packet instanceof ClientboundBlockEntityDataPacket blockEntityDataPacket)
|
|
|
|
+ {
|
|
|
|
+ packet = new ClientboundBlockEntityDataPacket(blockEntityDataPacket.getPos(), blockEntityDataPacket.getType(), new CompoundTag());
|
|
|
|
+ }
|
|
|
|
+ else if (packet instanceof ClientboundLevelChunkPacketData chunkPacket)
|
|
|
|
+ {
|
|
|
|
+ chunkPacket.clearNBT();
|
|
|
|
+ }
|
2023-04-08 19:10:07 +00:00
|
|
|
+ else if (packet instanceof ClientboundSetEntityDataPacket)
|
2022-07-28 03:57:50 +00:00
|
|
|
+ {
|
2023-04-08 19:10:07 +00:00
|
|
|
+ return null; // Skip
|
2022-07-28 03:57:50 +00:00
|
|
|
+ }
|
|
|
|
+ else if (packet instanceof ClientboundContainerSetContentPacket containerSetContentPacket)
|
|
|
|
+ {
|
2023-04-08 19:10:07 +00:00
|
|
|
+ packet = new ClientboundContainerSetContentPacket(containerSetContentPacket.getContainerId(), containerSetContentPacket.getStateId(), NonNullList.create(), ItemStack.EMPTY);
|
2022-07-28 03:57:50 +00:00
|
|
|
+ }
|
|
|
|
+ else if (packet instanceof ClientboundSetEquipmentPacket setEquipmentPacket)
|
|
|
|
+ {
|
2023-04-08 19:10:07 +00:00
|
|
|
+ packet = new ClientboundSetEquipmentPacket(setEquipmentPacket.getEntity(), Collections.emptyList());
|
2022-07-28 03:57:50 +00:00
|
|
|
+ }
|
|
|
|
+ else if (packet instanceof ClientboundContainerSetSlotPacket containerSetSlotPacket)
|
|
|
|
+ {
|
2023-04-08 19:10:07 +00:00
|
|
|
+ packet = new ClientboundContainerSetSlotPacket(containerSetSlotPacket.getContainerId(), containerSetSlotPacket.getStateId(), containerSetSlotPacket.getSlot(), ItemStack.EMPTY);
|
2022-07-28 03:57:50 +00:00
|
|
|
+ }
|
|
|
|
+ else if (packet instanceof ClientboundMapItemDataPacket mapItemDataPacket)
|
|
|
|
+ {
|
|
|
|
+ packet = new ClientboundMapItemDataPacket(mapItemDataPacket.getMapId(), mapItemDataPacket.getScale(), mapItemDataPacket.isLocked(), null, null);
|
|
|
|
+ }
|
2023-04-08 19:10:07 +00:00
|
|
|
+ else if (packet instanceof ClientboundSystemChatPacket)
|
2022-07-28 03:57:50 +00:00
|
|
|
+ {
|
2023-04-08 19:10:07 +00:00
|
|
|
+ return null;
|
2022-07-28 03:57:50 +00:00
|
|
|
+ }
|
2023-04-08 19:10:07 +00:00
|
|
|
+ else if (packet instanceof ClientboundDisguisedChatPacket)
|
2022-07-28 03:57:50 +00:00
|
|
|
+ {
|
2023-04-08 19:10:07 +00:00
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ else if (packet instanceof ClientboundPlayerChatPacket playerChatPacket)
|
|
|
|
+ {
|
|
|
|
+ final SignedMessageBody.Packed body = playerChatPacket.body();
|
|
|
|
+ packet = new ClientboundPlayerChatPacket(playerChatPacket.sender(), // Not sending this packet results in a kick when someone says something.
|
|
|
|
+ playerChatPacket.index(),
|
|
|
|
+ playerChatPacket.signature(),
|
|
|
|
+ playerChatPacket.body(),
|
|
|
|
+ Component.empty().append("** Message too large **").withStyle(ChatFormatting.RED),
|
|
|
|
+ playerChatPacket.filterMask(),
|
|
|
|
+ playerChatPacket.chatType()
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ LOGGER.error("Packet with ID {} was too large and was not caught. Please report this to the Scissors developers.", i);
|
|
|
|
+ return null;
|
2022-07-28 03:57:50 +00:00
|
|
|
+ }
|
2023-04-08 19:10:07 +00:00
|
|
|
+
|
|
|
|
+ return packet;
|
2022-07-28 03:57:50 +00:00
|
|
|
+ }
|
|
|
|
+ // 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
|
2023-04-08 19:10:07 +00:00
|
|
|
index 3944852921335c78a04a9dc301882ab5b152b1ed..96ee53c7cc862e059328c5cdf5e07f309df6a79e 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
|
2023-04-08 19:10:07 +00:00
|
|
|
@@ -24,7 +24,7 @@ public class ClientboundBlockEntityDataPacket implements Packet<ClientGamePacket
|
2022-07-28 03:57:50 +00:00
|
|
|
return create(blockEntity, BlockEntity::getUpdateTag);
|
|
|
|
}
|
|
|
|
|
|
|
|
- private ClientboundBlockEntityDataPacket(BlockPos pos, BlockEntityType<?> blockEntityType, CompoundTag nbt) {
|
2023-04-08 19:10:07 +00:00
|
|
|
+ public ClientboundBlockEntityDataPacket(BlockPos pos, BlockEntityType<?> blockEntityType, CompoundTag nbt) { // Scissors - private -> public
|
2022-07-28 03:57:50 +00:00
|
|
|
this.pos = pos;
|
|
|
|
this.type = blockEntityType;
|
|
|
|
this.tag = nbt.isEmpty() ? null : nbt;
|
|
|
|
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) {
|