Move OnChestItemChange to Bouncer

Fix issue where TShock didn't properly do anti-cheat on chest
item changes.
This commit is contained in:
Lucas Nicodemus 2017-12-15 12:12:21 -07:00
parent bcc1816071
commit 845fc3b7c8
3 changed files with 43 additions and 24 deletions

View file

@ -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) * 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) * 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 `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 ## 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. * 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.

View file

@ -42,6 +42,7 @@ namespace TShockAPI
{ {
// Setup hooks // Setup hooks
GetDataHandlers.ChestItemChange.Register(OnChestItemChange);
GetDataHandlers.NPCHome.Register(OnUpdateNPCHome); GetDataHandlers.NPCHome.Register(OnUpdateNPCHome);
GetDataHandlers.ChestOpen.Register(OnChestOpen); GetDataHandlers.ChestOpen.Register(OnChestOpen);
GetDataHandlers.PlaceChest.Register(OnPlaceChest); GetDataHandlers.PlaceChest.Register(OnPlaceChest);
@ -56,6 +57,40 @@ namespace TShockAPI
GetDataHandlers.TileEdit.Register(OnTileEdit); 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> /// <summary>The Bouncer handler for when an NPC is rehomed.</summary>
/// <param name="sender">The object that triggered the event.</param> /// <param name="sender">The object that triggered the event.</param>
/// <param name="args">The packet arguments that the event has.</param> /// <param name="args">The packet arguments that the event has.</param>

View file

@ -922,6 +922,8 @@ namespace TShockAPI
/// </summary> /// </summary>
public class ChestItemEventArgs : HandledEventArgs public class ChestItemEventArgs : HandledEventArgs
{ {
/// <summary>The TSPlayer that triggered the event.</summary>
public TSPlayer Player { get; set; }
/// <summary> /// <summary>
/// ChestID /// ChestID
/// </summary> /// </summary>
@ -948,13 +950,14 @@ namespace TShockAPI
/// </summary> /// </summary>
public static HandlerList<ChestItemEventArgs> ChestItemChange; 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) if (ChestItemChange == null)
return false; return false;
var args = new ChestItemEventArgs var args = new ChestItemEventArgs
{ {
Player = player,
ID = id, ID = id,
Slot = slot, Slot = slot,
Stacks = stacks, Stacks = stacks,
@ -2452,35 +2455,14 @@ namespace TShockAPI
var prefix = args.Data.ReadInt8(); var prefix = args.Data.ReadInt8();
var type = args.Data.ReadInt16(); var type = args.Data.ReadInt16();
if (OnChestItemChange(id, slot, stacks, prefix, type)) if (OnChestItemChange(args.Player, id, slot, stacks, prefix, type))
return true; 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 item = new Item();
item.netDefaults(type); item.netDefaults(type);
if (stacks > item.maxStack || TShock.Itembans.ItemIsBanned(EnglishLanguage.GetItemNameById(item.type), args.Player)) if (stacks > item.maxStack || TShock.Itembans.ItemIsBanned(EnglishLanguage.GetItemNameById(item.type), args.Player))
{ {
return false; return true;
}
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 false; return false;