Add & move OnPlaceItemFrame to Bouncer
This commit is contained in:
parent
748d7f7fab
commit
9f7c3ead09
3 changed files with 79 additions and 14 deletions
|
|
@ -80,6 +80,7 @@ Putting this stuff down here so things don't conflict as often.
|
|||
* Added `GetDataHandlers.MassWireOperation` hook and related arguments. (@hakusaro)
|
||||
* Added `GetDataHandlers.PlaceTileEntity` hook and related arguments. (@hakusaro)
|
||||
* Added `TSPlayer` to `GetDataHandlers.GemLockToggle`. (@hakusaro)
|
||||
* Added `GetDataHandlers.PlaceItemFrame` hook and related arguments. (@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.
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ using static TShockAPI.GetDataHandlers;
|
|||
using TerrariaApi.Server;
|
||||
using Terraria.ObjectData;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.Localization;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
|
|
@ -41,6 +42,7 @@ namespace TShockAPI
|
|||
{
|
||||
// Setup hooks
|
||||
|
||||
GetDataHandlers.PlaceItemFrame.Register(OnPlaceItemFrame);
|
||||
GetDataHandlers.GemLockToggle.Register(OnGemLockToggle);
|
||||
GetDataHandlers.PlaceTileEntity.Register(OnPlaceTileEntity);
|
||||
GetDataHandlers.PlayerAnimation.Register(OnPlayerAnimation);
|
||||
|
|
@ -62,6 +64,33 @@ namespace TShockAPI
|
|||
GetDataHandlers.TileEdit.Register(OnTileEdit);
|
||||
}
|
||||
|
||||
/// <summary>Fired when an item frame is placed for anti-cheat detection.</summary>
|
||||
/// <param name="sender">The object that triggered the event.</param>
|
||||
/// <param name="args">The packet arguments that the event has.</param>
|
||||
internal void OnPlaceItemFrame(object sender, GetDataHandlers.PlaceItemFrameEventArgs args)
|
||||
{
|
||||
if (TShock.CheckIgnores(args.Player))
|
||||
{
|
||||
NetMessage.SendData((int)PacketTypes.UpdateTileEntity, -1, -1, NetworkText.Empty, args.ItemFrame.ID, 0, 1);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (TShock.CheckTilePermission(args.Player, args.X, args.Y))
|
||||
{
|
||||
NetMessage.SendData((int)PacketTypes.UpdateTileEntity, -1, -1, NetworkText.Empty, args.ItemFrame.ID, 0, 1);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (TShock.CheckRangePermission(args.Player, args.X, args.Y))
|
||||
{
|
||||
NetMessage.SendData((int)PacketTypes.UpdateTileEntity, -1, -1, NetworkText.Empty, args.ItemFrame.ID, 0, 1);
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Handles the anti-cheat components of gem lock toggles.</summary>
|
||||
/// <param name="sender">The object that triggered the event.</param>
|
||||
/// <param name="args">The packet arguments that the event has.</param>
|
||||
|
|
|
|||
|
|
@ -3075,6 +3075,54 @@ namespace TShockAPI
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>The arguments to the PlaceItemFrame event.</summary>
|
||||
public class PlaceItemFrameEventArgs : HandledEventArgs
|
||||
{
|
||||
/// <summary>The TSPlayer that triggered the event.</summary>
|
||||
public TSPlayer Player { get; set; }
|
||||
|
||||
/// <summary>The X coordinate of the item frame.</summary>
|
||||
public short X { get; set; }
|
||||
|
||||
/// <summary>The Y coordinate of the item frame.</summary>
|
||||
public short Y { get; set; }
|
||||
|
||||
/// <summary>The ItemID of the item frame.</summary>
|
||||
public short ItemID { get; set; }
|
||||
|
||||
/// <summary>The prefix.</summary>
|
||||
public byte Prefix { get; set; }
|
||||
|
||||
/// <summary>The stack.</summary>
|
||||
public short Stack { get; set; }
|
||||
|
||||
/// <summary>The ItemFrame object associated with this event.</summary>
|
||||
public TEItemFrame ItemFrame { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>Fired when an ItemFrame is placed.</summary>
|
||||
public static HandlerList<PlaceItemFrameEventArgs> PlaceItemFrame;
|
||||
|
||||
private static bool OnPlaceItemFrame(TSPlayer player, short x, short y, short itemID, byte prefix, short stack, TEItemFrame itemFrame)
|
||||
{
|
||||
if (PlaceItemFrame == null)
|
||||
return false;
|
||||
|
||||
var args = new PlaceItemFrameEventArgs
|
||||
{
|
||||
Player = player,
|
||||
X = x,
|
||||
Y = y,
|
||||
ItemID = itemID,
|
||||
Prefix = prefix,
|
||||
Stack = stack,
|
||||
ItemFrame = itemFrame,
|
||||
};
|
||||
|
||||
PlaceItemFrame.Invoke(null, args);
|
||||
return args.Handled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For use with a ToggleGemLock event
|
||||
/// </summary>
|
||||
|
|
@ -3221,21 +3269,8 @@ namespace TShockAPI
|
|||
var stack = args.Data.ReadInt16();
|
||||
var itemFrame = (TEItemFrame)TileEntity.ByID[TEItemFrame.Find(x, y)];
|
||||
|
||||
if (TShock.CheckIgnores(args.Player))
|
||||
if (OnPlaceItemFrame(args.Player, x, y, itemID, prefix, stack, itemFrame))
|
||||
{
|
||||
NetMessage.SendData((int)PacketTypes.UpdateTileEntity, -1, -1, NetworkText.Empty, itemFrame.ID, 0, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (TShock.CheckTilePermission(args.Player, x, y))
|
||||
{
|
||||
NetMessage.SendData((int)PacketTypes.UpdateTileEntity, -1, -1, NetworkText.Empty, itemFrame.ID, 0, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (TShock.CheckRangePermission(args.Player, x, y))
|
||||
{
|
||||
NetMessage.SendData((int)PacketTypes.UpdateTileEntity, -1, -1, NetworkText.Empty, itemFrame.ID, 0, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue