aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid GirĂ³n <duhowpi@gmail.com>2015-07-12 23:08:59 +0200
committerShauren <shauren.trinity@gmail.com>2015-10-31 18:02:32 +0100
commitbc187f8760cc892340ec4d6b8dd29ff4aad8b883 (patch)
tree67233d3dcd9db12f8c0f81d47aa7f935ea39e5e1
parenta968595977b3c2f738a666cd270a00b75e54bf62 (diff)
Script/Commands: Add some sanity checks to cast commands
Closes #15061 (cherry picked from commit 15dec9a76ca56930c6764e8483cbf4ce8aae4f90)
-rw-r--r--src/server/scripts/Commands/cs_cast.cpp91
1 files changed, 34 insertions, 57 deletions
diff --git a/src/server/scripts/Commands/cs_cast.cpp b/src/server/scripts/Commands/cs_cast.cpp
index 59c919abd2b..f45e73b7c58 100644
--- a/src/server/scripts/Commands/cs_cast.cpp
+++ b/src/server/scripts/Commands/cs_cast.cpp
@@ -51,6 +51,25 @@ public:
return commandTable;
}
+ static bool CheckSpellExistsAndIsValid(ChatHandler* handler, uint32 spellId)
+ {
+ SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
+ if (!spellInfo)
+ {
+ handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
+ handler->SetSentErrorMessage(true);
+ return false;
+ }
+
+ if (!SpellMgr::IsSpellValid(spellInfo, handler->GetSession()->GetPlayer()))
+ {
+ handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
+ handler->SetSentErrorMessage(true);
+ return false;
+ }
+ return true;
+ }
+
static bool HandleCastCommand(ChatHandler* handler, char const* args)
{
if (!*args)
@@ -69,20 +88,8 @@ public:
if (!spellId)
return false;
- SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
- if (!spellInfo)
- {
- handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
- handler->SetSentErrorMessage(true);
+ if (!CheckSpellExistsAndIsValid(handler, spellId))
return false;
- }
-
- if (!SpellMgr::IsSpellValid(spellInfo, handler->GetSession()->GetPlayer()))
- {
- handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
- handler->SetSentErrorMessage(true);
- return false;
- }
char* triggeredStr = strtok(NULL, " ");
if (triggeredStr)
@@ -109,15 +116,13 @@ public:
return false;
}
- // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
uint32 spellId = handler->extractSpellIdFromLink((char*)args);
- if (!spellId || !sSpellMgr->GetSpellInfo(spellId))
- {
- handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
- handler->SetSentErrorMessage(true);
+ if (!spellId)
+ return false;
+
+ if (!CheckSpellExistsAndIsValid(handler, spellId))
return false;
- }
char* triggeredStr = strtok(NULL, " ");
if (triggeredStr)
@@ -144,20 +149,8 @@ public:
if (!spellId)
return false;
- SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
- if (!spellInfo)
- {
- handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
- handler->SetSentErrorMessage(true);
+ if (!CheckSpellExistsAndIsValid(handler, spellId))
return false;
- }
-
- if (!SpellMgr::IsSpellValid(spellInfo, handler->GetSession()->GetPlayer()))
- {
- handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
- handler->SetSentErrorMessage(true);
- return false;
- }
char* distStr = strtok(NULL, " ");
@@ -190,28 +183,14 @@ public:
return false;
Unit* target = handler->getSelectedUnit();
- if (!target)
- {
- handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
- handler->SetSentErrorMessage(true);
- return false;
- }
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
uint32 spellId = handler->extractSpellIdFromLink((char*)args);
if (!spellId)
return false;
- SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
- if (!spellInfo)
- return false;
-
- if (!SpellMgr::IsSpellValid(spellInfo, handler->GetSession()->GetPlayer()))
- {
- handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
- handler->SetSentErrorMessage(true);
+ if (!CheckSpellExistsAndIsValid(handler, spellId))
return false;
- }
target->CastSpell(target, spellId, false);
@@ -237,12 +216,11 @@ public:
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
uint32 spellId = handler->extractSpellIdFromLink((char*)args);
- if (!spellId || !sSpellMgr->GetSpellInfo(spellId))
- {
- handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
- handler->SetSentErrorMessage(true);
+ if (!spellId)
+ return false;
+
+ if (!CheckSpellExistsAndIsValid(handler, spellId))
return false;
- }
char* triggeredStr = strtok(NULL, " ");
if (triggeredStr)
@@ -271,12 +249,11 @@ public:
// number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
uint32 spellId = handler->extractSpellIdFromLink((char*)args);
- if (!spellId || !sSpellMgr->GetSpellInfo(spellId))
- {
- handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND);
- handler->SetSentErrorMessage(true);
+ if (!spellId)
+ return false;
+
+ if (!CheckSpellExistsAndIsValid(handler, spellId))
return false;
- }
char* posX = strtok(NULL, " ");
char* posY = strtok(NULL, " ");