diff options
author | xinef1 <w.szyszko2@gmail.com> | 2017-03-02 02:19:25 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2019-08-17 20:04:14 +0200 |
commit | 60663d1374beef3103f4787152654034fa4a8897 (patch) | |
tree | 38e07d44442ad903a9729536942e8e253a072274 /src | |
parent | 98180ecdc179386270e93b80c0db8344b659557f (diff) |
Ensure that all actions are compared to fixed point in time (ie. world update start) (#18910)
- Actions will not be dependent on processing moment
- Increased GameObjects cooldown resolution to milliseconds, fixes arming time of traps to be exactly one second and not something from range (1000, 1999)
- Created GameTime namespace and UpdateTime class and moved there some code out of world
(cherrypicked from 7567cafec84080d26ea513242a1f540a823b8f9d)
Diffstat (limited to 'src')
42 files changed, 486 insertions, 182 deletions
diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp index 369bf95dd43..7d528d3ea27 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp @@ -25,6 +25,7 @@ #include "CharacterCache.h" #include "Common.h" #include "DatabaseEnv.h" +#include "GameTime.h" #include "Language.h" #include "Log.h" #include "Mail.h" @@ -598,7 +599,7 @@ bool AuctionHouseObject::RemoveAuction(AuctionEntry* auction) void AuctionHouseObject::Update() { - time_t curTime = sWorld->GetGameTime(); + time_t curTime = GameTime::GetGameTime(); ///- Handle expired auctions // If storage is empty, no need to update. next == NULL in this case. @@ -684,7 +685,7 @@ void AuctionHouseObject::BuildListOwnerItems(WorldPackets::AuctionHouse::Auction void AuctionHouseObject::BuildListAuctionItems(WorldPackets::AuctionHouse::AuctionListItemsResult& packet, Player* player, std::wstring const& searchedname, uint32 listfrom, uint8 levelmin, uint8 levelmax, bool usable, Optional<AuctionSearchFilters> const& filters, uint32 quality) { - time_t curTime = sWorld->GetGameTime(); + time_t curTime = GameTime::GetGameTime(); for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr) { @@ -752,7 +753,7 @@ void AuctionHouseObject::BuildListAuctionItems(WorldPackets::AuctionHouse::Aucti void AuctionHouseObject::BuildReplicate(WorldPackets::AuctionHouse::AuctionReplicateResponse& auctionReplicateResult, Player* player, uint32 global, uint32 cursor, uint32 tombstone, uint32 count) { - time_t curTime = sWorld->GetGameTime(); + time_t curTime = GameTime::GetGameTime(); auto throttleItr = GetAllThrottleMap.find(player->GetGUID()); if (throttleItr != GetAllThrottleMap.end()) diff --git a/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp b/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp index 113ba812ea6..f5ce158ac4f 100644 --- a/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp +++ b/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp @@ -21,6 +21,7 @@ #include "Config.h" #include "Containers.h" #include "DatabaseEnv.h" +#include "GameTime.h" #include "Item.h" #include "Log.h" #include "World.h" @@ -486,7 +487,7 @@ void AuctionHouseBot::Rebuild(bool all) for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctionHouse->GetAuctionsBegin(); itr != auctionHouse->GetAuctionsEnd(); ++itr) if (!itr->second->owner || sAuctionBotConfig->IsBotChar(itr->second->owner)) // ahbot auction if (all || itr->second->bid == 0) // expire now auction if no bid or forced - itr->second->expire_time = sWorld->GetGameTime(); + itr->second->expire_time = GameTime::GetGameTime(); } } diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp index 404c2308f58..0f8d3609f62 100644 --- a/src/server/game/Battlegrounds/Battleground.cpp +++ b/src/server/game/Battlegrounds/Battleground.cpp @@ -25,6 +25,7 @@ #include "CreatureTextMgr.h" #include "DatabaseEnv.h" #include "Formulas.h" +#include "GameTime.h" #include "GridNotifiersImpl.h" #include "Group.h" #include "Guild.h" @@ -274,7 +275,7 @@ inline void Battleground::_ProcessOfflineQueue() BattlegroundPlayerMap::iterator itr = m_Players.find(*(m_OfflineQueue.begin())); if (itr != m_Players.end()) { - if (itr->second.OfflineRemoveTime <= sWorld->GetGameTime()) + if (itr->second.OfflineRemoveTime <= GameTime::GetGameTime()) { RemovePlayerAtLeave(itr->first, true, true);// remove player from BG m_OfflineQueue.pop_front(); // remove from offline queue @@ -1169,7 +1170,7 @@ void Battleground::EventPlayerLoggedOut(Player* player) // player is correct pointer, it is checked in WorldSession::LogoutPlayer() m_OfflineQueue.push_back(player->GetGUID()); - m_Players[guid].OfflineRemoveTime = sWorld->GetGameTime() + MAX_OFFLINE_TIME; + m_Players[guid].OfflineRemoveTime = GameTime::GetGameTime() + MAX_OFFLINE_TIME; if (GetStatus() == STATUS_IN_PROGRESS) { // drop flag and handle other cleanups diff --git a/src/server/game/Battlegrounds/BattlegroundQueue.cpp b/src/server/game/Battlegrounds/BattlegroundQueue.cpp index e0232ac3760..57ff626f1b4 100644 --- a/src/server/game/Battlegrounds/BattlegroundQueue.cpp +++ b/src/server/game/Battlegrounds/BattlegroundQueue.cpp @@ -23,6 +23,7 @@ #include "BattlegroundPackets.h" #include "Chat.h" #include "DB2Stores.h" +#include "GameTime.h" #include "Group.h" #include "Language.h" #include "Log.h" @@ -141,7 +142,7 @@ GroupQueueInfo* BattlegroundQueue::AddGroup(Player* leader, Group* grp, Battlegr ginfo->ArenaTeamId = arenateamid; ginfo->IsRated = isRated; ginfo->IsInvitedToBGInstanceGUID = 0; - ginfo->JoinTime = getMSTime(); + ginfo->JoinTime = GameTime::GetGameTimeMS(); ginfo->RemoveInviteTime = 0; ginfo->Team = leader->GetTeam(); ginfo->ArenaTeamRating = ArenaRating; @@ -159,7 +160,7 @@ GroupQueueInfo* BattlegroundQueue::AddGroup(Player* leader, Group* grp, Battlegr index++; TC_LOG_DEBUG("bg.battleground", "Adding Group to BattlegroundQueue bgTypeId : %u, bracket_id : %u, index : %u", BgTypeId, bracketId, index); - uint32 lastOnlineTime = getMSTime(); + uint32 lastOnlineTime = GameTime::GetGameTimeMS(); //announce world (this don't need mutex) if (isRated && sWorld->getBoolConfig(CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE)) @@ -236,7 +237,7 @@ GroupQueueInfo* BattlegroundQueue::AddGroup(Player* leader, Group* grp, Battlegr void BattlegroundQueue::PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo* ginfo, BattlegroundBracketId bracket_id) { - uint32 timeInQueue = getMSTimeDiff(ginfo->JoinTime, getMSTime()); + uint32 timeInQueue = getMSTimeDiff(ginfo->JoinTime, GameTime::GetGameTimeMS()); uint8 team_index = TEAM_ALLIANCE; //default set to TEAM_ALLIANCE - or non rated arenas! if (!ginfo->ArenaType) { @@ -448,7 +449,7 @@ bool BattlegroundQueue::InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg, if (bg->isArena() && bg->isRated()) bg->SetArenaTeamIdForTeam(ginfo->Team, ginfo->ArenaTeamId); - ginfo->RemoveInviteTime = getMSTime() + INVITE_ACCEPT_WAIT_TIME; + ginfo->RemoveInviteTime = GameTime::GetGameTimeMS() + INVITE_ACCEPT_WAIT_TIME; // loop through the players for (std::map<ObjectGuid, PlayerQueueInfo*>::iterator itr = ginfo->Players.begin(); itr != ginfo->Players.end(); ++itr) @@ -639,7 +640,7 @@ bool BattlegroundQueue::CheckPremadeMatch(BattlegroundBracketId bracket_id, uint // this could be 2 cycles but i'm checking only first team in queue - it can cause problem - // if first is invited to BG and seconds timer expired, but we can ignore it, because players have only 80 seconds to click to enter bg // and when they click or after 80 seconds the queue info is removed from queue - uint32 time_before = getMSTime() - sWorld->getIntConfig(CONFIG_BATTLEGROUND_PREMADE_GROUP_WAIT_FOR_MATCH); + uint32 time_before = GameTime::GetGameTimeMS() - sWorld->getIntConfig(CONFIG_BATTLEGROUND_PREMADE_GROUP_WAIT_FOR_MATCH); for (uint32 i = 0; i < BG_TEAMS_COUNT; i++) { if (!m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE + i].empty()) @@ -920,7 +921,7 @@ void BattlegroundQueue::BattlegroundQueueUpdate(uint32 /*diff*/, BattlegroundTyp // the discard time is current_time - time_to_discard, teams that joined after that, will have their ratings taken into account // else leave the discard time on 0, this way all ratings will be discarded // this has to be signed value - when the server starts, this value would be negative and thus overflow - int32 discardTime = getMSTime() - sBattlegroundMgr->GetRatingDiscardTimer(); + int32 discardTime = GameTime::GetGameTimeMS() - sBattlegroundMgr->GetRatingDiscardTimer(); // we need to find 2 teams which will play next game GroupsQueueType::iterator itr_teams[BG_TEAMS_COUNT]; diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp index 36ddedb1f32..1093ea178cb 100644 --- a/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp @@ -21,6 +21,7 @@ #include "CreatureAI.h" #include "DB2Stores.h" #include "GameObject.h" +#include "GameTime.h" #include "Log.h" #include "Map.h" #include "ObjectAccessor.h" @@ -985,11 +986,11 @@ void BattlegroundSA::UpdateDemolisherSpawns() // Demolisher is not in list if (DemoliserRespawnList.find(i) == DemoliserRespawnList.end()) { - DemoliserRespawnList[i] = getMSTime()+30000; + DemoliserRespawnList[i] = GameTime::GetGameTimeMS() +30000; } else { - if (DemoliserRespawnList[i] < getMSTime()) + if (DemoliserRespawnList[i] < GameTime::GetGameTimeMS()) { Demolisher->Relocate(BG_SA_NpcSpawnlocs[i]); Demolisher->Respawn(); diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index ae8ccf2c582..d73dfeb1308 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -27,6 +27,7 @@ #include "DatabaseEnv.h" #include "Formulas.h" #include "GameEventMgr.h" +#include "GameTime.h" #include "GossipDef.h" #include "GridNotifiersImpl.h" #include "Group.h" @@ -2413,7 +2414,7 @@ bool Creature::CanCreatureAttack(Unit const* victim, bool /*force*/) const return true; // don't check distance to home position if recently damaged, this should include taunt auras - if (!isWorldBoss() && (GetLastDamagedTime() > sWorld->GetGameTime() || HasAuraType(SPELL_AURA_MOD_TAUNT))) + if (!isWorldBoss() && (GetLastDamagedTime() > GameTime::GetGameTime() || HasAuraType(SPELL_AURA_MOD_TAUNT))) return true; } @@ -3134,7 +3135,7 @@ void Creature::ReleaseFocus(Spell const* focusSpell, bool withDelay) ClearUnitState(UNIT_STATE_CANNOT_TURN); m_focusSpell = nullptr; - m_focusDelay = (!IsPet() && withDelay) ? getMSTime() : 0; // don't allow re-target right away to prevent visual bugs + m_focusDelay = (!IsPet() && withDelay) ? GameTime::GetGameTimeMS() : 0; // don't allow re-target right away to prevent visual bugs } void Creature::StartPickPocketRefillTimer() diff --git a/src/server/game/Entities/DynamicObject/DynamicObject.cpp b/src/server/game/Entities/DynamicObject/DynamicObject.cpp index 5947680d131..c3972316290 100644 --- a/src/server/game/Entities/DynamicObject/DynamicObject.cpp +++ b/src/server/game/Entities/DynamicObject/DynamicObject.cpp @@ -18,6 +18,7 @@ #include "DynamicObject.h" #include "Common.h" +#include "GameTime.h" #include "Log.h" #include "Map.h" #include "ObjectAccessor.h" @@ -103,7 +104,7 @@ bool DynamicObject::CreateDynamicObject(ObjectGuid::LowType guidlow, Unit* caste SetUpdateFieldValue(dynamicObjectData.ModifyValue(&UF::DynamicObjectData::SpellXSpellVisualID), spellXSpellVisualId); SetUpdateFieldValue(dynamicObjectData.ModifyValue(&UF::DynamicObjectData::SpellID), spell->Id); SetUpdateFieldValue(dynamicObjectData.ModifyValue(&UF::DynamicObjectData::Radius), radius); - SetUpdateFieldValue(dynamicObjectData.ModifyValue(&UF::DynamicObjectData::CastTime), getMSTime()); + SetUpdateFieldValue(dynamicObjectData.ModifyValue(&UF::DynamicObjectData::CastTime), GameTime::GetGameTimeMS()); if (IsWorldObject()) setActive(true); //must before add to map to be put in world container diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index 7b38072a9e5..34d4a38e9b3 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -25,6 +25,7 @@ #include "GameObjectAI.h" #include "GameObjectModel.h" #include "GameObjectPackets.h" +#include "GameTime.h" #include "GridNotifiersImpl.h" #include "Group.h" #include "GroupMgr.h" @@ -514,10 +515,10 @@ void GameObject::Update(uint32 diff) // Bombs if (goInfo->trap.charges == 2) // Hardcoded tooltip value - m_cooldownTime = time(NULL) + 10; + m_cooldownTime = GameTime::GetGameTimeMS() + 10 * IN_MILLISECONDS; else if (Unit* owner = GetOwner()) if (owner->IsInCombat()) - m_cooldownTime = time(NULL) + goInfo->trap.startDelay; + m_cooldownTime = GameTime::GetGameTimeMS() + goInfo->trap.startDelay * IN_MILLISECONDS; SetLootState(GO_READY); break; @@ -682,7 +683,7 @@ void GameObject::Update(uint32 diff) GameObjectTemplate const* goInfo = GetGOInfo(); if (goInfo->type == GAMEOBJECT_TYPE_TRAP) { - if (m_cooldownTime >= time(NULL)) + if (GameTime::GetGameTimeMS() < m_cooldownTime) break; // Type 2 (bomb) does not need to be triggered by a unit and despawns after casting its spell. @@ -749,11 +750,11 @@ void GameObject::Update(uint32 diff) { case GAMEOBJECT_TYPE_DOOR: case GAMEOBJECT_TYPE_BUTTON: - if (m_cooldownTime && (m_cooldownTime < time(NULL))) + if (m_cooldownTime && GameTime::GetGameTimeMS() >= m_cooldownTime) ResetDoorOrButton(); break; case GAMEOBJECT_TYPE_GOOBER: - if (m_cooldownTime < time(NULL)) + if (GameTime::GetGameTimeMS() >= m_cooldownTime) { RemoveFlag(GO_FLAG_IN_USE); @@ -792,7 +793,7 @@ void GameObject::Update(uint32 diff) CastSpell(target, goInfo->trap.spell); // Template value or 4 seconds - m_cooldownTime = time(NULL) + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4)); + m_cooldownTime = GameTime::GetGameTimeMS() + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4)) * IN_MILLISECONDS; if (goInfo->trap.charges == 1) SetLootState(GO_JUST_DEACTIVATED); @@ -1355,7 +1356,7 @@ void GameObject::UseDoorOrButton(uint32 time_to_restore, bool alternative /* = f SwitchDoorOrButton(true, alternative); SetLootState(GO_ACTIVATED, user); - m_cooldownTime = time_to_restore ? (time(NULL) + time_to_restore) : 0; + m_cooldownTime = GameTime::GetGameTimeMS() + time_to_restore; } void GameObject::SetGoArtKit(uint8 kit) @@ -1413,10 +1414,10 @@ void GameObject::Use(Unit* user) // If cooldown data present in template if (uint32 cooldown = GetGOInfo()->GetCooldown()) { - if (m_cooldownTime > sWorld->GetGameTime()) + if (m_cooldownTime > GameTime::GetGameTime()) return; - m_cooldownTime = sWorld->GetGameTime() + cooldown; + m_cooldownTime = GameTime::GetGameTimeMS() + cooldown * IN_MILLISECONDS; } switch (GetGoType()) @@ -1443,7 +1444,7 @@ void GameObject::Use(Unit* user) if (goInfo->trap.spell) CastSpell(user, goInfo->trap.spell); - m_cooldownTime = time(NULL) + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4)); // template or 4 seconds + m_cooldownTime = GameTime::GetGameTimeMS() + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4)) * IN_MILLISECONDS; // template or 4 seconds if (goInfo->trap.charges == 1) // Deactivate after trigger SetLootState(GO_JUST_DEACTIVATED); @@ -1590,7 +1591,7 @@ void GameObject::Use(Unit* user) else SetGoState(GO_STATE_ACTIVE); - m_cooldownTime = time(NULL) + info->GetAutoCloseTime(); + m_cooldownTime = GameTime::GetGameTimeMS() + info->GetAutoCloseTime(); // cast this spell later if provided spellId = info->goober.spell; diff --git a/src/server/game/Entities/GameObject/GameObjectData.h b/src/server/game/Entities/GameObject/GameObjectData.h index 7f8c6e8b977..0bc3dc7e454 100644 --- a/src/server/game/Entities/GameObject/GameObjectData.h +++ b/src/server/game/Entities/GameObject/GameObjectData.h @@ -816,7 +816,7 @@ struct GameObjectTemplate case GAMEOBJECT_TYPE_TRAPDOOR: autoCloseTime = trapdoor.autoClose; break; default: break; } - return autoCloseTime / IN_MILLISECONDS; // prior to 3.0.3, conversion was / 0x10000; + return autoCloseTime; // prior to 3.0.3, conversion was / 0x10000; } uint32 GetLootId() const diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index b6c7bb03166..41e5e62f395 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -24,6 +24,7 @@ #include "CinematicMgr.h" #include "Common.h" #include "Creature.h" +#include "GameTime.h" #include "GridNotifiersImpl.h" #include "InstanceScenario.h" #include "Item.h" @@ -413,7 +414,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, CreateObjectBits flags) const if (go && go->ToTransport()) // ServerTime *data << uint32(go->GetGOValue()->Transport.PathProgress); else - *data << uint32(getMSTime()); + *data << uint32(GameTime::GetGameTimeMS()); } if (flags.Vehicle) diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 89c6ea7d2ce..6fcbaf5b621 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -63,6 +63,7 @@ #include "Group.h" #include "GroupMgr.h" #include "GameTables.h" +#include "GameTime.h" #include "Guild.h" #include "GuildMgr.h" #include "InstancePackets.h" @@ -317,7 +318,7 @@ Player::Player(WorldSession* session) : Unit(true), m_sceneMgr(this) m_timeSyncTimer = 0; m_timeSyncClient = 0; - m_timeSyncServer = 0; + m_timeSyncServer = GameTime::GetGameTimeMS(); for (uint8 i = 0; i < MAX_POWERS_PER_CLASS; ++i) m_powerFraction[i] = 0; @@ -1033,7 +1034,7 @@ void Player::Update(uint32 p_time) _cinematicMgr->m_cinematicDiff += p_time; if (_cinematicMgr->m_activeCinematicCameraId != 0 && GetMSTimeDiffToNow(_cinematicMgr->m_lastCinematicCheck) > CINEMATIC_UPDATEDIFF) { - _cinematicMgr->m_lastCinematicCheck = getMSTime(); + _cinematicMgr->m_lastCinematicCheck = GameTime::GetGameTimeMS(); _cinematicMgr->UpdateCinematicLocation(p_time); } @@ -3473,7 +3474,7 @@ uint32 Player::GetNextResetTalentsCost() const return 10*GOLD; else { - uint64 months = (sWorld->GetGameTime() - GetTalentResetTime())/MONTH; + uint64 months = (GameTime::GetGameTime() - GetTalentResetTime())/MONTH; if (months > 0) { // This cost will be reduced by a rate of 5 gold per month @@ -19121,10 +19122,10 @@ void Player::_LoadQuestStatus(PreparedQueryResult result) { AddTimedQuest(quest_id); - if (quest_time <= sWorld->GetGameTime()) + if (quest_time <= GameTime::GetGameTime()) questStatusData.Timer = 1; else - questStatusData.Timer = uint32((quest_time - sWorld->GetGameTime()) * IN_MILLISECONDS); + questStatusData.Timer = uint32((quest_time - GameTime::GetGameTime()) * IN_MILLISECONDS); } else quest_time = 0; @@ -20735,7 +20736,7 @@ void Player::_SaveQuestStatus(CharacterDatabaseTransaction& trans) stmt->setUInt64(0, GetGUID().GetCounter()); stmt->setUInt32(1, statusItr->first); stmt->setUInt8(2, uint8(qData.Status)); - stmt->setUInt32(3, uint32(qData.Timer / IN_MILLISECONDS+ sWorld->GetGameTime())); + stmt->setUInt32(3, uint32(qData.Timer / IN_MILLISECONDS+ GameTime::GetGameTime())); trans->Append(stmt); // Save objectives @@ -23704,8 +23705,8 @@ void Player::SendInitialPacketsBeforeAddToMap() static float const TimeSpeed = 0.01666667f; WorldPackets::Misc::LoginSetTimeSpeed loginSetTimeSpeed; loginSetTimeSpeed.NewSpeed = TimeSpeed; - loginSetTimeSpeed.GameTime = sWorld->GetGameTime(); - loginSetTimeSpeed.ServerTime = sWorld->GetGameTime(); + loginSetTimeSpeed.GameTime = GameTime::GetGameTime(); + loginSetTimeSpeed.ServerTime = GameTime::GetGameTime(); loginSetTimeSpeed.GameTimeHolidayOffset = 0; /// @todo loginSetTimeSpeed.ServerTimeHolidayOffset = 0; /// @todo SendDirectMessage(loginSetTimeSpeed.Write()); @@ -23891,7 +23892,7 @@ void Player::ApplyEquipCooldown(Item* pItem) if (proto->GetFlags() & ITEM_FLAG_NO_EQUIP_COOLDOWN) return; - std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); + std::chrono::steady_clock::time_point now = GameTime::GetGameTimeSteadyPoint(); for (uint8 i = 0; i < proto->Effects.size(); ++i) { ItemEffectEntry const* effectData = proto->Effects[i]; @@ -27072,7 +27073,7 @@ void Player::ResetTimeSync() { m_timeSyncTimer = 0; m_timeSyncClient = 0; - m_timeSyncServer = getMSTime(); + m_timeSyncServer = GameTime::GetGameTimeMS(); } void Player::SendTimeSync() @@ -27085,7 +27086,7 @@ void Player::SendTimeSync() // Schedule next sync in 10 sec m_timeSyncTimer = 10000; - m_timeSyncServer = getMSTime(); + m_timeSyncServer = GameTime::GetGameTimeMS(); if (m_timeSyncQueue.size() > 3) TC_LOG_ERROR("network", "Player::SendTimeSync: Did not receive CMSG_TIME_SYNC_RESP for over 30 seconds from '%s' (%s), possible cheater", diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index ffe8df10a6a..ce88d138cee 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -35,6 +35,7 @@ #include "CreatureAIImpl.h" #include "CreatureGroups.h" #include "Formulas.h" +#include "GameTime.h" #include "GridNotifiersImpl.h" #include "Group.h" #include "InstanceSaveMgr.h" @@ -884,7 +885,7 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam { // Part of Evade mechanics. DoT's and Thorns / Retribution Aura do not contribute to this if (damagetype != DOT && damage > 0 && !victim->GetOwnerGUID().IsPlayer() && (!spellProto || !spellProto->HasAura(GetMap()->GetDifficultyID(), SPELL_AURA_DAMAGE_SHIELD))) - victim->ToCreature()->SetLastDamagedTime(sWorld->GetGameTime() + MAX_AGGRO_RESET_TIME); + victim->ToCreature()->SetLastDamagedTime(GameTime::GetGameTime() + MAX_AGGRO_RESET_TIME); victim->AddThreat(this, float(damage), damageSchoolMask, spellProto); } @@ -9245,7 +9246,7 @@ void Unit::ApplyDiminishingAura(DiminishingGroup group, bool apply) // Remember time after last aura from group removed if (!diminish.stack) - diminish.hitTime = getMSTime(); + diminish.hitTime = GameTime::GetGameTimeMS(); } } @@ -10304,7 +10305,7 @@ void Unit::ProcSkillsAndReactives(bool isVictim, Unit* procTarget, uint32 typeMa void Unit::GetProcAurasTriggeredOnEvent(AuraApplicationProcContainer& aurasTriggeringProc, AuraApplicationList* procAuras, ProcEventInfo& eventInfo) { - std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); + std::chrono::steady_clock::time_point now = GameTime::GetGameTimeSteadyPoint(); // use provided list of auras which can proc if (procAuras) diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp index cc8cd627804..4861bbdeeb8 100644 --- a/src/server/game/Handlers/CharacterHandler.cpp +++ b/src/server/game/Handlers/CharacterHandler.cpp @@ -35,6 +35,7 @@ #include "DB2Stores.h" #include "EquipmentSetPackets.h" #include "GameObject.h" +#include "GameTime.h" #include "GitRevision.h" #include "Group.h" #include "Guild.h" @@ -920,7 +921,7 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder) WorldPackets::ClientConfig::AccountDataTimes accountDataTimes; accountDataTimes.PlayerGuid = playerGuid; - accountDataTimes.ServerTime = uint32(sWorld->GetGameTime()); + accountDataTimes.ServerTime = uint32(GameTime::GetGameTime()); for (uint32 i = 0; i < NUM_ACCOUNT_DATA_TYPES; ++i) accountDataTimes.AccountTimes[i] = uint32(GetAccountData(AccountDataType(i))->Time); @@ -1030,7 +1031,7 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder) loginStmt->setUInt32(0, GetAccountId()); LoginDatabase.Execute(loginStmt); - pCurrChar->SetInGameTime(getMSTime()); + pCurrChar->SetInGameTime(GameTime::GetGameTimeMS()); // announce group about member online (must be after add to player list to receive announce to self) if (Group* group = pCurrChar->GetGroup()) diff --git a/src/server/game/Handlers/HotfixHandler.cpp b/src/server/game/Handlers/HotfixHandler.cpp index eee0380e4d6..e052b36e3f6 100644 --- a/src/server/game/Handlers/HotfixHandler.cpp +++ b/src/server/game/Handlers/HotfixHandler.cpp @@ -18,6 +18,7 @@ #include "WorldSession.h" #include "Containers.h" #include "DB2Stores.h" +#include "GameTime.h" #include "HotfixPackets.h" #include "Log.h" #include "ObjectDefines.h" @@ -41,7 +42,7 @@ void WorldSession::HandleDBQueryBulk(WorldPackets::Hotfix::DBQueryBulk& dbQuery) if (store->HasRecord(record.RecordID)) { dbReply.Allow = true; - dbReply.Timestamp = sWorld->GetGameTime(); + dbReply.Timestamp = GameTime::GetGameTime(); store->WriteRecord(record.RecordID, GetSessionDbcLocale(), dbReply.Data); } else diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp index d48e8fa146c..e7797c17f7a 100644 --- a/src/server/game/Handlers/MiscHandler.cpp +++ b/src/server/game/Handlers/MiscHandler.cpp @@ -29,6 +29,7 @@ #include "Corpse.h" #include "DatabaseEnv.h" #include "DB2Stores.h" +#include "GameTime.h" #include "GossipDef.h" #include "Group.h" #include "Guild.h" @@ -850,7 +851,7 @@ void WorldSession::HandleTimeSyncResponse(WorldPackets::Misc::TimeSyncResponse& TC_LOG_DEBUG("network", "Time sync received: counter %u, client ticks %u, time since last sync %u", packet.SequenceIndex, packet.ClientTime, packet.ClientTime - _player->m_timeSyncClient); - uint32 ourTicks = packet.ClientTime + (getMSTime() - _player->m_timeSyncServer); + uint32 ourTicks = packet.ClientTime + (GameTime::GetGameTimeMS() - _player->m_timeSyncServer); // diff should be small TC_LOG_DEBUG("network", "Our ticks: %u, diff %u, latency %u", ourTicks, ourTicks - packet.ClientTime, GetLatency()); diff --git a/src/server/game/Handlers/MovementHandler.cpp b/src/server/game/Handlers/MovementHandler.cpp index 40609faa567..9ff173b8add 100644 --- a/src/server/game/Handlers/MovementHandler.cpp +++ b/src/server/game/Handlers/MovementHandler.cpp @@ -20,6 +20,7 @@ #include "Battleground.h" #include "Common.h" #include "Corpse.h" +#include "GameTime.h" #include "Garrison.h" #include "InstancePackets.h" #include "InstanceSaveMgr.h" @@ -388,7 +389,7 @@ void WorldSession::HandleMovementOpcode(OpcodeClient opcode, MovementInfo& movem plrMover->SetInWater(!plrMover->IsInWater() || plrMover->GetMap()->IsUnderWater(plrMover->GetPhaseShift(), movementInfo.pos.GetPositionX(), movementInfo.pos.GetPositionY(), movementInfo.pos.GetPositionZ())); } - uint32 mstime = getMSTime(); + uint32 mstime = GameTime::GetGameTimeMS(); /*----------------------*/ if (m_clientTimeDelay == 0) m_clientTimeDelay = mstime - movementInfo.time; diff --git a/src/server/game/Maps/MapScripts.cpp b/src/server/game/Maps/MapScripts.cpp index f6fed3dad9a..2e886a287c4 100644 --- a/src/server/game/Maps/MapScripts.cpp +++ b/src/server/game/Maps/MapScripts.cpp @@ -18,6 +18,7 @@ #include "Map.h" #include "CellImpl.h" +#include "GameTime.h" #include "GossipDef.h" #include "GridNotifiers.h" #include "Item.h" @@ -56,7 +57,7 @@ void Map::ScriptsStart(ScriptMapMap const& scripts, uint32 id, Object* source, O sa.ownerGUID = ownerGUID; sa.script = &iter->second; - m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(sWorld->GetGameTime() + iter->first), sa)); + m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(GameTime::GetGameTime() + iter->first), sa)); if (iter->first == 0) immedScript = true; @@ -86,7 +87,7 @@ void Map::ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* sou sa.ownerGUID = ownerGUID; sa.script = &script; - m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(sWorld->GetGameTime() + delay), sa)); + m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(GameTime::GetGameTime() + delay), sa)); sMapMgr->IncreaseScheduledScriptsCount(); @@ -300,7 +301,7 @@ void Map::ScriptsProcess() ///- Process overdue queued scripts ScriptScheduleMap::iterator iter = m_scriptSchedule.begin(); // ok as multimap is a *sorted* associative container - while (!m_scriptSchedule.empty() && (iter->first <= sWorld->GetGameTime())) + while (!m_scriptSchedule.empty() && (iter->first <= GameTime::GetGameTime())) { ScriptAction const& step = iter->second; diff --git a/src/server/game/Spells/Auras/SpellAuras.cpp b/src/server/game/Spells/Auras/SpellAuras.cpp index 8a1d43d9c6a..d79594b22cc 100644 --- a/src/server/game/Spells/Auras/SpellAuras.cpp +++ b/src/server/game/Spells/Auras/SpellAuras.cpp @@ -1850,7 +1850,7 @@ float Aura::CalcPPMProcChance(Unit* actor) const float ppm = m_spellInfo->CalcProcPPM(actor, m_castItemLevel); float averageProcInterval = 60.0f / ppm; - std::chrono::steady_clock::time_point currentTime = std::chrono::steady_clock::now(); + std::chrono::steady_clock::time_point currentTime = GameTime::GetGameTimeSteadyPoint(); float secondsSinceLastAttempt = std::min(std::chrono::duration_cast<FSeconds>(currentTime - m_lastProcAttemptTime).count(), 10.0f); float secondsSinceLastProc = std::min(std::chrono::duration_cast<FSeconds>(currentTime - m_lastProcSuccessTime).count(), 1000.0f); diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 8e7dcfa4fbd..61f6a669415 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -2256,7 +2256,7 @@ void Spell::DoAllEffectOnTarget(TargetInfo* target) if (unit->IsAlive() != target->alive) return; - if (getState() == SPELL_STATE_DELAYED && !m_spellInfo->IsPositive() && (getMSTime() - target->timeDelay) <= unit->m_lastSanctuaryTime) + if (getState() == SPELL_STATE_DELAYED && !m_spellInfo->IsPositive() && (GameTime::GetGameTimeMS() - target->timeDelay) <= unit->m_lastSanctuaryTime) return; // No missinfo in that case // Get original caster (if exist) and calculate damage/healing from him data diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index cf365e19e0c..7ac90a7fa64 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -35,6 +35,7 @@ #include "DynamicObject.h" #include "GameObject.h" #include "GameObjectAI.h" +#include "GameTime.h" #include "Garrison.h" #include "GossipDef.h" #include "GridNotifiers.h" @@ -3544,7 +3545,7 @@ void Spell::EffectSanctuary(SpellEffIndex /*effIndex*/) ++itr; } - unitTarget->m_lastSanctuaryTime = getMSTime(); + unitTarget->m_lastSanctuaryTime = GameTime::GetGameTimeMS(); // Vanish allows to remove all threat and cast regular stealth so other spells can be used if (m_caster->GetTypeId() == TYPEID_PLAYER diff --git a/src/server/game/Spells/SpellHistory.cpp b/src/server/game/Spells/SpellHistory.cpp index bb9953a30cd..90afeb11a38 100644 --- a/src/server/game/Spells/SpellHistory.cpp +++ b/src/server/game/Spells/SpellHistory.cpp @@ -210,7 +210,7 @@ void SpellHistory::SaveToDB(CharacterDatabaseTransaction& trans) void SpellHistory::Update() { - Clock::time_point now = Clock::now(); + Clock::time_point now = GameTime::GetGameTimeSystemPoint(); for (auto itr = _categoryCooldowns.begin(); itr != _categoryCooldowns.end();) { if (itr->second->CategoryEnd < now) @@ -293,7 +293,7 @@ void SpellHistory::WritePacket(WorldPackets::Spells::SendSpellHistory* sendSpell { sendSpellHistory->Entries.reserve(_spellCooldowns.size()); - Clock::time_point now = Clock::now(); + Clock::time_point now = GameTime::GetGameTimeSystemPoint(); for (auto const& p : _spellCooldowns) { WorldPackets::Spells::SpellHistoryEntry historyEntry; @@ -326,7 +326,7 @@ void SpellHistory::WritePacket(WorldPackets::Spells::SendSpellCharges* sendSpell { sendSpellCharges->Entries.reserve(_categoryCharges.size()); - Clock::time_point now = Clock::now(); + Clock::time_point now = GameTime::GetGameTimeSystemPoint(); for (auto const& p : _categoryCharges) { if (!p.second.empty()) @@ -347,7 +347,7 @@ void SpellHistory::WritePacket(WorldPackets::Spells::SendSpellCharges* sendSpell template<> void SpellHistory::WritePacket(WorldPackets::Pet::PetSpells* petSpells) const { - Clock::time_point now = Clock::now(); + Clock::time_point now = GameTime::GetGameTimeSystemPoint(); petSpells->Cooldowns.reserve(_spellCooldowns.size()); for (auto const& p : _spellCooldowns) @@ -401,7 +401,7 @@ void SpellHistory::StartCooldown(SpellInfo const* spellInfo, uint32 itemId, Spel GetCooldownDurations(spellInfo, itemId, &cooldown, &categoryId, &categoryCooldown); - Clock::time_point curTime = Clock::now(); + Clock::time_point curTime = GameTime::GetGameTimeSystemPoint(); Clock::time_point catrecTime; Clock::time_point recTime; bool needsCooldownPacket = false; @@ -556,7 +556,7 @@ void SpellHistory::ModifyCooldown(uint32 spellId, Clock::duration offset) if (!offset.count() || itr == _spellCooldowns.end()) return; - Clock::time_point now = Clock::now(); + Clock::time_point now = GameTime::GetGameTimeSystemPoint(); if (itr->second.CooldownEnd + offset > now) itr->second.CooldownEnd += offset; @@ -651,7 +651,7 @@ uint32 SpellHistory::GetRemainingCooldown(SpellInfo const* spellInfo) const end = catItr->second->CategoryEnd; } - Clock::time_point now = Clock::now(); + Clock::time_point now = GameTime::GetGameTimeSystemPoint(); if (end < now) return 0; @@ -661,7 +661,7 @@ uint32 SpellHistory::GetRemainingCooldown(SpellInfo const* spellInfo) const void SpellHistory::LockSpellSchool(SpellSchoolMask schoolMask, uint32 lockoutTime) { - Clock::time_point now = Clock::now(); + Clock::time_point now = GameTime::GetGameTimeSystemPoint(); Clock::time_point lockoutEnd = now + std::chrono::duration_cast<Clock::duration>(std::chrono::milliseconds(lockoutTime)); for (uint32 i = 0; i < MAX_SPELL_SCHOOL; ++i) if (SpellSchoolMask(1 << i) & schoolMask) @@ -714,7 +714,7 @@ void SpellHistory::LockSpellSchool(SpellSchoolMask schoolMask, uint32 lockoutTim bool SpellHistory::IsSchoolLocked(SpellSchoolMask schoolMask) const { - Clock::time_point now = Clock::now(); + Clock::time_point now = GameTime::GetGameTimeSystemPoint(); for (uint32 i = 0; i < MAX_SPELL_SCHOOL; ++i) if (SpellSchoolMask(1 << i) & schoolMask) if (_schoolLockouts[i] > now) @@ -734,7 +734,7 @@ bool SpellHistory::ConsumeCharge(uint32 chargeCategoryId) Clock::time_point recoveryStart; std::deque<ChargeEntry>& charges = _categoryCharges[chargeCategoryId]; if (charges.empty()) - recoveryStart = Clock::now(); + recoveryStart = GameTime::GetGameTimeSystemPoint(); else recoveryStart = charges.back().RechargeEnd; @@ -949,7 +949,7 @@ void SpellHistory::RestoreCooldownStateAfterDuel() for (auto const& c : _spellCooldowns) { - Clock::time_point now = Clock::now(); + Clock::time_point now = GameTime::GetGameTimeSystemPoint(); uint32 cooldownDuration = uint32(c.second.CooldownEnd > now ? std::chrono::duration_cast<std::chrono::milliseconds>(c.second.CooldownEnd - now).count() : 0); // cooldownDuration must be between 0 and 10 minutes in order to avoid any visual bugs diff --git a/src/server/game/Spells/SpellHistory.h b/src/server/game/Spells/SpellHistory.h index 8aa61889074..4ca2c35ee1b 100644 --- a/src/server/game/Spells/SpellHistory.h +++ b/src/server/game/Spells/SpellHistory.h @@ -20,6 +20,7 @@ #include "SharedDefines.h" #include "DatabaseEnvFwd.h" +#include "GameTime.h" #include <chrono> #include <deque> #include <vector> @@ -95,7 +96,7 @@ public: template<class Type, class Period> void AddCooldown(uint32 spellId, uint32 itemId, std::chrono::duration<Type, Period> cooldownDuration) { - Clock::time_point now = Clock::now(); + Clock::time_point now = GameTime::GetGameTimeSystemPoint(); AddCooldown(spellId, itemId, now + std::chrono::duration_cast<Clock::duration>(cooldownDuration), 0, now); } diff --git a/src/server/game/Time/GameTime.cpp b/src/server/game/Time/GameTime.cpp new file mode 100644 index 00000000000..8884d4612be --- /dev/null +++ b/src/server/game/Time/GameTime.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/> + + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "GameTime.h" +#include "Timer.h" + +namespace GameTime +{ + time_t const StartTime = time(nullptr); + + time_t GameTime = 0; + uint32 GameMSTime = 0; + + std::chrono::system_clock::time_point GameTimeSystemPoint = std::chrono::system_clock::time_point::min(); + std::chrono::steady_clock::time_point GameTimeSteadyPoint = std::chrono::steady_clock::time_point::min(); + + time_t GetStartTime() + { + return StartTime; + } + + time_t GetGameTime() + { + return GameTime; + } + + uint32 GetGameTimeMS() + { + return GameMSTime; + } + + std::chrono::system_clock::time_point GetGameTimeSystemPoint() + { + return GameTimeSystemPoint; + } + + std::chrono::steady_clock::time_point GetGameTimeSteadyPoint() + { + return GameTimeSteadyPoint; + } + + uint32 GetUptime() + { + return uint32(GameTime - StartTime); + } + + void UpdateGameTimers() + { + GameTime = time(nullptr); + GameMSTime = getMSTime(); + GameTimeSystemPoint = std::chrono::system_clock::now(); + GameTimeSteadyPoint = std::chrono::steady_clock::now(); + } +} diff --git a/src/server/game/Time/GameTime.h b/src/server/game/Time/GameTime.h new file mode 100644 index 00000000000..2b130962a02 --- /dev/null +++ b/src/server/game/Time/GameTime.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __GAMETIME_H +#define __GAMETIME_H + +#include "Define.h" + +#include <chrono> + +namespace GameTime +{ + // Server start time + time_t GetStartTime(); + + // Current server time (unix) in seconds + time_t GetGameTime(); + + // Milliseconds since server start + uint32 GetGameTimeMS(); + + /// Current chrono system_clock time point + std::chrono::system_clock::time_point GetGameTimeSystemPoint(); + + /// Current chrono steady_clock time point + std::chrono::steady_clock::time_point GetGameTimeSteadyPoint(); + + /// Uptime (in secs) + uint32 GetUptime(); + + void UpdateGameTimers(); +}; + +#endif diff --git a/src/server/game/Time/UpdateTime.cpp b/src/server/game/Time/UpdateTime.cpp new file mode 100644 index 00000000000..1cc9fd1c507 --- /dev/null +++ b/src/server/game/Time/UpdateTime.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/> + + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "UpdateTime.h" +#include "Timer.h" +#include "Config.h" +#include "Log.h" + +// create instance +WorldUpdateTime sWorldUpdateTime; + +UpdateTime::UpdateTime() +{ + _averageUpdateTime = 0; + _totalUpdateTime = 0; + _updateTimeTableIndex = 0; + _maxUpdateTime = 0; + _maxUpdateTimeOfLastTable = 0; + _maxUpdateTimeOfCurrentTable = 0; + + _updateTimeDataTable = { }; +} + +uint32 UpdateTime::GetAverageUpdateTime() const +{ + return _averageUpdateTime; +} + +uint32 UpdateTime::GetTimeWeightedAverageUpdateTime() const +{ + uint32 sum = 0, weightsum = 0; + for (uint32 diff : _updateTimeDataTable) + { + sum += diff * diff; + weightsum += diff; + } + return sum / weightsum; +} + +uint32 UpdateTime::GetMaxUpdateTime() const +{ + return _maxUpdateTime; +} + +uint32 UpdateTime::GetMaxUpdateTimeOfCurrentTable() const +{ + return std::max(_maxUpdateTimeOfCurrentTable, _maxUpdateTimeOfLastTable); +} + +uint32 UpdateTime::GetLastUpdateTime() const +{ + return _updateTimeDataTable[_updateTimeTableIndex != 0 ? _updateTimeTableIndex - 1 : _updateTimeDataTable.size() - 1]; +} + +void UpdateTime::UpdateWithDiff(uint32 diff) +{ + _totalUpdateTime = _totalUpdateTime - _updateTimeDataTable[_updateTimeTableIndex] + diff; + _updateTimeDataTable[_updateTimeTableIndex] = diff; + + if (diff > _maxUpdateTime) + _maxUpdateTime = diff; + + if (diff > _maxUpdateTimeOfCurrentTable) + _maxUpdateTimeOfCurrentTable = diff; + + if (++_updateTimeTableIndex >= _updateTimeDataTable.size()) + { + _updateTimeTableIndex = 0; + _maxUpdateTimeOfLastTable = _maxUpdateTimeOfCurrentTable; + _maxUpdateTimeOfCurrentTable = 0; + } + + if (_updateTimeDataTable[_updateTimeDataTable.size() - 1]) + _averageUpdateTime = _totalUpdateTime / _updateTimeDataTable.size(); + else if (_updateTimeTableIndex) + _averageUpdateTime = _totalUpdateTime / _updateTimeTableIndex; +} + +void UpdateTime::RecordUpdateTimeReset() +{ + _recordedTime = getMSTime(); +} + +void UpdateTime::_RecordUpdateTimeDuration(std::string const& text, uint32 minUpdateTime) +{ + uint32 thisTime = getMSTime(); + uint32 diff = getMSTimeDiff(_recordedTime, thisTime); + + if (diff > minUpdateTime) + TC_LOG_INFO("misc", "Recored Update Time of %s: %u.", text.c_str(), diff); + + _recordedTime = thisTime; +} + +void WorldUpdateTime::LoadFromConfig() +{ + _recordUpdateTimeInverval = sConfigMgr->GetIntDefault("RecordUpdateTimeDiffInterval", 60000); + _recordUpdateTimeMin = sConfigMgr->GetIntDefault("MinRecordUpdateTimeDiff", 100); +} + +void WorldUpdateTime::SetRecordUpdateTimeInterval(uint32 t) +{ + _recordUpdateTimeInverval = t; +} + +void WorldUpdateTime::RecordUpdateTime(uint32 gameTimeMs, uint32 diff, uint32 sessionCount) +{ + if (_recordUpdateTimeInverval > 0 && diff > _recordUpdateTimeMin) + { + if (getMSTimeDiff(_lastRecordTime, gameTimeMs) > _recordUpdateTimeInverval) + { + TC_LOG_DEBUG("misc", "Update time diff: %u. Players online: %u.", GetAverageUpdateTime(), sessionCount); + _lastRecordTime = gameTimeMs; + } + } +} + +void WorldUpdateTime::RecordUpdateTimeDuration(std::string const& text) +{ + _RecordUpdateTimeDuration(text, _recordUpdateTimeMin); +} diff --git a/src/server/game/Time/UpdateTime.h b/src/server/game/Time/UpdateTime.h new file mode 100644 index 00000000000..32ddf49c8a4 --- /dev/null +++ b/src/server/game/Time/UpdateTime.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __UPDATETIME_H +#define __UPDATETIME_H + +#include "Define.h" + +#define AVG_DIFF_COUNT 500 + +class TC_GAME_API UpdateTime +{ + using DiffTableArray = std::array<uint32, AVG_DIFF_COUNT>; + + public: + uint32 GetAverageUpdateTime() const; + uint32 GetTimeWeightedAverageUpdateTime() const; + uint32 GetMaxUpdateTime() const; + uint32 GetMaxUpdateTimeOfCurrentTable() const; + uint32 GetLastUpdateTime() const; + + void UpdateWithDiff(uint32 diff); + + void RecordUpdateTimeReset(); + + protected: + UpdateTime(); + + void _RecordUpdateTimeDuration(std::string const& text, uint32 minUpdateTime); + + private: + DiffTableArray _updateTimeDataTable; + uint32 _averageUpdateTime; + uint32 _totalUpdateTime; + uint32 _updateTimeTableIndex; + uint32 _maxUpdateTime; + uint32 _maxUpdateTimeOfLastTable; + uint32 _maxUpdateTimeOfCurrentTable; + + uint32 _recordedTime; +}; + +class WorldUpdateTime : public UpdateTime +{ + public: + WorldUpdateTime() : UpdateTime(), _recordUpdateTimeInverval(0), _recordUpdateTimeMin(0), _lastRecordTime(0) { } + void LoadFromConfig(); + void SetRecordUpdateTimeInterval(uint32 t); + void RecordUpdateTime(uint32 gameTimeMs, uint32 diff, uint32 sessionCount); + void RecordUpdateTimeDuration(std::string const& text); + + private: + uint32 _recordUpdateTimeInverval; + uint32 _recordUpdateTimeMin; + uint32 _lastRecordTime; +}; + +TC_GAME_API extern WorldUpdateTime sWorldUpdateTime; + +#endif diff --git a/src/server/game/Warden/Warden.cpp b/src/server/game/Warden/Warden.cpp index 5e3f731814c..40c59e4878f 100644 --- a/src/server/game/Warden/Warden.cpp +++ b/src/server/game/Warden/Warden.cpp @@ -22,6 +22,7 @@ #include "Log.h" #include "Opcodes.h" #include "ByteBuffer.h" +#include "GameTime.h" #include "World.h" #include "Util.h" #include "Warden.h" @@ -96,7 +97,7 @@ void Warden::Update() { if (_initialized) { - uint32 currentTimestamp = getMSTime(); + uint32 currentTimestamp = GameTime::GetGameTimeMS(); uint32 diff = currentTimestamp - _previousTimestamp; _previousTimestamp = currentTimestamp; diff --git a/src/server/game/Warden/WardenMac.cpp b/src/server/game/Warden/WardenMac.cpp index 81dcc50397c..8a401f4ab89 100644 --- a/src/server/game/Warden/WardenMac.cpp +++ b/src/server/game/Warden/WardenMac.cpp @@ -23,6 +23,7 @@ #include "Log.h" #include "Opcodes.h" #include "ByteBuffer.h" +#include "GameTime.h" #include "World.h" #include "Player.h" #include "Util.h" @@ -186,7 +187,7 @@ void WardenMac::HandleHashResult(ByteBuffer &buff) _initialized = true; - _previousTimestamp = getMSTime(); + _previousTimestamp = GameTime::GetGameTimeMS(); } void WardenMac::RequestData() diff --git a/src/server/game/Warden/WardenWin.cpp b/src/server/game/Warden/WardenWin.cpp index 488a9f8bf96..2452c4dc50a 100644 --- a/src/server/game/Warden/WardenWin.cpp +++ b/src/server/game/Warden/WardenWin.cpp @@ -25,6 +25,7 @@ #include "Opcodes.h" #include "ByteBuffer.h" #include "Database/DatabaseEnv.h" +#include "GameTime.h" #include "World.h" #include "Player.h" #include "Util.h" @@ -170,7 +171,7 @@ void WardenWin::HandleHashResult(ByteBuffer &buff) _initialized = true; - _previousTimestamp = getMSTime(); + _previousTimestamp = GameTime::GetGameTimeMS(); } void WardenWin::RequestData() @@ -184,7 +185,7 @@ void WardenWin::RequestData() if (_otherChecksTodo.empty()) _otherChecksTodo.assign(sWardenCheckMgr->OtherChecksIdPool.begin(), sWardenCheckMgr->OtherChecksIdPool.end()); - _serverTicks = getMSTime(); + _serverTicks = GameTime::GetGameTimeMS(); uint16 id; uint8 type; @@ -358,7 +359,7 @@ void WardenWin::HandleData(ByteBuffer &buff) uint32 newClientTicks; buff >> newClientTicks; - uint32 ticksNow = getMSTime(); + uint32 ticksNow = GameTime::GetGameTimeMS(); uint32 ourTicks = newClientTicks + (ticksNow - _serverTicks); TC_LOG_DEBUG("warden", "ServerTicks %u", ticksNow); // Now diff --git a/src/server/game/Weather/Weather.cpp b/src/server/game/Weather/Weather.cpp index a8fed651b91..857c7c98f6d 100644 --- a/src/server/game/Weather/Weather.cpp +++ b/src/server/game/Weather/Weather.cpp @@ -20,6 +20,7 @@ \ingroup world */ +#include "GameTime.h" #include "Weather.h" #include "Log.h" #include "MiscPackets.h" @@ -91,7 +92,7 @@ bool Weather::ReGenerate() //78 days between January 1st and March 20nd; 365/4=91 days by season // season source http://aa.usno.navy.mil/data/docs/EarthSeasons.html - time_t gtime = sWorld->GetGameTime(); + time_t gtime = GameTime::GetGameTime(); struct tm ltime; localtime_r(>ime, <ime); uint32 season = ((ltime.tm_yday - 78 + 365) / 91) % 4; diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index 22c0aa3d545..86431c96452 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -50,6 +50,7 @@ #include "GameEventMgr.h" #include "GameObjectModel.h" #include "GameTables.h" +#include "GameTime.h" #include "GarrisonMgr.h" #include "GitRevision.h" #include "GridNotifiersImpl.h" @@ -86,6 +87,7 @@ #include "TaxiPathGraph.h" #include "TransportMgr.h" #include "Unit.h" +#include "UpdateTime.h" #include "VMapFactory.h" #include "VMapManager2.h" #include "WardenCheckMgr.h" @@ -118,8 +120,7 @@ World::World() m_allowMovement = true; m_ShutdownMask = 0; m_ShutdownTimer = 0; - m_gameTime = time(NULL); - m_startTime = m_gameTime; + m_maxActiveSessionCount = 0; m_maxQueuedSessionCount = 0; m_PlayerCount = 0; @@ -136,10 +137,6 @@ World::World() mail_timer = 0; mail_timer_expires = 0; - m_updateTime = 0; - m_updateTimeSum = 0; - m_updateTimeCount = 0; - m_currentTime = 0; m_isClosed = false; @@ -471,6 +468,9 @@ void World::LoadConfigSettings(bool reload) TC_LOG_INFO("server.loading", "Using %s DBC Locale", localeNames[m_defaultDbcLocale]); + // load update time related configs + sWorldUpdateTime.LoadFromConfig(); + ///- Read the player limit and the Message of the day from the config file SetPlayerAmountLimit(sConfigMgr->GetIntDefault("PlayerLimit", 100)); SetMotd(sConfigMgr->GetStringDefault("Motd", "Welcome to a Trinity Core Server.")); @@ -1360,8 +1360,6 @@ void World::LoadConfigSettings(bool reload) m_bool_configs[CONFIG_SHOW_KICK_IN_WORLD] = sConfigMgr->GetBoolDefault("ShowKickInWorld", false); m_bool_configs[CONFIG_SHOW_MUTE_IN_WORLD] = sConfigMgr->GetBoolDefault("ShowMuteInWorld", false); m_bool_configs[CONFIG_SHOW_BAN_IN_WORLD] = sConfigMgr->GetBoolDefault("ShowBanInWorld", false); - m_int_configs[CONFIG_INTERVAL_LOG_UPDATE] = sConfigMgr->GetIntDefault("RecordUpdateTimeDiffInterval", 60000); - m_int_configs[CONFIG_MIN_LOG_UPDATE] = sConfigMgr->GetIntDefault("MinRecordUpdateTimeDiff", 100); m_int_configs[CONFIG_NUMTHREADS] = sConfigMgr->GetIntDefault("MapUpdate.Threads", 1); m_int_configs[CONFIG_MAX_RESULTS_LOOKUP_COMMANDS] = sConfigMgr->GetIntDefault("Command.LookupMaxResults", 0); @@ -2075,11 +2073,10 @@ void World::SetInitialWorldSettings() ///- Initialize game time and timers TC_LOG_INFO("server.loading", "Initialize game time and timers"); - m_gameTime = time(NULL); - m_startTime = m_gameTime; + GameTime::UpdateGameTimers(); LoginDatabase.PExecute("INSERT INTO uptime (realmid, starttime, uptime, revision) VALUES(%u, %u, 0, '%s')", - realm.Id.Realm, uint32(m_startTime), GitRevision::GetFullVersion()); // One-time query + realm.Id.Realm, uint32(GameTime::GetStartTime()), GitRevision::GetFullVersion()); // One-time query m_timers[WUPDATE_AUCTIONS].SetInterval(MINUTE*IN_MILLISECONDS); m_timers[WUPDATE_AUCTIONS_PENDING].SetInterval(250); @@ -2112,7 +2109,8 @@ void World::SetInitialWorldSettings() //one second is 1000 -(tested on win system) /// @todo Get rid of magic numbers tm localTm; - localtime_r(&m_gameTime, &localTm); + time_t gameTime = GameTime::GetGameTime(); + localtime_r(&gameTime, &localTm); mail_timer = ((((localTm.tm_hour + 20) % 24)* HOUR * IN_MILLISECONDS) / m_timers[WUPDATE_AUCTIONS].GetInterval()); //1440 mail_timer_expires = ((DAY * IN_MILLISECONDS) / (m_timers[WUPDATE_AUCTIONS].GetInterval())); @@ -2231,28 +2229,6 @@ void World::SetInitialWorldSettings() sLog->SetRealmId(realm.Id.Realm); } -void World::ResetTimeDiffRecord() -{ - if (m_updateTimeCount != 1) - return; - - m_currentTime = getMSTime(); -} - -void World::RecordTimeDiff(std::string const& text) -{ - if (m_updateTimeCount != 1) - return; - - uint32 thisTime = getMSTime(); - uint32 diff = getMSTimeDiff(m_currentTime, thisTime); - - if (diff > m_int_configs[CONFIG_MIN_LOG_UPDATE]) - TC_LOG_INFO("misc", "Difftime %s: %u.", text.c_str(), diff); - - m_currentTime = thisTime; -} - void World::LoadAutobroadcasts() { uint32 oldMSTime = getMSTime(); @@ -2284,22 +2260,14 @@ void World::LoadAutobroadcasts() /// Update the World ! void World::Update(uint32 diff) { - m_updateTime = diff; + ///- Update the game time and check for shutdown time + _UpdateGameTime(); + time_t currentGameTime = GameTime::GetGameTime(); - if (m_int_configs[CONFIG_INTERVAL_LOG_UPDATE] && diff > m_int_configs[CONFIG_MIN_LOG_UPDATE]) - { - if (m_updateTimeSum > m_int_configs[CONFIG_INTERVAL_LOG_UPDATE]) - { - TC_LOG_DEBUG("misc", "Update time diff: %u. Players online: %u.", m_updateTimeSum / m_updateTimeCount, GetActiveSessionCount()); - m_updateTimeSum = m_updateTime; - m_updateTimeCount = 1; - } - else - { - m_updateTimeSum += m_updateTime; - ++m_updateTimeCount; - } - } + sWorldUpdateTime.UpdateWithDiff(diff); + + // Record update if recording set in log and diff is greater then minimum set in log + sWorldUpdateTime.RecordUpdateTime(GameTime::GetGameTimeMS(), diff, GetActiveSessionCount()); ///- Update the different timers for (int i = 0; i < WUPDATE_COUNT; ++i) @@ -2317,31 +2285,28 @@ void World::Update(uint32 diff) sWhoListStorageMgr->Update(); } - ///- Update the game time and check for shutdown time - _UpdateGameTime(); - /// Handle daily quests reset time - if (m_gameTime > m_NextDailyQuestReset) + if (currentGameTime > m_NextDailyQuestReset) { DailyReset(); InitDailyQuestResetTime(false); } /// Handle weekly quests reset time - if (m_gameTime > m_NextWeeklyQuestReset) + if (currentGameTime > m_NextWeeklyQuestReset) ResetWeeklyQuests(); /// Handle monthly quests reset time - if (m_gameTime > m_NextMonthlyQuestReset) + if (currentGameTime > m_NextMonthlyQuestReset) ResetMonthlyQuests(); - if (m_gameTime > m_NextRandomBGReset) + if (currentGameTime > m_NextRandomBGReset) ResetRandomBG(); - if (m_gameTime > m_NextGuildReset) + if (currentGameTime > m_NextGuildReset) ResetGuildCap(); - if (m_gameTime > m_NextCurrencyReset) + if (currentGameTime > m_NextCurrencyReset) ResetCurrencyWeekCap(); /// <ul><li> Handle auctions when the timer has passed @@ -2402,14 +2367,14 @@ void World::Update(uint32 diff) } /// <li> Handle session updates when the timer has passed - ResetTimeDiffRecord(); + sWorldUpdateTime.RecordUpdateTimeReset(); UpdateSessions(diff); - RecordTimeDiff("UpdateSessions"); + sWorldUpdateTime.RecordUpdateTimeDuration("UpdateSessions"); /// <li> Update uptime table if (m_timers[WUPDATE_UPTIME].Passed()) { - uint32 tmpDiff = uint32(m_gameTime - m_startTime); + uint32 tmpDiff = GameTime::GetUptime(); uint32 maxOnlinePlayers = GetMaxPlayerCount(); m_timers[WUPDATE_UPTIME].Reset(); @@ -2419,7 +2384,7 @@ void World::Update(uint32 diff) stmt->setUInt32(0, tmpDiff); stmt->setUInt16(1, uint16(maxOnlinePlayers)); stmt->setUInt32(2, realm.Id.Realm); - stmt->setUInt32(3, uint32(m_startTime)); + stmt->setUInt32(3, uint32(GameTime::GetStartTime())); LoginDatabase.Execute(stmt); } @@ -2443,9 +2408,9 @@ void World::Update(uint32 diff) /// <li> Handle all other objects ///- Update objects when the timer has passed (maps, transport, creatures, ...) - ResetTimeDiffRecord(); + sWorldUpdateTime.RecordUpdateTimeReset(); sMapMgr->Update(diff); - RecordTimeDiff("UpdateMapMgr"); + sWorldUpdateTime.RecordUpdateTimeDuration("UpdateMapMgr"); if (sWorld->getBoolConfig(CONFIG_AUTOBROADCAST)) { @@ -2457,13 +2422,13 @@ void World::Update(uint32 diff) } sBattlegroundMgr->Update(diff); - RecordTimeDiff("UpdateBattlegroundMgr"); + sWorldUpdateTime.RecordUpdateTimeDuration("UpdateBattlegroundMgr"); sOutdoorPvPMgr->Update(diff); - RecordTimeDiff("UpdateOutdoorPvPMgr"); + sWorldUpdateTime.RecordUpdateTimeDuration("UpdateOutdoorPvPMgr"); sBattlefieldMgr->Update(diff); - RecordTimeDiff("BattlefieldMgr"); + sWorldUpdateTime.RecordUpdateTimeDuration("BattlefieldMgr"); ///- Delete all characters which have been deleted X days before if (m_timers[WUPDATE_DELETECHARS].Passed()) @@ -2473,14 +2438,14 @@ void World::Update(uint32 diff) } sLFGMgr->Update(diff); - RecordTimeDiff("UpdateLFGMgr"); + sWorldUpdateTime.RecordUpdateTimeDuration("UpdateLFGMgr"); sGroupMgr->Update(diff); - RecordTimeDiff("GroupMgr"); + sWorldUpdateTime.RecordUpdateTimeDuration("GroupMgr"); // execute callbacks from sql queries that were queued recently ProcessQueryCallbacks(); - RecordTimeDiff("ProcessQueryCallbacks"); + sWorldUpdateTime.RecordUpdateTimeDuration("ProcessQueryCallbacks"); ///- Erase corpses once every 20 minutes if (m_timers[WUPDATE_CORPSES].Passed()) @@ -2924,9 +2889,10 @@ bool World::RemoveBanCharacter(std::string const& name) void World::_UpdateGameTime() { ///- update the time - time_t thisTime = time(NULL); - uint32 elapsed = uint32(thisTime - m_gameTime); - m_gameTime = thisTime; + time_t lastGameTime = GameTime::GetGameTime(); + GameTime::UpdateGameTimers(); + + uint32 elapsed = uint32(GameTime::GetGameTime() - lastGameTime); ///- if there is a shutdown timer if (!IsStopped() && m_ShutdownTimer > 0 && elapsed > 0) diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h index eac00f7a2ba..b47b528cca3 100644 --- a/src/server/game/World/World.h +++ b/src/server/game/World/World.h @@ -331,8 +331,6 @@ enum WorldIntConfigs CONFIG_PVP_TOKEN_MAP_TYPE, CONFIG_PVP_TOKEN_ID, CONFIG_PVP_TOKEN_COUNT, - CONFIG_INTERVAL_LOG_UPDATE, - CONFIG_MIN_LOG_UPDATE, CONFIG_ENABLE_SINFO_LOGIN, CONFIG_PLAYER_ALLOW_COMMANDS, CONFIG_NUMTHREADS, @@ -648,16 +646,6 @@ class TC_GAME_API World /// Get the path where data (dbc, maps) are stored on disk std::string const& GetDataPath() const { return m_dataPath; } - /// When server started? - time_t const& GetStartTime() const { return m_startTime; } - /// What time is it? - time_t const& GetGameTime() const { return m_gameTime; } - /// Uptime (in secs) - uint32 GetUptime() const { return uint32(m_gameTime - m_startTime); } - /// Update time - uint32 GetUpdateTime() const { return m_updateTime; } - void SetRecordDiffInterval(int32 t) { if (t >= 0) m_int_configs[CONFIG_INTERVAL_LOG_UPDATE] = (uint32)t; } - /// Next daily quests and random bg reset time time_t GetNextDailyQuestsResetTime() const { return m_NextDailyQuestReset; } time_t GetNextWeeklyQuestsResetTime() const { return m_NextWeeklyQuestReset; } @@ -782,9 +770,6 @@ class TC_GAME_API World void LoadDBVersion(); char const* GetDBVersion() const { return m_DBVersion.c_str(); } - void ResetTimeDiffRecord(); - void RecordTimeDiff(std::string const& text); - void LoadAutobroadcasts(); void UpdateAreaDependentAuras(); @@ -799,6 +784,7 @@ class TC_GAME_API World protected: void _UpdateGameTime(); + // callback for UpdateRealmCharacters void _UpdateRealmCharCount(PreparedQueryResult resultCharCount); @@ -827,15 +813,10 @@ class TC_GAME_API World bool m_isClosed; - time_t m_startTime; - time_t m_gameTime; IntervalTimer m_timers[WUPDATE_COUNT]; time_t mail_timer; time_t mail_timer_expires; time_t blackmarket_timer; - uint32 m_updateTime, m_updateTimeSum; - uint32 m_updateTimeCount; - uint32 m_currentTime; SessionMap m_sessions; typedef std::unordered_map<uint32, time_t> DisconnectMap; diff --git a/src/server/scripts/Commands/cs_server.cpp b/src/server/scripts/Commands/cs_server.cpp index e7ce8d0845f..cd7adb4be82 100644 --- a/src/server/scripts/Commands/cs_server.cpp +++ b/src/server/scripts/Commands/cs_server.cpp @@ -27,6 +27,7 @@ EndScriptData */ #include "Config.h" #include "DatabaseEnv.h" #include "DatabaseLoader.h" +#include "GameTime.h" #include "GitRevision.h" #include "Language.h" #include "Log.h" @@ -34,6 +35,7 @@ EndScriptData */ #include "Player.h" #include "RBAC.h" #include "Realm.h" +#include "UpdateTime.h" #include "Util.h" #include "VMapFactory.h" #include "World.h" @@ -256,8 +258,8 @@ public: uint32 queuedClientsNum = sWorld->GetQueuedSessionCount(); uint32 maxActiveClientsNum = sWorld->GetMaxActiveSessionCount(); uint32 maxQueuedClientsNum = sWorld->GetMaxQueuedSessionCount(); - std::string uptime = secsToTimeString(sWorld->GetUptime()); - uint32 updateTime = sWorld->GetUpdateTime(); + std::string uptime = secsToTimeString(GameTime::GetUptime()); + uint32 updateTime = sWorldUpdateTime.GetLastUpdateTime(); handler->PSendSysMessage("%s", GitRevision::GetFullVersion()); handler->PSendSysMessage(LANG_CONNECTED_PLAYERS, playersNum, maxPlayersNum); @@ -455,7 +457,7 @@ public: if (newTime < 0) return false; - sWorld->SetRecordDiffInterval(newTime); + sWorldUpdateTime.SetRecordUpdateTimeInterval(newTime); printf("Record diff every %i ms\n", newTime); return true; diff --git a/src/server/scripts/Events/fireworks_show.cpp b/src/server/scripts/Events/fireworks_show.cpp index 4712090b032..a052063bf26 100644 --- a/src/server/scripts/Events/fireworks_show.cpp +++ b/src/server/scripts/Events/fireworks_show.cpp @@ -20,6 +20,7 @@ #include "EventMap.h" #include "GameObject.h" #include "GameObjectAI.h" +#include "GameTime.h" #include "CreatureAIImpl.h" #include "GameEventMgr.h" #include "World.h" @@ -796,7 +797,7 @@ public: { _events.Update(diff); - time_t time = sWorld->GetGameTime(); + time_t time = GameTime::GetGameTime(); tm localTm; localtime_r(&time, &localTm); diff --git a/src/server/scripts/Northrend/IcecrownCitadel/icecrown_citadel.cpp b/src/server/scripts/Northrend/IcecrownCitadel/icecrown_citadel.cpp index d2f311b9082..dec0409d601 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/icecrown_citadel.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/icecrown_citadel.cpp @@ -1842,7 +1842,7 @@ class spell_icc_sprit_alarm : public SpellScriptLoader } if (GameObject* trap = GetCaster()->FindNearestGameObject(trapId, 5.0f)) - trap->SetRespawnTime(trap->GetGOInfo()->GetAutoCloseTime()); + trap->SetRespawnTime(trap->GetGOInfo()->GetAutoCloseTime() / IN_MILLISECONDS); std::list<Creature*> wards; GetCaster()->GetCreatureListWithEntryInGrid(wards, NPC_DEATHBOUND_WARD, 150.0f); diff --git a/src/server/scripts/Northrend/Naxxramas/boss_four_horsemen.cpp b/src/server/scripts/Northrend/Naxxramas/boss_four_horsemen.cpp index 6a9dac9f620..3d12ac2cf67 100644 --- a/src/server/scripts/Northrend/Naxxramas/boss_four_horsemen.cpp +++ b/src/server/scripts/Northrend/Naxxramas/boss_four_horsemen.cpp @@ -15,6 +15,7 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "GameTime.h" #include "ScriptMgr.h" #include "InstanceScript.h" #include "Log.h" @@ -339,7 +340,7 @@ struct boss_four_horsemen_baseAI : public BossAI } Talk(SAY_DEATH); - _timeDied = getMSTime(); + _timeDied = GameTime::GetGameTimeMS(); for (Horseman boss : horsemen) { if (Creature* cBoss = getHorsemanHandle(boss)) diff --git a/src/server/scripts/Northrend/Nexus/Nexus/boss_magus_telestra.cpp b/src/server/scripts/Northrend/Nexus/Nexus/boss_magus_telestra.cpp index 27fb04e55eb..d320fd3cd38 100644 --- a/src/server/scripts/Northrend/Nexus/Nexus/boss_magus_telestra.cpp +++ b/src/server/scripts/Northrend/Nexus/Nexus/boss_magus_telestra.cpp @@ -18,6 +18,7 @@ #include "ScriptMgr.h" #include "GameEventMgr.h" +#include "GameTime.h" #include "InstanceScript.h" #include "MotionMaster.h" #include "nexus.h" @@ -171,7 +172,7 @@ public: while (time[i] != 0) ++i; - time[i] = sWorld->GetGameTime(); + time[i] = GameTime::GetGameTime(); if (i == 2 && (time[2] - time[1] < 5) && (time[1] - time[0] < 5)) ++splitPersonality; } diff --git a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_ignis.cpp b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_ignis.cpp index 40a49f5dfef..fde729203be 100644 --- a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_ignis.cpp +++ b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_ignis.cpp @@ -15,6 +15,7 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "GameTime.h" #include "ScriptMgr.h" #include "InstanceScript.h" #include "ObjectAccessor.h" @@ -197,7 +198,7 @@ class boss_ignis : public CreatureScript me->RemoveAuraFromStack(SPELL_STRENGHT); // Shattered Achievement - time_t secondKill = sWorld->GetGameTime(); + time_t secondKill = GameTime::GetGameTime(); if ((secondKill - _firstConstructKill) < 5) _shattered = true; _firstConstructKill = secondKill; diff --git a/src/server/scripts/Spells/spell_generic.cpp b/src/server/scripts/Spells/spell_generic.cpp index bbf86c4d9be..148009a780a 100644 --- a/src/server/scripts/Spells/spell_generic.cpp +++ b/src/server/scripts/Spells/spell_generic.cpp @@ -26,6 +26,7 @@ #include "Battleground.h" #include "CellImpl.h" #include "DB2Stores.h" +#include "GameTime.h" #include "GridNotifiersImpl.h" #include "Group.h" #include "InstanceScript.h" @@ -3589,7 +3590,7 @@ class spell_gen_turkey_marker : public SpellScriptLoader void OnApply(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/) { // store stack apply times, so we can pop them while they expire - _applyTimes.push_back(getMSTime()); + _applyTimes.push_back(GameTime::GetGameTimeMS()); Unit* target = GetTarget(); // on stack 15 cast the achievement crediting spell @@ -3603,7 +3604,7 @@ class spell_gen_turkey_marker : public SpellScriptLoader return; // pop stack if it expired for us - if (_applyTimes.front() + GetMaxDuration() < getMSTime()) + if (_applyTimes.front() + GetMaxDuration() < GameTime::GetGameTimeMS()) ModStackAmount(-1, AURA_REMOVE_BY_EXPIRE); } diff --git a/src/server/scripts/World/areatrigger_scripts.cpp b/src/server/scripts/World/areatrigger_scripts.cpp index 51a395f73db..157137fd386 100644 --- a/src/server/scripts/World/areatrigger_scripts.cpp +++ b/src/server/scripts/World/areatrigger_scripts.cpp @@ -38,6 +38,7 @@ EndContentData */ #include "ScriptMgr.h" #include "DB2Structure.h" #include "GameObject.h" +#include "GameTime.h" #include "MotionMaster.h" #include "ObjectAccessor.h" #include "ScriptedCreature.h" @@ -320,7 +321,7 @@ class AreaTrigger_at_brewfest : public AreaTriggerScript { uint32 triggerId = areaTrigger->ID; // Second trigger happened too early after first, skip for now - if (sWorld->GetGameTime() - _triggerTimes[triggerId] < AREATRIGGER_TALK_COOLDOWN) + if (GameTime::GetGameTime() - _triggerTimes[triggerId] < AREATRIGGER_TALK_COOLDOWN) return false; switch (triggerId) @@ -337,7 +338,7 @@ class AreaTrigger_at_brewfest : public AreaTriggerScript break; } - _triggerTimes[triggerId] = sWorld->GetGameTime(); + _triggerTimes[triggerId] = GameTime::GetGameTime(); return false; } @@ -376,7 +377,7 @@ class AreaTrigger_at_area_52_entrance : public AreaTriggerScript if (!player->IsAlive()) return false; - if (sWorld->GetGameTime() - _triggerTimes[areaTrigger->ID] < SUMMON_COOLDOWN) + if (GameTime::GetGameTime() - _triggerTimes[areaTrigger->ID] < SUMMON_COOLDOWN) return false; switch (areaTrigger->ID) @@ -405,7 +406,7 @@ class AreaTrigger_at_area_52_entrance : public AreaTriggerScript player->SummonCreature(NPC_SPOTLIGHT, x, y, z, 0.0f, TEMPSUMMON_TIMED_DESPAWN, 5000); player->AddAura(SPELL_A52_NEURALYZER, player); - _triggerTimes[areaTrigger->ID] = sWorld->GetGameTime(); + _triggerTimes[areaTrigger->ID] = GameTime::GetGameTime(); return false; } diff --git a/src/server/scripts/World/duel_reset.cpp b/src/server/scripts/World/duel_reset.cpp index 598b721dfed..a6db3b29e5f 100644 --- a/src/server/scripts/World/duel_reset.cpp +++ b/src/server/scripts/World/duel_reset.cpp @@ -15,6 +15,7 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "GameTime.h" #include "ScriptMgr.h" #include "Player.h" #include "Pet.h" @@ -94,7 +95,7 @@ class DuelResetScript : public PlayerScript // remove cooldowns on spells that have < 10 min CD > 30 sec and has no onHold player->GetSpellHistory()->ResetCooldowns([](SpellHistory::CooldownStorageType::iterator itr) -> bool { - SpellHistory::Clock::time_point now = SpellHistory::Clock::now(); + SpellHistory::Clock::time_point now = GameTime::GetGameTimeSystemPoint(); uint32 cooldownDuration = itr->second.CooldownEnd > now ? std::chrono::duration_cast<std::chrono::milliseconds>(itr->second.CooldownEnd - now).count() : 0; SpellInfo const* spellInfo = sSpellMgr->AssertSpellInfo(itr->first); return spellInfo->RecoveryTime < 10 * MINUTE * IN_MILLISECONDS diff --git a/src/server/scripts/World/go_scripts.cpp b/src/server/scripts/World/go_scripts.cpp index f6c83e707e0..20db17af5bc 100644 --- a/src/server/scripts/World/go_scripts.cpp +++ b/src/server/scripts/World/go_scripts.cpp @@ -49,6 +49,7 @@ EndContentData */ #include "DB2Structure.h" #include "GameObject.h" #include "GameObjectAI.h" +#include "GameTime.h" #include "Log.h" #include "Map.h" #include "MotionMaster.h" @@ -1572,7 +1573,7 @@ public: { if (eventId == GAME_EVENT_HOURLY_BELLS && start) { - time_t time = sWorld->GetGameTime(); + time_t time = GameTime::GetGameTime(); tm localTm; localtime_r(&time, &localTm); uint8 _rings = (localTm.tm_hour - 1) % 12 + 1; |