Merge pull request #2062 from Pryaxis/displaydollsynchook
Displaydollsynchook
This commit is contained in:
commit
eee7fac1a8
5 changed files with 140 additions and 5 deletions
|
|
@ -31,13 +31,15 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
|
|||
* `/itemban` - `/projban` - `/tileban` - Added a `default:` case to the commands so an invalid subcommand promts the player to enter the help subcommand to get more information on valid subcommands. (@Patrikkk)
|
||||
* `/world` - Renamed to /worldinfo to be more accurate to it's function. Command now displays the world's `Seed`. Reformatted the world information so each line isn't repeatedly starting with "World". (@Patrikkk)
|
||||
* `/who` - Changed the display format of the online players when the `-i` flag is used. From `PlayerName (ID: 0, ID: 0)` to `PlayerName (Index: 0, Account ID: 0)` for clarification. (@Patrikkk)
|
||||
* Adding DisplayDollItemSync event. An event that is called when a player modifies the slot of a DisplayDoll (Mannequin). This event provides information about the current item in the displaydoll, as well as the item that the player is about to set. (@Patrikkk)
|
||||
* Adding DisplayDollItemSyncHandler, which checks for building permissions of the player at the position of the DisplayDoll. (If they do not have permissions, it means they are hacking as they could not even open the doll in the first place.) (@Patrikkk)
|
||||
|
||||
## TShock 4.4.0 (Pre-release 11)
|
||||
* New permission `tshock.tp.pylon` to enable teleporting via Teleportation Pylons (@QuiCM)
|
||||
* New permission `tshock.journey.research` to enable sharing research via item sacrifice (@QuiCM)
|
||||
* Add Emoji event to GetDataHandler. This packet is received when a player tries to display an emote. (who?)
|
||||
* Adding EmojiHandler to handle an exploit. Adding `tshock.sendemoji` permission and checks. Added this permission to guest group by default. (who?)
|
||||
* Handled SyncCavernMonsterType packet to prevent an exploit where players could modify the server's cavern monster types and make the server spawn any NPCs - including bosses - onto other players. (who?)
|
||||
* Add Emoji event to GetDataHandler. This packet is received when a player tries to display an emote. (@Patrikkk)
|
||||
* Adding EmojiHandler to handle an exploit. Adding `tshock.sendemoji` permission and checks. Added this permission to guest group by default. (@Patrikkk)
|
||||
* Handled SyncCavernMonsterType packet to prevent an exploit where players could modify the server's cavern monster types and make the server spawn any NPCs - including bosses - onto other players. (@Patrikkk)
|
||||
* Added LandGolfBallInCup event which is accessible for developers to work with, as well as LandGolfBallInCup handler to handle exploits where players could send direct packets to trigger and imitate golf ball cup landing anywhere in the game world. Added two public lists in Handlers.LandGolfBallInCupHandler: GolfBallProjectileIDs and GolfClubItemIDs. (@Patrikkk)
|
||||
* Added SyncTilePicking event. This is called when a player damages a tile. Implementing SyncTilePickingHandler and patching tile damaging related exploits. (Preventing player sending invalid world position data which disconnects other players.)
|
||||
* Fixed the issue where mobs could not be fished out during bloodmoon because of Bouncer checks. (@Patrikkk)
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ namespace TShockAPI
|
|||
internal Handlers.SendTileSquareHandler STSHandler { get; set; }
|
||||
internal Handlers.NetModules.NetModulePacketHandler NetModuleHandler { get; set; }
|
||||
internal Handlers.EmojiHandler EmojiHandler { get; set; }
|
||||
internal Handlers.DisplayDollItemSyncHandler DisplayDollItemSyncHandler { get; set; }
|
||||
internal Handlers.LandGolfBallInCupHandler LandGolfBallInCupHandler { get; set; }
|
||||
internal Handlers.SyncTilePickingHandler SyncTilePickingHandler { get; set; }
|
||||
|
||||
|
|
@ -52,9 +53,12 @@ namespace TShockAPI
|
|||
NetModuleHandler = new Handlers.NetModules.NetModulePacketHandler();
|
||||
GetDataHandlers.ReadNetModule += NetModuleHandler.OnReceive;
|
||||
|
||||
DisplayDollItemSyncHandler = new Handlers.DisplayDollItemSyncHandler();
|
||||
GetDataHandlers.DisplayDollItemSync += DisplayDollItemSyncHandler.OnReceive;
|
||||
|
||||
EmojiHandler = new Handlers.EmojiHandler();
|
||||
GetDataHandlers.Emoji += EmojiHandler.OnReceive;
|
||||
|
||||
|
||||
LandGolfBallInCupHandler = new Handlers.LandGolfBallInCupHandler();
|
||||
GetDataHandlers.LandGolfBallInCup += LandGolfBallInCupHandler.OnReceive;
|
||||
|
||||
|
|
|
|||
|
|
@ -152,6 +152,7 @@ namespace TShockAPI
|
|||
{ PacketTypes.PlayerHurtV2, HandlePlayerDamageV2 },
|
||||
{ PacketTypes.PlayerDeathV2, HandlePlayerKillMeV2 },
|
||||
{ PacketTypes.Emoji, HandleEmoji },
|
||||
{ PacketTypes.TileEntityDisplayDollItemSync, HandleTileEntityDisplayDollItemSync },
|
||||
{ PacketTypes.SyncTilePicking, HandleSyncTilePicking },
|
||||
{ PacketTypes.SyncRevengeMarker, HandleSyncRevengeMarker },
|
||||
{ PacketTypes.LandGolfBallInCup, HandleLandGolfBallInCup },
|
||||
|
|
@ -1945,7 +1946,65 @@ namespace TShockAPI
|
|||
Emoji.Invoke(null, args);
|
||||
return args.Handled;
|
||||
}
|
||||
|
||||
|
||||
/// For use in a TileEntityDisplayDollItemSync event.
|
||||
/// </summary>
|
||||
public class DisplayDollItemSyncEventArgs : GetDataHandledEventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The player index in the packet who modifies the DisplayDoll item slot.
|
||||
/// </summary>
|
||||
public byte PlayerIndex { get; set; }
|
||||
/// <summary>
|
||||
/// The ID of the TileEntity that is being modified.
|
||||
/// </summary>
|
||||
public int TileEntityID { get; set; }
|
||||
/// <summary>
|
||||
/// The TEDisplayDoll object that is being modified.
|
||||
/// </summary>
|
||||
public TEDisplayDoll DisplayDollEntity { get; set; }
|
||||
/// <summary>
|
||||
/// The slot of the DisplayDoll that is being modified.
|
||||
/// </summary>
|
||||
public int Slot { get; set; }
|
||||
/// <summary>
|
||||
/// Wether or not the slot that is being modified is a Dye slot.
|
||||
/// </summary>
|
||||
public bool IsDye { get; set; }
|
||||
/// <summary>
|
||||
/// The current item that is present in the slot before the modification.
|
||||
/// </summary>
|
||||
public Item OldItem { get; set; }
|
||||
/// <summary>
|
||||
/// The item that is about to replace the OldItem in the slot that is being modified.
|
||||
/// </summary>
|
||||
public Item NewItem { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Called when a player modifies a DisplayDoll (Mannequin) item slot.
|
||||
/// </summary>
|
||||
public static HandlerList<DisplayDollItemSyncEventArgs> DisplayDollItemSync = new HandlerList<DisplayDollItemSyncEventArgs>();
|
||||
private static bool OnDisplayDollItemSync(TSPlayer player, MemoryStream data, byte playerIndex, int tileEntityID, TEDisplayDoll displayDollEntity, int slot, bool isDye, Item oldItem, Item newItem)
|
||||
{
|
||||
if (DisplayDollItemSync == null)
|
||||
return false;
|
||||
|
||||
var args = new DisplayDollItemSyncEventArgs
|
||||
{
|
||||
Player = player,
|
||||
Data = data,
|
||||
PlayerIndex = playerIndex,
|
||||
TileEntityID = tileEntityID,
|
||||
DisplayDollEntity = displayDollEntity,
|
||||
Slot = slot,
|
||||
IsDye = isDye,
|
||||
OldItem = oldItem,
|
||||
NewItem = newItem
|
||||
};
|
||||
DisplayDollItemSync.Invoke(null, args);
|
||||
return args.Handled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For use in a LandBallInCup event.
|
||||
/// </summary>
|
||||
|
|
@ -3703,6 +3762,48 @@ namespace TShockAPI
|
|||
return false;
|
||||
}
|
||||
|
||||
private static bool HandleTileEntityDisplayDollItemSync(GetDataHandlerArgs args)
|
||||
{
|
||||
byte playerIndex = args.Data.ReadInt8();
|
||||
int tileEntityID = args.Data.ReadInt32();
|
||||
int slot = args.Data.ReadByte();
|
||||
bool isDye = false;
|
||||
if (slot >= 8)
|
||||
{
|
||||
isDye = true;
|
||||
slot -= 8;
|
||||
}
|
||||
|
||||
Item newItem = new Item();
|
||||
Item oldItem = new Item();
|
||||
|
||||
if (!TileEntity.ByID.TryGetValue(tileEntityID, out TileEntity tileEntity))
|
||||
return false;
|
||||
|
||||
TEDisplayDoll displayDoll = tileEntity as TEDisplayDoll;
|
||||
if (displayDoll != null)
|
||||
{
|
||||
oldItem = displayDoll._items[slot];
|
||||
if (isDye)
|
||||
oldItem = displayDoll._dyes[slot];
|
||||
|
||||
ushort itemType = args.Data.ReadUInt16();
|
||||
ushort stack = args.Data.ReadUInt16();
|
||||
int prefix = args.Data.ReadByte();
|
||||
|
||||
if (oldItem.type == 0 && newItem.type == 0)
|
||||
return false;
|
||||
|
||||
newItem.SetDefaults(itemType);
|
||||
newItem.stack = stack;
|
||||
newItem.Prefix(prefix);
|
||||
|
||||
if (OnDisplayDollItemSync(args.Player, args.Data, playerIndex, tileEntityID, displayDoll, slot, isDye, oldItem, newItem))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool HandleSyncTilePicking(GetDataHandlerArgs args)
|
||||
{
|
||||
byte playerIndex = args.Data.ReadInt8();
|
||||
|
|
|
|||
27
TShockAPI/Handlers/DisplayDollItemSyncHandler.cs
Normal file
27
TShockAPI/Handlers/DisplayDollItemSyncHandler.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static TShockAPI.GetDataHandlers;
|
||||
|
||||
namespace TShockAPI.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles the TileEntityDisplayDollItemSync packets and checks for permissions.
|
||||
/// </summary>
|
||||
public class DisplayDollItemSyncHandler : IPacketHandler<DisplayDollItemSyncEventArgs>
|
||||
{
|
||||
public void OnReceive(object sender, DisplayDollItemSyncEventArgs args)
|
||||
{
|
||||
/// If the player has no building permissions means that they couldn't even see the content of the doll in the first place.
|
||||
/// Thus, they would not be able to modify its content. This means that a hacker attempted to send this packet directly, or through raw bytes to tamper with the DisplayDoll. This is why I do not bother with making sure the player gets their item back.
|
||||
if (!args.Player.HasBuildPermission(args.DisplayDollEntity.Position.X, args.DisplayDollEntity.Position.Y, false))
|
||||
{
|
||||
args.Player.SendErrorMessage("You do not have permission to modify a Mannequin in a protected area!");
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -88,6 +88,7 @@
|
|||
<Compile Include="DB\ResearchDatastore.cs" />
|
||||
<Compile Include="DB\TileManager.cs" />
|
||||
<Compile Include="Extensions\ExceptionExt.cs" />
|
||||
<Compile Include="Handlers\DisplayDollItemSyncHandler.cs" />
|
||||
<Compile Include="Handlers\IPacketHandler.cs" />
|
||||
<Compile Include="Handlers\NetModules\AmbienceHandler.cs" />
|
||||
<Compile Include="Handlers\NetModules\BestiaryHandler.cs" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue