better code

This commit is contained in:
AxeelAnder 2018-10-20 20:07:04 +08:00
parent b9dedd77dc
commit 6efa0d2bb6
3 changed files with 46 additions and 86 deletions

View file

@ -36,6 +36,31 @@ namespace TShockAPI
/// <summary>Bouncer is the TShock anti-hack and anti-cheat system.</summary> /// <summary>Bouncer is the TShock anti-hack and anti-cheat system.</summary>
internal sealed class Bouncer internal sealed class Bouncer
{ {
static Dictionary<byte, short> NPCAddBuffTimeMax = new Dictionary<byte, short>()
{
{ 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 }
};
/// <summary>Constructor call initializes Bouncer and related functionality.</summary> /// <summary>Constructor call initializes Bouncer and related functionality.</summary>
/// <returns>A new Bouncer.</returns> /// <returns>A new Bouncer.</returns>
internal Bouncer() internal Bouncer()
@ -484,52 +509,23 @@ namespace TShockAPI
return; return;
} }
if (!args.Player.HasPermission(Permissions.ignorenpcaddbuffdetection))
{
bool cheat = false; bool cheat = false;
if(TShock.NPCAddBuffTimeMax.ContainsKey(type)) if (NPCAddBuffTimeMax.ContainsKey(type))
{ {
if(time > TShock.NPCAddBuffTimeMax[type]) if (time > NPCAddBuffTimeMax[type])
{ {
cheat = true; cheat = true;
} }
if(npc.townNPC && npc.netID != NPCID.Guide && npc.netID != NPCID.Clothier) if (npc.townNPC && npc.netID != NPCID.Guide && npc.netID != NPCID.Clothier)
{ {
if(type != BuffID.Lovestruck && type != BuffID.Stinky && type != BuffID.DryadsWard && if (type != BuffID.Lovestruck && type != BuffID.Stinky && type != BuffID.DryadsWard &&
type != BuffID.Wet && type != BuffID.Slimed) type != BuffID.Wet && type != BuffID.Slimed)
{ {
cheat = true; 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 else
{ {
@ -542,7 +538,6 @@ namespace TShockAPI
args.Handled = true; args.Handled = true;
} }
} }
}
/// <summary>Handles Buff events.</summary> /// <summary>Handles Buff events.</summary>
/// <param name="sender">The object that triggered the event.</param> /// <param name="sender">The object that triggered the event.</param>

View file

@ -170,9 +170,6 @@ namespace TShockAPI
[Description("Prevents you from being disabled by abnormal MP.")] [Description("Prevents you from being disabled by abnormal MP.")]
public static readonly string ignoremp = "tshock.ignore.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 // tshock.item nodes
[Description("User can give items.")] [Description("User can give items.")]

View file

@ -131,9 +131,6 @@ namespace TShockAPI
/// </summary> /// </summary>
public static Dictionary<string, SecureRest.TokenData> RESTStartupTokens = new Dictionary<string, SecureRest.TokenData>(); public static Dictionary<string, SecureRest.TokenData> RESTStartupTokens = new Dictionary<string, SecureRest.TokenData>();
/// <summary>The longest time of buffs players can add to NPCs.</summary>
public static Dictionary<byte, short> NPCAddBuffTimeMax;
/// <summary>The TShock anti-cheat/anti-exploit system.</summary> /// <summary>The TShock anti-cheat/anti-exploit system.</summary>
internal Bouncer Bouncer; internal Bouncer Bouncer;
@ -326,7 +323,6 @@ namespace TShockAPI
RestApi = new SecureRest(Netplay.ServerIP, Config.RestApiPort); RestApi = new SecureRest(Netplay.ServerIP, Config.RestApiPort);
RestManager = new RestManager(RestApi); RestManager = new RestManager(RestApi);
RestManager.RegisterRestfulCommands(); RestManager.RegisterRestfulCommands();
NPCAddBuffTimeMax = InitNPCAddBuffTimeMax();
Bouncer = new Bouncer(); Bouncer = new Bouncer();
RegionSystem = new RegionHandler(Regions); RegionSystem = new RegionHandler(Regions);
@ -389,34 +385,6 @@ namespace TShockAPI
} }
} }
private Dictionary<byte, short> InitNPCAddBuffTimeMax()
{
var dict = new Dictionary<byte, short>();
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) protected void CrashReporter_HeapshotRequesting(object sender, EventArgs e)
{ {
foreach (TSPlayer player in TShock.Players) foreach (TSPlayer player in TShock.Players)