Scissors/patches/server/0030-Prevent-invalid-container-events.patch

47 lines
2.5 KiB
Diff
Raw Normal View History

2022-07-28 03:57:50 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Allink <arclicious@vivaldi.net>
Date: Sun, 10 Jul 2022 02:55:01 +0100
Subject: [PATCH] Prevent invalid container events
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2023-06-19 00:13:08 +00:00
index 77bf4cebd9cb92d6dfd03b6734b50d4457243bc9..f6f5efbf757f1508b628db90c9f63da382ebf4d5 100644
2022-07-28 03:57:50 +00:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2023-03-16 03:57:35 +00:00
@@ -30,6 +30,8 @@ import java.util.function.UnaryOperator;
2022-07-28 03:57:50 +00:00
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
+
+import net.kyori.adventure.text.format.NamedTextColor;
import net.minecraft.ChatFormatting;
import net.minecraft.CrashReport;
import net.minecraft.CrashReportCategory;
2023-06-19 00:13:08 +00:00
@@ -2989,6 +2991,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2022-07-28 03:57:50 +00:00
public void handleContainerClick(ServerboundContainerClickPacket packet) {
2023-06-09 00:58:46 +00:00
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
2022-07-28 03:57:50 +00:00
if (this.player.isImmobile()) return; // CraftBukkit
+
this.player.resetLastActionTime();
if (this.player.containerMenu.containerId == packet.getContainerId() && this.player.containerMenu.stillValid(this.player)) { // CraftBukkit
boolean cancelled = this.player.isSpectator(); // CraftBukkit - see below if
2023-06-19 00:13:08 +00:00
@@ -3010,6 +3013,18 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2022-07-28 03:57:50 +00:00
return;
}
+ // Scissors start - Do not call events when the slot/button number is invalid
+ final int sentSlotNum = packet.getSlotNum();
+ if((Mth.clamp(sentSlotNum, -1, this.player.containerMenu.slots.size() - 1) != sentSlotNum) && sentSlotNum != -999)
+ {
+ this.getCraftPlayer().kick(
+ net.kyori.adventure.text.Component.text("Invalid container click slot (Hacking?)")
+ .color(NamedTextColor.RED)
+ );
+ return;
+ }
+ // Scissors end
+
InventoryView inventory = this.player.containerMenu.getBukkitView();
SlotType type = inventory.getSlotType(packet.getSlotNum());