From bc187f8760cc892340ec4d6b8dd29ff4aad8b883 Mon Sep 17 00:00:00 2001 From: David GirĂ³n Date: Sun, 12 Jul 2015 23:08:59 +0200 Subject: Script/Commands: Add some sanity checks to cast commands Closes #15061 (cherry picked from commit 15dec9a76ca56930c6764e8483cbf4ce8aae4f90) --- src/server/scripts/Commands/cs_cast.cpp | 91 ++++++++++++--------------------- 1 file changed, 34 insertions(+), 57 deletions(-) (limited to 'src') 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, " "); -- cgit v1.2.3