From 199390015913adb1d468f95495d1800d0bc65609 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 16 May 2020 21:47:59 -0700 Subject: [PATCH] Move OnTileEdit ban checks: Bouncer -> Itembans This change moves the ban checks used to determine, during TileEdit events, if an item is banned, out of Bouncer and into the newly isolated ItemBan subsystem. Rather than creating a large pull request for all of these, I'm just going to create a series of commits and send them in one at a time. This should result in about one PR per hook that uses item bans that needs to move. --- CHANGELOG.md | 1 + TShockAPI/Bouncer.cs | 10 +--------- TShockAPI/ItemBans.cs | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a25311e..56ddb6a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -99,6 +99,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fix banned armour checks not clearing properly (thanks @tysonstrange) * Added warning message on invalid group comand (@hakusaro, thanks to IcyPhoenix, nuLLzy & Cy on Discord) * Moved item bans subsystem to isolated file/contained mini-plugin & reorganized codebase accordingly. (@hakusaro) +* Moved bouncer checks for item bans in OnTileEdit to item bans subsystem. (@hakusaro) ## TShock 4.3.25 * Fixed a critical exploit in the Terraria protocol that could cause massive unpreventable world corruption as well as a number of other problems. Thanks to @bartico6 for reporting. Fixed by the efforts of @QuiCM, @hakusaro, and tips in the right directioon from @bartico6. diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index f55c7aaa..5258e7dd 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -297,15 +297,7 @@ namespace TShockAPI return; } - // Using the actuation accessory can lead to actuator hacking - if (TShock.Itembans.ItemIsBanned("Actuator", args.Player) && args.Player.TPlayer.autoActuator) - { - args.Player.SendTileSquare(tileX, tileY, 1); - args.Player.SendErrorMessage("You do not have permission to place actuators."); - args.Handled = true; - return; - } - if (TShock.Itembans.ItemIsBanned(EnglishLanguage.GetItemNameById(selectedItem.netID), args.Player) || editData >= (action == EditAction.PlaceTile ? Main.maxTileSets : Main.maxWallTypes)) + if (editData >= (action == EditAction.PlaceTile ? Main.maxTileSets : Main.maxWallTypes)) { args.Player.SendTileSquare(tileX, tileY, 4); args.Handled = true; diff --git a/TShockAPI/ItemBans.cs b/TShockAPI/ItemBans.cs index b719db9c..a85f462c 100644 --- a/TShockAPI/ItemBans.cs +++ b/TShockAPI/ItemBans.cs @@ -59,6 +59,7 @@ namespace TShockAPI ServerApi.Hooks.GameUpdate.Register(plugin, OnGameUpdate); GetDataHandlers.PlayerUpdate += OnPlayerUpdate; GetDataHandlers.ChestItemChange += OnChestItemChange; + GetDataHandlers.TileEdit += OnTileEdit; } /// Called on the game update loop (the XNA tickrate). @@ -192,6 +193,27 @@ namespace TShockAPI return; } + internal void OnTileEdit(object sender, TileEditEventArgs args) + { + if (args.Action == EditAction.PlaceTile || args.Action == EditAction.PlaceWall) + { + if (args.Player.TPlayer.autoActuator && DataModel.ItemIsBanned("Actuator", args.Player)) + { + args.Player.SendTileSquare(args.X, args.Y, 1); + args.Player.SendErrorMessage("You do not have permission to place actuators."); + args.Handled = true; + return; + } + + if (DataModel.ItemIsBanned(EnglishLanguage.GetItemNameById(args.Player.SelectedItem.netID), args.Player)) + { + args.Player.SendTileSquare(args.X, args.Y, 4); + args.Handled = true; + return; + } + } + } + private void UnTaint(TSPlayer player) { player.IsDisabledForBannedWearable = false;