mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-22 18:15:31 +01:00
Script/Commands: Add some sanity checks to cast commands
Closes #15061
(cherry picked from commit 15dec9a76c)
This commit is contained in:
@@ -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,29 +183,15 @@ 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)
|
||||
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;
|
||||
}
|
||||
|
||||
target->CastSpell(target, spellId, false);
|
||||
|
||||
return true;
|
||||
@@ -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, " ");
|
||||
|
||||
Reference in New Issue
Block a user