Implement named args in item stack hack check

This addresses feedback from @QuiCM and @ijwu, who pointed out that C#
allows you to specify the arguments that go into a call during
invocation, which dramatically improves readability.
This commit is contained in:
Lucas Nicodemus 2017-12-21 23:00:09 -07:00
parent 6a7bc4540e
commit f93ffbc2e7
3 changed files with 13 additions and 13 deletions

View file

@ -83,7 +83,7 @@ namespace TShockAPI
if (!args.Player.HasPermission(Permissions.ignorestackhackdetection)) if (!args.Player.HasPermission(Permissions.ignorestackhackdetection))
{ {
args.Player.IsDisabledForStackDetection = args.Player.HasHackedItemStacks(true); args.Player.IsDisabledForStackDetection = args.Player.HasHackedItemStacks(shouldWarnPlayer: true);
} }
} }

View file

@ -308,9 +308,9 @@ namespace TShockAPI
} }
/// <summary>Checks to see if a player has hacked item stacks in their inventory, and messages them as it checks.</summary> /// <summary>Checks to see if a player has hacked item stacks in their inventory, and messages them as it checks.</summary>
/// <param name="shouldSendMessage">If the check should send a message to the player with the results of the check.</param> /// <param name="shouldWarnPlayer">If the check should send a message to the player with the results of the check.</param>
/// <returns>True if any stacks don't conform.</returns> /// <returns>True if any stacks don't conform.</returns>
public bool HasHackedItemStacks(bool shouldSendMessage = false) public bool HasHackedItemStacks(bool shouldWarnPlayer = false)
{ {
// Iterates through each inventory location a player has. // Iterates through each inventory location a player has.
// This section is sub divided into number ranges for what each range of slots corresponds to. // This section is sub divided into number ranges for what each range of slots corresponds to.
@ -340,7 +340,7 @@ namespace TShockAPI
if (inventory[i].stack > item.maxStack || inventory[i].stack < 0) if (inventory[i].stack > item.maxStack || inventory[i].stack < 0)
{ {
check = true; check = true;
if (shouldSendMessage) if (shouldWarnPlayer)
{ {
SendErrorMessage("Stack cheat detected. Remove item {0} ({1}) and then rejoin.", item.Name, inventory[i].stack); SendErrorMessage("Stack cheat detected. Remove item {0} ({1}) and then rejoin.", item.Name, inventory[i].stack);
} }
@ -360,7 +360,7 @@ namespace TShockAPI
if (armor[index].stack > item.maxStack || armor[index].stack < 0) if (armor[index].stack > item.maxStack || armor[index].stack < 0)
{ {
check = true; check = true;
if (shouldSendMessage) if (shouldWarnPlayer)
{ {
SendErrorMessage("Stack cheat detected. Remove armor {0} ({1}) and then rejoin.", item.Name, armor[index].stack); SendErrorMessage("Stack cheat detected. Remove armor {0} ({1}) and then rejoin.", item.Name, armor[index].stack);
} }
@ -380,7 +380,7 @@ namespace TShockAPI
if (dye[index].stack > item.maxStack || dye[index].stack < 0) if (dye[index].stack > item.maxStack || dye[index].stack < 0)
{ {
check = true; check = true;
if (shouldSendMessage) if (shouldWarnPlayer)
{ {
SendErrorMessage("Stack cheat detected. Remove dye {0} ({1}) and then rejoin.", item.Name, dye[index].stack); SendErrorMessage("Stack cheat detected. Remove dye {0} ({1}) and then rejoin.", item.Name, dye[index].stack);
} }
@ -400,7 +400,7 @@ namespace TShockAPI
if (miscEquips[index].stack > item.maxStack || miscEquips[index].stack < 0) if (miscEquips[index].stack > item.maxStack || miscEquips[index].stack < 0)
{ {
check = true; check = true;
if (shouldSendMessage) if (shouldWarnPlayer)
{ {
SendErrorMessage("Stack cheat detected. Remove item {0} ({1}) and then rejoin.", item.Name, miscEquips[index].stack); SendErrorMessage("Stack cheat detected. Remove item {0} ({1}) and then rejoin.", item.Name, miscEquips[index].stack);
} }
@ -420,7 +420,7 @@ namespace TShockAPI
if (miscDyes[index].stack > item.maxStack || miscDyes[index].stack < 0) if (miscDyes[index].stack > item.maxStack || miscDyes[index].stack < 0)
{ {
check = true; check = true;
if (shouldSendMessage) if (shouldWarnPlayer)
{ {
SendErrorMessage("Stack cheat detected. Remove item dye {0} ({1}) and then rejoin.", item.Name, miscDyes[index].stack); SendErrorMessage("Stack cheat detected. Remove item dye {0} ({1}) and then rejoin.", item.Name, miscDyes[index].stack);
} }
@ -441,7 +441,7 @@ namespace TShockAPI
if (piggy[index].stack > item.maxStack || piggy[index].stack < 0) if (piggy[index].stack > item.maxStack || piggy[index].stack < 0)
{ {
check = true; check = true;
if (shouldSendMessage) if (shouldWarnPlayer)
{ {
SendErrorMessage("Stack cheat detected. Remove piggy-bank item {0} ({1}) and then rejoin.", item.Name, piggy[index].stack); SendErrorMessage("Stack cheat detected. Remove piggy-bank item {0} ({1}) and then rejoin.", item.Name, piggy[index].stack);
} }
@ -462,7 +462,7 @@ namespace TShockAPI
if (safe[index].stack > item.maxStack || safe[index].stack < 0) if (safe[index].stack > item.maxStack || safe[index].stack < 0)
{ {
check = true; check = true;
if (shouldSendMessage) if (shouldWarnPlayer)
{ {
SendErrorMessage("Stack cheat detected. Remove safe item {0} ({1}) and then rejoin.", item.Name, safe[index].stack); SendErrorMessage("Stack cheat detected. Remove safe item {0} ({1}) and then rejoin.", item.Name, safe[index].stack);
} }
@ -482,7 +482,7 @@ namespace TShockAPI
if (trash.stack > item.maxStack) if (trash.stack > item.maxStack)
{ {
check = true; check = true;
if (shouldSendMessage) if (shouldWarnPlayer)
{ {
SendErrorMessage("Stack cheat detected. Remove trash item {0} ({1}) and then rejoin.", item.Name, trash.stack); SendErrorMessage("Stack cheat detected. Remove trash item {0} ({1}) and then rejoin.", item.Name, trash.stack);
} }
@ -503,7 +503,7 @@ namespace TShockAPI
if (forge[index].stack > item.maxStack || forge[index].stack < 0) if (forge[index].stack > item.maxStack || forge[index].stack < 0)
{ {
check = true; check = true;
if (shouldSendMessage) if (shouldWarnPlayer)
{ {
SendErrorMessage("Stack cheat detected. Remove Defender's Forge item {0} ({1}) and then rejoin.", item.Name, forge[index].stack); SendErrorMessage("Stack cheat detected. Remove Defender's Forge item {0} ({1}) and then rejoin.", item.Name, forge[index].stack);
} }

View file

@ -1098,7 +1098,7 @@ namespace TShockAPI
string check = "none"; string check = "none";
if (!player.HasPermission(Permissions.ignorestackhackdetection)) if (!player.HasPermission(Permissions.ignorestackhackdetection))
{ {
player.IsDisabledForStackDetection = player.HasHackedItemStacks(true); player.IsDisabledForStackDetection = player.HasHackedItemStacks(shouldWarnPlayer: true);
} }
check = "none"; check = "none";
// Please don't remove this for the time being; without it, players wearing banned equipment will only get debuffed once // Please don't remove this for the time being; without it, players wearing banned equipment will only get debuffed once