From 6c500dfa70ebba1a0fdcda12deabb4ca5b175d12 Mon Sep 17 00:00:00 2001
From: Cai <13110818005@qq.com>
Date: Sun, 15 Jun 2025 23:41:25 +0800
Subject: [PATCH] fix(Bouncer): players bypass region protection and build
permissions when using Quick Stack
---
TShockAPI/Bouncer.cs | 43 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 41 insertions(+), 2 deletions(-)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 488abe61..238c0992 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -19,7 +19,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Terraria.ID;
-using TShockAPI.Net;
using Terraria;
using Microsoft.Xna.Framework;
using TShockAPI.Localization;
@@ -29,6 +28,7 @@ using Terraria.DataStructures;
using Terraria.Localization;
using TShockAPI.Models.PlayerUpdate;
using System.Threading.Tasks;
+using OTAPI;
using Terraria.GameContent.Tile_Entities;
namespace TShockAPI
@@ -137,6 +137,7 @@ namespace TShockAPI
GetDataHandlers.KillMe += OnKillMe;
GetDataHandlers.FishOutNPC += OnFishOutNPC;
GetDataHandlers.FoodPlatterTryPlacing += OnFoodPlatterTryPlacing;
+ OTAPI.Hooks.Chest.QuickStack += OnChestOnQuickStack;
// The following section is based off Player.PlaceThing_Tiles_PlaceIt and Player.PlaceThing_Tiles_PlaceIt_GetLegacyTileStyle.
@@ -2505,7 +2506,7 @@ namespace TShockAPI
Main.item[num].playerIndexTheItemIsReservedFor = args.Player.Index;
NetMessage.SendData((int)PacketTypes.ItemDrop, args.Player.Index, -1, NetworkText.Empty, num, 1f);
NetMessage.SendData((int)PacketTypes.ItemOwner, args.Player.Index, -1, NetworkText.Empty, num);
-
+
TShock.Log.ConsoleDebug(GetString("Bouncer / OnPlaceItemFrame rejected permissions from {0}", args.Player.Name));
NetMessage.SendData((int)PacketTypes.UpdateTileEntity, -1, -1, NetworkText.Empty, args.ItemFrame.ID, 0, 1);
args.Handled = true;
@@ -2871,6 +2872,44 @@ namespace TShockAPI
}
}
+ ///
+ /// Called when a player is trying to put an item into chest through Quick Stack.
+ ///
+ ///
+ ///
+ internal void OnChestOnQuickStack(object sender, OTAPI.Hooks.Chest.QuickStackEventArgs args)
+ {
+ var id = args.ChestIndex;
+ var plr = TShock.Players[args.PlayerId];
+
+ if (plr is not { Active: true })
+ {
+ args.Result = HookResult.Cancel;
+ return;
+ }
+
+ if (plr.IsBeingDisabled())
+ {
+ TShock.Log.ConsoleDebug(GetString("Bouncer / OnQuickStack rejected from disable from {0}", plr.Name));
+ args.Result = HookResult.Cancel;
+ return;
+ }
+
+ if (!plr.HasBuildPermission(Main.chest[id].x, Main.chest[id].y) && TShock.Config.Settings.RegionProtectChests)
+ {
+ TShock.Log.ConsoleDebug(GetString("Bouncer / OnQuickStack rejected from region protection? from {0}", plr.Name));
+ args.Result = HookResult.Cancel;
+ return;
+ }
+
+ if (!plr.IsInRange(Main.chest[id].x, Main.chest[id].y, 600/16))
+ {
+ TShock.Log.ConsoleDebug(GetString("Bouncer / OnQuickStack rejected from range check from {0}", plr.Name));
+ args.Result = HookResult.Cancel;
+ return;
+ }
+ }
+
internal void OnSecondUpdate()
{
Task.Run(() =>