Skip to content

Commit

Permalink
Scripts/Duel: prevent possible abuse in Duel Reset system
Browse files Browse the repository at this point in the history
Core/Script: review

Scripts/Duel: prevent possible abuse in Duel Reset system
  • Loading branch information
GigaDev90 committed Jan 17, 2016
1 parent 2e59554 commit 6a2e7d8
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions src/server/scripts/World/duel_reset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
#include "Player.h"
#include "Pet.h"
#include "SpellInfo.h"
#include <chrono>

class DuelResetScript : public PlayerScript
{
public:
DuelResetScript() : PlayerScript("DuelResetScript") { }

typedef std::chrono::system_clock Clock;

// Called when a duel starts (after 3s countdown)
void OnDuelStart(Player* player1, Player* player2) override
{
Expand All @@ -34,9 +37,8 @@ class DuelResetScript : public PlayerScript
player1->GetSpellHistory()->SaveCooldownStateBeforeDuel();
player2->GetSpellHistory()->SaveCooldownStateBeforeDuel();


ResetSpellCooldowns(player1);
ResetSpellCooldowns(player2);
ResetSpellCooldowns(player1, true);
ResetSpellCooldowns(player2, true);
}

// Health and mana reset
Expand Down Expand Up @@ -73,9 +75,8 @@ class DuelResetScript : public PlayerScript
// Cooldown restore
if (sWorld->getBoolConfig(CONFIG_RESET_DUEL_COOLDOWNS))
{

ResetSpellCooldowns(winner);
ResetSpellCooldowns(loser);
ResetSpellCooldowns(winner, false);
ResetSpellCooldowns(loser, false);

winner->GetSpellHistory()->RestoreCooldownStateAfterDuel();
loser->GetSpellHistory()->RestoreCooldownStateAfterDuel();
Expand All @@ -98,14 +99,34 @@ class DuelResetScript : public PlayerScript
}
}

static void ResetSpellCooldowns(Player* player)
static void ResetSpellCooldowns(Player* player, bool onStartDuel)
{
// remove cooldowns on spells that have < 10 min CD and has no onHold
player->GetSpellHistory()->ResetCooldowns([](SpellHistory::CooldownStorageType::iterator itr) -> bool
if (onStartDuel)
{
// remove cooldowns on spells that have < 10 min CD > 30 sec and has no onHold
player->GetSpellHistory()->ResetCooldowns([](SpellHistory::CooldownStorageType::iterator itr) -> bool
{
Clock::time_point now = Clock::now();
uint32 cooldownDuration = itr->second.CooldownEnd > now ? std::chrono::duration_cast<std::chrono::milliseconds>(itr->second.CooldownEnd - now).count() : 0;
SpellInfo const* spellInfo = sSpellMgr->EnsureSpellInfo(itr->first);
return spellInfo->RecoveryTime < 10 * MINUTE * IN_MILLISECONDS
&& spellInfo->CategoryRecoveryTime < 10 * MINUTE * IN_MILLISECONDS
&& !itr->second.OnHold
&& cooldownDuration > 0
&& ( spellInfo->RecoveryTime - cooldownDuration ) > (MINUTE / 2) * IN_MILLISECONDS;
}, true);
}
else
{
SpellInfo const* spellInfo = sSpellMgr->EnsureSpellInfo(itr->first);
return spellInfo->RecoveryTime < 10 * MINUTE * IN_MILLISECONDS && spellInfo->CategoryRecoveryTime < 10 * MINUTE * IN_MILLISECONDS && !itr->second.OnHold;
}, true);
// remove cooldowns on spells that have < 10 min CD and has no onHold
player->GetSpellHistory()->ResetCooldowns([](SpellHistory::CooldownStorageType::iterator itr) -> bool
{
SpellInfo const* spellInfo = sSpellMgr->EnsureSpellInfo(itr->first);
return spellInfo->RecoveryTime < 10 * MINUTE * IN_MILLISECONDS
&& spellInfo->CategoryRecoveryTime < 10 * MINUTE * IN_MILLISECONDS
&& !itr->second.OnHold;
}, true);
}

// pet cooldowns
if (Pet* pet = player->GetPet())
Expand Down

0 comments on commit 6a2e7d8

Please sign in to comment.