From 51b8773528d7cf526d926ddb6edee2b0a8aec17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viste=28=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=29?= Date: Thu, 14 Feb 2019 21:22:17 +0300 Subject: [PATCH] feat(core): Ensure that all actions are compared to fixed point in time (#1236) (#1458) i.e. world update start --- src/server/game/AI/CoreAI/PetAI.cpp | 9 +- .../game/AI/ScriptedAI/ScriptedCreature.cpp | 5 +- .../game/Achievements/AchievementMgr.cpp | 11 +- .../game/ArenaSpectator/ArenaSpectator.h | 3 +- .../game/AuctionHouse/AuctionHouseMgr.cpp | 9 +- src/server/game/Battlefield/Battlefield.cpp | 11 +- .../game/Battlefield/BattlefieldHandler.cpp | 3 +- .../game/Battlefield/Zones/BattlefieldWG.cpp | 3 +- .../game/Battlegrounds/BattlegroundMgr.cpp | 7 +- .../game/Battlegrounds/BattlegroundQueue.cpp | 9 +- .../Battlegrounds/Zones/BattlegroundEY.cpp | 5 +- .../Battlegrounds/Zones/BattlegroundIC.cpp | 13 +- .../Battlegrounds/Zones/BattlegroundSA.cpp | 5 +- src/server/game/CMakeLists.txt | 3 + src/server/game/Calendar/CalendarMgr.cpp | 4 + src/server/game/Calendar/CalendarMgr.h | 3 +- src/server/game/Chat/Channels/Channel.cpp | 24 ++- src/server/game/Chat/Channels/Channel.h | 14 +- src/server/game/Combat/ThreatManager.cpp | 3 +- src/server/game/DungeonFinding/LFGMgr.cpp | 15 +- src/server/game/DungeonFinding/LFGQueue.cpp | 8 +- src/server/game/DungeonFinding/LFGQueue.h | 4 +- src/server/game/Entities/Corpse/Corpse.cpp | 8 +- src/server/game/Entities/Corpse/Corpse.h | 2 +- .../game/Entities/Creature/Creature.cpp | 55 ++++--- src/server/game/Entities/Creature/Creature.h | 9 +- .../Entities/DynamicObject/DynamicObject.cpp | 3 +- .../game/Entities/GameObject/GameObject.cpp | 59 ++++--- .../game/Entities/GameObject/GameObject.h | 19 +-- src/server/game/Entities/Item/Item.cpp | 7 +- src/server/game/Entities/Object/Object.cpp | 7 +- src/server/game/Entities/Pet/Pet.cpp | 17 +- src/server/game/Entities/Player/Player.cpp | 148 +++++++++++------- src/server/game/Entities/Player/Player.h | 30 +--- .../game/Entities/Transport/Transport.cpp | 5 +- src/server/game/Entities/Unit/Unit.cpp | 36 ++--- src/server/game/Events/GameEventMgr.cpp | 17 +- src/server/game/Globals/ObjectAccessor.cpp | 3 +- src/server/game/Globals/ObjectMgr.cpp | 5 +- src/server/game/Groups/Group.cpp | 11 ++ src/server/game/Groups/Group.h | 8 +- src/server/game/Guilds/Guild.cpp | 16 +- src/server/game/Guilds/Guild.h | 5 +- .../game/Handlers/AuctionHouseHandler.cpp | 11 +- .../game/Handlers/BattleGroundHandler.cpp | 5 +- src/server/game/Handlers/CalendarHandler.cpp | 19 +-- src/server/game/Handlers/CharacterHandler.cpp | 11 +- src/server/game/Handlers/ChatHandler.cpp | 4 +- src/server/game/Handlers/DuelHandler.cpp | 3 +- src/server/game/Handlers/LFGHandler.cpp | 3 +- src/server/game/Handlers/MailHandler.cpp | 15 +- src/server/game/Handlers/MiscHandler.cpp | 11 +- src/server/game/Handlers/MovementHandler.cpp | 6 +- src/server/game/Handlers/PetHandler.cpp | 9 +- src/server/game/Handlers/QueryHandler.cpp | 5 +- src/server/game/Handlers/TicketHandler.cpp | 3 +- src/server/game/Instances/InstanceSaveMgr.cpp | 9 +- src/server/game/Mails/Mail.cpp | 3 +- src/server/game/Maps/Map.cpp | 7 +- src/server/game/Movement/MotionMaster.cpp | 3 +- .../TargetedMovementGenerator.cpp | 9 +- .../WaypointMovementGenerator.cpp | 5 +- src/server/game/Scripting/MapScripts.cpp | 7 +- src/server/game/Server/Protocol/PacketLog.cpp | 3 +- src/server/game/Server/WorldSession.cpp | 11 +- src/server/game/Server/WorldSocket.cpp | 3 +- .../game/Spells/Auras/SpellAuraEffects.cpp | 3 +- src/server/game/Spells/Auras/SpellAuras.cpp | 7 +- src/server/game/Spells/Spell.cpp | 11 +- src/server/game/Spells/SpellEffects.cpp | 9 +- src/server/game/Tickets/TicketMgr.cpp | 19 ++- src/server/game/Tickets/TicketMgr.h | 8 +- src/server/game/Time/GameTime.cpp | 57 +++++++ src/server/game/Time/GameTime.h | 37 +++++ src/server/game/Time/UpdateTime.cpp | 124 +++++++++++++++ src/server/game/Time/UpdateTime.h | 65 ++++++++ src/server/game/Warden/Warden.cpp | 3 +- src/server/game/Warden/WardenMac.cpp | 3 +- src/server/game/Warden/WardenWin.cpp | 7 +- src/server/game/Weather/Weather.cpp | 3 +- src/server/game/World/World.cpp | 97 ++++++------ src/server/game/World/World.h | 18 --- src/server/scripts/CMakeLists.txt | 1 + src/server/scripts/Commands/cs_ban.cpp | 5 +- src/server/scripts/Commands/cs_event.cpp | 5 +- src/server/scripts/Commands/cs_gobject.cpp | 3 +- src/server/scripts/Commands/cs_instance.cpp | 5 +- src/server/scripts/Commands/cs_misc.cpp | 7 +- src/server/scripts/Commands/cs_npc.cpp | 3 +- src/server/scripts/Commands/cs_server.cpp | 8 +- src/server/scripts/Events/brewfest.cpp | 5 +- src/server/scripts/Events/midsummer.cpp | 5 +- .../instance_trial_of_the_crusader.cpp | 9 +- .../trial_of_the_crusader.cpp | 1 + .../boss_icecrown_gunship_battle.cpp | 29 ++-- .../IcecrownCitadel/boss_sindragosa.cpp | 3 +- .../IcecrownCitadel/boss_the_lich_king.cpp | 11 +- .../Northrend/Ulduar/Ulduar/boss_ignis.cpp | 5 +- .../Northrend/Ulduar/Ulduar/boss_mimiron.cpp | 11 +- .../Ulduar/Ulduar/instance_ulduar.cpp | 5 +- .../instance_vault_of_archavon.cpp | 7 +- .../scripts/Northrend/zone_wintergrasp.cpp | 3 +- .../botanica/instance_the_botanica.cpp | 5 +- src/server/scripts/Spells/spell_generic.cpp | 5 +- src/server/scripts/Spells/spell_item.cpp | 3 +- .../scripts/World/areatrigger_scripts.cpp | 9 +- src/server/scripts/World/go_scripts.cpp | 7 +- src/server/scripts/World/npcs_special.cpp | 5 +- 108 files changed, 933 insertions(+), 509 deletions(-) create mode 100644 src/server/game/Time/GameTime.cpp create mode 100644 src/server/game/Time/GameTime.h create mode 100644 src/server/game/Time/UpdateTime.cpp create mode 100644 src/server/game/Time/UpdateTime.h diff --git a/src/server/game/AI/CoreAI/PetAI.cpp b/src/server/game/AI/CoreAI/PetAI.cpp index 9ca9cbae2..3d151546b 100644 --- a/src/server/game/AI/CoreAI/PetAI.cpp +++ b/src/server/game/AI/CoreAI/PetAI.cpp @@ -9,6 +9,7 @@ #include "Pet.h" #include "Player.h" #include "DBCStores.h" +#include "GameTime.h" #include "Spell.h" #include "ObjectAccessor.h" #include "SpellMgr.h" @@ -51,7 +52,7 @@ bool PetAI::_needToStop() if (!me->_CanDetectFeignDeathOf(me->GetVictim())) return true; - if (me->isTargetNotAcceptableByMMaps(me->GetVictim()->GetGUID(), sWorld->GetGameTime(), me->GetVictim())) + if (me->isTargetNotAcceptableByMMaps(me->GetVictim()->GetGUID(), GameTime::GetGameTime(), me->GetVictim())) return true; return !me->CanCreatureAttack(me->GetVictim()); @@ -433,7 +434,7 @@ Unit* PetAI::SelectNextTarget(bool allowAutoSelect) const // Check pet attackers first so we don't drag a bunch of targets to the owner if (Unit* myAttacker = me->getAttackerForHelper()) - if (!myAttacker->HasBreakableByDamageCrowdControlAura() && me->_CanDetectFeignDeathOf(myAttacker) && me->CanCreatureAttack(myAttacker) && !me->isTargetNotAcceptableByMMaps(myAttacker->GetGUID(), sWorld->GetGameTime(), myAttacker)) + if (!myAttacker->HasBreakableByDamageCrowdControlAura() && me->_CanDetectFeignDeathOf(myAttacker) && me->CanCreatureAttack(myAttacker) && !me->isTargetNotAcceptableByMMaps(myAttacker->GetGUID(), GameTime::GetGameTime(), myAttacker)) return myAttacker; // Check pet's attackers first to prevent dragging mobs back to owner @@ -454,13 +455,13 @@ Unit* PetAI::SelectNextTarget(bool allowAutoSelect) const // Check owner attackers if (Unit* ownerAttacker = owner->getAttackerForHelper()) - if (!ownerAttacker->HasBreakableByDamageCrowdControlAura() && me->_CanDetectFeignDeathOf(ownerAttacker) && me->CanCreatureAttack(ownerAttacker) && !me->isTargetNotAcceptableByMMaps(ownerAttacker->GetGUID(), sWorld->GetGameTime(), ownerAttacker)) + if (!ownerAttacker->HasBreakableByDamageCrowdControlAura() && me->_CanDetectFeignDeathOf(ownerAttacker) && me->CanCreatureAttack(ownerAttacker) && !me->isTargetNotAcceptableByMMaps(ownerAttacker->GetGUID(), GameTime::GetGameTime(), ownerAttacker)) return ownerAttacker; // Check owner victim // 3.0.2 - Pets now start attacking their owners victim in defensive mode as soon as the hunter does if (Unit* ownerVictim = owner->GetVictim()) - if (me->_CanDetectFeignDeathOf(ownerVictim) && me->CanCreatureAttack(ownerVictim) && !me->isTargetNotAcceptableByMMaps(ownerVictim->GetGUID(), sWorld->GetGameTime(), ownerVictim)) + if (me->_CanDetectFeignDeathOf(ownerVictim) && me->CanCreatureAttack(ownerVictim) && !me->isTargetNotAcceptableByMMaps(ownerVictim->GetGUID(), GameTime::GetGameTime(), ownerVictim)) return ownerVictim; // Neither pet or owner had a target and aggressive pets can pick any target diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index 77e73b38b..7bd45cf51 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -10,6 +10,7 @@ #include "Spell.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" +#include "GameTime.h" #include "Cell.h" #include "CellImpl.h" #include "ObjectMgr.h" @@ -417,9 +418,9 @@ bool ScriptedAI::EnterEvadeIfOutOfCombatArea() if (me->IsInEvadeMode() || !me->IsInCombat()) return false; - if (_evadeCheckCooldown == time(NULL)) + if (_evadeCheckCooldown == GameTime::GetGameTime()) return false; - _evadeCheckCooldown = time(NULL); + _evadeCheckCooldown = GameTime::GetGameTime(); if (!CheckEvadeIfOutOfCombatArea()) return false; diff --git a/src/server/game/Achievements/AchievementMgr.cpp b/src/server/game/Achievements/AchievementMgr.cpp index d98b1ac31..89ca7b254 100644 --- a/src/server/game/Achievements/AchievementMgr.cpp +++ b/src/server/game/Achievements/AchievementMgr.cpp @@ -17,6 +17,7 @@ #include "DBCEnums.h" #include "DisableMgr.h" #include "GameEventMgr.h" +#include "GameTime.h" #include "GridNotifiersImpl.h" #include "Guild.h" #include "GuildMgr.h" @@ -434,7 +435,7 @@ bool AchievementCriteriaData::Meets(uint32 criteria_id, Player const* source, Un birthday_tm.tm_year += birthday_login.nth_birthday; time_t birthday = mktime(&birthday_tm); - time_t now = sWorld->GetGameTime(); + time_t now = GameTime::GetGameTime(); return now <= birthday + DAY && now >= birthday; } case ACHIEVEMENT_CRITERIA_DATA_TYPE_S_KNOWN_TITLE: @@ -642,7 +643,7 @@ void AchievementMgr::LoadFromDB(PreparedQueryResult achievementResult, PreparedQ continue; } - if (criteria->timeLimit && time_t(date + criteria->timeLimit) < time(NULL)) + if (criteria->timeLimit && time_t(date + criteria->timeLimit) < GameTime::GetGameTime()) continue; CriteriaProgress& progress = m_criteriaProgress[id]; @@ -701,7 +702,7 @@ void AchievementMgr::SendAchievementEarned(AchievementEntry const* achievement) WorldPacket data(SMSG_ACHIEVEMENT_EARNED, 8+4+8); data.append(GetPlayer()->GetPackGUID()); data << uint32(achievement->ID); - data.AppendPackedTime(time(NULL)); + data.AppendPackedTime(GameTime::GetGameTime()); data << uint32(0); GetPlayer()->SendMessageToSetInRange(&data, sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_SAY), true); } @@ -2043,7 +2044,7 @@ void AchievementMgr::SetCriteriaProgress(AchievementCriteriaEntry const* entry, } progress->changed = true; - progress->date = time(NULL); // set the date to the latest update. + progress->date = GameTime::GetGameTime(); // set the date to the latest update. uint32 timeElapsed = 0; bool timedCompleted = false; @@ -2163,7 +2164,7 @@ void AchievementMgr::CompletedAchievement(AchievementEntry const* achievement) SendAchievementEarned(achievement); CompletedAchievementData& ca = m_completedAchievements[achievement->ID]; - ca.date = time(NULL); + ca.date = GameTime::GetGameTime(); ca.changed = true; sScriptMgr->OnAchievementComplete(GetPlayer(), achievement); diff --git a/src/server/game/ArenaSpectator/ArenaSpectator.h b/src/server/game/ArenaSpectator/ArenaSpectator.h index f60cf9d9f..42d31785e 100644 --- a/src/server/game/ArenaSpectator/ArenaSpectator.h +++ b/src/server/game/ArenaSpectator/ArenaSpectator.h @@ -6,6 +6,7 @@ #include "World.h" #include "Map.h" #include "Battleground.h" +#include "GameTime.h" #include "Pet.h" #include "SpellAuras.h" #include "SpellAuraEffects.h" @@ -178,7 +179,7 @@ namespace ArenaSpectator SpellCooldowns const& sc = plr->GetSpellCooldownMap(); for (SpellCooldowns::const_iterator itrc = sc.begin(); itrc != sc.end(); ++itrc) if (itrc->second.sendToSpectator && itrc->second.maxduration >= SPECTATOR_COOLDOWN_MIN*IN_MILLISECONDS && itrc->second.maxduration <= SPECTATOR_COOLDOWN_MAX*IN_MILLISECONDS) - if (uint32 cd = (getMSTimeDiff(World::GetGameTimeMS(), itrc->second.end)/1000)) + if (uint32 cd = (getMSTimeDiff(GameTime::GetGameTimeMS(), itrc->second.end)/1000)) SendCommand_Cooldown(p, itr->first, "ACD", itrc->first, cd, itrc->second.maxduration/1000); // send all visible "AUR" diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp index 4aba5703b..ab3bf503a 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp @@ -18,6 +18,7 @@ #include "Item.h" #include "Language.h" #include "Logging/Log.h" +#include "GameTime.h" #include #include "AvgDiffTracker.h" #include "AsyncAuctionListing.h" @@ -424,7 +425,7 @@ bool AuctionHouseObject::RemoveAuction(AuctionEntry* auction) void AuctionHouseObject::Update() { - time_t checkTime = sWorld->GetGameTime() + 60; + time_t checkTime = GameTime::GetGameTime() + 60; ///- Handle expired auctions // If storage is empty, no need to update. next == NULL in this case. @@ -522,7 +523,7 @@ bool AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player return true; } - time_t curTime = sWorld->GetGameTime(); + time_t curTime = GameTime::GetGameTime(); int loc_idx = player->GetSession()->GetSessionDbLocaleIndex(); int locdbc_idx = player->GetSession()->GetSessionDbcLocale(); @@ -531,7 +532,7 @@ bool AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player { if (AsyncAuctionListingMgr::IsAuctionListingAllowed() == false) // pussywizard: World::Update is waiting for us... if ((itrcounter++) % 100 == 0) // check condition every 100 iterations - if (avgDiffTracker.getAverage() >= 30 || getMSTimeDiff(World::GetGameTimeMS(), getMSTime()) >= 10) // pussywizard: stop immediately if diff is high or waiting too long + if (avgDiffTracker.getAverage() >= 30 || getMSTimeDiff(GameTime::GetGameTimeMS(), getMSTime()) >= 10) // pussywizard: stop immediately if diff is high or waiting too long return false; AuctionEntry* Aentry = itr->second; @@ -669,7 +670,7 @@ bool AuctionEntry::BuildAuctionInfo(WorldPacket& data) const data << uint32(bid ? GetAuctionOutBid() : 0); // Minimal outbid data << uint32(buyout); // Auction->buyout - data << uint32((expire_time - time(NULL)) * IN_MILLISECONDS); // time left + data << uint32((expire_time - GameTime::GetGameTime()) * IN_MILLISECONDS); // time left data << uint64(bidder); // auction->bidder current data << uint32(bid); // current bid return true; diff --git a/src/server/game/Battlefield/Battlefield.cpp b/src/server/game/Battlefield/Battlefield.cpp index 21b532056..f33a82a50 100644 --- a/src/server/game/Battlefield/Battlefield.cpp +++ b/src/server/game/Battlefield/Battlefield.cpp @@ -8,6 +8,7 @@ #include "BattlefieldMgr.h" #include "ObjectAccessor.h" #include "ObjectMgr.h" +#include "GameTime.h" #include "Map.h" #include "MapManager.h" #include "Group.h" @@ -77,7 +78,7 @@ void Battlefield::HandlePlayerEnterZone(Player* player, uint32 /*zone*/) else // No more vacant places { // TODO: Send a packet to announce it to player - m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = time(NULL) + (player->IsGameMaster() ? 30*MINUTE : 10); + m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime() + (player->IsGameMaster() ? 30*MINUTE : 10); InvitePlayerToQueue(player); } } @@ -167,7 +168,7 @@ bool Battlefield::Update(uint32 diff) // Kick players who chose not to accept invitation to the battle if (m_uiKickDontAcceptTimer <= diff) { - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); for (int team = 0; team < 2; team++) for (PlayerTimerMap::iterator itr = m_InvitedPlayers[team].begin(); itr != m_InvitedPlayers[team].end(); ++itr) if (itr->second <= now) @@ -253,7 +254,7 @@ void Battlefield::InvitePlayersInZoneToWar() if (m_PlayersInWar[player->GetTeamId()].size() + m_InvitedPlayers[player->GetTeamId()].size() < m_MaxPlayer) InvitePlayerToWar(player); else if (m_PlayersWillBeKick[player->GetTeamId()].count(player->GetGUID()) == 0)// Battlefield is full of players - m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = time(NULL) + 10; + m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime() + 10; } } } @@ -277,7 +278,7 @@ void Battlefield::InvitePlayerToWar(Player* player) if (player->getLevel() < m_MinLevel) { if (m_PlayersWillBeKick[player->GetTeamId()].count(player->GetGUID()) == 0) - m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = time(NULL) + 10; + m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime() + 10; return; } @@ -286,7 +287,7 @@ void Battlefield::InvitePlayerToWar(Player* player) return; m_PlayersWillBeKick[player->GetTeamId()].erase(player->GetGUID()); - m_InvitedPlayers[player->GetTeamId()][player->GetGUID()] = time(NULL) + m_TimeForAcceptInvite; + m_InvitedPlayers[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime() + m_TimeForAcceptInvite; player->GetSession()->SendBfInvitePlayerToWar(m_BattleId, m_ZoneId, m_TimeForAcceptInvite); } diff --git a/src/server/game/Battlefield/BattlefieldHandler.cpp b/src/server/game/Battlefield/BattlefieldHandler.cpp index cdb20b6c4..08b9c081c 100644 --- a/src/server/game/Battlefield/BattlefieldHandler.cpp +++ b/src/server/game/Battlefield/BattlefieldHandler.cpp @@ -7,6 +7,7 @@ #include "Common.h" #include "ObjectAccessor.h" #include "ObjectMgr.h" +#include "GameTime.h" #include "WorldPacket.h" #include "WorldSession.h" @@ -25,7 +26,7 @@ void WorldSession::SendBfInvitePlayerToWar(uint32 BattleId, uint32 ZoneId, uint3 WorldPacket data(SMSG_BATTLEFIELD_MGR_ENTRY_INVITE, 12); data << uint32(BattleId); data << uint32(ZoneId); - data << uint32((time(NULL) + p_time)); + data << uint32((GameTime::GetGameTime() + p_time)); //Sending the packet to player SendPacket(&data); diff --git a/src/server/game/Battlefield/Zones/BattlefieldWG.cpp b/src/server/game/Battlefield/Zones/BattlefieldWG.cpp index 708891200..6ebc3b35f 100644 --- a/src/server/game/Battlefield/Zones/BattlefieldWG.cpp +++ b/src/server/game/Battlefield/Zones/BattlefieldWG.cpp @@ -10,6 +10,7 @@ #include "BattlefieldWG.h" #include "ObjectMgr.h" +#include "GameTime.h" #include "Opcodes.h" #include "Player.h" #include "SpellAuras.h" @@ -888,7 +889,7 @@ void BattlefieldWG::FillInitialWorldStates(WorldPacket& data) data << uint32(BATTLEFIELD_WG_WORLD_STATE_SHOW_WORLDSTATE) << uint32(IsWarTime() ? 1 : 0); for (uint32 i = 0; i < 2; ++i) - data << ClockWorldState[i] << uint32(time(NULL) + (m_Timer / 1000)); + data << ClockWorldState[i] << uint32(GameTime::GetGameTime() + (m_Timer / 1000)); data << uint32(BATTLEFIELD_WG_WORLD_STATE_VEHICLE_H) << uint32(GetData(BATTLEFIELD_WG_DATA_VEHICLE_H)); data << uint32(BATTLEFIELD_WG_WORLD_STATE_MAX_VEHICLE_H) << GetData(BATTLEFIELD_WG_DATA_MAX_VEHICLE_H); diff --git a/src/server/game/Battlegrounds/BattlegroundMgr.cpp b/src/server/game/Battlegrounds/BattlegroundMgr.cpp index 32d47992e..9beabab3a 100644 --- a/src/server/game/Battlegrounds/BattlegroundMgr.cpp +++ b/src/server/game/Battlegrounds/BattlegroundMgr.cpp @@ -9,6 +9,7 @@ #include "ArenaTeamMgr.h" #include "World.h" #include "WorldPacket.h" +#include "GameTime.h" #include "ArenaTeam.h" #include "BattlegroundMgr.h" @@ -129,7 +130,7 @@ void BattlegroundMgr::Update(uint32 diff) { if (m_AutoDistributionTimeChecker < diff) { - if (time(NULL) > m_NextAutoDistributionTime) + if (GameTime::GetGameTime() > m_NextAutoDistributionTime) { sArenaTeamMgr->DistributeArenaPoints(); m_NextAutoDistributionTime = m_NextAutoDistributionTime + BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY * sWorld->getIntConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_INTERVAL_DAYS); @@ -694,7 +695,7 @@ void BattlegroundMgr::InitAutomaticArenaPointDistribution() return; time_t wstime = time_t(sWorld->getWorldState(WS_ARENA_DISTRIBUTION_TIME)); - time_t curtime = time(NULL); + time_t curtime = GameTime::GetGameTime(); sLog->outString("AzerothCore Battleground: Initializing Automatic Arena Point Distribution"); if (wstime < curtime) { @@ -1051,7 +1052,7 @@ void BattlegroundMgr::InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg, T if (bg->isArena() && bg->isRated()) bg->SetArenaTeamIdForTeam(ginfo->teamId, ginfo->ArenaTeamId); - ginfo->RemoveInviteTime = World::GetGameTimeMS() + INVITE_ACCEPT_WAIT_TIME; + ginfo->RemoveInviteTime = GameTime::GetGameTimeMS() + INVITE_ACCEPT_WAIT_TIME; // loop through the players for (std::set::iterator itr = ginfo->Players.begin(); itr != ginfo->Players.end(); ++itr) diff --git a/src/server/game/Battlegrounds/BattlegroundQueue.cpp b/src/server/game/Battlegrounds/BattlegroundQueue.cpp index a35cece87..2e324b191 100644 --- a/src/server/game/Battlegrounds/BattlegroundQueue.cpp +++ b/src/server/game/Battlegrounds/BattlegroundQueue.cpp @@ -8,6 +8,7 @@ #include "ArenaTeamMgr.h" #include "BattlegroundMgr.h" #include "BattlegroundQueue.h" +#include "GameTime.h" #include "Chat.h" #include "Group.h" #include "Log.h" @@ -124,7 +125,7 @@ GroupQueueInfo* BattlegroundQueue::AddGroup(Player* leader, Group* grp, PvPDiffi ginfo->ArenaTeamId = arenateamid; ginfo->IsRated = isRated; ginfo->IsInvitedToBGInstanceGUID = 0; - ginfo->JoinTime = World::GetGameTimeMS(); + ginfo->JoinTime = GameTime::GetGameTimeMS(); ginfo->RemoveInviteTime = 0; ginfo->teamId = leader->GetTeamId(); ginfo->ArenaTeamRating = ArenaRating; @@ -210,7 +211,7 @@ GroupQueueInfo* BattlegroundQueue::AddGroup(Player* leader, Group* grp, PvPDiffi void BattlegroundQueue::PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo* ginfo) { - uint32 timeInQueue = std::max(1, getMSTimeDiff(ginfo->JoinTime, World::GetGameTimeMS())); + uint32 timeInQueue = std::max(1, getMSTimeDiff(ginfo->JoinTime, GameTime::GetGameTimeMS())); // team_index: bg alliance - TEAM_ALLIANCE, bg horde - TEAM_HORDE, arena skirmish - TEAM_ALLIANCE, arena rated - TEAM_HORDE uint8 team_index; @@ -538,7 +539,7 @@ bool BattlegroundQueue::CheckPremadeMatch(BattlegroundBracketId bracket_id, uint // this happens if timer has expired or group size lowered uint32 premade_time = sWorld->getIntConfig(CONFIG_BATTLEGROUND_PREMADE_GROUP_WAIT_FOR_MATCH); - uint32 time_before = World::GetGameTimeMS() >= premade_time ? World::GetGameTimeMS() - premade_time : 0; + uint32 time_before = GameTime::GetGameTimeMS() >= premade_time ? GameTime::GetGameTimeMS() - premade_time : 0; for (uint32 i = 0; i < BG_TEAMS_COUNT; i++) if (!m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE + i].empty()) @@ -789,7 +790,7 @@ void BattlegroundQueue::BattlegroundQueueUpdate(BattlegroundBracketId bracket_id { // pussywizard: everything inside this section is mine, do NOT destroy! - const uint32 currMSTime = World::GetGameTimeMS(); + const uint32 currMSTime = GameTime::GetGameTimeMS(); const uint32 discardTime = sBattlegroundMgr->GetRatingDiscardTimer(); const uint32 maxDefaultRatingDifference = (MaxPlayersPerTeam > 2 ? 300 : 200); const uint32 maxCountedMMR = 2500; diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp index 812c68d3d..2d49299ab 100644 --- a/src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp @@ -10,6 +10,7 @@ #include "Creature.h" #include "Language.h" #include "Object.h" +#include "GameTime.h" #include "Player.h" #include "Util.h" #include "WorldSession.h" @@ -56,7 +57,7 @@ void BattlegroundEY::PostUpdateImpl(uint32 diff) AddPoints(TEAM_ALLIANCE, BG_EY_TickPoints[_ownedPointsCount[TEAM_ALLIANCE] - 1]); if (_ownedPointsCount[TEAM_HORDE] > 0) AddPoints(TEAM_HORDE, BG_EY_TickPoints[_ownedPointsCount[TEAM_HORDE] - 1]); - _bgEvents.ScheduleEvent(BG_EY_EVENT_ADD_POINTS, BG_EY_FPOINTS_TICK_TIME - (World::GetGameTimeMS() % BG_EY_FPOINTS_TICK_TIME)); + _bgEvents.ScheduleEvent(BG_EY_EVENT_ADD_POINTS, BG_EY_FPOINTS_TICK_TIME - (GameTime::GetGameTimeMS() % BG_EY_FPOINTS_TICK_TIME)); break; case BG_EY_EVENT_FLAG_ON_GROUND: RespawnFlagAfterDrop(); @@ -66,7 +67,7 @@ void BattlegroundEY::PostUpdateImpl(uint32 diff) break; case BG_EY_EVENT_CHECK_CPOINTS: UpdatePointsState(); - _bgEvents.ScheduleEvent(BG_EY_EVENT_CHECK_CPOINTS, BG_EY_FPOINTS_CHECK_TIME - (World::GetGameTimeMS() % BG_EY_FPOINTS_CHECK_TIME)); + _bgEvents.ScheduleEvent(BG_EY_EVENT_CHECK_CPOINTS, BG_EY_FPOINTS_CHECK_TIME - (GameTime::GetGameTimeMS() % BG_EY_FPOINTS_CHECK_TIME)); break; } } diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundIC.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundIC.cpp index fc2a6fcb1..725cbeace 100644 --- a/src/server/game/Battlegrounds/Zones/BattlegroundIC.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundIC.cpp @@ -11,6 +11,7 @@ #include "WorldPacket.h" #include "GameObject.h" #include "ObjectMgr.h" +#include "GameTime.h" #include "Vehicle.h" #include "Transport.h" #include "WorldSession.h" @@ -127,7 +128,7 @@ void BattlegroundIC::PostUpdateImpl(uint32 diff) { // Check if creature respawn time is properly saved RespawnMap::iterator itr = respawnMap.find(catapult->GetGUIDLow()); - if (itr == respawnMap.end() || time(NULL) < itr->second) + if (itr == respawnMap.end() || GameTime::GetGameTime() < itr->second) continue; catapult->Relocate(BG_IC_DocksVehiclesCatapults[j].GetPositionX(), BG_IC_DocksVehiclesCatapults[j].GetPositionY(), BG_IC_DocksVehiclesCatapults[j].GetPositionZ(), BG_IC_DocksVehiclesCatapults[j].GetOrientation()); @@ -145,7 +146,7 @@ void BattlegroundIC::PostUpdateImpl(uint32 diff) { // Check if creature respawn time is properly saved RespawnMap::iterator itr = respawnMap.find(glaiveThrower->GetGUIDLow()); - if (itr == respawnMap.end() || time(NULL) < itr->second) + if (itr == respawnMap.end() || GameTime::GetGameTime() < itr->second) continue; glaiveThrower->Relocate(BG_IC_DocksVehiclesGlaives[j].GetPositionX(), BG_IC_DocksVehiclesGlaives[j].GetPositionY(), BG_IC_DocksVehiclesGlaives[j].GetPositionZ(), BG_IC_DocksVehiclesGlaives[j].GetOrientation()); @@ -174,7 +175,7 @@ void BattlegroundIC::PostUpdateImpl(uint32 diff) { // Check if creature respawn time is properly saved RespawnMap::iterator itr = respawnMap.find(siege->GetGUIDLow()); - if (itr == respawnMap.end() || time(NULL) < itr->second) + if (itr == respawnMap.end() || GameTime::GetGameTime() < itr->second) continue; siege->Relocate(BG_IC_WorkshopVehicles[4].GetPositionX(), BG_IC_WorkshopVehicles[4].GetPositionY(), BG_IC_WorkshopVehicles[4].GetPositionZ(), BG_IC_WorkshopVehicles[4].GetOrientation()); @@ -192,7 +193,7 @@ void BattlegroundIC::PostUpdateImpl(uint32 diff) { // Check if creature respawn time is properly saved RespawnMap::iterator itr = respawnMap.find(demolisher->GetGUIDLow()); - if (itr == respawnMap.end() || time(NULL) < itr->second) + if (itr == respawnMap.end() || GameTime::GetGameTime() < itr->second) continue; demolisher->Relocate(BG_IC_WorkshopVehicles[u].GetPositionX(), BG_IC_WorkshopVehicles[u].GetPositionY(), BG_IC_WorkshopVehicles[u].GetPositionZ(), BG_IC_WorkshopVehicles[u].GetOrientation()); @@ -520,7 +521,7 @@ void BattlegroundIC::HandleKillUnit(Creature* unit, Player* killer) // Xinef: Add to respawn list if (entry == NPC_DEMOLISHER || entry == NPC_SIEGE_ENGINE_H || entry == NPC_SIEGE_ENGINE_A || entry == NPC_GLAIVE_THROWER_A || entry == NPC_GLAIVE_THROWER_H || entry == NPC_CATAPULT) - respawnMap[unit->GetGUIDLow()] = time(NULL) + VEHICLE_RESPAWN_TIME; + respawnMap[unit->GetGUIDLow()] = GameTime::GetGameTime() + VEHICLE_RESPAWN_TIME; } } @@ -867,7 +868,7 @@ void BattlegroundIC::HandleCapturedNodes(ICNodePoint* nodePoint, bool recapture) if (!siegeVehicle->IsVehicleInUse()) Unit::Kill(siegeEngine, siegeEngine); - respawnMap[siegeEngine->GetGUIDLow()] = time(NULL) + VEHICLE_RESPAWN_TIME; + respawnMap[siegeEngine->GetGUIDLow()] = GameTime::GetGameTime() + VEHICLE_RESPAWN_TIME; } } diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp index b28340a9c..5990eca92 100644 --- a/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp @@ -9,6 +9,7 @@ #include "Player.h" #include "GameObject.h" #include "ObjectMgr.h" +#include "GameTime.h" #include "WorldPacket.h" #include "WorldSession.h" #include "GameGraveyard.h" @@ -1059,11 +1060,11 @@ void BattlegroundSA::UpdateDemolisherSpawns() // Demolisher is not in list if (DemoliserRespawnList.find(i) == DemoliserRespawnList.end()) { - DemoliserRespawnList[i] = World::GetGameTimeMS()+30000; + DemoliserRespawnList[i] = GameTime::GetGameTimeMS()+30000; } else { - if (DemoliserRespawnList[i] < World::GetGameTimeMS()) + if (DemoliserRespawnList[i] < GameTime::GetGameTimeMS()) { Demolisher->Relocate(BG_SA_NpcSpawnlocs[i][0], BG_SA_NpcSpawnlocs[i][1], BG_SA_NpcSpawnlocs[i][2], BG_SA_NpcSpawnlocs[i][3]); diff --git a/src/server/game/CMakeLists.txt b/src/server/game/CMakeLists.txt index 98e60ffa7..b7ee3bc33 100644 --- a/src/server/game/CMakeLists.txt +++ b/src/server/game/CMakeLists.txt @@ -49,6 +49,7 @@ file(GLOB_RECURSE sources_Spells Spells/*.cpp Spells/*.h) file(GLOB_RECURSE sources_Texts Texts/*.cpp Texts/*.h) file(GLOB_RECURSE sources_Tools Tools/*.cpp Tools/*.h) file(GLOB_RECURSE sources_Tickets Tickets/*.cpp Tickets/*.h) +file(GLOB_RECURSE sources_Time Time/*.cpp Time/*.h) file(GLOB_RECURSE sources_Warden Warden/*.cpp Warden/*.h) file(GLOB_RECURSE sources_Weather Weather/*.cpp Weather/*.h) file(GLOB_RECURSE sources_World World/*.cpp World/*.h) @@ -103,6 +104,7 @@ set(game_STAT_SRCS ${sources_Texts} ${sources_Tools} ${sources_Tickets} + ${sources_Time} ${sources_Warden} ${sources_Weather} ${sources_World} @@ -203,6 +205,7 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/Texts ${CMAKE_CURRENT_SOURCE_DIR}/Tools ${CMAKE_CURRENT_SOURCE_DIR}/Tickets + ${CMAKE_CURRENT_SOURCE_DIR}/Time ${CMAKE_CURRENT_SOURCE_DIR}/Warden ${CMAKE_CURRENT_SOURCE_DIR}/Warden/Modules ${CMAKE_CURRENT_SOURCE_DIR}/Weather diff --git a/src/server/game/Calendar/CalendarMgr.cpp b/src/server/game/Calendar/CalendarMgr.cpp index ec1d5dd15..e06b4cf03 100644 --- a/src/server/game/Calendar/CalendarMgr.cpp +++ b/src/server/game/Calendar/CalendarMgr.cpp @@ -8,10 +8,14 @@ #include "QueryResult.h" #include "Log.h" #include "Player.h" +#include "GameTime.h" #include "GuildMgr.h" #include "ObjectAccessor.h" #include "Opcodes.h" +CalendarInvite::CalendarInvite() : _inviteId(1), _eventId(0), _invitee(), _senderGUID(), _statusTime(GameTime::GetGameTime()), +_status(CALENDAR_STATUS_INVITED), _rank(CALENDAR_RANK_PLAYER), _text("") { } + CalendarInvite::~CalendarInvite() { sCalendarMgr->FreeInviteId(_inviteId); diff --git a/src/server/game/Calendar/CalendarMgr.h b/src/server/game/Calendar/CalendarMgr.h index c17ee23c4..d4bf966b5 100644 --- a/src/server/game/Calendar/CalendarMgr.h +++ b/src/server/game/Calendar/CalendarMgr.h @@ -130,8 +130,7 @@ struct CalendarInvite _text = calendarInvite.GetText(); } - CalendarInvite() : _inviteId(1), _eventId(0), _invitee(0), _senderGUID(0), _statusTime(time(NULL)), - _status(CALENDAR_STATUS_INVITED), _rank(CALENDAR_RANK_PLAYER), _text("") { } + CalendarInvite(); CalendarInvite(uint64 inviteId, uint64 eventId, uint64 invitee, uint64 senderGUID, time_t statusTime, CalendarInviteStatus status, CalendarModerationRank rank, std::string text) : diff --git a/src/server/game/Chat/Channels/Channel.cpp b/src/server/game/Chat/Channels/Channel.cpp index 337fdb305..d2d6134dd 100644 --- a/src/server/game/Chat/Channels/Channel.cpp +++ b/src/server/game/Chat/Channels/Channel.cpp @@ -7,6 +7,7 @@ #include "ChannelMgr.h" #include "Chat.h" #include "ObjectMgr.h" +#include "GameTime.h" #include "SocialMgr.h" #include "World.h" #include "DatabaseEnv.h" @@ -22,6 +23,7 @@ Channel::Channel(std::string const& name, uint32 channelId, uint32 channelDBId, _channelDBId(channelDBId), _teamId(teamId), _ownerGUID(0), + lastSpeakTime(0), _name(name), _password("") { @@ -83,7 +85,7 @@ Channel::Channel(std::string const& name, uint32 channelId, uint32 channelDBId, bool Channel::IsBanned(uint64 guid) const { BannedContainer::const_iterator itr = bannedStore.find(GUID_LOPART(guid)); - return itr != bannedStore.end() && itr->second > time(NULL); + return itr != bannedStore.end() && itr->second > GameTime::GetGameTime(); } void Channel::UpdateChannelInDB() const @@ -198,7 +200,6 @@ void Channel::JoinChannel(Player* player, std::string const& pass) PlayerInfo pinfo; pinfo.player = guid; pinfo.flags = MEMBER_FLAG_NONE; - pinfo.lastSpeakTime = 0; pinfo.plrPtr = player; playersStore[guid] = pinfo; @@ -405,8 +406,8 @@ void Channel::KickOrBan(Player const* player, std::string const& badname, bool b { if (!IsBanned(victim)) { - bannedStore[GUID_LOPART(victim)] = time(NULL) + CHANNEL_BAN_DURATION; - AddChannelBanToDB(GUID_LOPART(victim), time(NULL) + CHANNEL_BAN_DURATION); + bannedStore[GUID_LOPART(victim)] = GameTime::GetGameTime() + CHANNEL_BAN_DURATION; + AddChannelBanToDB(GUID_LOPART(victim), GameTime::GetGameTime() + CHANNEL_BAN_DURATION); if (notify) { @@ -786,9 +787,9 @@ void Channel::Say(uint64 guid, std::string const& what, uint32 lang) else if (playersStore.size() >= 10) speakDelay = 5; - if (!pinfo.IsAllowedToSpeak(speakDelay)) + if (IsAllowedToSpeak(speakDelay)) { - std::string timeStr = secsToTimeString(pinfo.lastSpeakTime + speakDelay - sWorld->GetGameTime()); + std::string timeStr = secsToTimeString(lastSpeakTime + speakDelay - GameTime::GetGameTime()); if (_channelRights.speakMessage.length() > 0) player->GetSession()->SendNotification("%s", _channelRights.speakMessage.c_str()); player->GetSession()->SendNotification("You must wait %s before speaking again.", timeStr.c_str()); @@ -1235,3 +1236,14 @@ void Channel::RemoveWatching(Player* p) if (itr != playersWatchingStore.end()) playersWatchingStore.erase(itr); } + +bool Channel::IsAllowedToSpeak(uint32 speakDelay) +{ + if (lastSpeakTime+speakDelay <= GameTime::GetGameTime()) + { + lastSpeakTime = GameTime::GetGameTime(); + return true; + } + else + return false; +} diff --git a/src/server/game/Chat/Channels/Channel.h b/src/server/game/Chat/Channels/Channel.h index 78b42f6ad..fda61d23b 100644 --- a/src/server/game/Chat/Channels/Channel.h +++ b/src/server/game/Chat/Channels/Channel.h @@ -12,6 +12,7 @@ #include #include "Common.h" +#include "GameTime.h" #include "Opcodes.h" #include "WorldPacket.h" @@ -139,7 +140,6 @@ class Channel { uint64 player; uint8 flags; - uint32 lastSpeakTime; // pussywizard Player* plrPtr; // pussywizard bool HasFlag(uint8 flag) const { return flags & flag; } @@ -162,16 +162,6 @@ class Channel if (state) flags |= MEMBER_FLAG_MUTED; else flags &= ~MEMBER_FLAG_MUTED; } - bool IsAllowedToSpeak(uint32 speakDelay) // pussywizard - { - if (lastSpeakTime+speakDelay <= sWorld->GetGameTime()) - { - lastSpeakTime = sWorld->GetGameTime(); - return true; - } - else - return false; - } }; public: @@ -219,6 +209,7 @@ class Channel // pussywizard: void AddWatching(Player* p); void RemoveWatching(Player* p); + bool IsAllowedToSpeak(uint32 speakDelay); // pussywizard private: // initial packet data (notify type and channel name) @@ -320,6 +311,7 @@ class Channel uint32 _channelDBId; TeamId _teamId; uint64 _ownerGUID; + uint32 lastSpeakTime; std::string _name; std::string _password; ChannelRights _channelRights; diff --git a/src/server/game/Combat/ThreatManager.cpp b/src/server/game/Combat/ThreatManager.cpp index 2c6399738..df734ed4b 100644 --- a/src/server/game/Combat/ThreatManager.cpp +++ b/src/server/game/Combat/ThreatManager.cpp @@ -11,6 +11,7 @@ #include "Map.h" #include "Player.h" #include "ObjectAccessor.h" +#include "GameTime.h" #include "UnitEvents.h" #include "SpellAuras.h" #include "SpellMgr.h" @@ -295,7 +296,7 @@ HostileReference* ThreatContainer::selectNextVictim(Creature* attacker, HostileR HostileReference* currentRef = NULL; bool found = false; bool noPriorityTargetFound = false; - uint32 currTime = sWorld->GetGameTime(); + uint32 currTime = GameTime::GetGameTime(); // pussywizard: currentVictim is needed to compare if threat was exceeded by 10%/30% for melee/range targets (only then switching current target) if (currentVictim) diff --git a/src/server/game/DungeonFinding/LFGMgr.cpp b/src/server/game/DungeonFinding/LFGMgr.cpp index 95a7aec98..cbe0fad8c 100644 --- a/src/server/game/DungeonFinding/LFGMgr.cpp +++ b/src/server/game/DungeonFinding/LFGMgr.cpp @@ -9,6 +9,7 @@ #include "DBCStores.h" #include "DisableMgr.h" #include "ObjectMgr.h" +#include "GameTime.h" #include "SocialMgr.h" #include "Language.h" #include "LFGMgr.h" @@ -260,7 +261,7 @@ void LFGMgr::Update(uint32 tdiff, uint8 task) if (task == 0) { - time_t currTime = time(NULL); + time_t currTime = GameTime::GetGameTime(); // Remove obsolete role checks for (LfgRoleCheckContainer::iterator it = RoleChecksStore.begin(); it != RoleChecksStore.end();) @@ -650,7 +651,7 @@ void LFGMgr::JoinLfg(Player* player, uint8 roles, LfgDungeonSet& dungeons, const // Create new rolecheck LfgRoleCheck& roleCheck = RoleChecksStore[gguid]; roleCheck.roles.clear(); // pussywizard: NEW rolecheck, not old one with trash data >_> - roleCheck.cancelTime = time_t(time(NULL)) + LFG_TIME_ROLECHECK; + roleCheck.cancelTime = time_t(GameTime::GetGameTime()) + LFG_TIME_ROLECHECK; roleCheck.state = LFG_ROLECHECK_INITIALITING; roleCheck.leader = guid; roleCheck.dungeons = dungeons; @@ -688,7 +689,7 @@ void LFGMgr::JoinLfg(Player* player, uint8 roles, LfgDungeonSet& dungeons, const LfgRolesMap rolesMap; rolesMap[guid] = roles; LFGQueue& queue = GetQueue(guid); - queue.AddQueueData(guid, time(NULL), dungeons, rolesMap); + queue.AddQueueData(guid, GameTime::GetGameTime(), dungeons, rolesMap); if (!isContinue) { @@ -887,7 +888,7 @@ void LFGMgr::UpdateRaidBrowser(uint32 diff) m_raidBrowserUpdateTimer[team] = 0; } - if (getMSTimeDiff(World::GetGameTimeMS(), getMSTime()) > (70*7)/5) // prevent lagging + if (getMSTimeDiff(GameTime::GetGameTimeMS(), getMSTime()) > (70*7)/5) // prevent lagging return; uint64 guid, groupGuid, instanceGuid; @@ -1355,7 +1356,7 @@ void LFGMgr::UpdateRoleCheck(uint64 gguid, uint64 guid /* = 0 */, uint8 roles /* { SetState(gguid, LFG_STATE_QUEUED); LFGQueue& queue = GetQueue(gguid); - queue.AddQueueData(gguid, time_t(time(NULL)), roleCheck.dungeons, roleCheck.roles); + queue.AddQueueData(gguid, time_t(GameTime::GetGameTime()), roleCheck.dungeons, roleCheck.roles); RoleChecksStore.erase(itRoleCheck); } else if (roleCheck.state != LFG_ROLECHECK_INITIALITING) @@ -1632,7 +1633,7 @@ void LFGMgr::UpdateProposal(uint32 proposalId, uint64 guid, bool accept) bool sendUpdate = proposal.state != LFG_PROPOSAL_SUCCESS; proposal.state = LFG_PROPOSAL_SUCCESS; - time_t joinTime = time(NULL); + time_t joinTime = GameTime::GetGameTime(); LFGQueue& queue = GetQueue(guid); LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_GROUP_FOUND); @@ -1818,7 +1819,7 @@ void LFGMgr::InitBoot(uint64 gguid, uint64 kicker, uint64 victim, std::string co LfgPlayerBoot& boot = BootsStore[gguid]; boot.inProgress = true; - boot.cancelTime = time_t(time(NULL)) + LFG_TIME_BOOT; + boot.cancelTime = time_t(GameTime::GetGameTime()) + LFG_TIME_BOOT; boot.reason = reason; boot.victim = victim; diff --git a/src/server/game/DungeonFinding/LFGQueue.cpp b/src/server/game/DungeonFinding/LFGQueue.cpp index 30ae2a4ec..4d70bac93 100644 --- a/src/server/game/DungeonFinding/LFGQueue.cpp +++ b/src/server/game/DungeonFinding/LFGQueue.cpp @@ -18,6 +18,7 @@ #include "Containers.h" #include "DBCStructure.h" #include "DBCStores.h" +#include "GameTime.h" #include "Group.h" #include "LFGQueue.h" #include "LFGMgr.h" @@ -29,6 +30,9 @@ namespace lfg { +LfgQueueData::LfgQueueData() : joinTime(GameTime::GetGameTime()), lastRefreshTime(joinTime), tanks(LFG_TANKS_NEEDED), healers(LFG_HEALERS_NEEDED), dps(LFG_DPS_NEEDED) +{ } + void LFGQueue::AddToQueue(uint64 guid, bool failedProposal) { //sLog->outString("ADD AddToQueue: %u, failed proposal: %u", GUID_LOPART(guid), failedProposal ? 1 : 0); @@ -409,7 +413,7 @@ LfgCompatibility LFGQueue::CheckCompatibility(Lfg5Guids const& checkWith, const return LFG_COMPATIBILITY_PENDING; // Create a new proposal - proposal.cancelTime = time(NULL) + LFG_TIME_PROPOSAL; + proposal.cancelTime = GameTime::GetGameTime() + LFG_TIME_PROPOSAL; proposal.state = LFG_PROPOSAL_INITIATING; proposal.leader = 0; proposal.dungeonId = Trinity::Containers::SelectRandomContainerElement(proposalDungeons); @@ -445,7 +449,7 @@ LfgCompatibility LFGQueue::CheckCompatibility(Lfg5Guids const& checkWith, const void LFGQueue::UpdateQueueTimers(uint32 diff) { - time_t currTime = time(NULL); + time_t currTime = GameTime::GetGameTime(); bool sendQueueStatus = false; if (m_QueueStatusTimer > LFG_QUEUEUPDATE_INTERVAL) diff --git a/src/server/game/DungeonFinding/LFGQueue.h b/src/server/game/DungeonFinding/LFGQueue.h index 8aa9e3442..9add4342f 100644 --- a/src/server/game/DungeonFinding/LFGQueue.h +++ b/src/server/game/DungeonFinding/LFGQueue.h @@ -28,9 +28,7 @@ enum LfgCompatibility /// Stores player or group queue info struct LfgQueueData { - LfgQueueData(): joinTime(time_t(time(NULL))), lastRefreshTime(joinTime), tanks(LFG_TANKS_NEEDED), - healers(LFG_HEALERS_NEEDED), dps(LFG_DPS_NEEDED) - { } + LfgQueueData(); LfgQueueData(time_t _joinTime, LfgDungeonSet const& _dungeons, LfgRolesMap const& _roles): joinTime(_joinTime), lastRefreshTime(_joinTime), tanks(LFG_TANKS_NEEDED), healers(LFG_HEALERS_NEEDED), diff --git a/src/server/game/Entities/Corpse/Corpse.cpp b/src/server/game/Entities/Corpse/Corpse.cpp index 608a2f1a6..2e5a71b79 100644 --- a/src/server/game/Entities/Corpse/Corpse.cpp +++ b/src/server/game/Entities/Corpse/Corpse.cpp @@ -6,6 +6,7 @@ #include "Common.h" #include "Corpse.h" +#include "GameTime.h" #include "Player.h" #include "UpdateMask.h" #include "ObjectAccessor.h" @@ -23,7 +24,7 @@ Corpse::Corpse(CorpseType type) : WorldObject(type != CORPSE_BONES), m_type(type m_valuesCount = CORPSE_END; - m_time = time(NULL); + m_time = GameTime::GetGameTime(); lootRecipient = NULL; } @@ -132,6 +133,11 @@ void Corpse::DeleteFromDB(SQLTransaction& trans) trans->Append(stmt); } +void Corpse::ResetGhostTime() +{ + m_time = GameTime::GetGameTime(); +} + bool Corpse::LoadCorpseFromDB(uint32 guid, Field* fields) { uint32 ownerGuid = fields[17].GetUInt32(); diff --git a/src/server/game/Entities/Corpse/Corpse.h b/src/server/game/Entities/Corpse/Corpse.h index 8bb7e6c08..005811251 100644 --- a/src/server/game/Entities/Corpse/Corpse.h +++ b/src/server/game/Entities/Corpse/Corpse.h @@ -54,7 +54,7 @@ class Corpse : public WorldObject, public GridObject uint64 GetOwnerGUID() const { return GetUInt64Value(CORPSE_FIELD_OWNER); } time_t const& GetGhostTime() const { return m_time; } - void ResetGhostTime() { m_time = time(NULL); } + void ResetGhostTime(); CorpseType GetType() const { return m_type; } GridCoord const& GetGridCoord() const { return _gridCoord; } diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index d6905da26..f2ba1c102 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -14,6 +14,7 @@ #include "DatabaseEnv.h" #include "Formulas.h" #include "GameEventMgr.h" +#include "GameTime.h" #include "GossipDef.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" @@ -46,6 +47,9 @@ #include "LuaEngine.h" #endif +VendorItemCount::VendorItemCount(uint32 _item, uint32 _count) + : itemId(_item), count(_count), lastIncrementTime(GameTime::GetGameTime()) { } + TrainerSpell const* TrainerSpellData::Find(uint32 spell_id) const { TrainerSpellMap::const_iterator itr = spellList.find(spell_id); @@ -268,7 +272,7 @@ void Creature::RemoveCorpse(bool setSpawnTime, bool skipVisibility) if (getDeathState() != CORPSE) return; - m_corpseRemoveTime = time(NULL); + m_corpseRemoveTime = GameTime::GetGameTime(); setDeathState(DEAD); RemoveAllAuras(); if (!skipVisibility) // pussywizard @@ -281,7 +285,7 @@ void Creature::RemoveCorpse(bool setSpawnTime, bool skipVisibility) // Should get removed later, just keep "compatibility" with scripts if (setSpawnTime) { - m_respawnTime = time(NULL) + respawnDelay; + m_respawnTime = GameTime::GetGameTime() + respawnDelay; //SaveRespawnTime(); } @@ -506,7 +510,7 @@ void Creature::Update(uint32 diff) break; case DEAD: { - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); if (m_respawnTime <= now) { bool allowed = IsAIEnabled ? AI()->CanRespawn() : true; // First check if there are any scripts that object to us respawning @@ -548,7 +552,7 @@ void Creature::Update(uint32 diff) } else m_groupLootTimer -= diff; } - else if (m_corpseRemoveTime <= time(NULL)) + else if (m_corpseRemoveTime <= GameTime::GetGameTime()) { RemoveCorpse(false); #if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) @@ -1477,7 +1481,7 @@ bool Creature::IsInvisibleDueToDespawn() const if (Unit::IsInvisibleDueToDespawn()) return true; - if (IsAlive() || m_corpseRemoveTime > time(NULL)) + if (IsAlive() || m_corpseRemoveTime > GameTime::GetGameTime()) return false; return true; @@ -1542,8 +1546,8 @@ void Creature::setDeathState(DeathState s, bool despawn) if (s == JUST_DIED) { - m_corpseRemoveTime = time(NULL) + m_corpseDelay; - m_respawnTime = time(NULL) + m_respawnDelay + m_corpseDelay; + m_corpseRemoveTime = GameTime::GetGameTime() + m_corpseDelay; + m_respawnTime = GameTime::GetGameTime() + m_respawnDelay + m_corpseDelay; // always save boss respawn time at death to prevent crash cheating if (GetMap()->IsDungeon() || isWorldBoss() || GetCreatureTemplate()->rank >= CREATURE_ELITE_ELITE) @@ -2126,7 +2130,7 @@ bool Creature::CanCreatureAttack(Unit const* victim, bool skipDistCheck) const // pussywizard: don't check distance to home position if recently damaged (allow kiting away from spawnpoint!) // xinef: 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; } @@ -2294,7 +2298,7 @@ void Creature::ProhibitSpellSchool(SpellSchoolMask idSchoolMask, uint32 unTimeMs { for (uint8 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; ++i) if (idSchoolMask & (1 << i)) - m_ProhibitSchoolTime[i] = World::GetGameTimeMS() + unTimeMs; + m_ProhibitSchoolTime[i] = GameTime::GetGameTimeMS() + unTimeMs; } bool Creature::IsSpellProhibited(SpellSchoolMask idSchoolMask) const @@ -2305,7 +2309,7 @@ bool Creature::IsSpellProhibited(SpellSchoolMask idSchoolMask) const for (uint8 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; ++i) if (idSchoolMask & (1 << i)) - if (m_ProhibitSchoolTime[i] >= World::GetGameTimeMS()) + if (m_ProhibitSchoolTime[i] >= GameTime::GetGameTimeMS()) return true; return false; @@ -2313,7 +2317,7 @@ bool Creature::IsSpellProhibited(SpellSchoolMask idSchoolMask) const void Creature::_AddCreatureSpellCooldown(uint32 spell_id, uint32 end_time) { - m_CreatureSpellCooldowns[spell_id] = World::GetGameTimeMS()+end_time; + m_CreatureSpellCooldowns[spell_id] = GameTime::GetGameTimeMS()+end_time; } void Creature::AddSpellCooldown(uint32 spell_id, uint32 /*itemid*/, uint32 end_time, bool /*needSendToClient*/, bool /*forceSendToSpectator*/) @@ -2360,13 +2364,13 @@ uint32 Creature::GetSpellCooldown(uint32 spell_id) const if (itr == m_CreatureSpellCooldowns.end()) return 0; - return itr->second > World::GetGameTimeMS() ? itr->second - World::GetGameTimeMS() : 0; + return itr->second > GameTime::GetGameTimeMS() ? itr->second - GameTime::GetGameTimeMS() : 0; } bool Creature::HasSpellCooldown(uint32 spell_id) const { CreatureSpellCooldowns::const_iterator itr = m_CreatureSpellCooldowns.find(spell_id); - return (itr != m_CreatureSpellCooldowns.end() && itr->second > World::GetGameTimeMS()); + return (itr != m_CreatureSpellCooldowns.end() && itr->second > GameTime::GetGameTimeMS()); } bool Creature::HasSpell(uint32 spellID) const @@ -2380,13 +2384,18 @@ bool Creature::HasSpell(uint32 spellID) const time_t Creature::GetRespawnTimeEx() const { - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); if (m_respawnTime > now) return m_respawnTime; else return now; } +void Creature::SetRespawnTime(uint32 respawn) +{ + m_respawnTime = respawn ? GameTime::GetGameTime() + respawn : 0; +} + void Creature::GetRespawnPosition(float &x, float &y, float &z, float* ori, float* dist) const { if (m_DBTableGuid) @@ -2431,7 +2440,7 @@ void Creature::AllLootRemovedFromCorpse() { if (!HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE)) { - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); if (m_corpseRemoveTime <= now) return; @@ -2445,7 +2454,7 @@ void Creature::AllLootRemovedFromCorpse() // corpse skinnable, but without skinning flag, and then skinned, corpse will despawn next update if (cinfo && cinfo->SkinLootId) - m_corpseRemoveTime = time(NULL); + m_corpseRemoveTime = GameTime::GetGameTime(); else m_corpseRemoveTime -= diff; } @@ -2499,7 +2508,7 @@ uint32 Creature::GetVendorItemCurrentCount(VendorItem const* vItem) VendorItemCount* vCount = &*itr; - time_t ptime = time(NULL); + time_t ptime = GameTime::GetGameTime(); if (time_t(vCount->lastIncrementTime + vItem->incrtime) <= ptime) { @@ -2538,7 +2547,7 @@ uint32 Creature::UpdateVendorItemCurrentCount(VendorItem const* vItem, uint32 us VendorItemCount* vCount = &*itr; - time_t ptime = time(NULL); + time_t ptime = GameTime::GetGameTime(); if (time_t(vCount->lastIncrementTime + vItem->incrtime) <= ptime) { @@ -2857,3 +2866,13 @@ float Creature::GetAttackDistance(Unit const* player) const return (retDistance*aggroRate); } + +void Creature::SetPickPocketLootTime() +{ + lootPickPocketRestoreTime = GameTime::GetGameTime() + MINUTE + GetCorpseDelay() + GetRespawnTime(); +} + +bool Creature::CanGeneratePickPocketLoot() const +{ + return (lootPickPocketRestoreTime == 0 || lootPickPocketRestoreTime < GameTime::GetGameTime()); +} diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 40e204624..35d32db7c 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -370,8 +370,7 @@ struct VendorItemData struct VendorItemCount { - explicit VendorItemCount(uint32 _item, uint32 _count) - : itemId(_item), count(_count), lastIncrementTime(time(NULL)) {} + VendorItemCount(uint32 _item, uint32 _count); uint32 itemId; uint32 count; @@ -573,8 +572,8 @@ class Creature : public Unit, public GridObject, public MovableMapObje Group* GetLootRecipientGroup() const; bool hasLootRecipient() const { return m_lootRecipient || m_lootRecipientGroup; } bool isTappedBy(Player const* player) const; // return true if the creature is tapped by the player or a member of his party. - bool CanGeneratePickPocketLoot() const { return lootPickPocketRestoreTime == 0 || lootPickPocketRestoreTime < time(NULL); } - void SetPickPocketLootTime() { lootPickPocketRestoreTime = time(NULL) + MINUTE + GetCorpseDelay() + GetRespawnTime(); } + bool CanGeneratePickPocketLoot() const; + void SetPickPocketLootTime(); void ResetPickPocketLootTime() { lootPickPocketRestoreTime = 0; } void SetLootRecipient (Unit* unit, bool withGroup = true); @@ -627,7 +626,7 @@ class Creature : public Unit, public GridObject, public MovableMapObje time_t const& GetRespawnTime() const { return m_respawnTime; } time_t GetRespawnTimeEx() const; - void SetRespawnTime(uint32 respawn) { m_respawnTime = respawn ? time(NULL) + respawn : 0; } + void SetRespawnTime(uint32 respawn); void Respawn(bool force = false); void SaveRespawnTime(); diff --git a/src/server/game/Entities/DynamicObject/DynamicObject.cpp b/src/server/game/Entities/DynamicObject/DynamicObject.cpp index ab00926c3..3d67a4487 100644 --- a/src/server/game/Entities/DynamicObject/DynamicObject.cpp +++ b/src/server/game/Entities/DynamicObject/DynamicObject.cpp @@ -10,6 +10,7 @@ #include "World.h" #include "ObjectAccessor.h" #include "DatabaseEnv.h" +#include "GameTime.h" #include "GridNotifiers.h" #include "CellImpl.h" #include "GridNotifiersImpl.h" @@ -107,7 +108,7 @@ bool DynamicObject::CreateDynamicObject(uint32 guidlow, Unit* caster, uint32 spe SetByteValue(DYNAMICOBJECT_BYTES, 0, type); SetUInt32Value(DYNAMICOBJECT_SPELLID, spellId); SetFloatValue(DYNAMICOBJECT_RADIUS, radius); - SetUInt32Value(DYNAMICOBJECT_CASTTIME, World::GetGameTimeMS()); + 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 cee784535..b4f19427b 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -6,6 +6,7 @@ #include #include "GameObjectAI.h" +#include "GameTime.h" #include "BattlegroundAV.h" #include "CellImpl.h" #include "CreatureAISelector.h" @@ -376,9 +377,9 @@ void GameObject::Update(uint32 diff) GameObjectTemplate const* goInfo = GetGOInfo(); // Bombs if (goInfo->trap.type == 2) - m_cooldownTime = World::GetGameTimeMS()+10*IN_MILLISECONDS; // Hardcoded tooltip value + m_cooldownTime = GameTime::GetGameTimeMS()+10*IN_MILLISECONDS; // Hardcoded tooltip value else if (GetOwner()) - m_cooldownTime = World::GetGameTimeMS()+goInfo->trap.startDelay*IN_MILLISECONDS; + m_cooldownTime = GameTime::GetGameTimeMS()+goInfo->trap.startDelay*IN_MILLISECONDS; m_lootState = GO_READY; break; @@ -386,7 +387,7 @@ void GameObject::Update(uint32 diff) case GAMEOBJECT_TYPE_FISHINGNODE: { // fishing code (bobber ready) - if (time(NULL) > m_respawnTime - FISHING_BOBBER_READY_TIME) + if (GameTime::GetGameTime() > m_respawnTime - FISHING_BOBBER_READY_TIME) { // splash bobber (bobber ready now) Unit* caster = GetOwner(); @@ -410,7 +411,7 @@ void GameObject::Update(uint32 diff) } case GAMEOBJECT_TYPE_SUMMONING_RITUAL: { - if (World::GetGameTimeMS() < m_cooldownTime) + if (GameTime::GetGameTimeMS() < m_cooldownTime) return; GameObjectTemplate const* info = GetGOInfo(); if (info->summoningRitual.animSpell) @@ -484,7 +485,7 @@ void GameObject::Update(uint32 diff) { if (m_respawnTime > 0) // timer on { - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); if (m_respawnTime <= now) // timer expired { uint64 dbtableHighGuid = MAKE_NEW_GUID(m_DBTableGuid, GetEntry(), HIGHGUID_GAMEOBJECT); @@ -560,7 +561,7 @@ void GameObject::Update(uint32 diff) GameObjectTemplate const* goInfo = GetGOInfo(); if (goInfo->type == GAMEOBJECT_TYPE_TRAP) { - if (World::GetGameTimeMS() < m_cooldownTime) + if (GameTime::GetGameTimeMS() < m_cooldownTime) break; // Type 2 - Bomb (will go away after casting it's spell) @@ -620,7 +621,7 @@ void GameObject::Update(uint32 diff) if (goInfo->trap.spellId) CastSpell(target, goInfo->trap.spellId); - m_cooldownTime = World::GetGameTimeMS()+(goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4))*IN_MILLISECONDS; // 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) SetLootState(GO_JUST_DEACTIVATED); @@ -652,11 +653,11 @@ void GameObject::Update(uint32 diff) { case GAMEOBJECT_TYPE_DOOR: case GAMEOBJECT_TYPE_BUTTON: - if (GetGOInfo()->GetAutoCloseTime() && World::GetGameTimeMS() >= m_cooldownTime) + if (GetGOInfo()->GetAutoCloseTime() && GameTime::GetGameTimeMS() >= m_cooldownTime) ResetDoorOrButton(); break; case GAMEOBJECT_TYPE_GOOBER: - if (World::GetGameTimeMS() >= m_cooldownTime) + if (GameTime::GetGameTimeMS() >= m_cooldownTime) { RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_IN_USE); @@ -728,7 +729,7 @@ void GameObject::Update(uint32 diff) return; } - m_respawnTime = time(NULL) + m_respawnDelayTime; + m_respawnTime = GameTime::GetGameTime() + m_respawnDelayTime; // if option not set then object will be saved at grid unload if (GetMap()->IsDungeon()) @@ -941,7 +942,7 @@ bool GameObject::LoadGameObjectFromDB(uint32 guid, Map* map, bool addToMap) m_respawnTime = GetMap()->GetGORespawnTime(m_DBTableGuid); // ready to respawn - if (m_respawnTime && m_respawnTime <= time(NULL)) + if (m_respawnTime && m_respawnTime <= GameTime::GetGameTime()) { m_respawnTime = 0; GetMap()->RemoveGORespawnTime(m_DBTableGuid); @@ -1025,7 +1026,7 @@ Unit* GameObject::GetOwner() const void GameObject::SaveRespawnTime() { - if (m_goData && m_goData->dbData && m_respawnTime > time(NULL) && m_spawnedByDefault) + if (m_goData && m_goData->dbData && m_respawnTime > GameTime::GetGameTime() && m_spawnedByDefault) GetMap()->SaveGORespawnTime(m_DBTableGuid, m_respawnTime); } @@ -1080,11 +1081,26 @@ bool GameObject::IsInvisibleDueToDespawn() const return false; } +time_t GameObject::GetRespawnTimeEx() const +{ + time_t now = GameTime::GetGameTime(); + if (m_respawnTime > now) + return m_respawnTime; + else + return now; +} + +void GameObject::SetRespawnTime(int32 respawn) +{ + m_respawnTime = respawn > 0 ? GameTime::GetGameTime() + respawn : 0; + m_respawnDelayTime = respawn > 0 ? respawn : 0; +} + void GameObject::Respawn() { if (m_spawnedByDefault && m_respawnTime > 0) { - m_respawnTime = time(NULL); + m_respawnTime = GameTime::GetGameTime(); GetMap()->RemoveGORespawnTime(m_DBTableGuid); } } @@ -1212,7 +1228,7 @@ void GameObject::UseDoorOrButton(uint32 time_to_restore, bool alternative /* = f SwitchDoorOrButton(true, alternative); SetLootState(GO_ACTIVATED, user); - m_cooldownTime = World::GetGameTimeMS()+time_to_restore; + m_cooldownTime = GameTime::GetGameTimeMS()+time_to_restore; } void GameObject::SetGoArtKit(uint8 kit) @@ -1279,10 +1295,10 @@ void GameObject::Use(Unit* user) // If cooldown data present in template if (uint32 cooldown = GetGOInfo()->GetCooldown()) { - if (World::GetGameTimeMS() < m_cooldownTime) + if (GameTime::GetGameTimeMS() < m_cooldownTime) return; - m_cooldownTime = World::GetGameTimeMS()+cooldown*IN_MILLISECONDS; + m_cooldownTime = GameTime::GetGameTimeMS()+cooldown*IN_MILLISECONDS; } switch (GetGoType()) @@ -1316,7 +1332,7 @@ void GameObject::Use(Unit* user) if (goInfo->trap.spellId) CastSpell(user, goInfo->trap.spellId); - m_cooldownTime = World::GetGameTimeMS()+(goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4))*IN_MILLISECONDS; // 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); @@ -1469,7 +1485,7 @@ void GameObject::Use(Unit* user) if (info->goober.customAnim) SendCustomAnim(GetGoAnimProgress()); - m_cooldownTime = World::GetGameTimeMS()+info->GetAutoCloseTime(); + m_cooldownTime = GameTime::GetGameTimeMS()+info->GetAutoCloseTime(); // cast this spell later if provided spellId = info->goober.spellId; @@ -1643,7 +1659,7 @@ void GameObject::Use(Unit* user) if (!info->summoningRitual.animSpell) m_cooldownTime = 0; else // channel ready, maintain this - m_cooldownTime = World::GetGameTimeMS()+5*IN_MILLISECONDS; + m_cooldownTime = GameTime::GetGameTimeMS()+5*IN_MILLISECONDS; } return; @@ -2196,6 +2212,11 @@ void GameObject::SetLootState(LootState state, Unit* unit) }*/ } +void GameObject::SetLootGenerationTime() +{ + m_lootGenerationTime = GameTime::GetGameTime(); +} + void GameObject::SetGoState(GOState state) { SetByteValue(GAMEOBJECT_BYTES_1, 0, state); diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h index ffb85fc05..63d95d3b0 100644 --- a/src/server/game/Entities/GameObject/GameObject.h +++ b/src/server/game/Entities/GameObject/GameObject.h @@ -700,20 +700,9 @@ class GameObject : public WorldObject, public GridObject, public Mov uint32 GetSpellId() const { return m_spellId;} time_t GetRespawnTime() const { return m_respawnTime; } - time_t GetRespawnTimeEx() const - { - time_t now = time(NULL); - if (m_respawnTime > now) - return m_respawnTime; - else - return now; - } - - void SetRespawnTime(int32 respawn) - { - m_respawnTime = respawn > 0 ? time(NULL) + respawn : 0; - m_respawnDelayTime = respawn > 0 ? respawn : 0; - } + time_t GetRespawnTimeEx() const; + + void SetRespawnTime(int32 respawn); void Respawn(); bool isSpawned() const { @@ -782,7 +771,7 @@ class GameObject : public WorldObject, public GridObject, public Mov bool HasLootRecipient() const { return m_lootRecipient || m_lootRecipientGroup; } uint32 m_groupLootTimer; // (msecs)timer used for group loot uint32 lootingGroupLowGUID; // used to find group which is looting - void SetLootGenerationTime() { m_lootGenerationTime = time(NULL); } + void SetLootGenerationTime(); uint32 GetLootGenerationTime() const { return m_lootGenerationTime; } bool hasQuest(uint32 quest_id) const; diff --git a/src/server/game/Entities/Item/Item.cpp b/src/server/game/Entities/Item/Item.cpp index e7c60566d..d0f0c4247 100644 --- a/src/server/game/Entities/Item/Item.cpp +++ b/src/server/game/Entities/Item/Item.cpp @@ -9,6 +9,7 @@ #include "ObjectMgr.h" #include "WorldPacket.h" #include "DatabaseEnv.h" +#include "GameTime.h" #include "ItemEnchantmentMgr.h" #include "SpellMgr.h" #include "SpellInfo.h" @@ -236,7 +237,7 @@ Item::Item() m_container = NULL; m_lootGenerated = false; mb_in_trade = false; - m_lastPlayedTimeUpdate = time(NULL); + m_lastPlayedTimeUpdate = GameTime::GetGameTime(); m_refundRecipient = 0; m_paidMoney = 0; @@ -1140,7 +1141,7 @@ void Item::UpdatePlayedTime(Player* owner) // Get current played time uint32 current_playtime = GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME); // Calculate time elapsed since last played time update - time_t curtime = time(NULL); + time_t curtime = GameTime::GetGameTime(); uint32 elapsed = uint32(curtime - m_lastPlayedTimeUpdate); uint32 new_playtime = current_playtime + elapsed; // Check if the refund timer has expired yet @@ -1161,7 +1162,7 @@ void Item::UpdatePlayedTime(Player* owner) uint32 Item::GetPlayedTime() { - time_t curtime = time(NULL); + time_t curtime = GameTime::GetGameTime(); uint32 elapsed = uint32(curtime - m_lastPlayedTimeUpdate); return GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME) + elapsed; } diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index b63514c40..698cf8ba6 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -15,6 +15,7 @@ #include "Player.h" #include "Vehicle.h" #include "ObjectMgr.h" +#include "GameTime.h" #include "UpdateData.h" #include "UpdateMask.h" #include "Util.h" @@ -940,7 +941,7 @@ void MovementInfo::OutDebug() sLog->outString("guid " UI64FMTD, guid); sLog->outString("flags %u", flags); sLog->outString("flags2 %u", flags2); - sLog->outString("time %u current time " UI64FMTD "", flags2, uint64(::time(NULL))); + sLog->outString("time %u current time " UI64FMTD "", flags2, uint64(::GameTime::GetGameTime())); sLog->outString("position: `%s`", pos.ToString().c_str()); if (flags & MOVEMENTFLAG_ONTRANSPORT) { @@ -2885,13 +2886,13 @@ void WorldObject::AddToNotify(uint16 f) { uint32 EVENT_VISIBILITY_DELAY = u->FindMap() ? DynamicVisibilityMgr::GetVisibilityNotifyDelay(u->FindMap()->GetEntry()->map_type) : 1000; - uint32 diff = getMSTimeDiff(u->m_last_notify_mstime, World::GetGameTimeMS()); + uint32 diff = getMSTimeDiff(u->m_last_notify_mstime, GameTime::GetGameTimeMS()); if (diff >= EVENT_VISIBILITY_DELAY/2) EVENT_VISIBILITY_DELAY /= 2; else EVENT_VISIBILITY_DELAY -= diff; u->m_delayed_unit_relocation_timer = EVENT_VISIBILITY_DELAY; - u->m_last_notify_mstime = World::GetGameTimeMS()+EVENT_VISIBILITY_DELAY-1; + u->m_last_notify_mstime = GameTime::GetGameTimeMS()+EVENT_VISIBILITY_DELAY-1; } else if (f & NOTIFY_AI_RELOCATION) { diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp index 59adaf393..75f5b882b 100644 --- a/src/server/game/Entities/Pet/Pet.cpp +++ b/src/server/game/Entities/Pet/Pet.cpp @@ -9,6 +9,7 @@ #include "Log.h" #include "WorldPacket.h" #include "ObjectMgr.h" +#include "GameTime.h" #include "SpellMgr.h" #include "Pet.h" #include "Formulas.h" @@ -237,7 +238,7 @@ void Pet::SavePetToDB(PetSaveMode mode, bool logout) stmt->setUInt32(12, curhealth); stmt->setUInt32(13, curmana); stmt->setUInt32(14, GetPower(POWER_HAPPINESS)); - stmt->setUInt32(15, time(NULL)); + stmt->setUInt32(15, GameTime::GetGameTime()); std::ostringstream ss; for (uint32 i = ACTION_BAR_INDEX_START; i < ACTION_BAR_INDEX_END; ++i) @@ -321,7 +322,7 @@ void Pet::Update(uint32 diff) { case CORPSE: { - if (getPetType() != HUNTER_PET || m_corpseRemoveTime <= time(NULL)) + if (getPetType() != HUNTER_PET || m_corpseRemoveTime <= GameTime::GetGameTime()) { Remove(PET_SAVE_NOT_IN_SLOT); //hunters' pets never get removed because of death, NEVER! return; @@ -1059,7 +1060,7 @@ void Pet::_LoadSpellCooldowns(PreparedQueryResult result) if (result) { - time_t curTime = time(NULL); + time_t curTime = GameTime::GetGameTime(); PacketCooldowns cooldowns; WorldPacket data; @@ -1105,8 +1106,8 @@ void Pet::_SaveSpellCooldowns(SQLTransaction& trans, bool logout) stmt->setUInt32(0, m_charmInfo->GetPetNumber()); trans->Append(stmt); - time_t curTime = time(NULL); - uint32 checkTime = World::GetGameTimeMS() + 30*IN_MILLISECONDS; + time_t curTime = GameTime::GetGameTime(); + uint32 checkTime = GameTime::GetGameTimeMS() + 30*IN_MILLISECONDS; // remove oudated and save active CreatureSpellCooldowns::iterator itr, itr2; @@ -1114,11 +1115,11 @@ void Pet::_SaveSpellCooldowns(SQLTransaction& trans, bool logout) { itr2 = itr; ++itr; - if (itr2->second <= World::GetGameTimeMS()+1000) + if (itr2->second <= GameTime::GetGameTimeMS()+1000) m_CreatureSpellCooldowns.erase(itr2); else if (logout || itr2->second > checkTime) { - uint32 cooldown = ((itr2->second-World::GetGameTimeMS())/IN_MILLISECONDS) + curTime; + uint32 cooldown = ((itr2->second-GameTime::GetGameTimeMS())/IN_MILLISECONDS) + curTime; stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_PET_SPELL_COOLDOWN); stmt->setUInt32(0, m_charmInfo->GetPetNumber()); stmt->setUInt32(1, itr2->first); @@ -2143,7 +2144,7 @@ void Pet::HandleAsynchLoadFailed(AsynchPetSummon* info, Player* player, uint8 as pet->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000); pet->SetFullHealth(); pet->SetPower(POWER_MANA, pet->GetMaxPower(POWER_MANA)); - pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(time(NULL))); // cast can't be helped in this case + pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(GameTime::GetGameTime())); // cast can't be helped in this case } map->AddToMap(pet->ToCreature(), true); diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index b64487f59..308dedfdd 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -27,6 +27,7 @@ #include "DisableMgr.h" #include "Formulas.h" #include "GameEventMgr.h" +#include "GameTime.h" #include "GossipDef.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" @@ -774,7 +775,7 @@ Player::Player(WorldSession* session): Unit(true), m_mover(this) for (uint8 j = 0; j < PLAYER_MAX_BATTLEGROUND_QUEUES; ++j) m_bgBattlegroundQueueID[j] = BATTLEGROUND_QUEUE_NONE; - m_logintime = time(NULL); + m_logintime = GameTime::GetGameTime(); m_Last_tick = m_logintime; m_Played_time[PLAYED_TIME_TOTAL] = 0; m_Played_time[PLAYED_TIME_LEVEL] = 0; @@ -847,7 +848,7 @@ Player::Player(WorldSession* session): Unit(true), m_mover(this) m_spellPenetrationItemMod = 0; // Honor System - m_lastHonorUpdateTime = time(NULL); + m_lastHonorUpdateTime = GameTime::GetGameTime(); m_IsBGRandomWinner = false; @@ -1101,7 +1102,7 @@ bool Player::Create(uint32 guidlow, CharacterCreateInfo* createInfo) } // Played time - m_Last_tick = time(NULL); + m_Last_tick = GameTime::GetGameTime(); m_Played_time[PLAYED_TIME_TOTAL] = 0; m_Played_time[PLAYED_TIME_LEVEL] = 0; @@ -1544,7 +1545,7 @@ void Player::Update(uint32 p_time) sScriptMgr->OnBeforePlayerUpdate(this, p_time); // undelivered mail - if (m_nextMailDelivereTime && m_nextMailDelivereTime <= time(NULL)) + if (m_nextMailDelivereTime && m_nextMailDelivereTime <= GameTime::GetGameTime()) { SendNewMail(); ++unReadMails; @@ -1558,7 +1559,7 @@ void Player::Update(uint32 p_time) Unit::Update(p_time); SetMustDelayTeleport(false); - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); UpdatePvPFlag(now); @@ -1709,7 +1710,7 @@ void Player::Update(uint32 p_time) { if (now > m_Last_tick && _restTime > 0) // freeze update { - time_t currTime = time(NULL); + time_t currTime = GameTime::GetGameTime(); time_t timeDiff = currTime - _restTime; if (timeDiff >= 10) // freeze update { @@ -1958,7 +1959,7 @@ void Player::setDeathState(DeathState s, bool /*despawn = false*/) void Player::SetRestState(uint32 triggerId) { _innTriggerId = triggerId; - _restTime = time(NULL); + _restTime = GameTime::GetGameTime(); SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING); } @@ -2274,7 +2275,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati if (MustDelayTeleport()) { SetHasDelayedTeleport(true); - SetSemaphoreTeleportNear(time(NULL)); + SetSemaphoreTeleportNear(GameTime::GetGameTime()); //lets save teleport destination for player teleportStore_dest = WorldLocation(mapid, x, y, z, orientation); teleportStore_options = options; @@ -2296,11 +2297,11 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati // this will be used instead of the current location in SaveToDB teleportStore_dest = WorldLocation(mapid, x, y, z, orientation); - SetFallInformation(time(NULL), z); + SetFallInformation(GameTime::GetGameTime(), z); // code for finish transfer called in WorldSession::HandleMovementOpcodes() // at client packet MSG_MOVE_TELEPORT_ACK - SetSemaphoreTeleportNear(time(NULL)); + SetSemaphoreTeleportNear(GameTime::GetGameTime()); // near teleport, triggering send MSG_MOVE_TELEPORT_ACK from client at landing if (!GetSession()->PlayerLogout()) { @@ -2336,7 +2337,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati if (MustDelayTeleport()) { SetHasDelayedTeleport(true); - SetSemaphoreTeleportFar(time(NULL)); + SetSemaphoreTeleportFar(GameTime::GetGameTime()); //lets save teleport destination for player teleportStore_dest = WorldLocation(mapid, x, y, z, orientation); teleportStore_options = options; @@ -2403,7 +2404,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati } teleportStore_dest = WorldLocation(mapid, x, y, z, orientation); - SetFallInformation(time(NULL), z); + SetFallInformation(GameTime::GetGameTime(), z); // if the player is saved before worldportack (at logout for example) // this will be used instead of the current location in SaveToDB @@ -2422,7 +2423,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati // move packet sent by client always after far teleport // code for finish transfer to new map called in WorldSession::HandleMoveWorldportAckOpcode at client packet - SetSemaphoreTeleportFar(time(NULL)); + SetSemaphoreTeleportFar(GameTime::GetGameTime()); } } return true; @@ -3468,8 +3469,8 @@ void Player::InitStatsForLevel(bool reapplyMods) void Player::SendInitialSpells() { - uint32 curTime = World::GetGameTimeMS(); - uint32 infTime = World::GetGameTimeMS()+infinityCooldownDelayCheck; + uint32 curTime = GameTime::GetGameTimeMS(); + uint32 infTime = GameTime::GetGameTimeMS()+infinityCooldownDelayCheck; uint16 spellCount = 0; @@ -3597,7 +3598,7 @@ void Player::UpdateNextMailTimeAndUnreads() { // calculate next delivery time (min. from non-delivered mails // and recalculate unReadMail - time_t cTime = time(NULL); + time_t cTime = GameTime::GetGameTime(); m_nextMailDelivereTime = 0; unReadMails = 0; for (PlayerMails::iterator itr = m_mail.begin(); itr != m_mail.end(); ++itr) @@ -3614,7 +3615,7 @@ void Player::UpdateNextMailTimeAndUnreads() void Player::AddNewMailDeliverTime(time_t deliver_time) { - if (deliver_time <= time(NULL)) // ready now + if (deliver_time <= GameTime::GetGameTime()) // ready now { ++unReadMails; SendNewMail(); @@ -4257,7 +4258,7 @@ void Player::RemoveCategoryCooldown(uint32 cat) void Player::RemoveArenaSpellCooldowns(bool removeActivePetCooldowns) { // remove cooldowns on spells that have < 10 min CD - uint32 infTime = World::GetGameTimeMS()+infinityCooldownDelayCheck; + uint32 infTime = GameTime::GetGameTimeMS()+infinityCooldownDelayCheck; SpellCooldowns::iterator itr, next; for (itr = m_spellCooldowns.begin(); itr != m_spellCooldowns.end(); itr = next) { @@ -4289,7 +4290,7 @@ void Player::RemoveArenaSpellCooldowns(bool removeActivePetCooldowns) void Player::RemoveAllSpellCooldown() { - uint32 infTime = World::GetGameTimeMS()+infinityCooldownDelayCheck; + uint32 infTime = GameTime::GetGameTimeMS()+infinityCooldownDelayCheck; if (!m_spellCooldowns.empty()) { for (SpellCooldowns::const_iterator itr = m_spellCooldowns.begin(); itr != m_spellCooldowns.end(); ++itr) @@ -4308,7 +4309,7 @@ void Player::_LoadSpellCooldowns(PreparedQueryResult result) if (result) { - time_t curTime = time(NULL); + time_t curTime = GameTime::GetGameTime(); do { @@ -4344,8 +4345,8 @@ void Player::_SaveSpellCooldowns(SQLTransaction& trans, bool logout) stmt->setUInt32(0, GetGUIDLow()); trans->Append(stmt); - time_t curTime = time(NULL); - uint32 curMSTime = World::GetGameTimeMS(); + time_t curTime = GameTime::GetGameTime(); + uint32 curMSTime = GameTime::GetGameTimeMS(); uint32 infTime = curMSTime + infinityCooldownDelayCheck; bool first_round = true; @@ -4399,7 +4400,7 @@ uint32 Player::resetTalentsCost() const return 10*GOLD; else { - uint64 months = (sWorld->GetGameTime() - m_resetTalentsTime)/MONTH; + uint64 months = (GameTime::GetGameTime() - m_resetTalentsTime)/MONTH; if (months > 0) { // This cost will be reduced by a rate of 5 gold per month @@ -4508,7 +4509,7 @@ bool Player::resetTalents(bool noResetCost) UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_NUMBER_OF_TALENT_RESETS, 1); m_resetTalentsCost = resetCost; - m_resetTalentsTime = time(NULL); + m_resetTalentsTime = GameTime::GetGameTime(); } return true; @@ -5049,7 +5050,7 @@ void Player::DeleteOldCharacters(uint32 keepDays) sLog->outString("Player::DeleteOldChars: Deleting all characters which have been deleted %u days before...", keepDays); PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_OLD_CHARS); - stmt->setUInt32(0, uint32(time(NULL) - time_t(keepDays * DAY))); + stmt->setUInt32(0, uint32(GameTime::GetGameTime() - time_t(keepDays * DAY))); PreparedQueryResult result = CharacterDatabase.Query(stmt); if (result) @@ -7166,8 +7167,8 @@ void Player::RewardReputation(Quest const* quest) void Player::UpdateHonorFields() { /// called when rewarding honor and at each save - time_t now = time_t(time(NULL)); - time_t today = time_t(time(NULL) / DAY) * DAY; + time_t now = time_t(GameTime::GetGameTime()); + time_t today = time_t(GameTime::GetGameTime() / DAY * DAY); if (m_lastHonorUpdateTime < today) { @@ -8977,7 +8978,7 @@ void Player::SendLoot(uint64 guid, LootType loot_type) // Xinef: loot was generated and respawntime has passed since then, allow to recreate loot // Xinef: to avoid bugs, this rule covers spawned gameobjects only - if (go->isSpawnedByDefault() && go->getLootState() == GO_ACTIVATED && !go->loot.isLooted() && go->GetLootGenerationTime()+go->GetRespawnDelay() < time(NULL)) + if (go->isSpawnedByDefault() && go->getLootState() == GO_ACTIVATED && !go->loot.isLooted() && go->GetLootGenerationTime()+go->GetRespawnDelay() < GameTime::GetGameTime()) go->SetLootState(GO_READY); if (go->getLootState() == GO_READY) @@ -10015,7 +10016,7 @@ void Player::SendBattlefieldWorldStates() SendUpdateWorldState(BATTLEFIELD_WG_WORLD_STATE_SHOW_WORLDSTATE, wg->IsWarTime() ? 1 : 0); for (uint32 i = 0; i < 2; ++i) - SendUpdateWorldState(ClockWorldState[i], uint32(time(NULL) + (wg->GetTimer() / 1000))); + SendUpdateWorldState(ClockWorldState[i], uint32(GameTime::GetGameTime() + (wg->GetTimer() / 1000))); } } } @@ -13916,7 +13917,7 @@ void Player::AddItemToBuyBackSlot(Item* pItem) #endif m_items[slot] = pItem; - time_t base = time(NULL); + time_t base = GameTime::GetGameTime(); uint32 etime = uint32(base - m_logintime + (30 * 3600)); uint32 eslot = slot - BUYBACK_SLOT_START; @@ -15670,7 +15671,7 @@ void Player::AddQuest(Quest const* quest, Object* questGiver) AddTimedQuest(quest_id); questStatusData.Timer = timeAllowed * IN_MILLISECONDS; - qtime = static_cast(time(NULL)) + timeAllowed; + qtime = static_cast(GameTime::GetGameTime()) + timeAllowed; } else questStatusData.Timer = 0; @@ -18059,7 +18060,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) SaveRecallPosition(); - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); time_t logoutTime = time_t(fields[27].GetUInt32()); // since last logout (in seconds) @@ -18227,7 +18228,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) SetUInt32Value(PLAYER_CHOSEN_TITLE, curTitle); // has to be called after last Relocate() in Player::LoadFromDB - SetFallInformation(time(NULL), GetPositionZ()); + SetFallInformation(GameTime::GetGameTime(), GetPositionZ()); _LoadSpellCooldowns(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_SPELL_COOLDOWNS)); @@ -19095,10 +19096,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; @@ -19363,7 +19364,7 @@ void Player::SendRaidInfo() size_t p_counter = data.wpos(); data << uint32(counter); // placeholder - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); for (uint8 i = 0; i < MAX_DIFFICULTY; ++i) { @@ -20033,7 +20034,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 < QUEST_OBJECTIVES_COUNT; i++) stmt->setUInt16(index++, statusItr->second.CreatureOrGOCount[i]); @@ -20956,7 +20957,7 @@ void Player::PetSpellInitialize() uint8 cooldownsCount = pet->m_CreatureSpellCooldowns.size(); data << uint8(cooldownsCount); - uint32 curTime = World::GetGameTimeMS(); + uint32 curTime = GameTime::GetGameTimeMS(); for (CreatureSpellCooldowns::const_iterator itr = pet->m_CreatureSpellCooldowns.begin(); itr != pet->m_CreatureSpellCooldowns.end(); ++itr) { @@ -21050,7 +21051,7 @@ void Player::VehicleSpellInitialize() // Cooldowns data << uint8(cooldownCount); - uint32 curTime = World::GetGameTimeMS(); + uint32 curTime = GameTime::GetGameTimeMS(); for (CreatureSpellCooldowns::const_iterator itr = vehicle->m_CreatureSpellCooldowns.begin(); itr != vehicle->m_CreatureSpellCooldowns.end(); ++itr) { @@ -22231,7 +22232,7 @@ void Player::UpdatePvPState(bool onlyFFA) else // in friendly area { if (IsPvP() && !HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP) && pvpInfo.EndTimer == 0) - pvpInfo.EndTimer = time(NULL); // start toggle-off + pvpInfo.EndTimer = GameTime::GetGameTime(); // start toggle-off } } @@ -22244,7 +22245,7 @@ void Player::UpdatePvP(bool state, bool _override) } else { - pvpInfo.EndTimer = time(NULL); + pvpInfo.EndTimer = GameTime::GetGameTime(); SetPvP(state); } RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER); @@ -22368,7 +22369,7 @@ void Player::AddSpellAndCategoryCooldowns(SpellInfo const* spellInfo, uint32 ite void Player::AddSpellCooldown(uint32 spellid, uint32 itemid, uint32 end_time, bool needSendToClient, bool forceSendToSpectator) { SpellCooldown sc; - sc.end = World::GetGameTimeMS()+end_time; + sc.end = GameTime::GetGameTimeMS()+end_time; sc.itemid = itemid; sc.maxduration = end_time; sc.sendToSpectator = false; @@ -22651,7 +22652,7 @@ void Player::LeaveBattleground(Battleground* bg) } // xinef: reset corpse reclaim time - m_deathExpireTime = time(NULL); + m_deathExpireTime = GameTime::GetGameTime(); // pussywizard: clear movement, because after porting player will move to arena cords GetMotionMaster()->MovementExpired(); @@ -23120,7 +23121,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); @@ -23302,7 +23303,7 @@ void Player::ApplyEquipCooldown(Item* pItem) // Don't replace longer cooldowns by equip cooldown if we have any. SpellCooldowns::iterator itr = m_spellCooldowns.find(spellData.SpellId); - if (itr != m_spellCooldowns.end() && itr->second.itemid == pItem->GetEntry() && itr->second.end > time(NULL) + 30) + if (itr != m_spellCooldowns.end() && itr->second.itemid == pItem->GetEntry() && itr->second.end > GameTime::GetGameTime() + 30) continue; // xinef: dont apply eqiup cooldown for spells with this attribute @@ -23474,7 +23475,7 @@ void Player::SetDailyQuestStatus(uint32 quest_id) if (!GetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1+quest_daily_idx)) { SetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1+quest_daily_idx, quest_id); - m_lastDailyQuestTime = time(NULL); // last daily quest time + m_lastDailyQuestTime = GameTime::GetGameTime(); // last daily quest time m_DailyQuestChanged = true; break; } @@ -23482,7 +23483,7 @@ void Player::SetDailyQuestStatus(uint32 quest_id) } else { m_DFQuests.insert(quest_id); - m_lastDailyQuestTime = time(NULL); + m_lastDailyQuestTime = GameTime::GetGameTime(); m_DailyQuestChanged = true; } } @@ -23740,7 +23741,7 @@ void Player::SummonIfPossible(bool agree, uint32 summoner_guid) } // expire and auto declined - if (m_summon_expire < time(NULL)) + if (m_summon_expire < GameTime::GetGameTime()) return; // drop flag at summon @@ -24262,7 +24263,7 @@ uint32 Player::GetCorpseReclaimDelay(bool pvp) const else if (!sWorld->getBoolConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVE)) return 0; - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); // 0..2 full period // should be ceil(x)-1 but not floor(x) uint64 count = (now < m_deathExpireTime - 1) ? (m_deathExpireTime - 1 - now) / DEATH_EXPIRE_STEP : 0; @@ -24277,7 +24278,7 @@ void Player::UpdateCorpseReclaimDelay() (!pvp && !sWorld->getBoolConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVE))) return; - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); if (now < m_deathExpireTime) { @@ -24321,7 +24322,7 @@ int32 Player::CalculateCorpseReclaimDelay(bool load) } time_t expected_time = corpse->GetGhostTime() + copseReclaimDelay[count]; - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); if (now >= expected_time) return -1; @@ -26287,7 +26288,7 @@ void Player::_SaveCharacter(bool create, SQLTransaction& trans) stmt->setUInt32(index++, m_Played_time[PLAYED_TIME_TOTAL]); stmt->setUInt32(index++, m_Played_time[PLAYED_TIME_LEVEL]); stmt->setFloat(index++, finiteAlways(_restBonus)); - stmt->setUInt32(index++, uint32(time(NULL))); + stmt->setUInt32(index++, uint32(GameTime::GetGameTime())); stmt->setUInt8(index++, (HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) ? 1 : 0)); //save, far from tavern/city //save, but in tavern/city @@ -26419,7 +26420,7 @@ void Player::_SaveCharacter(bool create, SQLTransaction& trans) stmt->setUInt32(index++, m_Played_time[PLAYED_TIME_TOTAL]); stmt->setUInt32(index++, m_Played_time[PLAYED_TIME_LEVEL]); stmt->setFloat(index++, finiteAlways(_restBonus)); - stmt->setUInt32(index++, uint32(time(NULL))); + stmt->setUInt32(index++, uint32(GameTime::GetGameTime())); stmt->setUInt8(index++, (HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) ? 1 : 0)); //save, far from tavern/city //save, but in tavern/city @@ -26867,7 +26868,7 @@ void Player::ResetTimeSync() m_timeSyncCounter = 0; m_timeSyncTimer = 0; m_timeSyncClient = 0; - m_timeSyncServer = World::GetGameTimeMS(); + m_timeSyncServer = GameTime::GetGameTimeMS(); } void Player::SendTimeSync() @@ -26878,7 +26879,7 @@ void Player::SendTimeSync() // Schedule next sync in 10 sec m_timeSyncTimer = 10000; - m_timeSyncServer = World::GetGameTimeMS(); + m_timeSyncServer = GameTime::GetGameTimeMS(); } void Player::SetReputation(uint32 factionentry, uint32 value) @@ -27330,7 +27331,7 @@ void Player::_LoadBrewOfTheMonth(PreparedQueryResult result) lastEventId = fields[0].GetUInt32(); } - time_t curtime = time(NULL); + time_t curtime = GameTime::GetGameTime(); tm localTime; ACE_OS::localtime_r(&curtime, &localTime); @@ -27413,7 +27414,7 @@ bool Player::SetCanFly(bool apply, bool packetOnly /*= false*/) return false; if (!apply) - SetFallInformation(time(NULL), GetPositionZ()); + SetFallInformation(GameTime::GetGameTime(), GetPositionZ()); WorldPacket data(apply ? SMSG_MOVE_SET_CAN_FLY : SMSG_MOVE_UNSET_CAN_FLY, 12); data.append(GetPackGUID()); @@ -27497,3 +27498,36 @@ void Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetTy AsynchPetSummon* asynchPetInfo = new AsynchPetSummon(entry, pos, petType, duration, createdBySpell, casterGUID); Pet::LoadPetFromDB(this, asynchLoadType, entry, 0, false, asynchPetInfo); } + +void Player::SetSummonPoint(uint32 mapid, float x, float y, float z, uint32 delay, bool asSpectator) +{ + m_summon_expire = GameTime::GetGameTime() + (delay ? delay : MAX_PLAYER_SUMMON_DELAY); + m_summon_mapid = mapid; + m_summon_x = x; + m_summon_y = y; + m_summon_z = z; + m_summon_asSpectator = asSpectator; +} + +bool Player::IsSummonAsSpectator() const +{ + return m_summon_asSpectator && m_summon_expire >= GameTime::GetGameTime(); +} + +bool Player::HasSpellCooldown(uint32 spell_id) const +{ + SpellCooldowns::const_iterator itr = m_spellCooldowns.find(spell_id); + return itr != m_spellCooldowns.end() && itr->second.end > GameTime::GetGameTimeMS(); +} + +bool Player::HasSpellItemCooldown(uint32 spell_id, uint32 itemid) const +{ + SpellCooldowns::const_iterator itr = m_spellCooldowns.find(spell_id); + return itr != m_spellCooldowns.end() && itr->second.end > GameTime::GetGameTimeMS() && itr->second.itemid == itemid; +} + +uint32 Player::GetSpellCooldownDelay(uint32 spell_id) const +{ + SpellCooldowns::const_iterator itr = m_spellCooldowns.find(spell_id); + return uint32(itr != m_spellCooldowns.end() && itr->second.end > GameTime::GetGameTimeMS() ? itr->second.end - GameTime::GetGameTimeMS() : 0); +} diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index d3b1f8fd1..46b5841fc 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -1104,16 +1104,8 @@ class Player : public Unit, public GridObject } bool TeleportToEntryPoint(); - void SetSummonPoint(uint32 mapid, float x, float y, float z, uint32 delay = 0, bool asSpectator = false) - { - m_summon_expire = time(NULL) + (delay ? delay : MAX_PLAYER_SUMMON_DELAY); - m_summon_mapid = mapid; - m_summon_x = x; - m_summon_y = y; - m_summon_z = z; - m_summon_asSpectator = asSpectator; - } - bool IsSummonAsSpectator() const { return m_summon_asSpectator && m_summon_expire >= time(NULL); } + void SetSummonPoint(uint32 mapid, float x, float y, float z, uint32 delay = 0, bool asSpectator = false); + bool IsSummonAsSpectator() const; void SetSummonAsSpectator(bool on) { m_summon_asSpectator = on; } void SummonIfPossible(bool agree, uint32 summoner_guid); time_t GetSummonExpireTimer() const { return m_summon_expire; } @@ -1738,21 +1730,9 @@ class Player : public Unit, public GridObject static uint32 const infinityCooldownDelay = 0x9A7EC800; // used for set "infinity cooldowns" for spells and check, MONTH*IN_MILLISECONDS static uint32 const infinityCooldownDelayCheck = 0x4D3F6400; //MONTH*IN_MILLISECONDS/2; - virtual bool HasSpellCooldown(uint32 spell_id) const - { - SpellCooldowns::const_iterator itr = m_spellCooldowns.find(spell_id); - return itr != m_spellCooldowns.end() && itr->second.end > World::GetGameTimeMS(); - } - virtual bool HasSpellItemCooldown(uint32 spell_id, uint32 itemid) const - { - SpellCooldowns::const_iterator itr = m_spellCooldowns.find(spell_id); - return itr != m_spellCooldowns.end() && itr->second.end > World::GetGameTimeMS() && itr->second.itemid == itemid; - } - uint32 GetSpellCooldownDelay(uint32 spell_id) const - { - SpellCooldowns::const_iterator itr = m_spellCooldowns.find(spell_id); - return uint32(itr != m_spellCooldowns.end() && itr->second.end > World::GetGameTimeMS() ? itr->second.end - World::GetGameTimeMS() : 0); - } + virtual bool HasSpellCooldown(uint32 spell_id) const; + virtual bool HasSpellItemCooldown(uint32 spell_id, uint32 itemid) const; + uint32 GetSpellCooldownDelay(uint32 spell_id) const; void AddSpellAndCategoryCooldowns(SpellInfo const* spellInfo, uint32 itemId, Spell* spell = NULL, bool infinityCooldown = false); virtual void AddSpellCooldown(uint32 spell_id, uint32 itemid, uint32 end_time, bool needSendToClient = false, bool forceSendToSpectator = false); void ModifySpellCooldown(uint32 spellId, int32 cooldown); diff --git a/src/server/game/Entities/Transport/Transport.cpp b/src/server/game/Entities/Transport/Transport.cpp index 7001d2bad..1fc2999f1 100644 --- a/src/server/game/Entities/Transport/Transport.cpp +++ b/src/server/game/Entities/Transport/Transport.cpp @@ -16,6 +16,7 @@ #include "Vehicle.h" #include "MapReference.h" #include "Player.h" +#include "GameTime.h" #include "Cell.h" #include "CellImpl.h" #include "WorldModel.h" @@ -281,7 +282,7 @@ void MotionTransport::RemovePassenger(WorldObject* passenger, bool withAll) if (Player* plr = passenger->ToPlayer()) { sScriptMgr->OnRemovePassenger(ToTransport(), plr); - plr->SetFallInformation(time(NULL), plr->GetPositionZ()); + plr->SetFallInformation(GameTime::GetGameTime(), plr->GetPositionZ()); } if (withAll) @@ -955,7 +956,7 @@ void StaticTransport::RemovePassenger(WorldObject* passenger, bool withAll) if (Player* plr = passenger->ToPlayer()) { sScriptMgr->OnRemovePassenger(ToTransport(), plr); - plr->SetFallInformation(time(NULL), plr->GetPositionZ()); + plr->SetFallInformation(GameTime::GetGameTime(), plr->GetPositionZ()); } if (withAll) diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 6fb8b3869..5601f7eca 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -278,12 +278,12 @@ i_motionMaster(new MotionMaster(this)), m_regenTimer(0), m_ThreatManager(this), bool GlobalCooldownMgr::HasGlobalCooldown(SpellInfo const* spellInfo) const { GlobalCooldownList::const_iterator itr = m_GlobalCooldowns.find(spellInfo->StartRecoveryCategory); - return itr != m_GlobalCooldowns.end() && itr->second.duration && getMSTimeDiff(itr->second.cast_time, World::GetGameTimeMS()) < itr->second.duration; + return itr != m_GlobalCooldowns.end() && itr->second.duration && getMSTimeDiff(itr->second.cast_time, GameTime::GetGameTimeMS()) < itr->second.duration; } void GlobalCooldownMgr::AddGlobalCooldown(SpellInfo const* spellInfo, uint32 gcd) { - m_GlobalCooldowns[spellInfo->StartRecoveryCategory] = GlobalCooldown(gcd, World::GetGameTimeMS()); + m_GlobalCooldowns[spellInfo->StartRecoveryCategory] = GlobalCooldown(gcd, GameTime::GetGameTimeMS()); } void GlobalCooldownMgr::CancelGlobalCooldown(SpellInfo const* spellInfo) @@ -446,7 +446,7 @@ void Unit::SendMonsterMove(float NewPosX, float NewPosY, float NewPosZ, uint32 T data << uint8(0); // new in 3.1 data << GetPositionX() << GetPositionY() << GetPositionZ() + GetHoverHeight(); - data << World::GetGameTimeMS(); + data << GameTime::GetGameTimeMS(); data << uint8(0); data << uint32(sf); data << TransitTime; // Time in between points @@ -894,7 +894,7 @@ uint32 Unit::DealDamage(Unit* attacker, Unit* victim, uint32 damage, CleanDamage { // Part of Evade mechanics. DoT's and Thorns / Retribution Aura do not contribute to this if (damagetype != DOT && damage > 0 && !IS_PLAYER_GUID(victim->GetOwnerGUID()) && (!spellProto || !spellProto->HasAura(SPELL_AURA_DAMAGE_SHIELD))) - victim->ToCreature()->SetLastDamagedTime(sWorld->GetGameTime()+MAX_AGGRO_RESET_TIME); + victim->ToCreature()->SetLastDamagedTime(GameTime::GetGameTime()+MAX_AGGRO_RESET_TIME); if (attacker) victim->AddThreat(attacker, float(damage), damageSchoolMask, spellProto); @@ -5137,7 +5137,7 @@ uint32 Unit::GetDiseasesByCaster(uint64 casterGUID, uint8 mode) { Aura* aura = (*i)->GetBase(); if (aura && !aura->IsRemoved() && aura->GetDuration() > 0) - if ((aura->GetApplyTime() + aura->GetMaxDuration()/1000 + 8) > (time(NULL) + aura->GetDuration()/1000)) + if ((aura->GetApplyTime() + aura->GetMaxDuration()/1000 + 8) > (GameTime::GetGameTime() + aura->GetDuration()/1000)) aura->SetDuration(aura->GetDuration()+3000); } } @@ -6819,7 +6819,7 @@ bool Unit::HandleDummyAuraProc(Unit* victim, uint32 damage, AuraEffect* triggere if (AuraEffect* aurEff = victim->GetAuraEffect(SPELL_AURA_PERIODIC_DAMAGE, SPELLFAMILY_ROGUE, 0x100000, 0, 0, GetGUID())) if (Aura* aur = aurEff->GetBase()) if (!aur->IsRemoved() && aur->GetDuration() > 0) - if ((aur->GetApplyTime() + aur->GetMaxDuration()/1000 + 5) > (time(NULL) + aur->GetDuration()/1000) ) + if ((aur->GetApplyTime() + aur->GetMaxDuration()/1000 + 5) > (GameTime::GetGameTime() + aur->GetDuration()/1000) ) { aur->SetDuration(aur->GetDuration()+2000); return true; @@ -12334,7 +12334,7 @@ void Unit::Mount(uint32 mount, uint32 VehicleId, uint32 creatureEntry) WorldPacket data(SMSG_MOVE_SET_COLLISION_HGT, GetPackGUID().size() + 4 + 4); data.append(GetPackGUID()); - data << uint32(sWorld->GetGameTime()); // Packet counter + data << uint32(GameTime::GetGameTime()); // Packet counter data << player->GetCollisionHeight(true); player->GetSession()->SendPacket(&data); } @@ -12354,7 +12354,7 @@ void Unit::Dismount() { WorldPacket data(SMSG_MOVE_SET_COLLISION_HGT, GetPackGUID().size() + 4 + 4); data.append(GetPackGUID()); - data << uint32(sWorld->GetGameTime()); // Packet counter + data << uint32(GameTime::GetGameTime()); // Packet counter data << thisPlayer->GetCollisionHeight(false); thisPlayer->GetSession()->SendPacket(&data); } @@ -13543,17 +13543,17 @@ Unit* Creature::SelectVictim() // pussywizard: if victim is not acceptable only due to mmaps, it may be for example a knockback, wait for a few secs before evading if (!target && !isWorldBoss() && !GetInstanceId() && IsAlive() && (!CanHaveThreatList() || !getThreatManager().isThreatListEmpty())) if (Unit* v = GetVictim()) - if (isTargetNotAcceptableByMMaps(v->GetGUID(), sWorld->GetGameTime(), v)) + if (isTargetNotAcceptableByMMaps(v->GetGUID(), GameTime::GetGameTime(), v)) if (_CanDetectFeignDeathOf(v) && CanCreatureAttack(v)) { if (m_mmapNotAcceptableStartTime) { - if (sWorld->GetGameTime() <= m_mmapNotAcceptableStartTime+4) + if (GameTime::GetGameTime() <= m_mmapNotAcceptableStartTime+4) return NULL; } else { - m_mmapNotAcceptableStartTime = sWorld->GetGameTime(); + m_mmapNotAcceptableStartTime = GameTime::GetGameTime(); return NULL; } } @@ -13792,7 +13792,7 @@ DiminishingLevels Unit::GetDiminishing(DiminishingGroup group) return DIMINISHING_LEVEL_1; // If last spell was casted more than 15 seconds ago - reset the count. - if (i->stack == 0 && getMSTimeDiff(i->hitTime, World::GetGameTimeMS()) > 15000) + if (i->stack == 0 && getMSTimeDiff(i->hitTime, GameTime::GetGameTimeMS()) > 15000) { i->hitCount = DIMINISHING_LEVEL_1; return DIMINISHING_LEVEL_1; @@ -13815,7 +13815,7 @@ void Unit::IncrDiminishing(DiminishingGroup group) i->hitCount += 1; return; } - m_Diminishing.push_back(DiminishingReturn(group, World::GetGameTimeMS(), DIMINISHING_LEVEL_2)); + m_Diminishing.push_back(DiminishingReturn(group, GameTime::GetGameTimeMS(), DIMINISHING_LEVEL_2)); } float Unit::ApplyDiminishingToDuration(DiminishingGroup group, int32 &duration, Unit* caster, DiminishingLevels Level, int32 limitduration) @@ -13894,7 +13894,7 @@ void Unit::ApplyDiminishingAura(DiminishingGroup group, bool apply) i->stack -= 1; // Remember time after last aura from group removed if (i->stack == 0) - i->hitTime = World::GetGameTimeMS(); + i->hitTime = GameTime::GetGameTimeMS(); } break; } @@ -15919,7 +15919,7 @@ float Unit::GetAPMultiplier(WeaponAttackType attType, bool normalized) bool Unit::IsUnderLastManaUseEffect() const { - return getMSTimeDiff(m_lastManaUse, World::GetGameTimeMS()) < 5000; + return getMSTimeDiff(m_lastManaUse, GameTime::GetGameTimeMS()) < 5000; } void Unit::SetContestedPvP(Player* attackedPlayer) @@ -17106,7 +17106,7 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type, AuraApplication const* au GetCharmInfo()->SetPetNumber(sObjectMgr->GeneratePetNumber(), true); // if charmed two demons the same session, the 2nd gets the 1st one's name - SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(time(NULL))); // cast can't be helped + SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(GameTime::GetGameTime())); // cast can't be helped } } GetMotionMaster()->MoveFollow(charmer, PET_FOLLOW_DIST, GetFollowAngle()); @@ -18331,7 +18331,7 @@ void Unit::_ExitVehicle(Position const* exitPosition) AddUnitState(UNIT_STATE_MOVE); if (player) - player->SetFallInformation(time(NULL), GetPositionZ()); + player->SetFallInformation(GameTime::GetGameTime(), GetPositionZ()); else if (HasUnitMovementFlag(MOVEMENTFLAG_ROOT)) { WorldPacket data(SMSG_SPLINE_MOVE_UNROOT, 8); @@ -18412,7 +18412,7 @@ void Unit::BuildMovementPacket(ByteBuffer *data) const else *data << uint32(GetUnitMovementFlags()); // movement flags *data << uint16(GetExtraUnitMovementFlags()); // 2.3.0 - *data << uint32(World::GetGameTimeMS()); // time / counter + *data << uint32(GameTime::GetGameTimeMS()); // time / counter *data << GetPositionX(); *data << GetPositionY(); *data << GetPositionZ() + GetHoverHeight(); diff --git a/src/server/game/Events/GameEventMgr.cpp b/src/server/game/Events/GameEventMgr.cpp index 050f89005..6b39e08d9 100644 --- a/src/server/game/Events/GameEventMgr.cpp +++ b/src/server/game/Events/GameEventMgr.cpp @@ -14,6 +14,7 @@ #include "MapManager.h" #include "GossipDef.h" #include "Player.h" +#include "GameTime.h" #include "BattlegroundMgr.h" #include "UnitAI.h" #include "GameObjectAI.h" @@ -30,7 +31,7 @@ bool GameEventMgr::CheckOneGameEvent(uint16 entry) const default: case GAMEEVENT_NORMAL: { - time_t currenttime = time(NULL); + time_t currenttime = GameTime::GetGameTime(); // Get the event information return mGameEvent[entry].start < currenttime && currenttime < mGameEvent[entry].end @@ -47,7 +48,7 @@ bool GameEventMgr::CheckOneGameEvent(uint16 entry) const // if inactive world event, check the prerequisite events case GAMEEVENT_WORLD_INACTIVE: { - time_t currenttime = time(NULL); + time_t currenttime = GameTime::GetGameTime(); for (std::set::const_iterator itr = mGameEvent[entry].prerequisite_events.begin(); itr != mGameEvent[entry].prerequisite_events.end(); ++itr) { if ((mGameEvent[*itr].state != GAMEEVENT_WORLD_NEXTPHASE && mGameEvent[*itr].state != GAMEEVENT_WORLD_FINISHED) || // if prereq not in nextphase or finished state, then can't start this one @@ -63,7 +64,7 @@ bool GameEventMgr::CheckOneGameEvent(uint16 entry) const uint32 GameEventMgr::NextCheck(uint16 entry) const { - time_t currenttime = time(NULL); + time_t currenttime = GameTime::GetGameTime(); // for NEXTPHASE state world events, return the delay to start the next event, so the followup event will be checked correctly if ((mGameEvent[entry].state == GAMEEVENT_WORLD_NEXTPHASE || mGameEvent[entry].state == GAMEEVENT_WORLD_FINISHED) && mGameEvent[entry].nextstart >= currenttime) @@ -123,7 +124,7 @@ bool GameEventMgr::StartEvent(uint16 event_id, bool overwrite) ApplyNewEvent(event_id); if (overwrite) { - mGameEvent[event_id].start = time(NULL); + mGameEvent[event_id].start = GameTime::GetGameTime(); if (data.end <= data.start) data.end = data.start + data.length; } @@ -171,7 +172,7 @@ void GameEventMgr::StopEvent(uint16 event_id, bool overwrite) if (overwrite && !serverwide_evt) { - data.start = time(NULL) - data.length * MINUTE; + data.start = GameTime::GetGameTime() - data.length * MINUTE; if (data.end <= data.start) data.end = data.start + data.length; } @@ -1086,7 +1087,7 @@ void GameEventMgr::StartArenaSeason() uint32 GameEventMgr::Update() // return the next event delay in ms { - time_t currenttime = time(NULL); + time_t currenttime = GameTime::GetGameTime(); uint32 nextEventDelay = max_ge_check_delay; // 1 day uint32 calcDelay; std::set activate, deactivate; @@ -1668,7 +1669,7 @@ bool GameEventMgr::CheckOneGameEventConditions(uint16 event_id) // set the followup events' start time if (!mGameEvent[event_id].nextstart) { - time_t currenttime = time(NULL); + time_t currenttime = GameTime::GetGameTime(); mGameEvent[event_id].nextstart = currenttime + mGameEvent[event_id].length * 60; } return true; @@ -1765,7 +1766,7 @@ void GameEventMgr::SetHolidayEventTime(GameEventData& event) bool singleDate = ((holiday->Date[0] >> 24) & 0x1F) == 31; // Events with fixed date within year have - 1 - time_t curTime = time(NULL); + time_t curTime = GameTime::GetGameTime(); for (int i = 0; i < MAX_HOLIDAY_DATES && holiday->Date[i]; ++i) { uint32 date = holiday->Date[i]; diff --git a/src/server/game/Globals/ObjectAccessor.cpp b/src/server/game/Globals/ObjectAccessor.cpp index a33054fe6..4d511170c 100644 --- a/src/server/game/Globals/ObjectAccessor.cpp +++ b/src/server/game/Globals/ObjectAccessor.cpp @@ -21,6 +21,7 @@ #include "Opcodes.h" #include "Pet.h" #include "Player.h" +#include "GameTime.h" #include "Vehicle.h" #include "World.h" #include "WorldPacket.h" @@ -381,7 +382,7 @@ Corpse* ObjectAccessor::ConvertCorpseForPlayer(uint64 player_guid, bool insignia void ObjectAccessor::RemoveOldCorpses() { - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); Player2CorpsesMapType::iterator next; for (Player2CorpsesMapType::iterator itr = i_player2corpse.begin(); itr != i_player2corpse.end(); itr = next) { diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 608e06fc5..2574e8d86 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -11,6 +11,7 @@ #include "Chat.h" #include "Common.h" #include "DatabaseEnv.h" +#include "GameTime.h" #include "DisableMgr.h" #include "GameEventMgr.h" #include "GossipDef.h" @@ -1023,7 +1024,7 @@ void ObjectMgr::LoadCreatureAddons() void ObjectMgr::LoadGameObjectAddons() { - uint32 oldMSTime = getMSTime(); + uint32 oldMSTime = GameTime::GetGameTimeMS(); // 0 1 2 QueryResult result = WorldDatabase.Query("SELECT guid, invisibilityType, invisibilityValue FROM gameobject_addon"); @@ -5506,7 +5507,7 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp) { uint32 oldMSTime = getMSTime(); - time_t curTime = time(NULL); + time_t curTime = GameTime::GetGameTime(); PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_EXPIRED_MAIL); stmt->setUInt32(0, curTime); diff --git a/src/server/game/Groups/Group.cpp b/src/server/game/Groups/Group.cpp index 2ae9af475..eda7fffbf 100644 --- a/src/server/game/Groups/Group.cpp +++ b/src/server/game/Groups/Group.cpp @@ -6,6 +6,7 @@ #include "Common.h" #include "DatabaseEnv.h" +#include "GameTime.h" #include "Group.h" #include "GroupMgr.h" #include "Log.h" @@ -2326,3 +2327,13 @@ void Group::ToggleGroupMemberFlag(member_witerator slot, uint8 flag, bool apply) slot->flags &= ~flag; } +uint32 Group::GetDifficultyChangePreventionTime() const +{ + return _difficultyChangePreventionTime > GameTime::GetGameTime() ? _difficultyChangePreventionTime - GameTime::GetGameTime() : 0; +} + +void Group::SetDifficultyChangePrevention(DifficultyPreventionChangeType type) +{ + _difficultyChangePreventionTime = GameTime::GetGameTime() + MINUTE; + _difficultyChangePreventionType = type; +} \ No newline at end of file diff --git a/src/server/game/Groups/Group.h b/src/server/game/Groups/Group.h index 484e191ef..c586019ca 100644 --- a/src/server/game/Groups/Group.h +++ b/src/server/game/Groups/Group.h @@ -299,13 +299,9 @@ class Group bool IsLfgHeroic() const { return isLFGGroup() && (m_lfgGroupFlags & GROUP_LFG_FLAG_IS_HEROIC); } // Difficulty Change - uint32 GetDifficultyChangePreventionTime() const { return _difficultyChangePreventionTime > time(NULL) ? _difficultyChangePreventionTime - time(NULL) : 0; } + uint32 GetDifficultyChangePreventionTime() const; DifficultyPreventionChangeType GetDifficultyChangePreventionReason() const { return _difficultyChangePreventionType; } - void SetDifficultyChangePrevention(DifficultyPreventionChangeType type) - { - _difficultyChangePreventionTime = time(NULL) + MINUTE; - _difficultyChangePreventionType = type; - } + void SetDifficultyChangePrevention(DifficultyPreventionChangeType type); protected: void _homebindIfInstance(Player* player); diff --git a/src/server/game/Guilds/Guild.cpp b/src/server/game/Guilds/Guild.cpp index 0bc5b990b..201054ab1 100644 --- a/src/server/game/Guilds/Guild.cpp +++ b/src/server/game/Guilds/Guild.cpp @@ -9,6 +9,7 @@ #include "Chat.h" #include "Config.h" #include "DatabaseEnv.h" +#include "GameTime.h" #include "Guild.h" #include "GuildMgr.h" #include "Language.h" @@ -160,6 +161,8 @@ inline uint32 Guild::LogHolder::GetNextGUID() return m_nextGUID; } +Guild::LogEntry::LogEntry(uint32 guildId, uint32 guid) : m_guildId(guildId), m_guid(guid), m_timestamp(GameTime::GetGameTime()) { } + // EventLogEntry void Guild::EventLogEntry::SaveToDB(SQLTransaction& trans) const { @@ -193,7 +196,7 @@ void Guild::EventLogEntry::WritePacket(WorldPacket& data) const if (m_eventType == GUILD_EVENT_LOG_PROMOTE_PLAYER || m_eventType == GUILD_EVENT_LOG_DEMOTE_PLAYER) data << uint8(m_newRank); // Event timestamp - data << uint32(::time(NULL) - m_timestamp); + data << uint32(::GameTime::GetGameTime() - m_timestamp); } // BankEventLogEntry @@ -243,7 +246,7 @@ void Guild::BankEventLogEntry::WritePacket(WorldPacket& data) const data << uint32(m_itemOrMoney); } - data << uint32(time(NULL) - m_timestamp); + data << uint32(GameTime::GetGameTime() - m_timestamp); } // RankInfo @@ -638,6 +641,11 @@ void Guild::Member::ChangeRank(uint8 newRank) CharacterDatabase.Execute(stmt); } +void Guild::Member::UpdateLogoutTime() +{ + m_logoutTime = GameTime::GetGameTime(); +} + void Guild::Member::SaveToDB(SQLTransaction& trans) const { PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_GUILD_MEMBER); @@ -708,7 +716,7 @@ void Guild::Member::WritePacket(WorldPacket& data, bool sendOfficerNote) const << uint32(m_zoneId); if (!m_flags) - data << float(float(::time(NULL) - m_logoutTime) / DAY); + data << float(float(::GameTime::GetGameTime() - m_logoutTime) / DAY); data << m_publicNote; @@ -1161,7 +1169,7 @@ bool Guild::Create(Player* pLeader, std::string const& name) m_info = ""; m_motd = "No message set."; m_bankMoney = 0; - m_createdDate = sWorld->GetGameTime(); + m_createdDate = GameTime::GetGameTime(); _CreateLogHolders(); #if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) diff --git a/src/server/game/Guilds/Guild.h b/src/server/game/Guilds/Guild.h index 4a8c68d78..e7fa9b0ac 100644 --- a/src/server/game/Guilds/Guild.h +++ b/src/server/game/Guilds/Guild.h @@ -281,7 +281,6 @@ public: // pussywizard: public class Member m_level(0), m_class(0), m_flags(GUILDMEMBER_STATUS_NONE), - m_logoutTime(::time(NULL)), m_accountId(0), m_rankId(rankId) { @@ -320,7 +319,7 @@ public: // pussywizard: public class Member void ChangeRank(uint8 newRank); - inline void UpdateLogoutTime() { m_logoutTime = ::time(NULL); } + inline void UpdateLogoutTime(); inline bool IsRank(uint8 rankId) const { return m_rankId == rankId; } inline bool IsRankNotLower(uint8 rankId) const { return m_rankId <= rankId; } inline bool IsSamePlayer(uint64 guid) const { return m_guid == guid; } @@ -375,7 +374,7 @@ private: class LogEntry { public: - LogEntry(uint32 guildId, uint32 guid) : m_guildId(guildId), m_guid(guid), m_timestamp(::time(NULL)) { } + LogEntry(uint32 guildId, uint32 guid); LogEntry(uint32 guildId, uint32 guid, time_t timestamp) : m_guildId(guildId), m_guid(guid), m_timestamp(timestamp) { } virtual ~LogEntry() { } diff --git a/src/server/game/Handlers/AuctionHouseHandler.cpp b/src/server/game/Handlers/AuctionHouseHandler.cpp index 15a46dbfd..1d1e18d87 100644 --- a/src/server/game/Handlers/AuctionHouseHandler.cpp +++ b/src/server/game/Handlers/AuctionHouseHandler.cpp @@ -13,6 +13,7 @@ #include "AuctionHouseMgr.h" #include "Log.h" #include "Language.h" +#include "GameTime.h" #include "Opcodes.h" #include "UpdateMask.h" #include "Util.h" @@ -278,7 +279,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket & recvData) AH->bidder = 0; AH->bid = 0; AH->buyout = buyout; - AH->expire_time = time(NULL) + auctionTime; + AH->expire_time = GameTime::GetGameTime() + auctionTime; AH->deposit = deposit; AH->auctionHouseEntry = auctionHouseEntry; @@ -320,7 +321,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket & recvData) AH->bidder = 0; AH->bid = 0; AH->buyout = buyout; - AH->expire_time = time(NULL) + auctionTime; + AH->expire_time = GameTime::GetGameTime() + auctionTime; AH->deposit = deposit; AH->auctionHouseEntry = auctionHouseEntry; @@ -648,7 +649,7 @@ void WorldSession::HandleAuctionListOwnerItems(WorldPacket & recvData) { // pussywizard: const uint32 delay = 4500; - const uint32 now = World::GetGameTimeMS(); + const uint32 now = GameTime::GetGameTimeMS(); if (_lastAuctionListOwnerItemsMSTime > now) // list is pending return; uint32 diff = getMSTimeDiff(_lastAuctionListOwnerItemsMSTime, now); @@ -665,7 +666,7 @@ void WorldSession::HandleAuctionListOwnerItemsEvent(WorldPacket & recvData) sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_AUCTION_LIST_OWNER_ITEMS"); #endif - _lastAuctionListOwnerItemsMSTime = World::GetGameTimeMS(); // pussywizard + _lastAuctionListOwnerItemsMSTime = GameTime::GetGameTimeMS(); // pussywizard uint32 listfrom; uint64 guid; @@ -740,7 +741,7 @@ void WorldSession::HandleAuctionListItems(WorldPacket & recvData) // pussywizard: const uint32 delay = 2000; - const uint32 now = World::GetGameTimeMS(); + const uint32 now = GameTime::GetGameTimeMS(); uint32 diff = getMSTimeDiff(_lastAuctionListItemsMSTime, now); if (diff > delay) diff = delay; diff --git a/src/server/game/Handlers/BattleGroundHandler.cpp b/src/server/game/Handlers/BattleGroundHandler.cpp index c44fc0505..8fa3039c2 100644 --- a/src/server/game/Handlers/BattleGroundHandler.cpp +++ b/src/server/game/Handlers/BattleGroundHandler.cpp @@ -14,6 +14,7 @@ #include "ArenaTeam.h" #include "BattlegroundMgr.h" #include "Battleground.h" +#include "GameTime.h" #include "Chat.h" #include "Language.h" #include "Log.h" @@ -535,7 +536,7 @@ void WorldSession::HandleBattlefieldStatusOpcode(WorldPacket & /*recvData*/) if (!bg) continue; - uint32 remainingTime = (World::GetGameTimeMS() < ginfo.RemoveInviteTime ? getMSTimeDiff(World::GetGameTimeMS(), ginfo.RemoveInviteTime) : 1); + uint32 remainingTime = (GameTime::GetGameTimeMS() < ginfo.RemoveInviteTime ? getMSTimeDiff(GameTime::GetGameTimeMS(), ginfo.RemoveInviteTime) : 1); sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, i, STATUS_WAIT_JOIN, remainingTime, 0, ginfo.ArenaType, TEAM_NEUTRAL, bg->isRated(), ginfo.BgTypeId); SendPacket(&data); } @@ -552,7 +553,7 @@ void WorldSession::HandleBattlefieldStatusOpcode(WorldPacket & /*recvData*/) continue; uint32 avgWaitTime = bgQueue.GetAverageQueueWaitTime(&ginfo); - sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bgt, i, STATUS_WAIT_QUEUE, avgWaitTime, getMSTimeDiff(ginfo.JoinTime, World::GetGameTimeMS()), ginfo.ArenaType, TEAM_NEUTRAL, ginfo.IsRated); + sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bgt, i, STATUS_WAIT_QUEUE, avgWaitTime, getMSTimeDiff(ginfo.JoinTime, GameTime::GetGameTimeMS()), ginfo.ArenaType, TEAM_NEUTRAL, ginfo.IsRated); SendPacket(&data); } } diff --git a/src/server/game/Handlers/CalendarHandler.cpp b/src/server/game/Handlers/CalendarHandler.cpp index b77e30cad..eb07cce17 100644 --- a/src/server/game/Handlers/CalendarHandler.cpp +++ b/src/server/game/Handlers/CalendarHandler.cpp @@ -31,6 +31,7 @@ Copied events should probably have a new owner #include "ObjectMgr.h" #include "ObjectAccessor.h" #include "DatabaseEnv.h" +#include "GameTime.h" #include "GuildMgr.h" #include "ArenaTeamMgr.h" #include "WorldSession.h" @@ -41,7 +42,7 @@ void WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recvData*/) uint64 guid = _player->GetGUID(); sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_GET_CALENDAR [" UI64FMTD "]", guid); - time_t currTime = time(NULL); + time_t currTime = GameTime::GetGameTime(); WorldPacket data(SMSG_CALENDAR_SEND_CALENDAR, 1000); // Average size if no instance @@ -228,7 +229,7 @@ void WorldSession::HandleCalendarAddEvent(WorldPacket& recvData) // prevent events in the past // To Do: properly handle timezones and remove the "- time_t(86400L)" hack - if (time_t(eventPackedTime) < (time(NULL) - time_t(86400L))) + if (time_t(eventPackedTime) < (GameTime::GetGameTime() - time_t(86400L))) { recvData.rfinish(); return; @@ -320,7 +321,7 @@ void WorldSession::HandleCalendarUpdateEvent(WorldPacket& recvData) // prevent events in the past // To Do: properly handle timezones and remove the "- time_t(86400L)" hack - if (time_t(eventPackedTime) < (time(NULL) - time_t(86400L))) + if (time_t(eventPackedTime) < (GameTime::GetGameTime() - time_t(86400L))) { recvData.rfinish(); return; @@ -377,7 +378,7 @@ void WorldSession::HandleCalendarCopyEvent(WorldPacket& recvData) // prevent events in the past // To Do: properly handle timezones and remove the "- time_t(86400L)" hack - if (time_t(eventTime) < (time(NULL) - time_t(86400L))) + if (time_t(eventTime) < (GameTime::GetGameTime() - time_t(86400L))) { recvData.rfinish(); return; @@ -517,7 +518,7 @@ void WorldSession::HandleCalendarEventSignup(WorldPacket& recvData) } CalendarInviteStatus status = tentative ? CALENDAR_STATUS_TENTATIVE : CALENDAR_STATUS_SIGNED_UP; - CalendarInvite* invite = new CalendarInvite(sCalendarMgr->GetFreeInviteId(), eventId, guid, guid, time(NULL), status, CALENDAR_RANK_PLAYER, ""); + CalendarInvite* invite = new CalendarInvite(sCalendarMgr->GetFreeInviteId(), eventId, guid, guid, GameTime::GetGameTime(), status, CALENDAR_RANK_PLAYER, ""); sCalendarMgr->AddInvite(calendarEvent, invite); sCalendarMgr->SendCalendarClearPendingAction(guid); } @@ -549,7 +550,7 @@ void WorldSession::HandleCalendarEventRsvp(WorldPacket& recvData) if (CalendarInvite* invite = sCalendarMgr->GetInvite(inviteId)) { invite->SetStatus(CalendarInviteStatus(status)); - invite->SetStatusTime(time(NULL)); + invite->SetStatusTime(GameTime::GetGameTime()); sCalendarMgr->UpdateInvite(invite); sCalendarMgr->SendCalendarEventStatus(*calendarEvent, *invite); @@ -613,7 +614,7 @@ void WorldSession::HandleCalendarEventStatus(WorldPacket& recvData) { invite->SetStatus((CalendarInviteStatus)status); // not sure if we should set response time when moderator changes invite status - //invite->SetStatusTime(time(NULL)); + //invite->SetStatusTime(GameTime::GetGameTime()); sCalendarMgr->UpdateInvite(invite); sCalendarMgr->SendCalendarEventStatus(*calendarEvent, *invite); @@ -713,7 +714,7 @@ void WorldSession::HandleSetSavedInstanceExtend(WorldPacket& recvData) void WorldSession::SendCalendarRaidLockout(InstanceSave const* save, bool add) { sLog->outDebug(LOG_FILTER_NETWORKIO, "%s", add ? "SMSG_CALENDAR_RAID_LOCKOUT_ADDED" : "SMSG_CALENDAR_RAID_LOCKOUT_REMOVED"); - time_t currTime = time(NULL); + time_t currTime = GameTime::GetGameTime(); WorldPacket data(SMSG_CALENDAR_RAID_LOCKOUT_REMOVED, (add ? 4 : 0) + 4 + 4 + 4 + 8); if (add) @@ -731,7 +732,7 @@ void WorldSession::SendCalendarRaidLockout(InstanceSave const* save, bool add) void WorldSession::SendCalendarRaidLockoutUpdated(InstanceSave const* save, bool isExtended) { - time_t currTime = time(NULL); + time_t currTime = GameTime::GetGameTime(); time_t resetTime = isExtended ? save->GetExtendedResetTime() : save->GetResetTime(); time_t resetTimeOp = isExtended ? save->GetResetTime() : save->GetExtendedResetTime(); WorldPacket data(SMSG_CALENDAR_RAID_LOCKOUT_UPDATED, 4 + 4 + 4 + 4 + 8); diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp index 79065a3ba..d3863f670 100644 --- a/src/server/game/Handlers/CharacterHandler.cpp +++ b/src/server/game/Handlers/CharacterHandler.cpp @@ -13,6 +13,7 @@ #include "Chat.h" #include "Common.h" #include "DatabaseEnv.h" +#include "GameTime.h" #include "Group.h" #include "Guild.h" #include "GuildMgr.h" @@ -109,7 +110,7 @@ bool LoginQueryHolder::Initialize() stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_MAILCOUNT); stmt->setUInt32(0, lowGuid); - stmt->setUInt64(1, uint64(time(NULL))); + stmt->setUInt64(1, uint64(GameTime::GetGameTime())); res &= SetPreparedQuery(PLAYER_LOGIN_QUERY_LOAD_MAIL_COUNT, stmt); stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_MAILDATE); @@ -1002,7 +1003,7 @@ void WorldSession::HandlePlayerLoginFromDB(LoginQueryHolder* holder) stmt->setUInt32(1, GetAccountId()); LoginDatabase.Execute(stmt); - pCurrChar->SetInGameTime(World::GetGameTimeMS()); + 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()) @@ -1017,7 +1018,7 @@ void WorldSession::HandlePlayerLoginFromDB(LoginQueryHolder* holder) if (mapDiff->resetTime) if (time_t timeReset = sInstanceSaveMgr->GetResetTimeFor(pCurrChar->GetMap()->GetId(), pCurrChar->GetMap()->GetDifficulty())) { - uint32 timeleft = uint32(timeReset - time(NULL)); + uint32 timeleft = uint32(timeReset - GameTime::GetGameTime()); pCurrChar->SendInstanceResetWarning(pCurrChar->GetMap()->GetId(), pCurrChar->GetMap()->GetDifficulty(), timeleft, true); } @@ -1263,7 +1264,7 @@ void WorldSession::HandlePlayerLoginToCharInWorld(Player* pCurrChar) uint32 currZone, currArea; pCurrChar->GetZoneAndAreaId(currZone, currArea, false); pCurrChar->SendInitWorldStates(currZone, currArea); - pCurrChar->SetInGameTime(World::GetGameTimeMS()); + pCurrChar->SetInGameTime(GameTime::GetGameTimeMS()); // Xinef: we need to resend all spell mods for (uint16 Opcode = SMSG_SET_FLAT_SPELL_MODIFIER; Opcode <= SMSG_SET_PCT_SPELL_MODIFIER; ++Opcode) // PCT = FLAT+1 @@ -1308,7 +1309,7 @@ void WorldSession::HandlePlayerLoginToCharInWorld(Player* pCurrChar) if (mapDiff->resetTime) if (time_t timeReset = sInstanceSaveMgr->GetResetTimeFor(pCurrChar->GetMap()->GetId(), pCurrChar->GetMap()->GetDifficulty())) { - uint32 timeleft = uint32(timeReset - time(NULL)); + uint32 timeleft = uint32(timeReset - GameTime::GetGameTime()); GetPlayer()->SendInstanceResetWarning(pCurrChar->GetMap()->GetId(), pCurrChar->GetMap()->GetDifficulty(), timeleft, true); } diff --git a/src/server/game/Handlers/ChatHandler.cpp b/src/server/game/Handlers/ChatHandler.cpp index 0b3eafe93..3441f45f4 100644 --- a/src/server/game/Handlers/ChatHandler.cpp +++ b/src/server/game/Handlers/ChatHandler.cpp @@ -279,7 +279,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recvData) if (!_player->CanSpeak()) { - std::string timeStr = secsToTimeString(m_muteTime - time(NULL)); + std::string timeStr = secsToTimeString(m_muteTime - GameTime::GetGameTime()); SendNotification(GetTrinityString(LANG_WAIT_BEFORE_SPEAKING), timeStr.c_str()); return; } @@ -666,7 +666,7 @@ void WorldSession::HandleTextEmoteOpcode(WorldPacket & recvData) if (!GetPlayer()->CanSpeak()) { - std::string timeStr = secsToTimeString(m_muteTime - time(NULL)); + std::string timeStr = secsToTimeString(m_muteTime - GameTime::GetGameTime()); SendNotification(GetTrinityString(LANG_WAIT_BEFORE_SPEAKING), timeStr.c_str()); return; } diff --git a/src/server/game/Handlers/DuelHandler.cpp b/src/server/game/Handlers/DuelHandler.cpp index 806d96dae..970c82a90 100644 --- a/src/server/game/Handlers/DuelHandler.cpp +++ b/src/server/game/Handlers/DuelHandler.cpp @@ -7,6 +7,7 @@ #include "Common.h" #include "WorldPacket.h" #include "WorldSession.h" +#include "GameTime.h" #include "Log.h" #include "Opcodes.h" #include "UpdateData.h" @@ -35,7 +36,7 @@ void WorldSession::HandleDuelAcceptedOpcode(WorldPacket& recvPacket) sLog->outStaticDebug("Player 2 is: %u (%s)", plTarget->GetGUIDLow(), plTarget->GetName().c_str()); #endif - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); player->duel->startTimer = now; plTarget->duel->startTimer = now; diff --git a/src/server/game/Handlers/LFGHandler.cpp b/src/server/game/Handlers/LFGHandler.cpp index ac0c80258..90c782506 100644 --- a/src/server/game/Handlers/LFGHandler.cpp +++ b/src/server/game/Handlers/LFGHandler.cpp @@ -6,6 +6,7 @@ #include "LFGMgr.h" #include "ObjectMgr.h" +#include "GameTime.h" #include "Group.h" #include "Player.h" #include "Opcodes.h" @@ -548,7 +549,7 @@ void WorldSession::SendLfgBootProposalUpdate(lfg::LfgPlayerBoot const& boot) lfg::LfgAnswer playerVote = boot.votes.find(guid)->second; uint8 votesNum = 0; uint8 agreeNum = 0; - uint32 secsleft = boot.cancelTime - time(NULL); + uint32 secsleft = boot.cancelTime - GameTime::GetGameTime(); for (lfg::LfgAnswerContainer::const_iterator it = boot.votes.begin(); it != boot.votes.end(); ++it) { if (it->second != lfg::LFG_ANSWER_PENDING) diff --git a/src/server/game/Handlers/MailHandler.cpp b/src/server/game/Handlers/MailHandler.cpp index ed845cf63..6f18f5740 100644 --- a/src/server/game/Handlers/MailHandler.cpp +++ b/src/server/game/Handlers/MailHandler.cpp @@ -9,6 +9,7 @@ #include "WorldPacket.h" #include "WorldSession.h" #include "Opcodes.h" +#include "GameTime.h" #include "Log.h" #include "World.h" #include "ObjectMgr.h" @@ -365,7 +366,7 @@ void WorldSession::HandleMailReturnToSender(WorldPacket & recvData) Player* player = _player; Mail* m = player->GetMail(mailId); - if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL)) + if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > GameTime::GetGameTime()) { player->SendMailResult(mailId, MAIL_RETURNED_TO_SENDER, MAIL_ERR_INTERNAL_ERROR); return; @@ -430,7 +431,7 @@ void WorldSession::HandleMailTakeItem(WorldPacket & recvData) Player* player = _player; Mail* m = player->GetMail(mailId); - if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL)) + if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > GameTime::GetGameTime()) { player->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_INTERNAL_ERROR); return; @@ -530,7 +531,7 @@ void WorldSession::HandleMailTakeMoney(WorldPacket& recvData) Player* player = _player; Mail* m = player->GetMail(mailId); - if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL)) + if (!m || m->state == MAIL_STATE_DELETED || m->deliver_time > GameTime::GetGameTime()) { player->SendMailResult(mailId, MAIL_MONEY_TAKEN, MAIL_ERR_INTERNAL_ERROR); return; @@ -579,7 +580,7 @@ void WorldSession::HandleGetMailList(WorldPacket & recvData) WorldPacket data(SMSG_MAIL_LIST_RESULT, (200)); // guess size data << uint32(0); // real mail's count data << uint8(0); // mail's count - time_t cur_time = time(NULL); + time_t cur_time = GameTime::GetGameTime(); for (PlayerMails::iterator itr = player->GetMailBegin(); itr != player->GetMailEnd(); ++itr) { @@ -626,7 +627,7 @@ void WorldSession::HandleGetMailList(WorldPacket & recvData) data << uint32((*itr)->stationery); // stationery (Stationery.dbc) data << uint32((*itr)->money); // Gold data << uint32((*itr)->checked); // flags - data << float(float((*itr)->expire_time-time(NULL))/DAY); // Time + data << float(float((*itr)->expire_time-GameTime::GetGameTime())/DAY); // Time data << uint32((*itr)->mailTemplateId); // mail template (MailTemplate.dbc) data << (*itr)->subject; // Subject string - once 00, when mail type = 3, max 256 data << (*itr)->body; // message? max 8000 @@ -690,7 +691,7 @@ void WorldSession::HandleMailCreateTextItem(WorldPacket & recvData) Player* player = _player; Mail* m = player->GetMail(mailId); - if (!m || (m->body.empty() && !m->mailTemplateId) || m->state == MAIL_STATE_DELETED || m->deliver_time > time(NULL) || (m->checked & MAIL_CHECK_MASK_COPIED)) + if (!m || (m->body.empty() && !m->mailTemplateId) || m->state == MAIL_STATE_DELETED || m->deliver_time > GameTime::GetGameTime() || (m->checked & MAIL_CHECK_MASK_COPIED)) { player->SendMailResult(mailId, MAIL_MADE_PERMANENT, MAIL_ERR_INTERNAL_ERROR); return; @@ -757,7 +758,7 @@ void WorldSession::HandleQueryNextMailTime(WorldPacket & /*recvData*/) data << uint32(0); // count uint32 count = 0; - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); std::set sentSenders; for (PlayerMails::iterator itr = _player->GetMailBegin(); itr != _player->GetMailEnd(); ++itr) { diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp index ccaacf408..7d2833772 100644 --- a/src/server/game/Handlers/MiscHandler.cpp +++ b/src/server/game/Handlers/MiscHandler.cpp @@ -15,6 +15,7 @@ #include "World.h" #include "ObjectMgr.h" #include "GuildMgr.h" +#include "GameTime.h" #include "WorldSession.h" #include "BigNumber.h" #include "SHA1.h" @@ -218,7 +219,7 @@ void WorldSession::HandleWhoOpcode(WorldPacket& recvData) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Recvd CMSG_WHO Message"); - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); if (now < timeWhoCommandAllowed) return; timeWhoCommandAllowed = now + 3; @@ -466,7 +467,7 @@ void WorldSession::HandleLogoutRequestOpcode(WorldPacket & /*recv_data*/) GetPlayer()->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED); } - LogoutRequest(time(NULL)); + LogoutRequest(GameTime::GetGameTime()); } void WorldSession::HandlePlayerLogoutOpcode(WorldPacket & /*recv_data*/) @@ -817,7 +818,7 @@ void WorldSession::HandleReclaimCorpseOpcode(WorldPacket &recv_data) return; // prevent resurrect before 30-sec delay after body release not finished - if (time_t(corpse->GetGhostTime() + _player->GetCorpseReclaimDelay(corpse->GetType() == CORPSE_RESURRECTABLE_PVP)) > time_t(time(NULL))) + if (time_t(corpse->GetGhostTime() + _player->GetCorpseReclaimDelay(corpse->GetType() == CORPSE_RESURRECTABLE_PVP)) > time_t(GameTime::GetGameTime())) return; if (!corpse->IsWithinDistInMap(_player, CORPSE_RECLAIM_RADIUS, true)) @@ -1524,7 +1525,7 @@ void WorldSession::HandleTimeSyncResp(WorldPacket & recv_data) { uint32 counter, clientTicks; recv_data >> counter >> clientTicks; - //uint32 ourTicks = clientTicks + (World::GetGameTimeMS() - _player->m_timeSyncServer); + //uint32 ourTicks = clientTicks + (GameTime::GetGameTimeMS() - _player->m_timeSyncServer); _player->m_timeSyncClient = clientTicks; } @@ -1858,7 +1859,7 @@ void WorldSession::HandleWorldStateUITimerUpdate(WorldPacket& /*recv_data*/) #endif WorldPacket data(SMSG_WORLD_STATE_UI_TIMER_UPDATE, 4); - data << uint32(time(NULL)); + data << uint32(GameTime::GetGameTime()); SendPacket(&data); } diff --git a/src/server/game/Handlers/MovementHandler.cpp b/src/server/game/Handlers/MovementHandler.cpp index e62bf28cf..6939a41b6 100644 --- a/src/server/game/Handlers/MovementHandler.cpp +++ b/src/server/game/Handlers/MovementHandler.cpp @@ -152,7 +152,7 @@ void WorldSession::HandleMoveWorldportAckOpcode() _player->SetIsSpectator(false); GetPlayer()->SetPendingSpectatorForBG(0); - timeWhoCommandAllowed = time(NULL) + sWorld->GetNextWhoListUpdateDelaySecs() + 1; // after exiting arena Subscribe will scan for a player and cached data says he is still in arena, so disallow until next update + timeWhoCommandAllowed = GameTime::GetGameTime() + sWorld->GetNextWhoListUpdateDelaySecs() + 1; // after exiting arena Subscribe will scan for a player and cached data says he is still in arena, so disallow until next update if (uint32 inviteInstanceId = _player->GetPendingSpectatorInviteInstanceId()) { @@ -193,7 +193,7 @@ void WorldSession::HandleMoveWorldportAckOpcode() if (mapDiff->resetTime) if (time_t timeReset = sInstanceSaveMgr->GetResetTimeFor(mEntry->MapID, diff)) { - uint32 timeleft = uint32(timeReset - time(NULL)); + uint32 timeleft = uint32(timeReset - GameTime::GetGameTime()); GetPlayer()->SendInstanceResetWarning(mEntry->MapID, diff, timeleft, true); } allowMount = mInstance->AllowMount; @@ -408,7 +408,7 @@ void WorldSession::HandleMovementOpcodes(WorldPacket & recvData) if (mover->GetGUID() != _player->GetGUID()) movementInfo.flags &= ~MOVEMENTFLAG_WALKING; - uint32 mstime = World::GetGameTimeMS(); + uint32 mstime = GameTime::GetGameTimeMS(); /*----------------------*/ if(m_clientTimeDelay == 0) m_clientTimeDelay = mstime > movementInfo.time ? std::min(mstime - movementInfo.time, (uint32)100) : 0; diff --git a/src/server/game/Handlers/PetHandler.cpp b/src/server/game/Handlers/PetHandler.cpp index 3417ea75b..b0f8b6664 100644 --- a/src/server/game/Handlers/PetHandler.cpp +++ b/src/server/game/Handlers/PetHandler.cpp @@ -8,6 +8,7 @@ #include "WorldPacket.h" #include "WorldSession.h" #include "ObjectMgr.h" +#include "GameTime.h" #include "SpellMgr.h" #include "Log.h" #include "Opcodes.h" @@ -128,7 +129,7 @@ uint8 WorldSession::HandleLoadPetFromDBFirstCallback(PreparedQueryResult result, Map* map = owner->GetMap(); uint32 guid = sObjectMgr->GenerateLowGuid(HIGHGUID_PET); Pet* pet = new Pet(owner, pet_type); - LoadPetFromDBQueryHolder* holder = new LoadPetFromDBQueryHolder(pet_number, current, uint32(time(NULL) - fields[14].GetUInt32()), fields[13].GetString(), savedhealth, savedmana); + LoadPetFromDBQueryHolder* holder = new LoadPetFromDBQueryHolder(pet_number, current, uint32(GameTime::GetGameTime() - fields[14].GetUInt32()), fields[13].GetString(), savedhealth, savedmana); if (!pet->Create(guid, map, owner->GetPhaseMask(), petentry, pet_number) || !holder->Initialize()) { delete pet; @@ -198,7 +199,7 @@ uint8 WorldSession::HandleLoadPetFromDBFirstCallback(PreparedQueryResult result, break; } - pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(time(NULL))); // cast can't be helped here + pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(GameTime::GetGameTime())); // cast can't be helped here pet->SetCreatorGUID(owner->GetGUID()); owner->SetMinion(pet, true); @@ -552,7 +553,7 @@ void WorldSession::HandlePetActionHelper(Unit* pet, uint64 guid1, uint16 spellid // pussywizard: if (Creature* creaturePet = pet->ToCreature()) - if (!creaturePet->_CanDetectFeignDeathOf(TargetUnit) || !creaturePet->CanCreatureAttack(TargetUnit) || creaturePet->isTargetNotAcceptableByMMaps(TargetUnit->GetGUID(), sWorld->GetGameTime(), TargetUnit)) + if (!creaturePet->_CanDetectFeignDeathOf(TargetUnit) || !creaturePet->CanCreatureAttack(TargetUnit) || creaturePet->isTargetNotAcceptableByMMaps(TargetUnit->GetGUID(), GameTime::GetGameTime(), TargetUnit)) return; // Not let attack through obstructions @@ -1191,7 +1192,7 @@ void WorldSession::HandlePetRename(WorldPacket & recvData) CharacterDatabase.CommitTransaction(trans); - pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(time(NULL))); // cast can't be helped + pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(GameTime::GetGameTime())); // cast can't be helped } void WorldSession::HandlePetAbandon(WorldPacket & recvData) diff --git a/src/server/game/Handlers/QueryHandler.cpp b/src/server/game/Handlers/QueryHandler.cpp index 02aa82755..bdc94f1e5 100644 --- a/src/server/game/Handlers/QueryHandler.cpp +++ b/src/server/game/Handlers/QueryHandler.cpp @@ -7,6 +7,7 @@ #include "Common.h" #include "Language.h" #include "DatabaseEnv.h" +#include "GameTime.h" #include "WorldPacket.h" #include "WorldSession.h" #include "Opcodes.h" @@ -72,8 +73,8 @@ void WorldSession::HandleQueryTimeOpcode(WorldPacket & /*recvData*/) void WorldSession::SendQueryTimeResponse() { WorldPacket data(SMSG_QUERY_TIME_RESPONSE, 4+4); - data << uint32(time(NULL)); - data << uint32(sWorld->GetNextDailyQuestsResetTime() - time(NULL)); + data << uint32(GameTime::GetGameTime()); + data << uint32(sWorld->GetNextDailyQuestsResetTime() - GameTime::GetGameTime()); SendPacket(&data); } diff --git a/src/server/game/Handlers/TicketHandler.cpp b/src/server/game/Handlers/TicketHandler.cpp index 2e00ca48b..52ae83d49 100644 --- a/src/server/game/Handlers/TicketHandler.cpp +++ b/src/server/game/Handlers/TicketHandler.cpp @@ -9,6 +9,7 @@ #include "Language.h" #include "ObjectMgr.h" #include "Opcodes.h" +#include "GameTime.h" #include "Player.h" #include "TicketMgr.h" #include "Util.h" @@ -237,7 +238,7 @@ void WorldSession::HandleReportLag(WorldPacket& recv_data) stmt->setFloat (4, y); stmt->setFloat (5, z); stmt->setUInt32(6, GetLatency()); - stmt->setUInt32(7, time(NULL)); + stmt->setUInt32(7, GameTime::GetGameTime()); CharacterDatabase.Execute(stmt); } diff --git a/src/server/game/Instances/InstanceSaveMgr.cpp b/src/server/game/Instances/InstanceSaveMgr.cpp index 0fe54b8e4..9b4d4e9b7 100644 --- a/src/server/game/Instances/InstanceSaveMgr.cpp +++ b/src/server/game/Instances/InstanceSaveMgr.cpp @@ -20,6 +20,7 @@ #include "ObjectMgr.h" #include "World.h" #include "Group.h" +#include "GameTime.h" #include "InstanceScript.h" #include "ScriptMgr.h" @@ -77,7 +78,7 @@ InstanceSave* InstanceSaveManager::AddInstanceSave(uint32 mapId, uint32 instance } else { - resetTime = time(NULL) + 3*DAY; // normals expire after 3 days even if someone is still bound to them, cleared on startup + resetTime = GameTime::GetGameTime() + 3*DAY; // normals expire after 3 days even if someone is still bound to them, cleared on startup extendedResetTime = 0; } InstanceSave* save = new InstanceSave(mapId, instanceId, difficulty, resetTime, extendedResetTime); @@ -239,7 +240,7 @@ void InstanceSaveManager::LoadInstances() void InstanceSaveManager::LoadResetTimes() { - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); time_t today = (now / DAY) * DAY; // load the global respawn times for raid/heroic instances @@ -400,7 +401,7 @@ void InstanceSaveManager::ScheduleReset(time_t time, InstResetEvent event) void InstanceSaveManager::Update() { - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); time_t t; bool resetOccurred = false; @@ -499,7 +500,7 @@ void InstanceSaveManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficulty, b if (!mapEntry->Instanceable()) return; - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); if (!warn) { diff --git a/src/server/game/Mails/Mail.cpp b/src/server/game/Mails/Mail.cpp index 6683fe2f1..2dc0706bf 100644 --- a/src/server/game/Mails/Mail.cpp +++ b/src/server/game/Mails/Mail.cpp @@ -9,6 +9,7 @@ #include "Log.h" #include "World.h" #include "ObjectMgr.h" +#include "GameTime.h" #include "Player.h" #include "Unit.h" #include "BattlegroundMgr.h" @@ -175,7 +176,7 @@ void MailDraft::SendMailTo(SQLTransaction& trans, MailReceiver const& receiver, uint32 mailId = sObjectMgr->GenerateMailID(); - time_t deliver_time = time(NULL) + deliver_delay; + time_t deliver_time = GameTime::GetGameTime() + deliver_delay; //expire time if COD 3 days, if no COD 30 days, if auction sale pending 1 hour uint32 expire_delay; diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 107d978f5..f57b2d862 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -23,6 +23,7 @@ #include "Vehicle.h" #include "VMapFactory.h" #include "LFGMgr.h" +#include "GameTime.h" #include "Chat.h" #ifdef ELUNA #include "LuaEngine.h" @@ -2648,7 +2649,7 @@ bool InstanceMap::AddPlayerToMap(Player* player) // increase current instances (hourly limit) // xinef: specific instances are still limited if (!group || !group->isLFGGroup() || !group->IsLfgRandomInstance()) - player->AddInstanceEnterTime(GetInstanceId(), time(NULL)); + player->AddInstanceEnterTime(GetInstanceId(), GameTime::GetGameTime()); if (!playerBind->perm && !mapSave->CanReset() && (!group || !group->isLFGGroup() || !group->IsLfgRandomInstance())) { @@ -2994,7 +2995,7 @@ void Map::SaveCreatureRespawnTime(uint32 dbGuid, time_t& respawnTime) return; } - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); if (GetInstanceResetPeriod() > 0 && respawnTime-now+5 >= GetInstanceResetPeriod()) respawnTime = now+YEAR; @@ -3028,7 +3029,7 @@ void Map::SaveGORespawnTime(uint32 dbGuid, time_t& respawnTime) return; } - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); if (GetInstanceResetPeriod() > 0 && respawnTime-now+5 >= GetInstanceResetPeriod()) respawnTime = now+YEAR; diff --git a/src/server/game/Movement/MotionMaster.cpp b/src/server/game/Movement/MotionMaster.cpp index d681dcff3..2ae63bbc9 100644 --- a/src/server/game/Movement/MotionMaster.cpp +++ b/src/server/game/Movement/MotionMaster.cpp @@ -7,6 +7,7 @@ #include "MotionMaster.h" #include "CreatureAISelector.h" #include "Creature.h" +#include "GameTime.h" #include "ConfusedMovementGenerator.h" #include "FleeingMovementGenerator.h" @@ -535,7 +536,7 @@ void MotionMaster::MoveFall(uint32 id /*=0*/, bool addFlagForNPC) { _owner->AddUnitMovementFlag(MOVEMENTFLAG_FALLING); _owner->m_movementInfo.SetFallTime(0); - _owner->ToPlayer()->SetFallInformation(time(NULL), _owner->GetPositionZ()); + _owner->ToPlayer()->SetFallInformation(GameTime::GetGameTime(), _owner->GetPositionZ()); } else if (_owner->GetTypeId() == TYPEID_UNIT && addFlagForNPC) // pussywizard { diff --git a/src/server/game/Movement/MovementGenerators/TargetedMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/TargetedMovementGenerator.cpp index 2cd1496d3..87c763430 100644 --- a/src/server/game/Movement/MovementGenerators/TargetedMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/TargetedMovementGenerator.cpp @@ -13,6 +13,7 @@ #include "MoveSplineInit.h" #include "MoveSpline.h" #include "Player.h" +#include "GameTime.h" #include "Spell.h" #include "BattlegroundRV.h" #include "VehicleDefines.h" @@ -66,7 +67,7 @@ void TargetedMovementGeneratorMedium::_setTargetLocation(T* owner, bool ini if (useMMaps && !inRange && (!isPlayerPet || i_target->GetPositionZ()-z > 50.0f)) { //useMMaps = false; - owner->m_targetsNotAcceptable[i_target->GetGUID()] = MMapTargetData(sWorld->GetGameTime()+DISALLOW_TIME_AFTER_FAIL, owner, i_target.getTarget()); + owner->m_targetsNotAcceptable[i_target->GetGUID()] = MMapTargetData(GameTime::GetGameTime()+DISALLOW_TIME_AFTER_FAIL, owner, i_target.getTarget()); return; } @@ -174,7 +175,7 @@ void TargetedMovementGeneratorMedium::_setTargetLocation(T* owner, bool ini } } - if (!forceDest && getMSTimeDiff(lastPathingFailMSTime, World::GetGameTimeMS()) < 1000) + if (!forceDest && getMSTimeDiff(lastPathingFailMSTime, GameTime::GetGameTimeMS()) < 1000) { lastOwnerXYZ.Relocate(-5000.0f, -5000.0f, -5000.0f); return; @@ -186,8 +187,8 @@ void TargetedMovementGeneratorMedium::_setTargetLocation(T* owner, bool ini float maxDist = MELEE_RANGE + owner->GetMeleeReach() + i_target->GetMeleeReach(); if (!forceDest && (i_path->GetPathType() & PATHFIND_NOPATH || (!i_offset && !isPlayerPet && i_target->GetExactDistSq(i_path->GetActualEndPosition().x, i_path->GetActualEndPosition().y, i_path->GetActualEndPosition().z) > maxDist*maxDist))) { - lastPathingFailMSTime = World::GetGameTimeMS(); - owner->m_targetsNotAcceptable[i_target->GetGUID()] = MMapTargetData(sWorld->GetGameTime()+DISALLOW_TIME_AFTER_FAIL, owner, i_target.getTarget()); + lastPathingFailMSTime = GameTime::GetGameTimeMS(); + owner->m_targetsNotAcceptable[i_target->GetGUID()] = MMapTargetData(GameTime::GetGameTime()+DISALLOW_TIME_AFTER_FAIL, owner, i_target.getTarget()); return; } else diff --git a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp index 4c76aa74e..b7243347e 100644 --- a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp @@ -9,6 +9,7 @@ #include "ObjectMgr.h" #include "World.h" #include "Transport.h" +#include "GameTime.h" //Flightmaster grid preloading #include "MapManager.h" //Creature-specific headers @@ -317,7 +318,7 @@ void FlightPathMovementGenerator::DoFinalize(Player* player) // this prevent cheating with landing point at lags // when client side flight end early in comparison server side player->StopMoving(); - player->SetFallInformation(time(NULL), player->GetPositionZ()); + player->SetFallInformation(GameTime::GetGameTime(), player->GetPositionZ()); } player->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_TAXI_BENCHMARK); @@ -406,7 +407,7 @@ bool FlightPathMovementGenerator::DoUpdate(Player* player, uint32 /*diff*/) if (i_currentNode >= i_path.size() - 1) { player->CleanupAfterTaxiFlight(); - player->SetFallInformation(time(NULL), player->GetPositionZ()); + player->SetFallInformation(GameTime::GetGameTime(), player->GetPositionZ()); if (player->pvpInfo.IsHostile) player->CastSpell(player, 2479, true); diff --git a/src/server/game/Scripting/MapScripts.cpp b/src/server/game/Scripting/MapScripts.cpp index 4609933d5..1d6477e56 100644 --- a/src/server/game/Scripting/MapScripts.cpp +++ b/src/server/game/Scripting/MapScripts.cpp @@ -12,6 +12,7 @@ #include "MapManager.h" #include "MapRefManager.h" #include "ObjectMgr.h" +#include "GameTime.h" #include "Pet.h" #include "ScriptedCreature.h" #include "ScriptMgr.h" @@ -43,7 +44,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; @@ -73,7 +74,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)); sScriptMgr->IncreaseScheduledScriptsCount(); @@ -280,7 +281,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/Server/Protocol/PacketLog.cpp b/src/server/game/Server/Protocol/PacketLog.cpp index 51df454d6..4f05bff92 100644 --- a/src/server/game/Server/Protocol/PacketLog.cpp +++ b/src/server/game/Server/Protocol/PacketLog.cpp @@ -8,6 +8,7 @@ #include "Config.h" #include "ByteBuffer.h" #include "WorldPacket.h" +#include "GameTime.h" PacketLog::PacketLog() : _file(NULL) { @@ -40,7 +41,7 @@ void PacketLog::LogPacket(WorldPacket const& packet, Direction direction) ByteBuffer data(4+4+4+1+packet.size()); data << int32(packet.GetOpcode()); data << int32(packet.size()); - data << uint32(time(NULL)); + data << uint32(GameTime::GetGameTime()); data << uint8(direction); for (uint32 i = 0; i < packet.size(); i++) diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index f209dc334..21747f6dd 100644 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -22,6 +22,7 @@ #include "GuildMgr.h" #include "Group.h" #include "Guild.h" +#include "GameTime.h" #include "World.h" #include "ObjectAccessor.h" #include "BattlegroundMgr.h" @@ -197,13 +198,13 @@ void WorldSession::SendPacket(WorldPacket const* packet) static uint64 sendPacketCount = 0; static uint64 sendPacketBytes = 0; - static time_t firstTime = time(NULL); + static time_t firstTime = GameTime::GetGameTime(); static time_t lastTime = firstTime; // next 60 secs start time static uint64 sendLastPacketCount = 0; static uint64 sendLastPacketBytes = 0; - time_t cur_time = time(NULL); + time_t cur_time = GameTime::GetGameTime(); if ((cur_time - lastTime) < 60) { @@ -389,7 +390,7 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater) if (updater.ProcessLogout()) { - time_t currTime = time(NULL); + time_t currTime = GameTime::GetGameTime(); if (ShouldLogOut(currTime) && !m_playerLoading) LogoutPlayer(true); @@ -426,7 +427,7 @@ void WorldSession::HandleTeleportTimeout(bool updateInSessions) // pussywizard: handle teleport ack timeout if (m_Socket && !m_Socket->IsClosed() && GetPlayer() && GetPlayer()->IsBeingTeleported()) { - time_t currTime = time(NULL); + time_t currTime = GameTime::GetGameTime(); if (updateInSessions) // session update from World::UpdateSessions { if (GetPlayer()->IsBeingTeleportedFar() && GetPlayer()->GetSemaphoreTeleportFar()+sWorld->getIntConfig(CONFIG_TELEPORT_TIMEOUT_FAR) < currTime) @@ -769,7 +770,7 @@ void WorldSession::SetAccountData(AccountDataType type, time_t tm, std::string c void WorldSession::SendAccountDataTimes(uint32 mask) { WorldPacket data(SMSG_ACCOUNT_DATA_TIMES, 4 + 1 + 4 + 8 * 4); // changed in WotLK - data << uint32(time(NULL)); // unix time of something + data << uint32(GameTime::GetGameTime()); // unix time of something data << uint8(1); data << uint32(mask); // type mask for (uint32 i = 0; i < NUM_ACCOUNT_DATA_TYPES; ++i) diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp index 13a462375..0c3dc00ce 100644 --- a/src/server/game/Server/WorldSocket.cpp +++ b/src/server/game/Server/WorldSocket.cpp @@ -25,6 +25,7 @@ #include "ByteBuffer.h" #include "Opcodes.h" #include "DatabaseEnv.h" +#include "GameTime.h" #include "BigNumber.h" #include "SHA1.h" #include "WorldSession.h" @@ -839,7 +840,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket) //! Negative mutetime indicates amount of seconds to be muted effective on next login - which is now. if (mutetime < 0) { - mutetime = time(NULL) + llabs(mutetime); + mutetime = GameTime::GetGameTime() + llabs(mutetime); PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_MUTE_TIME_LOGIN); diff --git a/src/server/game/Spells/Auras/SpellAuraEffects.cpp b/src/server/game/Spells/Auras/SpellAuraEffects.cpp index bc4fcbe4e..5898a0685 100644 --- a/src/server/game/Spells/Auras/SpellAuraEffects.cpp +++ b/src/server/game/Spells/Auras/SpellAuraEffects.cpp @@ -21,6 +21,7 @@ #include "Formulas.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" +#include "GameTime.h" #include "CellImpl.h" #include "ScriptMgr.h" #include "Vehicle.h" @@ -2843,7 +2844,7 @@ void AuraEffect::HandleAuraFeatherFall(AuraApplication const* aurApp, uint8 mode // start fall from current height if (!apply && target->GetTypeId() == TYPEID_PLAYER) - target->ToPlayer()->SetFallInformation(time(NULL), target->GetPositionZ()); + target->ToPlayer()->SetFallInformation(GameTime::GetGameTime(), target->GetPositionZ()); } void AuraEffect::HandleAuraHover(AuraApplication const* aurApp, uint8 mode, bool apply) const diff --git a/src/server/game/Spells/Auras/SpellAuras.cpp b/src/server/game/Spells/Auras/SpellAuras.cpp index a1a2281b1..b184669f1 100644 --- a/src/server/game/Spells/Auras/SpellAuras.cpp +++ b/src/server/game/Spells/Auras/SpellAuras.cpp @@ -19,6 +19,7 @@ #include "Util.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" +#include "GameTime.h" #include "CellImpl.h" #include "ScriptMgr.h" #include "SpellScript.h" @@ -395,7 +396,7 @@ Aura* Aura::Create(SpellInfo const* spellproto, uint8 effMask, WorldObject* owne Aura::Aura(SpellInfo const* spellproto, WorldObject* owner, Unit* caster, Item* castItem, uint64 casterGUID) : m_spellInfo(spellproto), m_casterGuid(casterGUID ? casterGUID : caster->GetGUID()), -m_castItemGuid(castItem ? castItem->GetGUID() : 0),m_castItemEntry(castItem ? castItem->GetEntry() : 0), m_applyTime(time(NULL)), +m_castItemGuid(castItem ? castItem->GetGUID() : 0),m_castItemEntry(castItem ? castItem->GetEntry() : 0), m_applyTime(GameTime::GetGameTime()), m_owner(owner), m_timeCla(0), m_updateTargetMapInterval(0), m_casterLevel(caster ? caster->getLevel() : m_spellInfo->SpellLevel), m_procCharges(0), m_stackAmount(1), m_isRemoved(false), m_isSingleTarget(false), m_isUsingCharges(false) @@ -2015,7 +2016,7 @@ bool Aura::IsProcOnCooldown() const { /*if (m_procCooldown) { - if (m_procCooldown > time(NULL)) + if (m_procCooldown > GameTime::GetGameTime()) return true; }*/ return false; @@ -2023,7 +2024,7 @@ bool Aura::IsProcOnCooldown() const void Aura::AddProcCooldown(uint32 /*msec*/) { - //m_procCooldown = time(NULL) + msec; + //m_procCooldown = GameTime::GetGameTime() + msec; } void Aura::PrepareProcToTrigger(AuraApplication* aurApp, ProcEventInfo& eventInfo) diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index cd286f3fb..9ade08991 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -23,6 +23,7 @@ #include "Spell.h" #include "DynamicObject.h" #include "Group.h" +#include "GameTime.h" #include "UpdateData.h" #include "MapManager.h" #include "ObjectAccessor.h" @@ -2576,7 +2577,7 @@ void Spell::DoAllEffectOnTarget(TargetInfo* target) // Xinef: absorb delayed projectiles for 500ms if (getState() == SPELL_STATE_DELAYED && !m_spellInfo->IsTargetingArea() && !m_spellInfo->IsPositive() && - (World::GetGameTimeMS() - target->timeDelay) <= effectUnit->m_lastSanctuaryTime && World::GetGameTimeMS() < (effectUnit->m_lastSanctuaryTime + 500) && + (GameTime::GetGameTimeMS() - target->timeDelay) <= effectUnit->m_lastSanctuaryTime && GameTime::GetGameTimeMS() < (effectUnit->m_lastSanctuaryTime + 500) && effectUnit->FindMap() && !effectUnit->FindMap()->IsDungeon() ) return; // No missinfo in that case @@ -4517,7 +4518,7 @@ void Spell::SendSpellGo() data << uint8(m_cast_count); // pending spell cast? data << uint32(m_spellInfo->Id); // spellId data << uint32(castFlags); // cast flags - data << uint32(World::GetGameTimeMS()); // timestamp + data << uint32(GameTime::GetGameTimeMS()); // timestamp WriteSpellGoTargets(&data); @@ -5000,7 +5001,7 @@ void Spell::TakePower() // Set the five second timer if (powerType == POWER_MANA && m_powerCost > 0) - m_caster->SetLastManaUse(World::GetGameTimeMS()); + m_caster->SetLastManaUse(GameTime::GetGameTimeMS()); } void Spell::TakeAmmo() @@ -6022,7 +6023,7 @@ SpellCastResult Spell::CheckCast(bool strict) return SPELL_FAILED_BAD_TARGETS; // Xinef: Implement summon pending error - if (target->GetSummonExpireTimer() > time(NULL)) + if (target->GetSummonExpireTimer() > GameTime::GetGameTime()) return SPELL_FAILED_SUMMON_PENDING; // check if our map is dungeon @@ -6062,7 +6063,7 @@ SpellCastResult Spell::CheckCast(bool strict) return SPELL_FAILED_BAD_TARGETS; // Xinef: Implement summon pending error - if (target->GetSummonExpireTimer() > time(NULL)) + if (target->GetSummonExpireTimer() > GameTime::GetGameTime()) return SPELL_FAILED_SUMMON_PENDING; break; diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index 371cfb987..c50a48cc2 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -21,6 +21,7 @@ #include "SpellAuras.h" #include "SpellAuraEffects.h" #include "Group.h" +#include "GameTime.h" #include "UpdateData.h" #include "MapManager.h" #include "ObjectAccessor.h" @@ -702,7 +703,7 @@ void Spell::EffectDummy(SpellEffIndex effIndex) case 17731: case 69294: { - if( !gameObjTarget || gameObjTarget->GetRespawnTime() > time(NULL) ) + if( !gameObjTarget || gameObjTarget->GetRespawnTime() > GameTime::GetGameTime() ) return; gameObjTarget->SetRespawnTime(10); @@ -4210,7 +4211,7 @@ void Spell::EffectSanctuary(SpellEffIndex /*effIndex*/) } // Xinef: Set last sanctuary time - unitTarget->m_lastSanctuaryTime = World::GetGameTimeMS(); + 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 @@ -4942,7 +4943,7 @@ void Spell::EffectCharge(SpellEffIndex /*effIndex*/) // charge changes fall time if( m_caster->GetTypeId() == TYPEID_PLAYER ) - m_caster->ToPlayer()->SetFallInformation(time(NULL), m_caster->GetPositionZ()); + m_caster->ToPlayer()->SetFallInformation(GameTime::GetGameTime(), m_caster->GetPositionZ()); if (m_pathFinder) { @@ -5063,7 +5064,7 @@ void Spell::EffectLeapBack(SpellEffIndex effIndex) // xinef: changes fall time if (m_caster->GetTypeId() == TYPEID_PLAYER) - m_caster->ToPlayer()->SetFallInformation(time(NULL), m_caster->GetPositionZ()); + m_caster->ToPlayer()->SetFallInformation(GameTime::GetGameTime(), m_caster->GetPositionZ()); } void Spell::EffectQuestClear(SpellEffIndex effIndex) diff --git a/src/server/game/Tickets/TicketMgr.cpp b/src/server/game/Tickets/TicketMgr.cpp index 233cc24ce..45393c772 100644 --- a/src/server/game/Tickets/TicketMgr.cpp +++ b/src/server/game/Tickets/TicketMgr.cpp @@ -7,6 +7,7 @@ #include "Common.h" #include "TicketMgr.h" #include "DatabaseEnv.h" +#include "GameTime.h" #include "Language.h" #include "Log.h" #include "WorldPacket.h" @@ -16,7 +17,7 @@ #include "Player.h" #include "Opcodes.h" -inline float GetAge(uint64 t) { return float(time(NULL) - t) / DAY; } +inline float GetAge(uint64 t) { return float(GameTime::GetGameTime() - t) / DAY; } /////////////////////////////////////////////////////////////////////////////////////////////////// // GM ticket @@ -24,7 +25,7 @@ GmTicket::GmTicket() : _id(0), _playerGuid(0), _type(TICKET_TYPE_OPEN), _posX(0) _closedBy(0), _resolvedBy(0), _assignedTo(0), _completed(false), _escalatedStatus(TICKET_UNASSIGNED), _viewed(false), _needResponse(false), _needMoreHelp(false) { } -GmTicket::GmTicket(Player* player) : _type(TICKET_TYPE_OPEN), _createTime(time(NULL)), _lastModifiedTime(time(NULL)), _closedBy(0), _resolvedBy(0), _assignedTo(0), _completed(false), _escalatedStatus(TICKET_UNASSIGNED), _viewed(false), _needMoreHelp(false) +GmTicket::GmTicket(Player* player) : _type(TICKET_TYPE_OPEN), _createTime(GameTime::GetGameTime()), _lastModifiedTime(GameTime::GetGameTime()), _closedBy(0), _resolvedBy(0), _assignedTo(0), _completed(false), _escalatedStatus(TICKET_UNASSIGNED), _viewed(false), _needMoreHelp(false) { _id = sTicketMgr->GenerateTicketId(); _playerName = player->GetName(); @@ -147,7 +148,7 @@ void GmTicket::SendResponse(WorldSession* session) const std::string GmTicket::FormatMessageString(ChatHandler& handler, bool detailed) const { - time_t curTime = time(NULL); + time_t curTime = GameTime::GetGameTime(); std::stringstream ss; ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTGUID, _id); @@ -186,6 +187,12 @@ std::string GmTicket::FormatMessageString(ChatHandler& handler, const char* szCl return ss.str(); } +void GmTicket::SetMessage(std::string const& message) +{ + _message = message; + _lastModifiedTime = uint64(GameTime::GetGameTime()); +} + void GmTicket::SetUnassigned() { _assignedTo = 0; @@ -235,7 +242,7 @@ void GmTicket::SetChatLog(std::list time, std::string const& log) /////////////////////////////////////////////////////////////////////////////////////////////////// // Ticket manager -TicketMgr::TicketMgr() : _status(true), _lastTicketId(0), _lastSurveyId(0), _openTicketCount(0), _lastChange(time(NULL)) { } +TicketMgr::TicketMgr() : _status(true), _lastTicketId(0), _lastSurveyId(0), _openTicketCount(0), _lastChange(GameTime::GetGameTime()) { } TicketMgr::~TicketMgr() { @@ -369,6 +376,10 @@ void TicketMgr::ResolveAndCloseTicket(uint32 ticketId, int64 source) } } +void TicketMgr::UpdateLastChange() +{ + _lastChange = uint64(GameTime::GetGameTime()); +} void TicketMgr::ShowList(ChatHandler& handler, bool onlineOnly) const { diff --git a/src/server/game/Tickets/TicketMgr.h b/src/server/game/Tickets/TicketMgr.h index 29537182d..ed6aba6ea 100644 --- a/src/server/game/Tickets/TicketMgr.h +++ b/src/server/game/Tickets/TicketMgr.h @@ -118,11 +118,7 @@ public: void SetClosedBy(int64 value) { _closedBy = value; _type = TICKET_TYPE_CLOSED; } void SetResolvedBy(int64 value) { _resolvedBy = value; } void SetCompleted() { _completed = true; } - void SetMessage(std::string const& message) - { - _message = message; - _lastModifiedTime = uint64(time(NULL)); - } + void SetMessage(std::string const& message); void SetComment(std::string const& comment) { _comment = comment; } void SetViewed() { _viewed = true; } void SetUnassigned(); @@ -219,7 +215,7 @@ public: void SetStatus(bool status) { _status = status; } uint64 GetLastChange() const { return _lastChange; } - void UpdateLastChange() { _lastChange = uint64(time(NULL)); } + void UpdateLastChange(); uint32 GenerateTicketId() { return ++_lastTicketId; } uint32 GetOpenTicketCount() const { return _openTicketCount; } diff --git a/src/server/game/Time/GameTime.cpp b/src/server/game/Time/GameTime.cpp new file mode 100644 index 000000000..6f24a356e --- /dev/null +++ b/src/server/game/Time/GameTime.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2016+ AzerothCore , released under GNU GPL v2 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-GPL2 + * Copyright (C) 2008-2016 TrinityCore + * Copyright (C) 2005-2009 MaNGOS + */ + +#include "GameTime.h" +#include "Timer.h" + +namespace GameTime +{ + time_t const StartTime = time(nullptr); + + time_t GameTime = time(nullptr); + 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(); + } +} \ No newline at end of file diff --git a/src/server/game/Time/GameTime.h b/src/server/game/Time/GameTime.h new file mode 100644 index 000000000..2a8995d70 --- /dev/null +++ b/src/server/game/Time/GameTime.h @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2016+ AzerothCore , released under GNU GPL v2 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-GPL2 + * Copyright (C) 2008-2016 TrinityCore + * Copyright (C) 2005-2009 MaNGOS + */ + +#ifndef __GAMETIME_H +#define __GAMETIME_H + +#include "Define.h" + +#include + +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 \ No newline at end of file diff --git a/src/server/game/Time/UpdateTime.cpp b/src/server/game/Time/UpdateTime.cpp new file mode 100644 index 000000000..631ec234f --- /dev/null +++ b/src/server/game/Time/UpdateTime.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2016+ AzerothCore , released under GNU GPL v2 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-GPL2 + * Copyright (C) 2008-2016 TrinityCore + * Copyright (C) 2005-2009 MaNGOS + */ + +#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) + sLog->outError("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) + { + sLog->outError("Update time diff: %u. Players online: %u.", GetAverageUpdateTime(), sessionCount); + _lastRecordTime = gameTimeMs; + } + } +} + +void WorldUpdateTime::RecordUpdateTimeDuration(std::string const& text) +{ + _RecordUpdateTimeDuration(text, _recordUpdateTimeMin); +} \ No newline at end of file diff --git a/src/server/game/Time/UpdateTime.h b/src/server/game/Time/UpdateTime.h new file mode 100644 index 000000000..f2ebdb6e6 --- /dev/null +++ b/src/server/game/Time/UpdateTime.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2016+ AzerothCore , released under GNU GPL v2 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-GPL2 + * Copyright (C) 2008-2016 TrinityCore + * Copyright (C) 2005-2009 MaNGOS + */ + +#ifndef __UPDATETIME_H +#define __UPDATETIME_H + +#include + +#include "Define.h" + +#define AVG_DIFF_COUNT 500 + +class 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 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; +}; + +extern WorldUpdateTime sWorldUpdateTime; + +#endif \ No newline at end of file diff --git a/src/server/game/Warden/Warden.cpp b/src/server/game/Warden/Warden.cpp index 84ca06f74..1d9ce00fb 100644 --- a/src/server/game/Warden/Warden.cpp +++ b/src/server/game/Warden/Warden.cpp @@ -13,6 +13,7 @@ #include #include #include "World.h" +#include "GameTime.h" #include "Player.h" #include "Util.h" #include "Warden.h" @@ -88,7 +89,7 @@ void Warden::Update() { if (_initialized) { - uint32 currentTimestamp = World::GetGameTimeMS(); + uint32 currentTimestamp = GameTime::GetGameTimeMS(); uint32 diff = getMSTimeDiff(_previousTimestamp, currentTimestamp); _previousTimestamp = currentTimestamp; diff --git a/src/server/game/Warden/WardenMac.cpp b/src/server/game/Warden/WardenMac.cpp index 4684cd048..c61b33c85 100644 --- a/src/server/game/Warden/WardenMac.cpp +++ b/src/server/game/Warden/WardenMac.cpp @@ -13,6 +13,7 @@ #include "ByteBuffer.h" #include #include "World.h" +#include "GameTime.h" #include "Player.h" #include "Util.h" #include "WardenMac.h" @@ -189,7 +190,7 @@ void WardenMac::HandleHashResult(ByteBuffer &buff) _initialized = true; - _previousTimestamp = World::GetGameTimeMS(); + _previousTimestamp = GameTime::GetGameTimeMS(); } void WardenMac::RequestData() diff --git a/src/server/game/Warden/WardenWin.cpp b/src/server/game/Warden/WardenWin.cpp index 4bf09d262..a6ed0562f 100644 --- a/src/server/game/Warden/WardenWin.cpp +++ b/src/server/game/Warden/WardenWin.cpp @@ -15,6 +15,7 @@ #include #include "Database/DatabaseEnv.h" #include "World.h" +#include "GameTime.h" #include "Player.h" #include "Util.h" #include "WardenWin.h" @@ -183,7 +184,7 @@ void WardenWin::HandleHashResult(ByteBuffer &buff) _initialized = true; - _previousTimestamp = World::GetGameTimeMS(); + _previousTimestamp = GameTime::GetGameTimeMS(); } void WardenWin::RequestData() @@ -199,7 +200,7 @@ void WardenWin::RequestData() if (_otherChecksTodo.empty()) _otherChecksTodo.assign(sWardenCheckMgr->OtherChecksIdPool.begin(), sWardenCheckMgr->OtherChecksIdPool.end()); - _serverTicks = World::GetGameTimeMS(); + _serverTicks = GameTime::GetGameTimeMS(); uint16 id; uint8 type; @@ -387,7 +388,7 @@ void WardenWin::HandleData(ByteBuffer &buff) buff >> newClientTicks; #if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) - uint32 ticksNow = World::GetGameTimeMS(); + uint32 ticksNow = GameTime::GetGameTimeMS(); uint32 ourTicks = newClientTicks + (ticksNow - _serverTicks); sLog->outDebug(LOG_FILTER_WARDEN, "ServerTicks %u", ticksNow); // Now diff --git a/src/server/game/Weather/Weather.cpp b/src/server/game/Weather/Weather.cpp index a989a1661..98f121e5c 100644 --- a/src/server/game/Weather/Weather.cpp +++ b/src/server/game/Weather/Weather.cpp @@ -12,6 +12,7 @@ #include "WorldPacket.h" #include "Player.h" #include "World.h" +#include "GameTime.h" #include "Log.h" #include "ObjectMgr.h" #include "Util.h" @@ -82,7 +83,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; ACE_OS::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 d1a82ee70..2f836f1ea 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -78,6 +78,8 @@ #include "ServerMotd.h" #include "GameGraveyard.h" #include +#include "GameTime.h" +#include "UpdateTime.h" #ifdef ELUNA #include "LuaEngine.h" #endif @@ -85,7 +87,6 @@ ACE_Atomic_Op World::m_stopEvent = false; uint8 World::m_ExitCode = SHUTDOWN_EXIT_CODE; uint32 World::m_worldLoopCounter = 0; -uint32 World::m_gameMSTime = 0; float World::m_MaxVisibleDistanceOnContinents = DEFAULT_VISIBILITY_DISTANCE; float World::m_MaxVisibleDistanceInInstances = DEFAULT_VISIBILITY_INSTANCE; @@ -99,9 +100,6 @@ World::World() m_allowMovement = true; m_ShutdownMask = 0; m_ShutdownTimer = 0; - m_gameTime = time(NULL); - m_gameMSTime = getMSTime(); - m_startTime = m_gameTime; m_maxActiveSessionCount = 0; m_maxQueuedSessionCount = 0; m_PlayerCount = 0; @@ -115,8 +113,6 @@ World::World() m_defaultDbcLocale = LOCALE_enUS; mail_expire_check_timer = 0; - m_updateTime = 0; - m_updateTimeSum = 0; m_isClosed = false; @@ -261,7 +257,7 @@ void World::AddSession_(WorldSession* s) WorldSession* oldSession = old->second; if (!RemoveQueuedPlayer(oldSession) && getIntConfig(CONFIG_INTERVAL_DISCONNECT_TOLERANCE)) - m_disconnects[s->GetAccountId()] = time(NULL); + m_disconnects[s->GetAccountId()] = GameTime::GetGameTime(); // pussywizard: if (oldSession->HandleSocketClosed()) @@ -275,7 +271,7 @@ void World::AddSession_(WorldSession* s) tmp->SetShouldSetOfflineInDB(false); delete tmp; } - oldSession->SetOfflineTime(time(NULL)); + oldSession->SetOfflineTime(GameTime::GetGameTime()); m_offlineSessions[oldSession->GetAccountId()] = oldSession; } else @@ -317,7 +313,7 @@ bool World::HasRecentlyDisconnected(WorldSession* session) { for (DisconnectMap::iterator i = m_disconnects.begin(); i != m_disconnects.end();) { - if ((time(NULL) - i->second) < tolerance) + if ((GameTime::GetGameTime() - i->second) < tolerance) { if (i->first == session->GetAccountId()) return true; @@ -463,6 +459,9 @@ void World::LoadConfigSettings(bool reload) // to change log confs at start sLog->ReloadConfig(); + // load update time related configs + sWorldUpdateTime.LoadFromConfig(); + ///- Read the player limit and the Message of the day from the config file if (!reload) SetPlayerAmountLimit(sConfigMgr->GetIntDefault("PlayerLimit", 100)); @@ -1231,8 +1230,6 @@ void World::LoadConfigSettings(bool reload) m_bool_configs[CONFIG_NO_RESET_TALENT_COST] = sConfigMgr->GetBoolDefault("NoResetTalentsCost", false); m_bool_configs[CONFIG_SHOW_KICK_IN_WORLD] = sConfigMgr->GetBoolDefault("ShowKickInWorld", 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); @@ -1317,7 +1314,7 @@ void World::SetInitialWorldSettings() uint32 startupBegin = getMSTime(); ///- Initialize the random number generator - srand((unsigned int)time(NULL)); + srand((unsigned int)GameTime::GetGameTime()); ///- Initialize detour memory management dtAllocSetCustom(dtCustomAlloc, dtCustomFree); @@ -1834,11 +1831,10 @@ void World::SetInitialWorldSettings() ///- Initialize game time and timers sLog->outString("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')", - realmID, uint32(m_startTime), GitRevision::GetFullVersion()); // One-time query + realmID, uint32(GameTime::GetStartTime()), GitRevision::GetFullVersion()); // One-time query @@ -1859,7 +1855,7 @@ void World::SetInitialWorldSettings() // our speed up m_timers[WUPDATE_5_SECS].SetInterval(5*IN_MILLISECONDS); - mail_expire_check_timer = time(NULL) + 6*3600; + mail_expire_check_timer = GameTime::GetGameTime() + 6*3600; ///- Initilize static helper structures AIRegistry::Initialize(); @@ -2047,18 +2043,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]) - { - m_updateTimeSum += diff; - if (m_updateTimeSum > m_int_configs[CONFIG_INTERVAL_LOG_UPDATE]) - { - sLog->outBasic("Average update time diff: %u. Players online: %u.", avgDiffTracker.getAverage(), (uint32)GetActiveSessionCount()); - m_updateTimeSum = 0; - } - } + 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()); DynamicVisibilityMgr::Update(GetActiveSessionCount()); ///- Update the different timers @@ -2083,25 +2075,22 @@ void World::Update(uint32 diff) WhoListCacheMgr::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(); /// 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(); // pussywizard: @@ -2122,13 +2111,15 @@ void World::Update(uint32 diff) AsyncAuctionListingMgr::Update(diff); - if (m_gameTime > mail_expire_check_timer) + if (currentGameTime > mail_expire_check_timer) { sObjectMgr->ReturnOrDeleteOldMails(true); - mail_expire_check_timer = m_gameTime + 6*3600; + mail_expire_check_timer = currentGameTime + 6*3600; } + sWorldUpdateTime.RecordUpdateTimeReset(); UpdateSessions(diff); + sWorldUpdateTime.RecordUpdateTimeDuration("UpdateSessions"); } // end of section with mutex AsyncAuctionListingMgr::SetAuctionListingAllowed(true); @@ -2156,9 +2147,12 @@ void World::Update(uint32 diff) } } + sWorldUpdateTime.RecordUpdateTimeReset(); sLFGMgr->Update(diff, 0); // pussywizard: remove obsolete stuff before finding compatibility during map update + sWorldUpdateTime.RecordUpdateTimeDuration("UpdateLFGMgr"); sMapMgr->Update(diff); + sWorldUpdateTime.RecordUpdateTimeDuration("UpdateMapMgr"); if (sWorld->getBoolConfig(CONFIG_AUTOBROADCAST)) { @@ -2170,20 +2164,25 @@ void World::Update(uint32 diff) } sBattlegroundMgr->Update(diff); + sWorldUpdateTime.RecordUpdateTimeDuration("UpdateBattlegroundMgr"); sOutdoorPvPMgr->Update(diff); + sWorldUpdateTime.RecordUpdateTimeDuration("UpdateOutdoorPvPMgr"); sBattlefieldMgr->Update(diff); + sWorldUpdateTime.RecordUpdateTimeDuration("BattlefieldMgr"); sLFGMgr->Update(diff, 2); // pussywizard: handle created proposals + sWorldUpdateTime.RecordUpdateTimeDuration("UpdateLFGMgr2"); // execute callbacks from sql queries that were queued recently ProcessQueryCallbacks(); + sWorldUpdateTime.RecordUpdateTimeDuration("ProcessQueryCallbacks"); ///
  • 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(); @@ -2193,7 +2192,7 @@ void World::Update(uint32 diff) stmt->setUInt32(0, tmpDiff); stmt->setUInt16(1, uint16(maxOnlinePlayers)); stmt->setUInt32(2, realmID); - stmt->setUInt32(3, uint32(m_startTime)); + stmt->setUInt32(3, uint32(GameTime::GetStartTime())); LoginDatabase.Execute(stmt); } @@ -2497,7 +2496,7 @@ BanReturn World::BanAccount(BanMode mode, std::string const& nameOrIP, std::stri PreparedStatement* stmtx = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BANNED); stmtx->setUInt32(0, account); PreparedQueryResult banresultx = LoginDatabase.Query(stmtx); - if (banresultx && ((*banresultx)[0].GetUInt32() == (*banresultx)[1].GetUInt32() || ((*banresultx)[1].GetUInt32() > time(NULL)+duration_secs && duration_secs))) + if (banresultx && ((*banresultx)[0].GetUInt32() == (*banresultx)[1].GetUInt32() || ((*banresultx)[1].GetUInt32() > GameTime::GetGameTime()+duration_secs && duration_secs))) return BAN_LONGER_EXISTS; // make sure there is only one active ban @@ -2616,10 +2615,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; - m_gameMSTime = getMSTime(); + 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) @@ -2752,7 +2751,7 @@ void World::UpdateSessions(uint32 diff) if (pSession->HandleSocketClosed()) { if (!RemoveQueuedPlayer(pSession) && getIntConfig(CONFIG_INTERVAL_DISCONNECT_TOLERANCE)) - m_disconnects[pSession->GetAccountId()] = time(NULL); + m_disconnects[pSession->GetAccountId()] = GameTime::GetGameTime(); m_sessions.erase(itr); // there should be no offline session if current one is logged onto a character SessionMap::iterator iter; @@ -2763,7 +2762,7 @@ void World::UpdateSessions(uint32 diff) tmp->SetShouldSetOfflineInDB(false); delete tmp; } - pSession->SetOfflineTime(time(NULL)); + pSession->SetOfflineTime(GameTime::GetGameTime()); m_offlineSessions[pSession->GetAccountId()] = pSession; continue; } @@ -2771,7 +2770,7 @@ void World::UpdateSessions(uint32 diff) if (!pSession->Update(diff, updater)) { if (!RemoveQueuedPlayer(pSession) && getIntConfig(CONFIG_INTERVAL_DISCONNECT_TOLERANCE)) - m_disconnects[pSession->GetAccountId()] = time(NULL); + m_disconnects[pSession->GetAccountId()] = GameTime::GetGameTime(); m_sessions.erase(itr); if (m_offlineSessions.find(pSession->GetAccountId()) != m_offlineSessions.end()) // pussywizard: don't set offline in db because offline session for that acc is present (character is in world) pSession->SetShouldSetOfflineInDB(false); @@ -2782,7 +2781,7 @@ void World::UpdateSessions(uint32 diff) // pussywizard: if (m_offlineSessions.empty()) return; - uint32 currTime = time(NULL); + uint32 currTime = GameTime::GetGameTime(); for (SessionMap::iterator itr = m_offlineSessions.begin(), next; itr != m_offlineSessions.end(); itr = next) { next = itr; @@ -2920,7 +2919,7 @@ time_t World::GetNextTimeWithDayAndHour(int8 dayOfWeek, int8 hour) { if (hour < 0 || hour > 23) hour = 0; - time_t curr = time(NULL); + time_t curr = GameTime::GetGameTime(); tm localTm; ACE_OS::localtime_r(&curr, &localTm); localTm.tm_hour = hour; @@ -2941,7 +2940,7 @@ time_t World::GetNextTimeWithMonthAndHour(int8 month, int8 hour) { if (hour < 0 || hour > 23) hour = 0; - time_t curr = time(NULL); + time_t curr = GameTime::GetGameTime(); tm localTm; ACE_OS::localtime_r(&curr, &localTm); localTm.tm_mday = 1; diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h index a6d37e25f..ad5129d87 100644 --- a/src/server/game/World/World.h +++ b/src/server/game/World/World.h @@ -292,8 +292,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, @@ -620,18 +618,6 @@ class 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; } - /// What time is it? in ms - static uint32 GetGameTimeMS() { return m_gameMSTime; } - /// 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; } @@ -812,12 +798,8 @@ class World bool m_isClosed; - time_t m_startTime; - time_t m_gameTime; IntervalTimer m_timers[WUPDATE_COUNT]; time_t mail_expire_check_timer; - uint32 m_updateTime, m_updateTimeSum; - static uint32 m_gameMSTime; SessionMap m_sessions; SessionMap m_offlineSessions; diff --git a/src/server/scripts/CMakeLists.txt b/src/server/scripts/CMakeLists.txt index 9748bab2b..78796a7c0 100644 --- a/src/server/scripts/CMakeLists.txt +++ b/src/server/scripts/CMakeLists.txt @@ -168,6 +168,7 @@ include_directories( ${CMAKE_SOURCE_DIR}/src/server/game/Spells/Auras ${CMAKE_SOURCE_DIR}/src/server/game/Texts ${CMAKE_SOURCE_DIR}/src/server/game/Tickets + ${CMAKE_SOURCE_DIR}/src/server/game/Time ${CMAKE_SOURCE_DIR}/src/server/game/Tools ${CMAKE_SOURCE_DIR}/src/server/game/Warden ${CMAKE_SOURCE_DIR}/src/server/game/Warden/Modules diff --git a/src/server/scripts/Commands/cs_ban.cpp b/src/server/scripts/Commands/cs_ban.cpp index 585e58ae6..b0644b57e 100644 --- a/src/server/scripts/Commands/cs_ban.cpp +++ b/src/server/scripts/Commands/cs_ban.cpp @@ -17,6 +17,7 @@ EndScriptData */ #include "ObjectAccessor.h" #include "ObjectMgr.h" #include "Player.h" +#include "GameTime.h" #include "ScriptMgr.h" class ban_commandscript : public CommandScript @@ -245,7 +246,7 @@ public: time_t unbanDate = time_t(fields[3].GetUInt32()); bool active = false; - if (fields[2].GetBool() && (fields[1].GetUInt64() == uint64(0) || unbanDate >= time(nullptr))) + if (fields[2].GetBool() && (fields[1].GetUInt64() == uint64(0) || unbanDate >= GameTime::GetGameTime())) active = true; bool permanent = (fields[1].GetUInt64() == uint64(0)); std::string banTime = permanent ? handler->GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].GetUInt64(), true); @@ -293,7 +294,7 @@ public: Field* fields = result->Fetch(); time_t unbanDate = time_t(fields[3].GetUInt32()); bool active = false; - if (fields[2].GetUInt8() && (!fields[1].GetUInt32() || unbanDate >= time(nullptr))) + if (fields[2].GetUInt8() && (!fields[1].GetUInt32() || unbanDate >= GameTime::GetGameTime())) active = true; bool permanent = (fields[1].GetUInt32() == uint32(0)); std::string banTime = permanent ? handler->GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].GetUInt64(), true); diff --git a/src/server/scripts/Commands/cs_event.cpp b/src/server/scripts/Commands/cs_event.cpp index d80d3b878..acff1b1d4 100644 --- a/src/server/scripts/Commands/cs_event.cpp +++ b/src/server/scripts/Commands/cs_event.cpp @@ -15,6 +15,7 @@ EndScriptData */ #include "GameEventMgr.h" #include "Language.h" #include "Player.h" +#include "GameTime.h" #include "ScriptMgr.h" class event_commandscript : public CommandScript @@ -104,8 +105,8 @@ public: std::string endTimeStr = TimeToTimestampStr(eventData.end); uint32 delay = sGameEventMgr->NextCheck(eventId); - time_t nextTime = time(nullptr) + delay; - std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? TimeToTimestampStr(time(nullptr) + delay) : "-"; + time_t nextTime = GameTime::GetGameTime() + delay; + std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? TimeToTimestampStr(GameTime::GetGameTime() + delay) : "-"; std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE, true); std::string lengthStr = secsToTimeString(eventData.length * MINUTE, true); diff --git a/src/server/scripts/Commands/cs_gobject.cpp b/src/server/scripts/Commands/cs_gobject.cpp index 85a91794d..c6e7db2af 100644 --- a/src/server/scripts/Commands/cs_gobject.cpp +++ b/src/server/scripts/Commands/cs_gobject.cpp @@ -19,6 +19,7 @@ EndScriptData */ #include "Chat.h" #include "Language.h" #include "Player.h" +#include "GameTime.h" #include "Opcodes.h" #include "Transport.h" #include "GameObject.h" @@ -310,7 +311,7 @@ public: if (target) { - int32 curRespawnDelay = int32(target->GetRespawnTimeEx() - time(nullptr)); + int32 curRespawnDelay = int32(target->GetRespawnTimeEx() - GameTime::GetGameTime()); if (curRespawnDelay < 0) curRespawnDelay = 0; diff --git a/src/server/scripts/Commands/cs_instance.cpp b/src/server/scripts/Commands/cs_instance.cpp index f5fddb549..aa20c177e 100644 --- a/src/server/scripts/Commands/cs_instance.cpp +++ b/src/server/scripts/Commands/cs_instance.cpp @@ -18,6 +18,7 @@ EndScriptData */ #include "InstanceScript.h" #include "MapManager.h" #include "Player.h" +#include "GameTime.h" #include "Language.h" class instance_commandscript : public CommandScript @@ -71,7 +72,7 @@ public: { InstanceSave* save = itr->second.save; uint32 resetTime = itr->second.extended ? save->GetExtendedResetTime() : save->GetResetTime(); - uint32 ttr = (resetTime >= time(nullptr) ? resetTime - time(nullptr) : 0); + uint32 ttr = (resetTime >= GameTime::GetGameTime() ? resetTime - GameTime::GetGameTime() : 0); std::string timeleft = GetTimeString(ttr); handler->PSendSysMessage("map: %d, inst: %d, perm: %s, diff: %d, canReset: %s, TTR: %s%s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str(), (itr->second.extended ? " (extended)" : "")); counter++; @@ -115,7 +116,7 @@ public: if (itr->first != player->GetMapId() && (!MapId || MapId == itr->first) && (diff == -1 || diff == save->GetDifficulty())) { uint32 resetTime = itr->second.extended ? save->GetExtendedResetTime() : save->GetResetTime(); - uint32 ttr = (resetTime >= time(nullptr) ? resetTime - time(nullptr) : 0); + uint32 ttr = (resetTime >= GameTime::GetGameTime() ? resetTime - GameTime::GetGameTime() : 0); std::string timeleft = GetTimeString(ttr); handler->PSendSysMessage("unbinding map: %d, inst: %d, perm: %s, diff: %d, canReset: %s, TTR: %s%s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str(), (itr->second.extended ? " (extended)" : "")); sInstanceSaveMgr->PlayerUnbindInstance(player->GetGUIDLow(), itr->first, Difficulty(i), true, player); diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp index 6fb08f45a..8d0dc8615 100644 --- a/src/server/scripts/Commands/cs_misc.cpp +++ b/src/server/scripts/Commands/cs_misc.cpp @@ -22,6 +22,7 @@ #include "WeatherMgr.h" #include "ace/INET_Addr.h" #include "Player.h" +#include "GameTime.h" #include "Pet.h" #include "LFG.h" #include "GroupMgr.h" @@ -1997,11 +1998,11 @@ public: // Output III. LANG_PINFO_BANNED if ban exists and is applied if (banTime >= 0) - handler->PSendSysMessage(LANG_PINFO_BANNED, banType.c_str(), banReason.c_str(), banTime > 0 ? secsToTimeString(banTime - time(nullptr), true).c_str() : handler->GetTrinityString(LANG_PERMANENTLY), bannedBy.c_str()); + handler->PSendSysMessage(LANG_PINFO_BANNED, banType.c_str(), banReason.c_str(), banTime > 0 ? secsToTimeString(banTime - GameTime::GetGameTime(), true).c_str() : handler->GetTrinityString(LANG_PERMANENTLY), bannedBy.c_str()); // Output IV. LANG_PINFO_MUTED if mute is applied if (muteTime > 0) - handler->PSendSysMessage(LANG_PINFO_MUTED, muteReason.c_str(), secsToTimeString(muteTime - time(nullptr), true).c_str(), muteBy.c_str()); + handler->PSendSysMessage(LANG_PINFO_MUTED, muteReason.c_str(), secsToTimeString(muteTime - GameTime::GetGameTime(), true).c_str(), muteBy.c_str()); // Output V. LANG_PINFO_ACC_ACCOUNT handler->PSendSysMessage(LANG_PINFO_ACC_ACCOUNT, userName.c_str(), accId, security); @@ -2240,7 +2241,7 @@ public: if (target) { // Target is online, mute will be in effect right away. - int64 muteTime = time(nullptr) + notSpeakTime * MINUTE; + int64 muteTime = GameTime::GetGameTime() + notSpeakTime * MINUTE; target->GetSession()->m_muteTime = muteTime; stmt->setInt64(0, muteTime); ChatHandler(target->GetSession()).PSendSysMessage(LANG_YOUR_CHAT_DISABLED, notSpeakTime, muteBy.c_str(), muteReasonStr.c_str()); diff --git a/src/server/scripts/Commands/cs_npc.cpp b/src/server/scripts/Commands/cs_npc.cpp index 49b3db28a..c3a00cd8c 100644 --- a/src/server/scripts/Commands/cs_npc.cpp +++ b/src/server/scripts/Commands/cs_npc.cpp @@ -20,6 +20,7 @@ EndScriptData */ #include "TargetedMovementGenerator.h" // for HandleNpcUnFollowCommand #include "CreatureAI.h" #include "Player.h" +#include "GameTime.h" #include "Pet.h" struct NpcFlagText @@ -719,7 +720,7 @@ public: uint32 nativeid = target->GetNativeDisplayId(); uint32 Entry = target->GetEntry(); - int64 curRespawnDelay = target->GetRespawnTimeEx()-time(nullptr); + int64 curRespawnDelay = target->GetRespawnTimeEx()-GameTime::GetGameTime(); if (curRespawnDelay < 0) curRespawnDelay = 0; std::string curRespawnDelayStr = secsToTimeString(uint64(curRespawnDelay), true); diff --git a/src/server/scripts/Commands/cs_server.cpp b/src/server/scripts/Commands/cs_server.cpp index 7796c7a68..0869e7171 100644 --- a/src/server/scripts/Commands/cs_server.cpp +++ b/src/server/scripts/Commands/cs_server.cpp @@ -15,6 +15,8 @@ EndScriptData */ #include "Config.h" #include "Language.h" #include "ObjectAccessor.h" +#include "GameTime.h" +#include "UpdateTime.h" #include "Player.h" #include "ScriptMgr.h" #include "GitRevision.h" @@ -96,8 +98,8 @@ public: uint32 activeSessionCount = sWorld->GetActiveSessionCount(); uint32 queuedSessionCount = sWorld->GetQueuedSessionCount(); uint32 connPeak = sWorld->GetMaxActiveSessionCount(); - std::string uptime = secsToTimeString(sWorld->GetUptime()).append("."); - uint32 updateTime = sWorld->GetUpdateTime(); + std::string uptime = secsToTimeString(GameTime::GetUptime()); + uint32 updateTime = sWorldUpdateTime.GetLastUpdateTime(); uint32 avgUpdateTime = avgDiffTracker.getAverage(); handler->PSendSysMessage("%s", GitRevision::GetFullVersion()); @@ -355,7 +357,7 @@ public: if (newTime < 0) return false; - sWorld->SetRecordDiffInterval(newTime); + sWorldUpdateTime.SetRecordUpdateTimeInterval(newTime); printf("Record diff every %u ms\n", newTime); return true; diff --git a/src/server/scripts/Events/brewfest.cpp b/src/server/scripts/Events/brewfest.cpp index 1ac19d4f2..8fbf1ad04 100644 --- a/src/server/scripts/Events/brewfest.cpp +++ b/src/server/scripts/Events/brewfest.cpp @@ -9,6 +9,7 @@ #include "SpellScript.h" #include "GameEventMgr.h" #include "Group.h" +#include "GameTime.h" #include "LFGMgr.h" #include "PassiveAI.h" #include "CellImpl.h" @@ -435,7 +436,7 @@ class npc_brewfest_keg_reciver : public CreatureScript { if (Aura* aur = player->GetAura(SPELL_RAM_AURA)) { - int32 diff = aur->GetApplyTime() - (time(NULL)-(HOUR*18)+spellCooldown); + int32 diff = aur->GetApplyTime() - (GameTime::GetGameTime()-(HOUR*18)+spellCooldown); if (diff > 10) // aura applied later return; @@ -843,7 +844,7 @@ class npc_dark_iron_attack_generator : public CreatureScript bool AllowStart() { - time_t curtime = time(NULL); + time_t curtime = GameTime::GetGameTime(); tm strDate; ACE_OS::localtime_r(&curtime, &strDate); diff --git a/src/server/scripts/Events/midsummer.cpp b/src/server/scripts/Events/midsummer.cpp index 6f7fcec5d..1d5b94081 100644 --- a/src/server/scripts/Events/midsummer.cpp +++ b/src/server/scripts/Events/midsummer.cpp @@ -1,6 +1,7 @@ // Scripted by Xinef #include "ScriptMgr.h" +#include "GameTime.h" #include "ScriptedCreature.h" #include "ScriptedGossip.h" #include "Spell.h" @@ -184,7 +185,7 @@ class npc_midsummer_torch_target : public CreatureScript Position pos; pos.Relocate(posVec.at(num)); me->m_last_notify_position.Relocate(0.0f, 0.0f, 0.0f); - me->m_last_notify_mstime = World::GetGameTimeMS() + 10000; + me->m_last_notify_mstime = GameTime::GetGameTimeMS() + 10000; me->NearTeleportTo(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation()); } @@ -300,7 +301,7 @@ public: } // Achievement - if ((time(NULL) - GetApplyTime()) > 60 && target->GetTypeId() == TYPEID_PLAYER) + if ((GameTime::GetGameTime() - GetApplyTime()) > 60 && target->GetTypeId() == TYPEID_PLAYER) target->ToPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET, 58934, 0, target); } } diff --git a/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/instance_trial_of_the_crusader.cpp b/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/instance_trial_of_the_crusader.cpp index beb13db48..549ef86bc 100644 --- a/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/instance_trial_of_the_crusader.cpp +++ b/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/instance_trial_of_the_crusader.cpp @@ -6,6 +6,7 @@ #include "ScriptedCreature.h" #include "trial_of_the_crusader.h" #include "Group.h" +#include "GameTime.h" #include "Player.h" #define CLEANUP_CHECK_INTERVAL 5000 @@ -322,7 +323,7 @@ public: c->DespawnOrUnsummon(10000); if( Creature* c = instance->GetCreature(NPC_DreadscaleGUID) ) c->DespawnOrUnsummon(10000); - if( AchievementTimer+10 >= time(NULL) ) + if( AchievementTimer+10 >= GameTime::GetGameTime() ) DoUpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET, SPELL_JORMUNGAR_ACHIEV); AchievementTimer = 0; @@ -339,7 +340,7 @@ public: } else // first one died, start timer for achievement { - AchievementTimer = time(NULL); + AchievementTimer = GameTime::GetGameTime(); } } else @@ -428,14 +429,14 @@ public: HandleGameObject(GO_EnterGateGUID, true); - if( AchievementTimer+60 >= time(NULL) ) + if( AchievementTimer+60 >= GameTime::GetGameTime() ) DoUpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET, SPELL_RESILIENCE_WILL_FIX_IT_CREDIT); AchievementTimer = 0; SaveToDB(); } else if( Counter == 1 ) - AchievementTimer = time(NULL); + AchievementTimer = GameTime::GetGameTime(); } break; case TYPE_FACTION_CHAMPIONS_START: diff --git a/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/trial_of_the_crusader.cpp b/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/trial_of_the_crusader.cpp index 0b0d02dc2..574f18569 100644 --- a/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/trial_of_the_crusader.cpp +++ b/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/trial_of_the_crusader.cpp @@ -7,6 +7,7 @@ #include "ScriptedGossip.h" #include "trial_of_the_crusader.h" #include "Player.h" +#include "GameTime.h" enum MenuTexts { diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_icecrown_gunship_battle.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_icecrown_gunship_battle.cpp index 8f68fe45d..7aaa56607 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_icecrown_gunship_battle.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_icecrown_gunship_battle.cpp @@ -11,6 +11,7 @@ #include "TransportMgr.h" #include "Vehicle.h" #include "icecrown_citadel.h" +#include "GameTime.h" enum Texts { @@ -406,7 +407,7 @@ public: return false; bool summoned = false; - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); for (int32 i = first; i <= last; ++i) { if (_respawnCooldowns[i] > now) @@ -442,7 +443,7 @@ public: void ClearSlot(PassengerSlots slot) { _controlledSlots[slot] = 0; - _respawnCooldowns[slot] = time(NULL) + _slotInfo[slot].Cooldown; + _respawnCooldowns[slot] = GameTime::GetGameTime() + _slotInfo[slot].Cooldown; } private: @@ -731,7 +732,7 @@ class npc_high_overlord_saurfang_igb : public CreatureScript _controller.ResetSlots(TEAM_HORDE, creature->GetTransport()->ToMotionTransport()); me->SetRegeneratingHealth(false); me->m_CombatDistance = 70.0f; - _firstMageCooldown = time(NULL) + 45; + _firstMageCooldown = GameTime::GetGameTime() + 45; _axethrowersYellCooldown = time_t(0); _rocketeersYellCooldown = time_t(0); checkTimer = 1000; @@ -796,7 +797,7 @@ class npc_high_overlord_saurfang_igb : public CreatureScript } else if (action == ACTION_SPAWN_MAGE) { - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); if (_firstMageCooldown > now) _events.ScheduleEvent(EVENT_SUMMON_MAGE, (_firstMageCooldown - now) * IN_MILLISECONDS); else @@ -971,10 +972,10 @@ class npc_high_overlord_saurfang_igb : public CreatureScript case EVENT_CHECK_RIFLEMAN: if (_controller.SummonCreatures(me, SLOT_RIFLEMAN_1, Is25ManRaid() ? SLOT_RIFLEMAN_8 : SLOT_RIFLEMAN_4)) { - if (_axethrowersYellCooldown < time(NULL)) + if (_axethrowersYellCooldown < GameTime::GetGameTime()) { Talk(SAY_SAURFANG_AXETHROWERS); - _axethrowersYellCooldown = time(NULL) + 5; + _axethrowersYellCooldown = GameTime::GetGameTime() + 5; } } _events.ScheduleEvent(EVENT_CHECK_RIFLEMAN, 1500); @@ -982,10 +983,10 @@ class npc_high_overlord_saurfang_igb : public CreatureScript case EVENT_CHECK_MORTAR: if (_controller.SummonCreatures(me, SLOT_MORTAR_1, Is25ManRaid() ? SLOT_MORTAR_4 : SLOT_MORTAR_2)) { - if (_rocketeersYellCooldown < time(NULL)) + if (_rocketeersYellCooldown < GameTime::GetGameTime()) { Talk(SAY_SAURFANG_ROCKETEERS); - _rocketeersYellCooldown = time(NULL) + 5; + _rocketeersYellCooldown = GameTime::GetGameTime() + 5; } } _events.ScheduleEvent(EVENT_CHECK_MORTAR, 1500); @@ -1066,7 +1067,7 @@ class npc_muradin_bronzebeard_igb : public CreatureScript _controller.ResetSlots(TEAM_ALLIANCE, creature->GetTransport()->ToMotionTransport()); me->SetRegeneratingHealth(false); me->m_CombatDistance = 70.0f; - _firstMageCooldown = time(NULL) + 45; + _firstMageCooldown = GameTime::GetGameTime() + 45; _riflemanYellCooldown = time_t(0); _mortarYellCooldown = time_t(0); checkTimer = 1000; @@ -1132,7 +1133,7 @@ class npc_muradin_bronzebeard_igb : public CreatureScript } else if (action == ACTION_SPAWN_MAGE) { - time_t now = time(NULL); + time_t now = GameTime::GetGameTime(); if (_firstMageCooldown > now) _events.ScheduleEvent(EVENT_SUMMON_MAGE, (_firstMageCooldown - now) * IN_MILLISECONDS); else @@ -1310,10 +1311,10 @@ class npc_muradin_bronzebeard_igb : public CreatureScript case EVENT_CHECK_RIFLEMAN: if (_controller.SummonCreatures(me, SLOT_RIFLEMAN_1, Is25ManRaid() ? SLOT_RIFLEMAN_8 : SLOT_RIFLEMAN_4)) { - if (_riflemanYellCooldown < time(NULL)) + if (_riflemanYellCooldown < GameTime::GetGameTime()) { Talk(SAY_MURADIN_RIFLEMAN); - _riflemanYellCooldown = time(NULL) + 5; + _riflemanYellCooldown = GameTime::GetGameTime() + 5; } } _events.ScheduleEvent(EVENT_CHECK_RIFLEMAN, 1500); @@ -1321,10 +1322,10 @@ class npc_muradin_bronzebeard_igb : public CreatureScript case EVENT_CHECK_MORTAR: if (_controller.SummonCreatures(me, SLOT_MORTAR_1, Is25ManRaid() ? SLOT_MORTAR_4 : SLOT_MORTAR_2)) { - if (_mortarYellCooldown < time(NULL)) + if (_mortarYellCooldown < GameTime::GetGameTime()) { Talk(SAY_MURADIN_MORTAR); - _mortarYellCooldown = time(NULL) + 5; + _mortarYellCooldown = GameTime::GetGameTime() + 5; } } _events.ScheduleEvent(EVENT_CHECK_MORTAR, 1500); diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_sindragosa.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_sindragosa.cpp index 1e9c426e0..888aa5d95 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_sindragosa.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_sindragosa.cpp @@ -5,6 +5,7 @@ #include "ObjectMgr.h" #include "ScriptMgr.h" #include "ScriptedCreature.h" +#include "GameTime.h" #include "GridNotifiers.h" #include "icecrown_citadel.h" #include "Player.h" @@ -948,7 +949,7 @@ class spell_sindragosa_unchained_magic : public SpellScriptLoader if (!spellInfo) return false; - uint32 currMSTime = World::GetGameTimeMS(); + uint32 currMSTime = GameTime::GetGameTimeMS(); std::map::iterator itr = _lastMSTimeForSpell.find(spellInfo->Id); if (itr != _lastMSTimeForSpell.end()) { diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_the_lich_king.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_the_lich_king.cpp index 27cbb5a54..ef64ec8f2 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_the_lich_king.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_the_lich_king.cpp @@ -8,6 +8,7 @@ #include "SpellScript.h" #include "SpellAuraEffects.h" #include "Spell.h" +#include "GameTime.h" #include "Vehicle.h" #include "Unit.h" #include "Cell.h" @@ -686,9 +687,9 @@ class boss_the_lich_king : public CreatureScript void KilledUnit(Unit* victim) { - if (victim->GetTypeId() == TYPEID_PLAYER && !me->IsInEvadeMode() && _phase != PHASE_OUTRO && _lastTalkTimeKill+5 < time(NULL)) + if (victim->GetTypeId() == TYPEID_PLAYER && !me->IsInEvadeMode() && _phase != PHASE_OUTRO && _lastTalkTimeKill+5 < GameTime::GetGameTime()) { - _lastTalkTimeKill = time(NULL); + _lastTalkTimeKill = GameTime::GetGameTime(); Talk(SAY_LK_KILL); } } @@ -717,7 +718,7 @@ class boss_the_lich_king : public CreatureScript events.RescheduleEvent(EVENT_START_ATTACK, 1000); EntryCheckPredicate pred(NPC_STRANGULATE_VEHICLE); summons.DoAction(ACTION_TELEPORT_BACK, pred); - if (!IsHeroic() && _phase != PHASE_OUTRO && me->IsInCombat() && _lastTalkTimeBuff+5 <= time(NULL)) + if (!IsHeroic() && _phase != PHASE_OUTRO && me->IsInCombat() && _lastTalkTimeBuff+5 <= GameTime::GetGameTime()) Talk(SAY_LK_FROSTMOURNE_ESCAPE); } break; @@ -874,9 +875,9 @@ class boss_the_lich_king : public CreatureScript void SpellHit(Unit* /*caster*/, SpellInfo const* spell) { - if (spell->Id == HARVESTED_SOUL_BUFF && me->IsInCombat() && !IsHeroic() && _phase != PHASE_OUTRO && _lastTalkTimeBuff+5 <= time(NULL)) + if (spell->Id == HARVESTED_SOUL_BUFF && me->IsInCombat() && !IsHeroic() && _phase != PHASE_OUTRO && _lastTalkTimeBuff+5 <= GameTime::GetGameTime()) { - _lastTalkTimeBuff = time(NULL); + _lastTalkTimeBuff = GameTime::GetGameTime(); Talk(SAY_LK_FROSTMOURNE_KILL); } } diff --git a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_ignis.cpp b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_ignis.cpp index 739236580..f305c1e85 100644 --- a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_ignis.cpp +++ b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_ignis.cpp @@ -5,6 +5,7 @@ #include "ScriptMgr.h" #include "ScriptedCreature.h" #include "SpellScript.h" +#include "GameTime.h" #include "ulduar.h" #include "Vehicle.h" #include "SpellAuras.h" @@ -261,10 +262,10 @@ public: if (id == 1337) { if (lastShatterMSTime) - if (getMSTimeDiff(lastShatterMSTime, World::GetGameTimeMS()) <= 5000) + if (getMSTimeDiff(lastShatterMSTime, GameTime::GetGameTimeMS()) <= 5000) bShattered = true; - lastShatterMSTime = World::GetGameTimeMS(); + lastShatterMSTime = GameTime::GetGameTimeMS(); } } diff --git a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_mimiron.cpp b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_mimiron.cpp index 6ee534bd0..a0043221f 100644 --- a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_mimiron.cpp +++ b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_mimiron.cpp @@ -5,6 +5,7 @@ #include "ScriptMgr.h" #include "ScriptedCreature.h" #include "SpellScript.h" +#include "GameTime.h" #include "ulduar.h" #include "Vehicle.h" #include "Spell.h" @@ -452,7 +453,7 @@ public: case EVENT_SPAWN_FLAMES_INITIAL: { if (changeAllowedFlameSpreadTime) - allowedFlameSpreadTime = time(NULL); + allowedFlameSpreadTime = GameTime::GetGameTime(); std::vector pg; Map::PlayerList const &pl = me->GetMap()->GetPlayers(); @@ -2236,7 +2237,7 @@ public: bool Load() { - lastMSTime = World::GetGameTimeMS(); + lastMSTime = GameTime::GetGameTimeMS(); lastOrientation = -1.0f; return true; } @@ -2247,14 +2248,14 @@ public: { if (c->GetTypeId() != TYPEID_UNIT) return; - uint32 diff = getMSTimeDiff(lastMSTime, World::GetGameTimeMS()); + uint32 diff = getMSTimeDiff(lastMSTime, GameTime::GetGameTimeMS()); if (lastOrientation == -1.0f) { lastOrientation = (c->ToCreature()->AI()->GetData(0)*2*M_PI)/100.0f; diff = 0; } float new_o = Position::NormalizeOrientation(lastOrientation-(M_PI/60)*(diff/250.0f)); - lastMSTime = World::GetGameTimeMS(); + lastMSTime = GameTime::GetGameTimeMS(); lastOrientation = new_o; c->SetOrientation(new_o); c->SetFacingTo(new_o); @@ -2316,7 +2317,7 @@ public: { npc_ulduar_flames_initialAI(Creature *pCreature) : NullCreatureAI(pCreature) { - CreateTime = time(NULL); + CreateTime = GameTime::GetGameTime(); events.Reset(); events.ScheduleEvent(EVENT_FLAMES_SPREAD, 5750); if( Creature* flame = me->SummonCreature(NPC_FLAMES_SPREAD, me->GetPositionX(), me->GetPositionY(), 364.32f, 0.0f) ) diff --git a/src/server/scripts/Northrend/Ulduar/Ulduar/instance_ulduar.cpp b/src/server/scripts/Northrend/Ulduar/Ulduar/instance_ulduar.cpp index a7312583b..9ff1e599f 100644 --- a/src/server/scripts/Northrend/Ulduar/Ulduar/instance_ulduar.cpp +++ b/src/server/scripts/Northrend/Ulduar/Ulduar/instance_ulduar.cpp @@ -7,6 +7,7 @@ #include "ulduar.h" #include "Vehicle.h" #include "Player.h" +#include "GameTime.h" #include "WorldPacket.h" #include "WorldSession.h" #include "Transport.h" @@ -887,10 +888,10 @@ public: } else if (unit->GetTypeId() == TYPEID_UNIT && unit->GetAreaId() == 4656 /*Conservatory of Life*/) { - if (time(NULL) > (m_conspeedatoryAttempt + DAY)) + if (GameTime::GetGameTime() > (m_conspeedatoryAttempt + DAY)) { DoStartTimedAchievement(ACHIEVEMENT_TIMED_TYPE_EVENT, 21597 /*CON-SPEED-ATORY_TIMED_CRITERIA*/); - m_conspeedatoryAttempt = time(NULL); + m_conspeedatoryAttempt = GameTime::GetGameTime(); SaveToDB(); } } diff --git a/src/server/scripts/Northrend/VaultOfArchavon/instance_vault_of_archavon.cpp b/src/server/scripts/Northrend/VaultOfArchavon/instance_vault_of_archavon.cpp index d6dbc63a2..236a87391 100644 --- a/src/server/scripts/Northrend/VaultOfArchavon/instance_vault_of_archavon.cpp +++ b/src/server/scripts/Northrend/VaultOfArchavon/instance_vault_of_archavon.cpp @@ -11,6 +11,7 @@ #include "BattlefieldMgr.h" #include "SpellAuras.h" #include "Player.h" +#include "GameTime.h" /* Vault of Archavon encounters: 1 - Archavon the Stone Watcher event @@ -179,13 +180,13 @@ class instance_vault_of_archavon : public InstanceMapScript switch (type) { case EVENT_ARCHAVON: - ArchavonDeath = time(NULL); + ArchavonDeath = GameTime::GetGameTime(); break; case EVENT_EMALON: - EmalonDeath = time(NULL); + EmalonDeath = GameTime::GetGameTime(); break; case EVENT_KORALON: - KoralonDeath = time(NULL); + KoralonDeath = GameTime::GetGameTime(); break; default: return; diff --git a/src/server/scripts/Northrend/zone_wintergrasp.cpp b/src/server/scripts/Northrend/zone_wintergrasp.cpp index 00647069c..3573fda3d 100644 --- a/src/server/scripts/Northrend/zone_wintergrasp.cpp +++ b/src/server/scripts/Northrend/zone_wintergrasp.cpp @@ -29,6 +29,7 @@ #include "Player.h" #include "PoolMgr.h" #include "GameGraveyard.h" +#include "GameTime.h" #include "World.h" #define GOSSIP_HELLO_DEMO1 "Build catapult." @@ -294,7 +295,7 @@ class npc_wg_queue : public CreatureScript else { uint32 timer = wintergrasp->GetTimer() / 1000; - player->SendUpdateWorldState(4354, time(NULL) + timer); + player->SendUpdateWorldState(4354, GameTime::GetGameTime() + timer); if (timer < 15 * MINUTE) { player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Queue for Wintergrasp.", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF); diff --git a/src/server/scripts/Outland/TempestKeep/botanica/instance_the_botanica.cpp b/src/server/scripts/Outland/TempestKeep/botanica/instance_the_botanica.cpp index b6b3e445f..3e78cbabf 100644 --- a/src/server/scripts/Outland/TempestKeep/botanica/instance_the_botanica.cpp +++ b/src/server/scripts/Outland/TempestKeep/botanica/instance_the_botanica.cpp @@ -3,6 +3,7 @@ */ #include "ScriptMgr.h" +#include "GameTime.h" #include "InstanceScript.h" #include "the_botanica.h" @@ -150,7 +151,7 @@ class spell_botanica_shift_form : public SpellScriptLoader { if (SpellInfo const* spellInfo = eventInfo.GetDamageInfo()->GetSpellInfo()) { - if ((spellInfo->GetSchoolMask() & _lastSchool) && _swapTime > time(NULL)) + if ((spellInfo->GetSchoolMask() & _lastSchool) && _swapTime > GameTime::GetGameTime()) return false; uint32 form = 0; @@ -166,7 +167,7 @@ class spell_botanica_shift_form : public SpellScriptLoader if (form) { - _swapTime = time(NULL) + 6; + _swapTime = GameTime::GetGameTime() + 6; _lastSchool = spellInfo->GetSchoolMask(); GetUnitOwner()->RemoveAurasDueToSpell(_lastForm); _lastForm = form; diff --git a/src/server/scripts/Spells/spell_generic.cpp b/src/server/scripts/Spells/spell_generic.cpp index bdf7c471e..657f6a7bd 100644 --- a/src/server/scripts/Spells/spell_generic.cpp +++ b/src/server/scripts/Spells/spell_generic.cpp @@ -22,6 +22,7 @@ #include "GridNotifiers.h" #include "GridNotifiersImpl.h" #include "Group.h" +#include "GameTime.h" #include "InstanceScript.h" #include "LFGMgr.h" #include "Pet.h" @@ -2650,12 +2651,12 @@ class spell_gen_turkey_marker : public SpellScriptLoader { if (GetStackAmount() > stackAmount) { - _applyTimes.push_back(World::GetGameTimeMS()); + _applyTimes.push_back(GameTime::GetGameTimeMS()); stackAmount++; } // pop stack if it expired for us - if (_applyTimes.front() + GetMaxDuration() < World::GetGameTimeMS()) + if (_applyTimes.front() + GetMaxDuration() < GameTime::GetGameTimeMS()) { stackAmount--; ModStackAmount(-1, AURA_REMOVE_BY_EXPIRE); diff --git a/src/server/scripts/Spells/spell_item.cpp b/src/server/scripts/Spells/spell_item.cpp index 3d5b2c787..ef0854837 100644 --- a/src/server/scripts/Spells/spell_item.cpp +++ b/src/server/scripts/Spells/spell_item.cpp @@ -17,6 +17,7 @@ #include "SpellAuraEffects.h" #include "SkillDiscovery.h" #include "Battleground.h" +#include "GameTime.h" class spell_item_massive_seaforium_charge : public SpellScriptLoader { @@ -3092,7 +3093,7 @@ class spell_item_crystal_prison_dummy_dnd : public SpellScriptLoader if (Creature* target = GetHitCreature()) if (target->isDead() && !target->IsPet()) { - GetCaster()->SummonGameObject(OBJECT_IMPRISONED_DOOMGUARD, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), target->GetOrientation(), 0, 0, 0, 0, uint32(target->GetRespawnTime()-time(NULL))); + GetCaster()->SummonGameObject(OBJECT_IMPRISONED_DOOMGUARD, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), target->GetOrientation(), 0, 0, 0, 0, uint32(target->GetRespawnTime()-GameTime::GetGameTime())); target->DespawnOrUnsummon(); } } diff --git a/src/server/scripts/World/areatrigger_scripts.cpp b/src/server/scripts/World/areatrigger_scripts.cpp index 8a736d40c..7ea7ac32f 100644 --- a/src/server/scripts/World/areatrigger_scripts.cpp +++ b/src/server/scripts/World/areatrigger_scripts.cpp @@ -26,6 +26,7 @@ EndContentData */ #include "ScriptMgr.h" #include "ScriptedCreature.h" #include "Player.h" +#include "GameTime.h" #include "SpellMgr.h" // Ours @@ -382,7 +383,7 @@ class AreaTrigger_at_brewfest : public AreaTriggerScript { uint32 triggerId = trigger->entry; // 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) @@ -399,7 +400,7 @@ class AreaTrigger_at_brewfest : public AreaTriggerScript break; } - _triggerTimes[triggerId] = sWorld->GetGameTime(); + _triggerTimes[triggerId] = GameTime::GetGameTime(); return false; } @@ -439,7 +440,7 @@ class AreaTrigger_at_area_52_entrance : public AreaTriggerScript return false; uint32 triggerId = trigger->entry; - if (sWorld->GetGameTime() - _triggerTimes[trigger->entry] < SUMMON_COOLDOWN) + if (GameTime::GetGameTime() - _triggerTimes[trigger->entry] < SUMMON_COOLDOWN) return false; switch (triggerId) @@ -468,7 +469,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->entry] = sWorld->GetGameTime(); + _triggerTimes[trigger->entry] = GameTime::GetGameTime(); return false; } diff --git a/src/server/scripts/World/go_scripts.cpp b/src/server/scripts/World/go_scripts.cpp index 6811ef861..390530dab 100644 --- a/src/server/scripts/World/go_scripts.cpp +++ b/src/server/scripts/World/go_scripts.cpp @@ -36,6 +36,7 @@ EndContentData */ #include "GameObjectAI.h" #include "Spell.h" #include "Player.h" +#include "GameTime.h" #include "WorldSession.h" // Ours @@ -836,7 +837,7 @@ class go_inconspicuous_landmark : public GameObjectScript public: go_inconspicuous_landmark() : GameObjectScript("go_inconspicuous_landmark") { - _lastUsedTime = time(NULL); + _lastUsedTime = GameTime::GetGameTime(); } bool OnGossipHello(Player* player, GameObject* /*go*/) @@ -844,10 +845,10 @@ class go_inconspicuous_landmark : public GameObjectScript if (player->HasItemCount(ITEM_CUERGOS_KEY)) return true; - if (_lastUsedTime > time(NULL)) + if (_lastUsedTime > GameTime::GetGameTime()) return true; - _lastUsedTime = time(NULL) + MINUTE; + _lastUsedTime = GameTime::GetGameTime() + MINUTE; player->CastSpell(player, SPELL_SUMMON_PIRATES_TREASURE_AND_TRIGGER_MOB, true); return true; } diff --git a/src/server/scripts/World/npcs_special.cpp b/src/server/scripts/World/npcs_special.cpp index f6310333c..6f2dd651a 100644 --- a/src/server/scripts/World/npcs_special.cpp +++ b/src/server/scripts/World/npcs_special.cpp @@ -33,6 +33,7 @@ EndContentData */ #include "ObjectMgr.h" #include "ScriptMgr.h" #include "World.h" +#include "GameTime.h" #include "CreatureTextMgr.h" #include "PassiveAI.h" #include "GameEventMgr.h" @@ -108,7 +109,7 @@ public: { case EVENT_CLEARWATER_ANNOUNCE: { - time_t curtime = time(NULL); + time_t curtime = GameTime::GetGameTime(); tm strdate; ACE_OS::localtime_r(&curtime, &strdate); @@ -253,7 +254,7 @@ public: { case EVENT_RIGGLE_ANNOUNCE: { - time_t curtime = time(NULL); + time_t curtime = GameTime::GetGameTime(); tm strdate; ACE_OS::localtime_r(&curtime, &strdate); if (!startWarning && strdate.tm_hour == 14 && strdate.tm_min == 0)