diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7b25a146..e70c9d0a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,12 +11,20 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
* Do not insert tabs into this file, under any circumstances, ever.
* Do not forget to sign every line you change with your name. (@hakusaro)
* If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change.
+## Upcoming changes
+* Added hook `GetDataHandlers.OnReleaseNpc` to handling ReleaseNPC packet and a bouncer to stops unregistered and logged out players on SSC servers from releasing critters NPC. The bouncer has additional filter to stops players who tried to release different critter using crafted packet, e.g. using bunny item to release golden bunny. (@tru321)
+* Added filter in `GetDataHandlers.HandleCatchNpc` that stops unregistered and logged out players on SSC servers to catch critters. (@tru321)
+
+## Upcoming changes
+* Fixed rejection check inside of `HandlePaintTile` to account for the Paint Sprayer (or Architect Gizmo Pack) being inside your inventory, rather than on an accessory slot. (@drunderscore)
## TShock 4.5.12
* Fixed the ability to spawn Zenith projectile with non-original items. (@AgaSpace)
* Fixed item dupe via /logout & NPC. (@Terrarxxn)
* Added hook `GetDataHandlers.OnNpcTalk` for NpcTalk and a handler for it that stops unregistered and logged out players from interacting with NPCs, preventing them from smuggling or duplicating items via NPC item slots. (@tru321)
* Fixed the ability to create custom messages with your death (or the death of another player) (@AgaSpace)
+* Added the `OnSignRead` handler in `GetDataHandler`, and added the `SignRead` event. Added check to ensure the sign being read is within world bounds `(x >= 0 && y >= 0 && x < Main.maxTilesX && y < Main.maxTilesY)`. (@drunderscore)
+* Added check to `HandleNpcTalk` to ensure the passed NPC index is within bounds (>= -1 && < `Main.maxNPCs`). (@drunderscore)
## TShock 4.5.11
* Add the new allowed buff TentacleSpike to NPC buff cheat detection bouncer. (@sgkoishi)
diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs
index 1d1ccf26..7f3894c1 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -105,6 +105,7 @@ namespace TShockAPI
GetDataHandlers.NPCAddBuff += OnNPCAddBuff;
GetDataHandlers.NPCHome += OnUpdateNPCHome;
GetDataHandlers.HealOtherPlayer += OnHealOtherPlayer;
+ GetDataHandlers.ReleaseNPC += OnReleaseNPC;
GetDataHandlers.PlaceObject += OnPlaceObject;
GetDataHandlers.PlaceTileEntity += OnPlaceTileEntity;
GetDataHandlers.PlaceItemFrame += OnPlaceItemFrame;
@@ -1829,6 +1830,52 @@ namespace TShockAPI
return;
}
+ ///
+ /// A bouncer for checking NPC released by player
+ ///
+ /// The object that triggered the event.
+ /// The packet arguments that the event has.
+ internal void OnReleaseNPC(object sender, GetDataHandlers.ReleaseNpcEventArgs args)
+ {
+ int x = args.X;
+ int y = args.Y;
+ short type = args.Type;
+ byte style = args.Style;
+
+ // if npc released outside allowed tile
+ if (x >= Main.maxTilesX * 16 - 16 || x < 0 || y >= Main.maxTilesY * 16 - 16 || y < 0)
+ {
+ TShock.Log.ConsoleDebug("Bouncer / OnReleaseNPC rejected out of bounds from {0}", args.Player.Name);
+ args.Handled = true;
+ return;
+ }
+
+ // if player disabled
+ if (args.Player.IsBeingDisabled())
+ {
+ TShock.Log.ConsoleDebug("Bouncer / OnReleaseNPC rejected npc release from {0}", args.Player.Name);
+ args.Handled = true;
+ return;
+ }
+
+ // if released npc not from its item (from crafted packet)
+ // e.g. using bunny item to release golden bunny
+ if (args.Player.TPlayer.lastVisualizedSelectedItem.makeNPC != type && args.Player.TPlayer.lastVisualizedSelectedItem.placeStyle != style)
+ {
+ TShock.Log.ConsoleDebug("Bouncer / OnReleaseNPC released different critter from {0}", args.Player.Name);
+ args.Player.Kick("Released critter was not from its item.", true);
+ args.Handled = true;
+ return;
+ }
+
+ if (args.Player.IsBouncerThrottled())
+ {
+ TShock.Log.ConsoleDebug("Bouncer / OnReleaseNPC rejected throttle from {0}", args.Player.Name);
+ args.Handled = true;
+ return;
+ }
+ }
+
/// Bouncer's PlaceObject hook reverts malicious tile placement.
/// The object that triggered the event.
/// The packet arguments that the event has.
@@ -2249,8 +2296,10 @@ namespace TShockAPI
*
* If the player was not specified, that is, the player index is -1, then it is definitely a custom cause, as you can only deal damage with a projectile or another player.
* This is how everything else works. If an NPC is specified, its value is not -1, which is a custom cause.
+ *
+ * Checking whether this damage came from the player is necessary, because the damage from the player can come even when it is hit by a NPC
*/
- if (TShock.Config.Settings.DisableCustomDeathMessages &&
+ if (TShock.Config.Settings.DisableCustomDeathMessages && id != args.Player.Index &&
(reason._sourcePlayerIndex == -1 || reason._sourceNPCIndex != -1 || reason._sourceOtherIndex != -1 || reason._sourceCustomReason != null))
{
TShock.Log.ConsoleDebug("Bouncer / OnPlayerDamage rejected custom death message from {0}", args.Player.Name);
diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs
index bf0fb54e..e2ab3a47 100644
--- a/TShockAPI/GetDataHandlers.cs
+++ b/TShockAPI/GetDataHandlers.cs
@@ -122,6 +122,7 @@ namespace TShockAPI
{ PacketTypes.PlayerAnimation, HandlePlayerAnimation },
{ PacketTypes.PlayerMana, HandlePlayerMana },
{ PacketTypes.PlayerTeam, HandlePlayerTeam },
+ { PacketTypes.SignRead, HandleSignRead },
{ PacketTypes.SignNew, HandleSign },
{ PacketTypes.LiquidSet, HandleLiquidSet },
{ PacketTypes.PlayerBuff, HandlePlayerBuffList },
@@ -135,6 +136,7 @@ namespace TShockAPI
{ PacketTypes.Teleport, HandleTeleport },
{ PacketTypes.PlayerHealOther, HandleHealOther },
{ PacketTypes.CatchNPC, HandleCatchNpc },
+ { PacketTypes.ReleaseNPC, HandleReleaseNpc },
{ PacketTypes.TeleportationPotion, HandleTeleportationPotion },
{ PacketTypes.CompleteAnglerQuest, HandleCompleteAnglerQuest },
{ PacketTypes.NumberOfAnglerQuestsCompleted, HandleNumberOfAnglerQuestsCompleted },
@@ -1187,6 +1189,43 @@ namespace TShockAPI
return args.Handled;
}
+ ///
+ /// For use in a SignRead event
+ ///
+ public class SignReadEventArgs : GetDataHandledEventArgs
+ {
+ ///
+ /// X location of the sign
+ ///
+ public int X { get; set; }
+
+ ///
+ /// Y location of the sign
+ ///
+ public int Y { get; set; }
+ }
+
+ ///
+ /// Sign - Called when a sign is read
+ ///
+ public static HandlerList SignRead = new HandlerList();
+
+ private static bool OnSignRead(TSPlayer player, MemoryStream data, int x, int y)
+ {
+ if (SignRead == null)
+ return false;
+
+ var args = new SignReadEventArgs
+ {
+ Player = player,
+ Data = data,
+ X = x,
+ Y = y,
+ };
+ SignRead.Invoke(null, args);
+ return args.Handled;
+ }
+
///
/// For use in a Sign event
///
@@ -1638,6 +1677,56 @@ namespace TShockAPI
return args.Handled;
}
+ ///
+ /// The ReleaseNPC event arguments
+ ///
+ public class ReleaseNpcEventArgs : GetDataHandledEventArgs
+ {
+ ///
+ /// The X value of where NPC released
+ ///
+ public int X { get; set; }
+
+ ///
+ /// The Y value of where NPC released
+ ///
+ public int Y { get; set; }
+
+ ///
+ /// The NPC Type that player release
+ ///
+ public short Type { get; set; }
+
+ ///
+ /// The NPC release style
+ ///
+ public byte Style { get; set; }
+ }
+
+ ///
+ /// Called when player release a NPC, for checking critter released from item.
+ ///
+ public static HandlerList ReleaseNPC = new HandlerList();
+ private static bool OnReleaseNpc(TSPlayer player, MemoryStream data, int _x, int _y, short _type, byte _style)
+ {
+ if (ReleaseNPC == null)
+ {
+ return false;
+ }
+
+ var args = new ReleaseNpcEventArgs
+ {
+ Player = player,
+ Data = data,
+ X = _x,
+ Y = _y,
+ Type = _type,
+ Style = _style
+ };
+ ReleaseNPC.Invoke(null, args);
+ return args.Handled;
+ }
+
/// The arguments to the PlaceObject hook.
public class PlaceObjectEventArgs : GetDataHandledEventArgs
{
@@ -3160,9 +3249,16 @@ namespace TShockAPI
TShock.Log.ConsoleDebug("Bouncer / HandleNpcTalk rejected from bouncer throttle from {0}", args.Player.Name);
return true;
}
+
+ // -1 is a magic value, represents not talking to an NPC
+ if (npc < -1 || npc >= Main.maxNPCs)
+ {
+ TShock.Log.ConsoleDebug("Bouncer / HandleNpcTalk rejected from bouncer out of bounds from {0}", args.Player.Name);
+ return true;
+ }
return false;
- }
-
+ }
+
private static bool HandlePlayerAnimation(GetDataHandlerArgs args)
{
if (OnPlayerAnimation(args.Player, args.Data))
@@ -3217,6 +3313,23 @@ namespace TShockAPI
return false;
}
+ private static bool HandleSignRead(GetDataHandlerArgs args)
+ {
+ var x = args.Data.ReadInt16();
+ var y = args.Data.ReadInt16();
+
+ if (OnSignRead(args.Player, args.Data, x, y))
+ return true;
+
+ if (x < 0 || y < 0 || x >= Main.maxTilesX || y >= Main.maxTilesY)
+ {
+ TShock.Log.ConsoleDebug("GetDataHandlers / HandleSignRead rejected out of bounds {0}", args.Player.Name);
+ return true;
+ }
+
+ return false;
+ }
+
private static bool HandleSign(GetDataHandlerArgs args)
{
var id = args.Data.ReadInt16();
@@ -3487,6 +3600,11 @@ namespace TShockAPI
return true;
}
+ bool hasPaintSprayerAbilities(Item item) =>
+ item != null
+ && item.stack > 0
+ && (item.type == ItemID.PaintSprayer || item.type == ItemID.ArchitectGizmoPack);
+
// Not selecting paintbrush or paint scraper or the spectre versions? Hacking.
if (args.Player.SelectedItem.type != ItemID.PaintRoller &&
args.Player.SelectedItem.type != ItemID.PaintScraper &&
@@ -3494,8 +3612,8 @@ namespace TShockAPI
args.Player.SelectedItem.type != ItemID.SpectrePaintRoller &&
args.Player.SelectedItem.type != ItemID.SpectrePaintScraper &&
args.Player.SelectedItem.type != ItemID.SpectrePaintbrush &&
- !args.Player.Accessories.Any(i => i != null && i.stack > 0 &&
- (i.type == ItemID.PaintSprayer || i.type == ItemID.ArchitectGizmoPack)))
+ !args.Player.Accessories.Any(hasPaintSprayerAbilities) &&
+ !args.Player.Inventory.Any(hasPaintSprayerAbilities))
{
TShock.Log.ConsoleDebug("GetDataHandlers / HandlePaintTile rejected select consistency {0}", args.Player.Name);
args.Player.SendData(PacketTypes.PaintTile, "", x, y, Main.tile[x, y].color());
@@ -3658,10 +3776,31 @@ namespace TShockAPI
NetMessage.SendData((int)PacketTypes.NpcUpdate, -1, -1, NetworkText.Empty, npcID);
return true;
}
+
+ if(args.Player.IsBeingDisabled())
+ {
+ TShock.Log.ConsoleDebug("GetDataHandlers / HandleCatchNpc rejected catch npc {0}", args.Player.Name);
+ return true;
+ }
return false;
}
+ private static bool HandleReleaseNpc(GetDataHandlerArgs args)
+ {
+ var x = args.Data.ReadInt32();
+ var y = args.Data.ReadInt32();
+ var type = args.Data.ReadInt16();
+ var style = args.Data.ReadInt8();
+
+ if (OnReleaseNpc(args.Player, args.Data, x, y, type, style))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
private static bool HandleTeleportationPotion(GetDataHandlerArgs args)
{
var type = args.Data.ReadByte();
diff --git a/TShockAPI/Properties/AssemblyInfo.cs b/TShockAPI/Properties/AssemblyInfo.cs
index 3a2c541d..df44eb86 100644
--- a/TShockAPI/Properties/AssemblyInfo.cs
+++ b/TShockAPI/Properties/AssemblyInfo.cs
@@ -53,5 +53,5 @@ using System.Runtime.InteropServices;
// Also, be sure to release on github with the exact assembly version tag as below
// so that the update manager works correctly (via the Github releases api and mimic)
-[assembly: AssemblyVersion("4.5.11")]
-[assembly: AssemblyFileVersion("4.5.11")]
+[assembly: AssemblyVersion("4.5.12")]
+[assembly: AssemblyFileVersion("4.5.12")]
diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs
index e6ceac32..00ff790b 100644
--- a/TShockAPI/TSPlayer.cs
+++ b/TShockAPI/TSPlayer.cs
@@ -898,6 +898,18 @@ namespace TShockAPI
}
}
+ ///
+ /// Gets the player's inventory (first 5 rows)
+ ///
+ public IEnumerable- Inventory
+ {
+ get
+ {
+ for (int i = 0; i < 50; i++)
+ yield return TPlayer.inventory[i];
+ }
+ }
+
///
/// Gets the player's accessories.
///
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 00000000..245dbcdc
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,56 @@
+version: '{build}'
+max_jobs: 16
+image: Visual Studio 2019
+build_script:
+- ps: >-
+ git submodule update --init --recursive
+
+ cd ./TerrariaServerAPI/
+
+
+ nuget restore TShock.4.OTAPI.sln
+
+ msbuild TShock.4.OTAPI.sln /p:Configuration=Debug
+
+
+ cd ./TShock.Modifications.Bootstrapper/bin/Debug/
+
+
+ ./TShock.Modifications.Bootstrapper.exe
+
+
+ cd ../../../
+
+
+ msbuild ./TerrariaServerAPI/TerrariaServerAPI.csproj /p:Configuration=Debug
+
+
+ msbuild TShock.4.OTAPI.sln /p:Configuration=Release
+
+
+ cd ./TShock.Modifications.Bootstrapper/bin/Release/
+
+
+ ./TShock.Modifications.Bootstrapper.exe
+
+
+ cd ../../../
+
+
+ msbuild ./TerrariaServerAPI/TerrariaServerAPI.csproj /p:Configuration=Release
+
+
+ cd ../
+
+
+ nuget restore TShock.sln
+
+
+ msbuild ./TShockAPI/TShockAPI.csproj /p:Configuration=Release
+
+ msbuild ./TShockAPI/TShockAPI.csproj /p:Configuration=Debug
+artifacts:
+- path: ./TShockAPI/bin/Debug/
+ name: TShockAVDebug
+- path: ./TShockAPI/bin/Release/
+ name: TShockAVRelease