From a2a13ce4949a6c89b628884ec0553da0dfdd4d27 Mon Sep 17 00:00:00 2001
From: tru321 <84877585+tru321@users.noreply.github.com>
Date: Wed, 1 Dec 2021 13:44:41 +0800
Subject: [PATCH 1/4] Added DataHandler for NpcTalk
This should stopping unregistered and logged out players to interact with NPC. Which prevent them smuggling or duplicating items via NPC items slot.
---
TShockAPI/GetDataHandlers.cs | 57 ++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs
index c4366961..a668cdef 100644
--- a/TShockAPI/GetDataHandlers.cs
+++ b/TShockAPI/GetDataHandlers.cs
@@ -118,6 +118,7 @@ namespace TShockAPI
{ PacketTypes.PlaceChest, HandlePlaceChest },
{ PacketTypes.Zones, HandlePlayerZone },
{ PacketTypes.PasswordSend, HandlePassword },
+ { PacketTypes.NpcTalk, HandleNpcTalk },
{ PacketTypes.PlayerAnimation, HandlePlayerAnimation },
{ PacketTypes.PlayerMana, HandlePlayerMana },
{ PacketTypes.PlayerTeam, HandlePlayerTeam },
@@ -1066,6 +1067,39 @@ namespace TShockAPI
return args.Handled;
}
+ ///
+ /// Using when player trying to talk to a NPC
+ ///
+ public class NpcTalkEventArgs : GetDataHandledEventArgs
+ {
+ ///
+ /// Player Id
+ ///
+ public byte PlayerId { get; set; }
+ ///
+ /// NPC Id player's talk to
+ ///
+ public short NPCTalkTarget { get; set; }
+ }
+ public static HandlerList NpcTalk = new HandlerList();
+ private static bool OnNpcTalk(TSPlayer player, MemoryStream data, byte _plr, short _npctarget)
+ {
+ if (NpcTalk == null)
+ {
+ return false;
+ }
+
+ var args = new NpcTalkEventArgs
+ {
+ Player = player,
+ Data = data,
+ PlayerId = _plr,
+ NPCTalkTarget = _npctarget,
+ };
+ NpcTalk.Invoke(null, args);
+ return args.Handled;
+ }
+
///
/// For use with a PlayerAnimation event
///
@@ -3104,6 +3138,29 @@ namespace TShockAPI
return true;
}
+ private static bool HandleNpcTalk(GetDataHandlerArgs args)
+ {
+ var plr = args.Data.ReadInt8();
+ var npc = args.Data.ReadInt16();
+
+ if (OnNpcTalk(args.Player, args.Data, plr, npc))
+ return true;
+ //Rejecting player who trying to talk to a npc if player were disabled, mainly for unregistered and logged out players. Preventing smuggling or duplicating their items if player put it in a npc's item slot
+ if (args.Player.IsBeingDisabled())
+ {
+ TShock.Log.ConsoleDebug("GetDataHandlers / HandleNpcTalk rejected npc talk {0}", args.Player.Name);
+ args.Player.SendData(PacketTypes.NpcTalk, "", plr, -1);
+ return true;
+ }
+
+ if (args.Player.IsBouncerThrottled())
+ {
+ TShock.Log.ConsoleDebug("Bouncer / HandleNpcTalk rejected from bouncer throttle from {0}", args.Player.Name);
+ return true;
+ }
+ return false;
+ }
+
private static bool HandlePlayerAnimation(GetDataHandlerArgs args)
{
if (OnPlayerAnimation(args.Player, args.Data))
From 0b1da29cf848b631b7993d35f333af7ddad57be1 Mon Sep 17 00:00:00 2001
From: tru321 <84877585+tru321@users.noreply.github.com>
Date: Wed, 1 Dec 2021 14:35:02 +0800
Subject: [PATCH 2/4] Update GetDataHandlers.cs
---
TShockAPI/GetDataHandlers.cs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs
index a668cdef..bf0fb54e 100644
--- a/TShockAPI/GetDataHandlers.cs
+++ b/TShockAPI/GetDataHandlers.cs
@@ -1073,11 +1073,12 @@ namespace TShockAPI
public class NpcTalkEventArgs : GetDataHandledEventArgs
{
///
- /// Player Id
+ /// The Terraria ID of the player talking to the NPC
///
public byte PlayerId { get; set; }
+
///
- /// NPC Id player's talk to
+ /// The NPC ID of the NPC the player is talking to
///
public short NPCTalkTarget { get; set; }
}
@@ -3145,6 +3146,7 @@ namespace TShockAPI
if (OnNpcTalk(args.Player, args.Data, plr, npc))
return true;
+
//Rejecting player who trying to talk to a npc if player were disabled, mainly for unregistered and logged out players. Preventing smuggling or duplicating their items if player put it in a npc's item slot
if (args.Player.IsBeingDisabled())
{
From 0d60d1654d4a253c25bfc8af7900fc1d4c7c86d7 Mon Sep 17 00:00:00 2001
From: tru321 <84877585+tru321@users.noreply.github.com>
Date: Wed, 1 Dec 2021 14:51:53 +0800
Subject: [PATCH 3/4] Update CHANGELOG.md
---
CHANGELOG.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 62a73f8c..15b0bf04 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
## TShock 4.5.12
* Fixed the ability to spawn Zenith projectile with non-original items. (@AgaSpace)
+* Added hook `GetDataHandlers.OnNpcTalk` for NpcTalk and a handler for it that stopping unregistered and logged out players to interact with NPC, preventing them to smuggling or duplicating items via NPC item slots. (@tru321)
## TShock 4.5.11
* Add the new allowed buff TentacleSpike to NPC buff cheat detection bouncer. (@sgkoishi)
From c6b870a480788e30780ac1210a8289730308d577 Mon Sep 17 00:00:00 2001
From: tru321 <84877585+tru321@users.noreply.github.com>
Date: Wed, 1 Dec 2021 15:49:59 +0800
Subject: [PATCH 4/4] Update CHANGELOG.md
Co-authored-by: Lucas Nicodemus
---
CHANGELOG.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 15b0bf04..4412bdb8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,7 +14,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
## TShock 4.5.12
* Fixed the ability to spawn Zenith projectile with non-original items. (@AgaSpace)
-* Added hook `GetDataHandlers.OnNpcTalk` for NpcTalk and a handler for it that stopping unregistered and logged out players to interact with NPC, preventing them to smuggling or duplicating items via NPC item slots. (@tru321)
+* 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)
## TShock 4.5.11
* Add the new allowed buff TentacleSpike to NPC buff cheat detection bouncer. (@sgkoishi)