[9388] Implement max cast chain length for triggered spells.

* New config option MaxSpellCastsInChain ( 0 is disabled old way work )
* Check added for prevent stack overflow crashes in case infinity triggered casts sequences
  with more useful error output instead crash.
* Default config steeing in 10 casts expected to allow all possible in game proper cast chains.
This commit is contained in:
VladimirMangos 2010-02-15 12:10:08 +03:00
parent 574f396b0d
commit 58d188f21a
7 changed files with 45 additions and 1 deletions

View file

@ -2522,6 +2522,19 @@ void Spell::cast(bool skipCheck)
{
SetExecutedCurrently(true);
if (!m_caster->CheckAndIncreaseCastCounter())
{
if (m_triggeredByAuraSpell)
sLog.outError("Spell %u triggered by aura spell %u too deep in cast chain for cast. Cast not allowed for prevent overflow stack crash.");
else
sLog.outError("Spell %u too deep in cast chain for cast. Cast not allowed for prevent overflow stack crash.");
SendCastResult(SPELL_FAILED_ERROR);
finish(false);
SetExecutedCurrently(false);
return;
}
// update pointers base at GUIDs to prevent access to non-existed already object
UpdatePointers();
@ -2529,6 +2542,7 @@ void Spell::cast(bool skipCheck)
if(!m_targets.getUnitTarget() && m_targets.getUnitTargetGUID() && m_targets.getUnitTargetGUID() != m_caster->GetGUID())
{
cancel();
m_caster->DecreaseCastCounter();
SetExecutedCurrently(false);
return;
}
@ -2541,6 +2555,7 @@ void Spell::cast(bool skipCheck)
{
SendCastResult(castResult);
finish(false);
m_caster->DecreaseCastCounter();
SetExecutedCurrently(false);
return;
}
@ -2553,6 +2568,7 @@ void Spell::cast(bool skipCheck)
{
SendCastResult(castResult);
finish(false);
m_caster->DecreaseCastCounter();
SetExecutedCurrently(false);
return;
}
@ -2667,6 +2683,7 @@ void Spell::cast(bool skipCheck)
if(m_spellState == SPELL_STATE_FINISHED) // stop cast if spell marked as finish somewhere in FillTargetMap
{
m_caster->DecreaseCastCounter();
SetExecutedCurrently(false);
return;
}
@ -2699,6 +2716,7 @@ void Spell::cast(bool skipCheck)
handle_immediate();
}
m_caster->DecreaseCastCounter();
SetExecutedCurrently(false);
}