[8860] Prevent spam to clients by iupdates non-modifed threat list.

Also make more stricted access to threat list content.
This commit is contained in:
VladimirMangos 2009-11-23 01:38:43 +03:00
parent d63ea646a0
commit 67e070870b
6 changed files with 59 additions and 39 deletions

View file

@ -351,7 +351,8 @@ HostileReference* ThreatContainer::selectNextVictim(Creature* pAttacker, Hostile
//=================== ThreatManager ==========================
//============================================================
ThreatManager::ThreatManager(Unit* owner) : iCurrentVictim(NULL), iOwner(owner), iUpdateTimer(THREAT_UPDATE_INTERVAL)
ThreatManager::ThreatManager(Unit* owner)
: iCurrentVictim(NULL), iOwner(owner), iUpdateTimer(THREAT_UPDATE_INTERVAL), iUpdateNeed(false)
{
}
@ -363,6 +364,7 @@ void ThreatManager::clearReferences()
iThreatOfflineContainer.clearReferences();
iCurrentVictim = NULL;
iUpdateTimer.Reset(THREAT_UPDATE_INTERVAL);
iUpdateNeed = false;
}
//============================================================
@ -379,7 +381,7 @@ void ThreatManager::addThreat(Unit* pVictim, float pThreat, bool crit, SpellScho
return;
// not to GM
if(!pVictim || (pVictim->GetTypeId() == TYPEID_PLAYER && ((Player*)pVictim)->isGameMaster()) )
if (!pVictim || (pVictim->GetTypeId() == TYPEID_PLAYER && ((Player*)pVictim)->isGameMaster()) )
return;
// not to dead and not for dead
@ -391,8 +393,11 @@ void ThreatManager::addThreat(Unit* pVictim, float pThreat, bool crit, SpellScho
float threat = ThreatCalcHelper::calcThreat(pVictim, iOwner, pThreat, crit, schoolMask, pThreatSpell);
HostileReference* ref = iThreatContainer.addThreat(pVictim, threat);
// Ref is online
if (ref)
iUpdateNeed = true;
// Ref is not in the online refs, search the offline refs next
if(!ref)
else
ref = iThreatOfflineContainer.addThreat(pVictim, threat);
if(!ref) // there was no ref => create a new one
@ -401,6 +406,7 @@ void ThreatManager::addThreat(Unit* pVictim, float pThreat, bool crit, SpellScho
HostileReference* hostileReference = new HostileReference(pVictim, this, 0);
iThreatContainer.addReference(hostileReference);
hostileReference->addThreat(threat); // now we add the real threat
iUpdateNeed = true;
if(pVictim->GetTypeId() == TYPEID_PLAYER && ((Player*)pVictim)->isGameMaster())
hostileReference->setOnlineOfflineState(false); // GM is always offline
}
@ -411,6 +417,7 @@ void ThreatManager::addThreat(Unit* pVictim, float pThreat, bool crit, SpellScho
void ThreatManager::modifyThreatPercent(Unit *pVictim, int32 pPercent)
{
iThreatContainer.modifyThreatPercent(pVictim, pPercent);
iUpdateNeed = true;
}
//============================================================
@ -440,12 +447,17 @@ float ThreatManager::getThreat(Unit *pVictim, bool pAlsoSearchOfflineList)
void ThreatManager::tauntApply(Unit* pTaunter)
{
HostileReference* ref = iThreatContainer.getReferenceByTarget(pTaunter);
if(getCurrentVictim() && ref && (ref->getThreat() < getCurrentVictim()->getThreat()))
if(HostileReference* ref = iThreatContainer.getReferenceByTarget(pTaunter))
{
if(ref->getTempThreatModifyer() == 0.0f)
// Ok, temp threat is unused
ref->setTempThreat(getCurrentVictim()->getThreat());
if(getCurrentVictim() && (ref->getThreat() < getCurrentVictim()->getThreat()))
{
// Ok, temp threat is unused
if(ref->getTempThreatModifyer() == 0.0f)
{
ref->setTempThreat(getCurrentVictim()->getThreat());
iUpdateNeed = true;
}
}
}
}
@ -453,19 +465,26 @@ void ThreatManager::tauntApply(Unit* pTaunter)
void ThreatManager::tauntFadeOut(Unit *pTaunter)
{
HostileReference* ref = iThreatContainer.getReferenceByTarget(pTaunter);
if(ref)
if(HostileReference* ref = iThreatContainer.getReferenceByTarget(pTaunter))
{
ref->resetTempThreat();
iUpdateNeed = true;
}
}
//============================================================
void ThreatManager::setCurrentVictim(HostileReference* pHostileReference)
{
if (pHostileReference && pHostileReference != iCurrentVictim)
// including NULL==NULL case
if (pHostileReference == iCurrentVictim)
return;
if (pHostileReference)
iOwner->SendHighestThreatUpdate(pHostileReference);
iCurrentVictim = pHostileReference;
iUpdateNeed = true;
}
//============================================================
@ -494,6 +513,7 @@ void ThreatManager::processThreatEvent(ThreatRefStatusChangeEvent* threatRefStat
setDirty(true);
}
iThreatContainer.remove(hostileReference);
iUpdateNeed = true;
iThreatOfflineContainer.addReference(hostileReference);
}
else
@ -501,6 +521,7 @@ void ThreatManager::processThreatEvent(ThreatRefStatusChangeEvent* threatRefStat
if(getCurrentVictim() && hostileReference->getThreat() > (1.1f * getCurrentVictim()->getThreat()))
setDirty(true);
iThreatContainer.addReference(hostileReference);
iUpdateNeed = true;
iThreatOfflineContainer.remove(hostileReference);
}
break;
@ -512,7 +533,10 @@ void ThreatManager::processThreatEvent(ThreatRefStatusChangeEvent* threatRefStat
}
iOwner->SendThreatRemove(hostileReference);
if(hostileReference->isOnline())
{
iThreatContainer.remove(hostileReference);
iUpdateNeed = true;
}
else
iThreatOfflineContainer.remove(hostileReference);
break;
@ -521,7 +545,7 @@ void ThreatManager::processThreatEvent(ThreatRefStatusChangeEvent* threatRefStat
void ThreatManager::UpdateForClient(uint32 diff)
{
if (isThreatListEmpty())
if (!iUpdateNeed || isThreatListEmpty())
return;
iUpdateTimer.Update(diff);
@ -529,5 +553,6 @@ void ThreatManager::UpdateForClient(uint32 diff)
{
iOwner->SendThreatUpdate();
iUpdateTimer.Reset(THREAT_UPDATE_INTERVAL);
iUpdateNeed = false;
}
}