diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp index 5974f449ce3..3c9a7257b4f 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp @@ -31,6 +31,7 @@ #include "Item.h" #include "Language.h" #include "Log.h" +#include "GameTime.h" enum eAuctionHouse { @@ -591,7 +592,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. @@ -686,7 +687,7 @@ void AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player int loc_idx = player->GetSession()->GetSessionDbLocaleIndex(); int locdbc_idx = player->GetSession()->GetSessionDbcLocale(); - time_t curTime = sWorld->GetGameTime(); + time_t curTime = GameTime::GetGameTime(); PlayerGetAllThrottleMap::const_iterator itr = GetAllThrottleMap.find(player->GetGUID()); time_t throttleTime = itr != GetAllThrottleMap.end() ? itr->second : curTime; diff --git a/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp b/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp index 10013738c73..5643465212b 100644 --- a/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp +++ b/src/server/game/AuctionHouseBot/AuctionHouseBot.cpp @@ -25,6 +25,7 @@ #include "AuctionHouseBot.h" #include "AuctionHouseBotBuyer.h" #include "AuctionHouseBotSeller.h" +#include "GameTime.h" AuctionBotConfig* AuctionBotConfig::instance() { @@ -494,7 +495,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 12b94461259..03298abe71a 100644 --- a/src/server/game/Battlegrounds/Battleground.cpp +++ b/src/server/game/Battlegrounds/Battleground.cpp @@ -36,6 +36,7 @@ #include "Util.h" #include "WorldPacket.h" #include "Transport.h" +#include "GameTime.h" namespace Trinity { @@ -316,7 +317,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()) { if (isBattleground() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_TRACK_DESERTERS) && (GetStatus() == STATUS_IN_PROGRESS || GetStatus() == STATUS_WAIT_JOIN)) @@ -1211,7 +1212,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 06f537b09ef..991319fb1c7 100644 --- a/src/server/game/Battlegrounds/BattlegroundQueue.cpp +++ b/src/server/game/Battlegrounds/BattlegroundQueue.cpp @@ -21,6 +21,7 @@ #include "BattlegroundMgr.h" #include "BattlegroundQueue.h" #include "Chat.h" +#include "GameTime.h" #include "Group.h" #include "Log.h" #include "Language.h" @@ -138,7 +139,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; @@ -156,7 +157,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)) @@ -233,7 +234,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) { @@ -445,7 +446,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::iterator itr = ginfo->Players.begin(); itr != ginfo->Players.end(); ++itr) @@ -638,7 +639,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()) @@ -919,7 +920,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 2daeee0c351..1d7417284bb 100644 --- a/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp @@ -18,6 +18,7 @@ #include "BattlegroundSA.h" #include "GameObject.h" +#include "GameTime.h" #include "Language.h" #include "ObjectMgr.h" #include "Player.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 c280578ac41..d80fdb9cdfa 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -26,6 +26,7 @@ #include "DatabaseEnv.h" #include "Formulas.h" #include "GameEventMgr.h" +#include "GameTime.h" #include "GossipDef.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" @@ -2894,7 +2895,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 97de2df6096..458672227f6 100644 --- a/src/server/game/Entities/DynamicObject/DynamicObject.cpp +++ b/src/server/game/Entities/DynamicObject/DynamicObject.cpp @@ -21,6 +21,7 @@ #include "World.h" #include "ObjectAccessor.h" #include "DatabaseEnv.h" +#include "GameTime.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" #include "ScriptMgr.h" @@ -97,7 +98,7 @@ bool DynamicObject::CreateDynamicObject(ObjectGuid::LowType guidlow, Unit* caste SetUInt32Value(DYNAMICOBJECT_BYTES, spell->SpellVisual[0] | (type << 28)); SetUInt32Value(DYNAMICOBJECT_SPELLID, spell->Id); SetFloatValue(DYNAMICOBJECT_RADIUS, radius); - SetUInt32Value(DYNAMICOBJECT_CASTTIME, getMSTime()); + SetUInt32Value(DYNAMICOBJECT_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 5e1ac4a809e..24c2bf615b1 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -21,6 +21,7 @@ #include "CellImpl.h" #include "CreatureAISelector.h" #include "GameObjectModel.h" +#include "GameTime.h" #include "GridNotifiersImpl.h" #include "Group.h" #include "GroupMgr.h" @@ -365,10 +366,10 @@ void GameObject::Update(uint32 diff) // Bombs if (goInfo->trap.type == 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; @@ -532,7 +533,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. @@ -599,16 +600,14 @@ 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(GAMEOBJECT_FLAGS, GO_FLAG_IN_USE); - SetLootState(GO_JUST_DEACTIVATED); - m_cooldownTime = 0; } break; case GAMEOBJECT_TYPE_CHEST: @@ -641,7 +640,7 @@ void GameObject::Update(uint32 diff) CastSpell(target, goInfo->trap.spellId); // 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.type == 1) SetLootState(GO_JUST_DEACTIVATED); @@ -1196,7 +1195,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) @@ -1254,10 +1253,10 @@ void GameObject::Use(Unit* user) // If cooldown data present in template if (uint32 cooldown = GetGOInfo()->GetCooldown()) { - if (m_cooldownTime > sWorld->GetGameTime()) + if (GameTime::GetGameTimeMS() < m_cooldownTime) return; - m_cooldownTime = sWorld->GetGameTime() + cooldown; + m_cooldownTime = GameTime::GetGameTimeMS() + cooldown * IN_MILLISECONDS; } switch (GetGoType()) @@ -1284,7 +1283,7 @@ void GameObject::Use(Unit* user) if (goInfo->trap.spellId) CastSpell(user, goInfo->trap.spellId); - 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.type == 1) // Deactivate after trigger SetLootState(GO_JUST_DEACTIVATED); @@ -1431,7 +1430,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.spellId; diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h index 9a6d1807f55..09b612a8256 100644 --- a/src/server/game/Entities/GameObject/GameObject.h +++ b/src/server/game/Entities/GameObject/GameObject.h @@ -520,7 +520,7 @@ struct GameObjectTemplate case GAMEOBJECT_TYPE_AREADAMAGE: autoCloseTime = areadamage.autoCloseTime; 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 f99745568e9..2a8f236dbf5 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -52,6 +52,7 @@ #include "BattlefieldMgr.h" #include "Battleground.h" #include "Chat.h" +#include "GameTime.h" Object::Object() : m_PackGUID(sizeof(uint64)+1) { @@ -544,7 +545,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const *data << self->GetSpeed(MOVE_WALK); //if (true) // Has time, controlled by bit just after HasTransport - *data << uint32(getMSTime()); + *data << uint32(GameTime::GetGameTimeMS()); *data << self->GetSpeed(MOVE_TURN_RATE); data->WriteByteSeq(guid[6]); @@ -659,7 +660,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const if (go && go->ToTransport()) *data << uint32(go->GetGOValue()->Transport.PathProgress); else - *data << uint32(getMSTime()); + *data << uint32(GameTime::GetGameTimeMS()); } } diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index a694d914817..a11566e1ade 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -41,6 +41,7 @@ #include "DisableMgr.h" #include "Formulas.h" #include "GameEventMgr.h" +#include "GameTime.h" #include "GossipDef.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" @@ -1226,7 +1227,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); } @@ -3981,7 +3982,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 @@ -18603,10 +18604,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; @@ -20147,7 +20148,7 @@ void Player::_SaveQuestStatus(SQLTransaction& trans) stmt->setUInt32(index++, statusItr->first); stmt->setUInt8(index++, uint8(statusItr->second.Status)); stmt->setBool(index++, statusItr->second.Explored); - stmt->setUInt32(index++, uint32(statusItr->second.Timer / IN_MILLISECONDS+ sWorld->GetGameTime())); + stmt->setUInt32(index++, uint32(statusItr->second.Timer / IN_MILLISECONDS+ GameTime::GetGameTime())); for (uint8 i = 0; i < 4; i++) stmt->setUInt16(index++, statusItr->second.CreatureOrGOCount[i]); @@ -23215,7 +23216,7 @@ void Player::SendInitialPacketsBeforeAddToMap() SendEquipmentSetList(); data.Initialize(SMSG_LOGIN_SETTIMESPEED, 4 + 4 + 4); - data.AppendPackedTime(sWorld->GetGameTime()); + data.AppendPackedTime(GameTime::GetGameTime()); data << float(0.01666667f); // game speed data << uint32(0); // added in 3.1.2 GetSession()->SendPacket(&data); @@ -26757,7 +26758,7 @@ void Player::ResetTimeSync() { m_timeSyncTimer = 0; m_timeSyncClient = 0; - m_timeSyncServer = getMSTime(); + m_timeSyncServer = GameTime::GetGameTimeMS(); } void Player::SendTimeSync() @@ -26770,7 +26771,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", "Not received CMSG_TIME_SYNC_RESP for over 30 seconds from player %u (%s), possible cheater", GetGUID().GetCounter(), GetName().c_str()); diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index db2baf764cc..c108c4fe0b3 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -30,6 +30,7 @@ #include "CreatureGroups.h" #include "Creature.h" #include "Formulas.h" +#include "GameTime.h" #include "GridNotifiersImpl.h" #include "Group.h" #include "InstanceSaveMgr.h" diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index d8c3c8485c9..1889d6bfb21 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -226,7 +226,6 @@ bool SpellClickInfo::IsFitToRequirements(Unit const* clicker, Unit const* clicke ObjectMgr::ObjectMgr(): _auctionId(1), _equipmentSetGuid(1), - _itemTextId(1), _mailId(1), _hiPetNumber(1), _voidItemId(1), diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index 19aae051609..5c54e31951c 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -1404,9 +1404,8 @@ class TC_GAME_API ObjectMgr // first free id for selected id type uint32 _auctionId; uint64 _equipmentSetGuid; - uint32 _itemTextId; - uint32 _mailId; - uint32 _hiPetNumber; + std::atomic _mailId; + std::atomic _hiPetNumber; uint64 _voidItemId; uint32 _creatureSpawnId; diff --git a/src/server/game/Handlers/BattleGroundHandler.cpp b/src/server/game/Handlers/BattleGroundHandler.cpp index 5ce03363ebd..da1f3f4f88c 100644 --- a/src/server/game/Handlers/BattleGroundHandler.cpp +++ b/src/server/game/Handlers/BattleGroundHandler.cpp @@ -27,6 +27,7 @@ #include "BattlegroundMgr.h" #include "Battleground.h" #include "Chat.h" +#include "GameTime.h" #include "Language.h" #include "Log.h" #include "Player.h" @@ -659,7 +660,7 @@ void WorldSession::HandleBattlefieldStatusOpcode(WorldPacket & /*recvData*/) continue; // send status invited to Battleground - sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, GetPlayer(), i, STATUS_WAIT_JOIN, getMSTimeDiff(getMSTime(), ginfo.RemoveInviteTime), _player->GetBattlegroundQueueJoinTime(bgTypeId), arenaType); + sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, GetPlayer(), i, STATUS_WAIT_JOIN, getMSTimeDiff(GameTime::GetGameTimeMS(), ginfo.RemoveInviteTime), _player->GetBattlegroundQueueJoinTime(bgTypeId), arenaType); SendPacket(&data); } else diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp index 7f7c281842e..8db9e1b6334 100644 --- a/src/server/game/Handlers/CharacterHandler.cpp +++ b/src/server/game/Handlers/CharacterHandler.cpp @@ -24,6 +24,7 @@ #include "Chat.h" #include "Common.h" #include "DatabaseEnv.h" +#include "GameTime.h" #include "Group.h" #include "Guild.h" #include "GuildFinderMgr.h" @@ -953,7 +954,7 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder) stmt->setUInt32(0, GetAccountId()); LoginDatabase.Execute(stmt); - 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/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp index 9cb3940fe8e..b3df68bf14f 100644 --- a/src/server/game/Handlers/MiscHandler.cpp +++ b/src/server/game/Handlers/MiscHandler.cpp @@ -23,6 +23,7 @@ #include "Opcodes.h" #include "Log.h" #include "Player.h" +#include "GameTime.h" #include "GossipDef.h" #include "World.h" #include "ObjectMgr.h" @@ -1371,7 +1372,7 @@ void WorldSession::HandleTimeSyncResp(WorldPacket& recvData) TC_LOG_DEBUG("network", "Time sync received: counter %u, client ticks %u, time since last sync %u", counter, clientTicks, clientTicks - _player->m_timeSyncClient); - uint32 ourTicks = clientTicks + (getMSTime() - _player->m_timeSyncServer); + uint32 ourTicks = clientTicks + (GameTime::GetGameTimeMS() - _player->m_timeSyncServer); // diff should be small TC_LOG_DEBUG("network", "Our ticks: %u, diff %u, latency %u", ourTicks, ourTicks - clientTicks, GetLatency()); diff --git a/src/server/game/Handlers/MovementHandler.cpp b/src/server/game/Handlers/MovementHandler.cpp index bb4bc89a209..08fb1e02499 100644 --- a/src/server/game/Handlers/MovementHandler.cpp +++ b/src/server/game/Handlers/MovementHandler.cpp @@ -31,6 +31,7 @@ #include "ObjectMgr.h" #include "MovementStructures.h" #include "Vehicle.h" +#include "GameTime.h" #define MOVEMENT_PACKET_TIME_DELAY 0 @@ -382,7 +383,7 @@ void WorldSession::HandleMovementOpcodes(WorldPacket& recvPacket) plrMover->SetInWater(!plrMover->IsInWater() || plrMover->GetBaseMap()->IsUnderWater(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 868d60f2a1c..a5bdc9c2ff0 100644 --- a/src/server/game/Maps/MapScripts.cpp +++ b/src/server/game/Maps/MapScripts.cpp @@ -17,6 +17,7 @@ */ #include "CellImpl.h" +#include "GameTime.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" #include "GossipDef.h" @@ -55,7 +56,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; @@ -85,7 +86,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(); @@ -285,7 +286,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/Spell.cpp b/src/server/game/Spells/Spell.cpp index 5809f74eead..dd899503c1a 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -20,6 +20,7 @@ #include "DatabaseEnv.h" #include "WorldPacket.h" #include "WorldSession.h" +#include "GameTime.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" #include "Opcodes.h" @@ -2301,7 +2302,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 @@ -4085,7 +4086,7 @@ void Spell::SendSpellGo() data << uint32(m_spellInfo->Id); // spellId data << uint32(castFlags); // cast flags data << uint32(m_timer); - data << uint32(getMSTime()); // timestamp + data << uint32(GameTime::GetGameTimeMS()); // timestamp WriteSpellGoTargets(&data); diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index c3f8b4c8a09..9acfb31fef7 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -3730,7 +3730,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 f53a4b7c36b..95855c3535e 100644 --- a/src/server/game/Spells/SpellHistory.cpp +++ b/src/server/game/Spells/SpellHistory.cpp @@ -21,7 +21,6 @@ #include "Player.h" #include "SpellInfo.h" #include "Spell.h" -#include "World.h" #include "Opcodes.h" SpellHistory::Clock::duration const SpellHistory::InfinityCooldownDelay = std::chrono::duration_cast(std::chrono::seconds(MONTH)); @@ -136,7 +135,7 @@ void SpellHistory::SaveToDB(SQLTransaction& 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) @@ -195,7 +194,7 @@ bool SpellHistory::IsReady(SpellInfo const* spellInfo, uint32 itemId /*= 0*/, bo template<> void SpellHistory::WritePacket(WorldPacket& packet) const { - Clock::time_point now = Clock::now(); + Clock::time_point now = GameTime::GetGameTimeSystemPoint(); uint8 cooldownsCount = _spellCooldowns.size(); packet << uint8(cooldownsCount); @@ -232,7 +231,7 @@ void SpellHistory::WritePacket(WorldPacket& packet) const template<> void SpellHistory::WritePacket(WorldPacket& packet) const { - Clock::time_point now = Clock::now(); + Clock::time_point now = GameTime::GetGameTimeSystemPoint(); packet << uint16(_spellCooldowns.size()); @@ -281,7 +280,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; @@ -428,7 +427,7 @@ void SpellHistory::ModifyCooldown(uint32 spellId, int32 cooldownModMs) if (!cooldownModMs || itr == _spellCooldowns.end()) return; - Clock::time_point now = Clock::now(); + Clock::time_point now = GameTime::GetGameTimeSystemPoint(); Clock::duration offset = std::chrono::duration_cast(std::chrono::milliseconds(cooldownModMs)); if (itr->second.CooldownEnd + offset > now) itr->second.CooldownEnd += offset; @@ -522,7 +521,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; @@ -532,7 +531,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(std::chrono::milliseconds(lockoutTime)); for (uint32 i = 0; i < MAX_SPELL_SCHOOL; ++i) if (SpellSchoolMask(1 << i) & schoolMask) @@ -589,7 +588,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) @@ -601,12 +600,12 @@ bool SpellHistory::IsSchoolLocked(SpellSchoolMask schoolMask) const bool SpellHistory::HasGlobalCooldown(SpellInfo const* spellInfo) const { auto itr = _globalCooldowns.find(spellInfo->StartRecoveryCategory); - return itr != _globalCooldowns.end() && itr->second > Clock::now(); + return itr != _globalCooldowns.end() && itr->second > GameTime::GetGameTimeSystemPoint(); } void SpellHistory::AddGlobalCooldown(SpellInfo const* spellInfo, uint32 duration) { - _globalCooldowns[spellInfo->StartRecoveryCategory] = Clock::now() + std::chrono::duration_cast(std::chrono::milliseconds(duration)); + _globalCooldowns[spellInfo->StartRecoveryCategory] = GameTime::GetGameTimeSystemPoint() + std::chrono::duration_cast(std::chrono::milliseconds(duration)); } void SpellHistory::CancelGlobalCooldown(SpellInfo const* spellInfo) @@ -750,7 +749,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(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 7f6c8875974..c93d3e67e66 100644 --- a/src/server/game/Spells/SpellHistory.h +++ b/src/server/game/Spells/SpellHistory.h @@ -21,7 +21,7 @@ #include "SharedDefines.h" #include "QueryResult.h" #include "Transaction.h" -#include +#include "GameTime.h" #include class Item; @@ -75,7 +75,7 @@ public: template void AddCooldown(uint32 spellId, uint32 itemId, std::chrono::duration cooldownDuration) { - Clock::time_point now = Clock::now(); + Clock::time_point now = GameTime::GetGameTimeSystemPoint(); AddCooldown(spellId, itemId, now + std::chrono::duration_cast(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 + + * 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 . + */ + +#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..c1060d53e0b --- /dev/null +++ b/src/server/game/Time/GameTime.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2008-2017 TrinityCore + * + * 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 . + */ + +#ifndef __GAMETIME_H +#define __GAMETIME_H + +#include "Define.h" + +#include + +namespace GameTime +{ + // Server start time + TC_GAME_API time_t GetStartTime(); + + // Current server time (unix) in seconds + TC_GAME_API time_t GetGameTime(); + + // Milliseconds since server start + TC_GAME_API uint32 GetGameTimeMS(); + + /// Current chrono system_clock time point + TC_GAME_API std::chrono::system_clock::time_point GetGameTimeSystemPoint(); + + /// Current chrono steady_clock time point + TC_GAME_API std::chrono::steady_clock::time_point GetGameTimeSteadyPoint(); + + /// Uptime (in secs) + TC_GAME_API 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 + + * 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 . + */ + +#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..5d486a96323 --- /dev/null +++ b/src/server/game/Time/UpdateTime.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2008-2017 TrinityCore + * + * 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 . + */ + +#ifndef __UPDATETIME_H +#define __UPDATETIME_H + +#include "Define.h" + +#define AVG_DIFF_COUNT 500 + +class TC_GAME_API UpdateTime +{ + using DiffTableArray = std::array; + + 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 TC_GAME_API 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 8149257c1e4..fae8198e092 100644 --- a/src/server/game/Warden/Warden.cpp +++ b/src/server/game/Warden/Warden.cpp @@ -22,7 +22,7 @@ #include "Log.h" #include "Opcodes.h" #include "ByteBuffer.h" -#include "World.h" +#include "GameTime.h" #include "Util.h" #include "Warden.h" #include "AccountMgr.h" @@ -95,7 +95,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 1866116b758..12391db498b 100644 --- a/src/server/game/Warden/WardenMac.cpp +++ b/src/server/game/Warden/WardenMac.cpp @@ -23,7 +23,7 @@ #include "Log.h" #include "Opcodes.h" #include "ByteBuffer.h" -#include "World.h" +#include "GameTime.h" #include "Player.h" #include "Util.h" #include "WardenMac.h" @@ -185,7 +185,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 c3f2f324f21..8f19559499e 100644 --- a/src/server/game/Warden/WardenWin.cpp +++ b/src/server/game/Warden/WardenWin.cpp @@ -25,7 +25,7 @@ #include "Opcodes.h" #include "ByteBuffer.h" #include "Database/DatabaseEnv.h" -#include "World.h" +#include "GameTime.h" #include "Player.h" #include "Util.h" #include "WardenWin.h" @@ -166,7 +166,7 @@ void WardenWin::HandleHashResult(ByteBuffer &buff) _initialized = true; - _previousTimestamp = getMSTime(); + _previousTimestamp = GameTime::GetGameTimeMS(); } void WardenWin::RequestData() @@ -180,7 +180,7 @@ void WardenWin::RequestData() if (_otherChecksTodo.empty()) _otherChecksTodo.assign(sWardenCheckMgr->OtherChecksIdPool.begin(), sWardenCheckMgr->OtherChecksIdPool.end()); - _serverTicks = getMSTime(); + _serverTicks = GameTime::GetGameTimeMS(); uint16 id; uint8 type; @@ -354,7 +354,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 7bf5fc70523..50c6138e680 100644 --- a/src/server/game/Weather/Weather.cpp +++ b/src/server/game/Weather/Weather.cpp @@ -23,7 +23,7 @@ #include "Weather.h" #include "WorldPacket.h" #include "Player.h" -#include "World.h" +#include "GameTime.h" #include "Log.h" #include "Util.h" #include "ScriptMgr.h" @@ -92,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 2d4ae20b218..dd80674244f 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -69,6 +69,8 @@ #include "WorldSession.h" #include "M2Stores.h" #include "WhoListStorage.h" +#include "GameTime.h" +#include "UpdateTime.h" TC_GAME_API std::atomic World::m_stopEvent(false); TC_GAME_API uint8 World::m_ExitCode = SHUTDOWN_EXIT_CODE; @@ -91,8 +93,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; @@ -109,10 +110,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; @@ -411,6 +408,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.")); @@ -1281,8 +1281,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); @@ -1930,11 +1928,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_WEATHERS].SetInterval(1*IN_MILLISECONDS); m_timers[WUPDATE_AUCTIONS].SetInterval(MINUTE*IN_MILLISECONDS); @@ -1964,7 +1961,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())); @@ -2068,28 +2066,6 @@ void World::SetInitialWorldSettings() sLog->SetRealmId(realmId); } -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(); @@ -2127,22 +2103,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) @@ -2160,31 +2128,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) { ResetDailyQuests(); 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(); ///
  • Handle auctions when the timer has passed @@ -2226,9 +2191,9 @@ void World::Update(uint32 diff) } ///
  • Handle session updates when the timer has passed - ResetTimeDiffRecord(); + sWorldUpdateTime.RecordUpdateTimeReset(); UpdateSessions(diff); - RecordTimeDiff("UpdateSessions"); + sWorldUpdateTime.RecordUpdateTimeDuration("UpdateSessions"); ///
  • Handle weather updates when the timer has passed if (m_timers[WUPDATE_WEATHERS].Passed()) @@ -2240,7 +2205,7 @@ void World::Update(uint32 diff) ///
  • 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(); @@ -2250,7 +2215,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); } @@ -2274,9 +2239,9 @@ void World::Update(uint32 diff) ///
  • 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)) { @@ -2288,13 +2253,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()) @@ -2304,11 +2269,11 @@ void World::Update(uint32 diff) } sLFGMgr->Update(diff); - RecordTimeDiff("UpdateLFGMgr"); + sWorldUpdateTime.RecordUpdateTimeDuration("UpdateLFGMgr"); // 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()) @@ -2736,9 +2701,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 65eb23668f5..609cab53832 100644 --- a/src/server/game/World/World.h +++ b/src/server/game/World/World.h @@ -328,8 +328,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, @@ -659,16 +657,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; } @@ -788,9 +776,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(); @@ -817,6 +802,7 @@ class TC_GAME_API World protected: void _UpdateGameTime(); + // callback for UpdateRealmCharacters void _UpdateRealmCharCount(PreparedQueryResult resultCharCount); @@ -845,14 +831,9 @@ 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; - uint32 m_updateTime, m_updateTimeSum; - uint32 m_updateTimeCount; - uint32 m_currentTime; SessionMap m_sessions; typedef std::unordered_map DisconnectMap; diff --git a/src/server/scripts/Commands/cs_server.cpp b/src/server/scripts/Commands/cs_server.cpp index ede890b773f..96067b7b18f 100644 --- a/src/server/scripts/Commands/cs_server.cpp +++ b/src/server/scripts/Commands/cs_server.cpp @@ -30,6 +30,8 @@ EndScriptData */ #include "ScriptMgr.h" #include "GitRevision.h" #include "Util.h" +#include "GameTime.h" +#include "UpdateTime.h" class server_commandscript : public CommandScript { @@ -108,8 +110,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->SendSysMessage(GitRevision::GetFullVersion()); handler->PSendSysMessage(LANG_CONNECTED_PLAYERS, playersNum, maxPlayersNum); @@ -304,7 +306,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 85858fa569d..97c0e33b944 100644 --- a/src/server/scripts/Events/fireworks_show.cpp +++ b/src/server/scripts/Events/fireworks_show.cpp @@ -19,6 +19,7 @@ #include "GameObjectAI.h" #include "CreatureAIImpl.h" #include "GameEventMgr.h" +#include "GameTime.h" enum FireworksShowTypeObjects { @@ -792,7 +793,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 094c572c43d..c64773bdcec 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/icecrown_citadel.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/icecrown_citadel.cpp @@ -1836,7 +1836,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 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 186c6bed11e..ad304c711cf 100644 --- a/src/server/scripts/Northrend/Naxxramas/boss_four_horsemen.cpp +++ b/src/server/scripts/Northrend/Naxxramas/boss_four_horsemen.cpp @@ -16,6 +16,7 @@ */ #include "Player.h" +#include "GameTime.h" #include "ScriptMgr.h" #include "ScriptedCreature.h" #include "SpellScript.h" @@ -327,7 +328,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 d6309982d81..26a427dbbe6 100644 --- a/src/server/scripts/Northrend/Nexus/Nexus/boss_magus_telestra.cpp +++ b/src/server/scripts/Northrend/Nexus/Nexus/boss_magus_telestra.cpp @@ -17,6 +17,7 @@ */ #include "GameEventMgr.h" +#include "GameTime.h" #include "ScriptMgr.h" #include "ScriptedCreature.h" #include "nexus.h" @@ -167,7 +168,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 03d4d60a6c7..399718d49cf 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 . */ +#include "GameTime.h" #include "ScriptMgr.h" #include "ScriptedCreature.h" #include "SpellScript.h" @@ -194,7 +195,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 87bd32c726d..7325015c2d8 100644 --- a/src/server/scripts/Spells/spell_generic.cpp +++ b/src/server/scripts/Spells/spell_generic.cpp @@ -23,6 +23,7 @@ */ #include "ScriptMgr.h" +#include "GameTime.h" #include "Battleground.h" #include "Cell.h" #include "CellImpl.h" @@ -3199,7 +3200,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 @@ -3213,7 +3214,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 72ae363c743..a3fb056ba8f 100644 --- a/src/server/scripts/World/areatrigger_scripts.cpp +++ b/src/server/scripts/World/areatrigger_scripts.cpp @@ -35,6 +35,7 @@ at_brewfest at_area_52_entrance EndContentData */ +#include "GameTime.h" #include "ScriptMgr.h" #include "ScriptedCreature.h" #include "Player.h" @@ -314,7 +315,7 @@ class AreaTrigger_at_brewfest : public AreaTriggerScript { uint32 triggerId = trigger->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) @@ -331,7 +332,7 @@ class AreaTrigger_at_brewfest : public AreaTriggerScript break; } - _triggerTimes[triggerId] = sWorld->GetGameTime(); + _triggerTimes[triggerId] = GameTime::GetGameTime(); return false; } @@ -371,7 +372,7 @@ class AreaTrigger_at_area_52_entrance : public AreaTriggerScript return false; uint32 triggerId = trigger->id; - if (sWorld->GetGameTime() - _triggerTimes[trigger->id] < SUMMON_COOLDOWN) + if (GameTime::GetGameTime() - _triggerTimes[trigger->id] < SUMMON_COOLDOWN) return false; switch (triggerId) @@ -400,7 +401,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[trigger->id] = sWorld->GetGameTime(); + _triggerTimes[trigger->id] = GameTime::GetGameTime(); return false; } diff --git a/src/server/scripts/World/duel_reset.cpp b/src/server/scripts/World/duel_reset.cpp index d792a1cb47f..3d8692780b6 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 . */ +#include "GameTime.h" #include "ScriptMgr.h" #include "Player.h" #include "Pet.h" @@ -103,7 +104,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(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 4f775ffe53a..4c09cd216f8 100644 --- a/src/server/scripts/World/go_scripts.cpp +++ b/src/server/scripts/World/go_scripts.cpp @@ -53,6 +53,7 @@ EndContentData */ #include "Player.h" #include "WorldSession.h" #include "GameEventMgr.h" +#include "GameTime.h" /*###### ## go_cat_figurine @@ -1573,7 +1574,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;