From 6efa0d2bb6d0c53cc2094ca681236261429788b7 Mon Sep 17 00:00:00 2001 From: AxeelAnder <1491773534@qq.com> Date: Sat, 20 Oct 2018 20:07:04 +0800 Subject: [PATCH] better code --- TShockAPI/Bouncer.cs | 97 +++++++++++++++++++--------------------- TShockAPI/Permissions.cs | 3 -- TShockAPI/TShock.cs | 32 ------------- 3 files changed, 46 insertions(+), 86 deletions(-) diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 79dce7d1..ba7c2c85 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -36,6 +36,31 @@ namespace TShockAPI /// Bouncer is the TShock anti-hack and anti-cheat system. internal sealed class Bouncer { + static Dictionary NPCAddBuffTimeMax = new Dictionary() + { + { BuffID.Poisoned, 3600 }, + { BuffID.OnFire, 1200 }, + { BuffID.CursedInferno, 420 }, + { BuffID.Frostburn, 900 }, + { BuffID.Ichor, 1200 }, + { BuffID.Venom, 1260 }, + { BuffID.Midas, 120 }, + { BuffID.Wet, 1500 }, + { BuffID.Slimed, 1500 }, + { BuffID.Lovestruck, 1800 }, + { BuffID.Stinky, 1800 }, + { BuffID.SoulDrain, 30 }, + { BuffID.ShadowFlame, 660 }, + { BuffID.DryadsWard, 120 }, + { BuffID.BoneJavelin, 900 }, + { BuffID.StardustMinionBleed, 900 }, + { BuffID.DryadsWardDebuff, 120 }, + { BuffID.Daybreak, 300 }, + { BuffID.BetsysCurse, 600 }, + { BuffID.Oiled, 540 } + }; + + /// Constructor call initializes Bouncer and related functionality. /// A new Bouncer. internal Bouncer() @@ -454,7 +479,7 @@ namespace TShockAPI return; } } - + /// Handles NPCAddBuff events. /// The object that triggered the event. /// The packet arguments that the event has. @@ -484,64 +509,34 @@ namespace TShockAPI return; } - if (!args.Player.HasPermission(Permissions.ignorenpcaddbuffdetection)) + bool cheat = false; + + if (NPCAddBuffTimeMax.ContainsKey(type)) { - bool cheat = false; - - if(TShock.NPCAddBuffTimeMax.ContainsKey(type)) - { - if(time > TShock.NPCAddBuffTimeMax[type]) - { - cheat = true; - } - - if(npc.townNPC && npc.netID != NPCID.Guide && npc.netID != NPCID.Clothier) - { - if(type != BuffID.Lovestruck && type != BuffID.Stinky && type != BuffID.DryadsWard && - type != BuffID.Wet && type != BuffID.Slimed) - { - cheat = true; - } - } - // Want to check voodoo doll but it may be wrong. - //else if(npc.netID == NPCID.Guide) - //{ - // bool hasDoll = false; - // foreach (var item in args.Player.Accessories) - // { - // if (item.netID == ItemID.GuideVoodooDoll) - // { - // hasDoll = true; - // break; - // } - // } - // cheat = !hasDoll; - //} - //else if (npc.netID == NPCID.Clothier) - //{ - // bool hasDoll = false; - // foreach (var item in args.Player.Accessories) - // { - // if (item.netID == ItemID.ClothierVoodooDoll) - // { - // hasDoll = true; - // break; - // } - // } - // cheat = !hasDoll; - //} - } - else + if (time > NPCAddBuffTimeMax[type]) { cheat = true; } - if (cheat) + if (npc.townNPC && npc.netID != NPCID.Guide && npc.netID != NPCID.Clothier) { - args.Player.Disable("Add buff to NPC abnormally.", DisableFlags.WriteToLogAndConsole); - args.Handled = true; + if (type != BuffID.Lovestruck && type != BuffID.Stinky && type != BuffID.DryadsWard && + type != BuffID.Wet && type != BuffID.Slimed) + { + cheat = true; + } } } + else + { + cheat = true; + } + + if (cheat) + { + args.Player.Disable("Add buff to NPC abnormally.", DisableFlags.WriteToLogAndConsole); + args.Handled = true; + } } /// Handles Buff events. diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index dec457d3..7733f110 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -169,9 +169,6 @@ namespace TShockAPI [Description("Prevents you from being disabled by abnormal MP.")] public static readonly string ignoremp = "tshock.ignore.mp"; - - [Description("Prevents you from being disabled by add buffs to npcs abnormally.")] - public static readonly string ignorenpcaddbuffdetection = "tshock.ignore.npcaddbuff"; // tshock.item nodes diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 18cff28e..f839019d 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -131,9 +131,6 @@ namespace TShockAPI /// public static Dictionary RESTStartupTokens = new Dictionary(); - /// The longest time of buffs players can add to NPCs. - public static Dictionary NPCAddBuffTimeMax; - /// The TShock anti-cheat/anti-exploit system. internal Bouncer Bouncer; @@ -326,7 +323,6 @@ namespace TShockAPI RestApi = new SecureRest(Netplay.ServerIP, Config.RestApiPort); RestManager = new RestManager(RestApi); RestManager.RegisterRestfulCommands(); - NPCAddBuffTimeMax = InitNPCAddBuffTimeMax(); Bouncer = new Bouncer(); RegionSystem = new RegionHandler(Regions); @@ -389,34 +385,6 @@ namespace TShockAPI } } - private Dictionary InitNPCAddBuffTimeMax() - { - var dict = new Dictionary(); - - dict.Add(BuffID.Poisoned, 3600); - dict.Add(BuffID.OnFire, 1200); - dict.Add(BuffID.CursedInferno, 420); - dict.Add(BuffID.Frostburn, 900); - dict.Add(BuffID.Ichor, 1200); - dict.Add(BuffID.Venom, 1260); - dict.Add(BuffID.Midas, 120); - dict.Add(BuffID.Wet, 1500); - dict.Add(BuffID.Slimed, 1500); - dict.Add(BuffID.Lovestruck, 1800); - dict.Add(BuffID.Stinky, 1800); - dict.Add(BuffID.SoulDrain, 30); - dict.Add(BuffID.ShadowFlame, 660); - dict.Add(BuffID.DryadsWard, 120); - dict.Add(BuffID.BoneJavelin, 900); - dict.Add(BuffID.StardustMinionBleed, 900); - dict.Add(BuffID.DryadsWardDebuff, 120); - dict.Add(BuffID.Daybreak, 300); - dict.Add(BuffID.BetsysCurse, 600); - dict.Add(BuffID.Oiled, 540); - - return dict; - } - protected void CrashReporter_HeapshotRequesting(object sender, EventArgs e) { foreach (TSPlayer player in TShock.Players)