Move OnChestItemChange to Bouncer
Fix issue where TShock didn't properly do anti-cheat on chest item changes.
This commit is contained in:
parent
bcc1816071
commit
845fc3b7c8
3 changed files with 43 additions and 24 deletions
|
|
@ -70,6 +70,8 @@ Putting this stuff down here so things don't conflict as often.
|
|||
* Fixed invasions started by TShock not reporting size correctly and probably not working at all. (@hakusaro)
|
||||
* Removed `GetDataHandlers.TileKill` and replaced it with `GetDataHandlers.PlaceChest` as the packet originally designated as tile kill is now only used for chests. (@hakusaro)
|
||||
* Added `TSPlayer` to `GetDataHandlers.NPCHome`. (@hakusaro)
|
||||
* Added a `TSPlayer` to `GetDataHandlers.ChestItemChanged`. (@hakusaro)
|
||||
* Fixed chest item changes not triggering any range checks, tile checks, or correct chest checks. (@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.
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ namespace TShockAPI
|
|||
{
|
||||
// Setup hooks
|
||||
|
||||
GetDataHandlers.ChestItemChange.Register(OnChestItemChange);
|
||||
GetDataHandlers.NPCHome.Register(OnUpdateNPCHome);
|
||||
GetDataHandlers.ChestOpen.Register(OnChestOpen);
|
||||
GetDataHandlers.PlaceChest.Register(OnPlaceChest);
|
||||
|
|
@ -56,6 +57,40 @@ namespace TShockAPI
|
|||
GetDataHandlers.TileEdit.Register(OnTileEdit);
|
||||
}
|
||||
|
||||
internal void OnChestItemChange(object sender, GetDataHandlers.ChestItemEventArgs args)
|
||||
{
|
||||
short id = args.ID;
|
||||
byte slot = args.Slot;
|
||||
short stacks = args.Stacks;
|
||||
byte prefix = args.Prefix;
|
||||
short type = args.Type;
|
||||
|
||||
if (args.Player.TPlayer.chest != id)
|
||||
{
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (TShock.CheckIgnores(args.Player))
|
||||
{
|
||||
args.Player.SendData(PacketTypes.ChestItem, "", id, slot);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (TShock.CheckTilePermission(args.Player, Main.chest[id].x, Main.chest[id].y) && TShock.Config.RegionProtectChests)
|
||||
{
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (TShock.CheckRangePermission(args.Player, Main.chest[id].x, Main.chest[id].y))
|
||||
{
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The Bouncer handler for when an NPC is rehomed.</summary>
|
||||
/// <param name="sender">The object that triggered the event.</param>
|
||||
/// <param name="args">The packet arguments that the event has.</param>
|
||||
|
|
|
|||
|
|
@ -922,6 +922,8 @@ namespace TShockAPI
|
|||
/// </summary>
|
||||
public class ChestItemEventArgs : HandledEventArgs
|
||||
{
|
||||
/// <summary>The TSPlayer that triggered the event.</summary>
|
||||
public TSPlayer Player { get; set; }
|
||||
/// <summary>
|
||||
/// ChestID
|
||||
/// </summary>
|
||||
|
|
@ -948,13 +950,14 @@ namespace TShockAPI
|
|||
/// </summary>
|
||||
public static HandlerList<ChestItemEventArgs> ChestItemChange;
|
||||
|
||||
private static bool OnChestItemChange(short id, byte slot, short stacks, byte prefix, short type)
|
||||
private static bool OnChestItemChange(TSPlayer player, short id, byte slot, short stacks, byte prefix, short type)
|
||||
{
|
||||
if (ChestItemChange == null)
|
||||
return false;
|
||||
|
||||
var args = new ChestItemEventArgs
|
||||
{
|
||||
Player = player,
|
||||
ID = id,
|
||||
Slot = slot,
|
||||
Stacks = stacks,
|
||||
|
|
@ -2452,35 +2455,14 @@ namespace TShockAPI
|
|||
var prefix = args.Data.ReadInt8();
|
||||
var type = args.Data.ReadInt16();
|
||||
|
||||
if (OnChestItemChange(id, slot, stacks, prefix, type))
|
||||
if (OnChestItemChange(args.Player, id, slot, stacks, prefix, type))
|
||||
return true;
|
||||
|
||||
if (args.TPlayer.chest != id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TShock.CheckIgnores(args.Player))
|
||||
{
|
||||
args.Player.SendData(PacketTypes.ChestItem, "", id, slot);
|
||||
return true;
|
||||
}
|
||||
|
||||
Item item = new Item();
|
||||
item.netDefaults(type);
|
||||
if (stacks > item.maxStack || TShock.Itembans.ItemIsBanned(EnglishLanguage.GetItemNameById(item.type), args.Player))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TShock.CheckTilePermission(args.Player, Main.chest[id].x, Main.chest[id].y) && TShock.Config.RegionProtectChests)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TShock.CheckRangePermission(args.Player, Main.chest[id].x, Main.chest[id].y))
|
||||
{
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue