Improve invalid container event patch (#36)

This commit is contained in:
Allink 2022-07-10 07:07:55 +01:00 committed by GitHub
parent c2b2427622
commit 3b8ad1a45d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,7 @@ 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
index ca595abe940463a62da033c7082c868c4c4b28d8..6f43eec3490dd44d0f680977710f1d65dc6fc3b2 100644
index ca595abe940463a62da033c7082c868c4c4b28d8..d6aa46443b0ec9b02259222d8ee9a7ff0cec4ae7 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -24,6 +24,8 @@ import java.util.function.UnaryOperator;
@ -17,12 +17,14 @@ index ca595abe940463a62da033c7082c868c4c4b28d8..6f43eec3490dd44d0f680977710f1d65
import net.minecraft.ChatFormatting;
import net.minecraft.CrashReport;
import net.minecraft.CrashReportCategory;
@@ -2782,6 +2784,17 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
}
if (packet.getClickType() != net.minecraft.world.inventory.ClickType.QUICK_CRAFT) {
@@ -2593,6 +2595,19 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
public void handleContainerClick(ServerboundContainerClickPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
if (this.player.isImmobile()) return; // CraftBukkit
+
+ // Scissors start - Do not call events when the slot/button number is invalid
+ if(packet.getSlotNum() > 45)
+ final int sentSlotNum = packet.getSlotNum();
+ if(Mth.clamp(sentSlotNum, 0, 45) != sentSlotNum)
+ {
+ this.getCraftPlayer().kick(
+ net.kyori.adventure.text.Component.text("Invalid container click slot (Hacking?)")
@ -32,6 +34,6 @@ index ca595abe940463a62da033c7082c868c4c4b28d8..6f43eec3490dd44d0f680977710f1d65
+ }
+ // Scissors end
+
if (click == ClickType.NUMBER_KEY) {
event = new InventoryClickEvent(inventory, type, packet.getSlotNum(), click, action, packet.getButtonNum());
} else {
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