Skip to content

Commit adae2fe

Browse files
committed
Ensure that all actions are compared to fixed point in time (ie. world update start)
1 parent 00babf2 commit adae2fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+479
-185
lines changed

src/server/game/AuctionHouse/AuctionHouseMgr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "Item.h"
3232
#include "Language.h"
3333
#include "Log.h"
34+
#include "GameTime.h"
3435

3536
enum eAuctionHouse
3637
{
@@ -591,7 +592,7 @@ bool AuctionHouseObject::RemoveAuction(AuctionEntry* auction)
591592

592593
void AuctionHouseObject::Update()
593594
{
594-
time_t curTime = sWorld->GetGameTime();
595+
time_t curTime = GameTime::GetGameTime();
595596
///- Handle expired auctions
596597

597598
// If storage is empty, no need to update. next == NULL in this case.
@@ -686,7 +687,7 @@ void AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player
686687
int loc_idx = player->GetSession()->GetSessionDbLocaleIndex();
687688
int locdbc_idx = player->GetSession()->GetSessionDbcLocale();
688689

689-
time_t curTime = sWorld->GetGameTime();
690+
time_t curTime = GameTime::GetGameTime();
690691

691692
PlayerGetAllThrottleMap::const_iterator itr = GetAllThrottleMap.find(player->GetGUID());
692693
time_t throttleTime = itr != GetAllThrottleMap.end() ? itr->second : curTime;

src/server/game/AuctionHouseBot/AuctionHouseBot.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "AuctionHouseBot.h"
2626
#include "AuctionHouseBotBuyer.h"
2727
#include "AuctionHouseBotSeller.h"
28+
#include "GameTime.h"
2829

2930
AuctionBotConfig* AuctionBotConfig::instance()
3031
{
@@ -494,7 +495,7 @@ void AuctionHouseBot::Rebuild(bool all)
494495
for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctionHouse->GetAuctionsBegin(); itr != auctionHouse->GetAuctionsEnd(); ++itr)
495496
if (!itr->second->owner || sAuctionBotConfig->IsBotChar(itr->second->owner)) // ahbot auction
496497
if (all || itr->second->bid == 0) // expire now auction if no bid or forced
497-
itr->second->expire_time = sWorld->GetGameTime();
498+
itr->second->expire_time = GameTime::GetGameTime();
498499
}
499500
}
500501

src/server/game/Battlegrounds/Battleground.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "Util.h"
3737
#include "WorldPacket.h"
3838
#include "Transport.h"
39+
#include "GameTime.h"
3940

4041
namespace Trinity
4142
{
@@ -316,7 +317,7 @@ inline void Battleground::_ProcessOfflineQueue()
316317
BattlegroundPlayerMap::iterator itr = m_Players.find(*(m_OfflineQueue.begin()));
317318
if (itr != m_Players.end())
318319
{
319-
if (itr->second.OfflineRemoveTime <= sWorld->GetGameTime())
320+
if (itr->second.OfflineRemoveTime <= GameTime::GetGameTime())
320321
{
321322
if (isBattleground() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_TRACK_DESERTERS) &&
322323
(GetStatus() == STATUS_IN_PROGRESS || GetStatus() == STATUS_WAIT_JOIN))
@@ -1211,7 +1212,7 @@ void Battleground::EventPlayerLoggedOut(Player* player)
12111212

12121213
// player is correct pointer, it is checked in WorldSession::LogoutPlayer()
12131214
m_OfflineQueue.push_back(player->GetGUID());
1214-
m_Players[guid].OfflineRemoveTime = sWorld->GetGameTime() + MAX_OFFLINE_TIME;
1215+
m_Players[guid].OfflineRemoveTime = GameTime::GetGameTime() + MAX_OFFLINE_TIME;
12151216
if (GetStatus() == STATUS_IN_PROGRESS)
12161217
{
12171218
// drop flag and handle other cleanups

src/server/game/Battlegrounds/BattlegroundQueue.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "BattlegroundMgr.h"
2222
#include "BattlegroundQueue.h"
2323
#include "Chat.h"
24+
#include "GameTime.h"
2425
#include "Group.h"
2526
#include "Log.h"
2627
#include "Language.h"
@@ -138,7 +139,7 @@ GroupQueueInfo* BattlegroundQueue::AddGroup(Player* leader, Group* grp, Battlegr
138139
ginfo->ArenaTeamId = arenateamid;
139140
ginfo->IsRated = isRated;
140141
ginfo->IsInvitedToBGInstanceGUID = 0;
141-
ginfo->JoinTime = getMSTime();
142+
ginfo->JoinTime = GameTime::GetGameTimeMS();
142143
ginfo->RemoveInviteTime = 0;
143144
ginfo->Team = leader->GetTeam();
144145
ginfo->ArenaTeamRating = ArenaRating;
@@ -156,7 +157,7 @@ GroupQueueInfo* BattlegroundQueue::AddGroup(Player* leader, Group* grp, Battlegr
156157
index++;
157158
TC_LOG_DEBUG("bg.battleground", "Adding Group to BattlegroundQueue bgTypeId : %u, bracket_id : %u, index : %u", BgTypeId, bracketId, index);
158159

159-
uint32 lastOnlineTime = getMSTime();
160+
uint32 lastOnlineTime = GameTime::GetGameTimeMS();
160161

161162
//announce world (this don't need mutex)
162163
if (isRated && sWorld->getBoolConfig(CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE))
@@ -233,7 +234,7 @@ GroupQueueInfo* BattlegroundQueue::AddGroup(Player* leader, Group* grp, Battlegr
233234

234235
void BattlegroundQueue::PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo* ginfo, BattlegroundBracketId bracket_id)
235236
{
236-
uint32 timeInQueue = getMSTimeDiff(ginfo->JoinTime, getMSTime());
237+
uint32 timeInQueue = getMSTimeDiff(ginfo->JoinTime, GameTime::GetGameTimeMS());
237238
uint8 team_index = TEAM_ALLIANCE; //default set to TEAM_ALLIANCE - or non rated arenas!
238239
if (!ginfo->ArenaType)
239240
{
@@ -445,7 +446,7 @@ bool BattlegroundQueue::InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg,
445446
if (bg->isArena() && bg->isRated())
446447
bg->SetArenaTeamIdForTeam(ginfo->Team, ginfo->ArenaTeamId);
447448

448-
ginfo->RemoveInviteTime = getMSTime() + INVITE_ACCEPT_WAIT_TIME;
449+
ginfo->RemoveInviteTime = GameTime::GetGameTimeMS() + INVITE_ACCEPT_WAIT_TIME;
449450

450451
// loop through the players
451452
for (std::map<ObjectGuid, PlayerQueueInfo*>::iterator itr = ginfo->Players.begin(); itr != ginfo->Players.end(); ++itr)
@@ -638,7 +639,7 @@ bool BattlegroundQueue::CheckPremadeMatch(BattlegroundBracketId bracket_id, uint
638639
// this could be 2 cycles but i'm checking only first team in queue - it can cause problem -
639640
// if first is invited to BG and seconds timer expired, but we can ignore it, because players have only 80 seconds to click to enter bg
640641
// and when they click or after 80 seconds the queue info is removed from queue
641-
uint32 time_before = getMSTime() - sWorld->getIntConfig(CONFIG_BATTLEGROUND_PREMADE_GROUP_WAIT_FOR_MATCH);
642+
uint32 time_before = GameTime::GetGameTimeMS() - sWorld->getIntConfig(CONFIG_BATTLEGROUND_PREMADE_GROUP_WAIT_FOR_MATCH);
642643
for (uint32 i = 0; i < BG_TEAMS_COUNT; i++)
643644
{
644645
if (!m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE + i].empty())
@@ -919,7 +920,7 @@ void BattlegroundQueue::BattlegroundQueueUpdate(uint32 /*diff*/, BattlegroundTyp
919920
// the discard time is current_time - time_to_discard, teams that joined after that, will have their ratings taken into account
920921
// else leave the discard time on 0, this way all ratings will be discarded
921922
// this has to be signed value - when the server starts, this value would be negative and thus overflow
922-
int32 discardTime = getMSTime() - sBattlegroundMgr->GetRatingDiscardTimer();
923+
int32 discardTime = GameTime::GetGameTimeMS() - sBattlegroundMgr->GetRatingDiscardTimer();
923924

924925
// we need to find 2 teams which will play next game
925926
GroupsQueueType::iterator itr_teams[BG_TEAMS_COUNT];

src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "BattlegroundSA.h"
2020
#include "GameObject.h"
21+
#include "GameTime.h"
2122
#include "Language.h"
2223
#include "ObjectMgr.h"
2324
#include "Player.h"
@@ -985,11 +986,11 @@ void BattlegroundSA::UpdateDemolisherSpawns()
985986
// Demolisher is not in list
986987
if (DemoliserRespawnList.find(i) == DemoliserRespawnList.end())
987988
{
988-
DemoliserRespawnList[i] = getMSTime()+30000;
989+
DemoliserRespawnList[i] = GameTime::GetGameTimeMS()+30000;
989990
}
990991
else
991992
{
992-
if (DemoliserRespawnList[i] < getMSTime())
993+
if (DemoliserRespawnList[i] < GameTime::GetGameTimeMS())
993994
{
994995
Demolisher->Relocate(BG_SA_NpcSpawnlocs[i]);
995996
Demolisher->Respawn();

src/server/game/Entities/Creature/Creature.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "DatabaseEnv.h"
2727
#include "Formulas.h"
2828
#include "GameEventMgr.h"
29+
#include "GameTime.h"
2930
#include "GossipDef.h"
3031
#include "GridNotifiers.h"
3132
#include "GridNotifiersImpl.h"
@@ -2894,7 +2895,7 @@ void Creature::ReleaseFocus(Spell const* focusSpell, bool withDelay)
28942895
ClearUnitState(UNIT_STATE_CANNOT_TURN);
28952896

28962897
m_focusSpell = nullptr;
2897-
m_focusDelay = (!IsPet() && withDelay) ? getMSTime() : 0; // don't allow re-target right away to prevent visual bugs
2898+
m_focusDelay = (!IsPet() && withDelay) ? GameTime::GetGameTimeMS() : 0; // don't allow re-target right away to prevent visual bugs
28982899
}
28992900

29002901
void Creature::StartPickPocketRefillTimer()

src/server/game/Entities/DynamicObject/DynamicObject.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "World.h"
2222
#include "ObjectAccessor.h"
2323
#include "DatabaseEnv.h"
24+
#include "GameTime.h"
2425
#include "GridNotifiers.h"
2526
#include "GridNotifiersImpl.h"
2627
#include "ScriptMgr.h"
@@ -97,7 +98,7 @@ bool DynamicObject::CreateDynamicObject(ObjectGuid::LowType guidlow, Unit* caste
9798
SetUInt32Value(DYNAMICOBJECT_BYTES, spell->SpellVisual[0] | (type << 28));
9899
SetUInt32Value(DYNAMICOBJECT_SPELLID, spell->Id);
99100
SetFloatValue(DYNAMICOBJECT_RADIUS, radius);
100-
SetUInt32Value(DYNAMICOBJECT_CASTTIME, getMSTime());
101+
SetUInt32Value(DYNAMICOBJECT_CASTTIME, GameTime::GetGameTimeMS());
101102

102103
if (IsWorldObject())
103104
setActive(true); //must before add to map to be put in world container

src/server/game/Entities/GameObject/GameObject.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "CellImpl.h"
2222
#include "CreatureAISelector.h"
2323
#include "GameObjectModel.h"
24+
#include "GameTime.h"
2425
#include "GridNotifiersImpl.h"
2526
#include "Group.h"
2627
#include "GroupMgr.h"
@@ -365,10 +366,10 @@ void GameObject::Update(uint32 diff)
365366
// Bombs
366367
if (goInfo->trap.type == 2)
367368
// Hardcoded tooltip value
368-
m_cooldownTime = time(NULL) + 10;
369+
m_cooldownTime = GameTime::GetGameTimeMS() + 10 * IN_MILLISECONDS;
369370
else if (Unit* owner = GetOwner())
370371
if (owner->IsInCombat())
371-
m_cooldownTime = time(NULL) + goInfo->trap.startDelay;
372+
m_cooldownTime = GameTime::GetGameTimeMS() + goInfo->trap.startDelay * IN_MILLISECONDS;
372373

373374
SetLootState(GO_READY);
374375
break;
@@ -532,7 +533,7 @@ void GameObject::Update(uint32 diff)
532533
GameObjectTemplate const* goInfo = GetGOInfo();
533534
if (goInfo->type == GAMEOBJECT_TYPE_TRAP)
534535
{
535-
if (m_cooldownTime >= time(NULL))
536+
if (GameTime::GetGameTimeMS() < m_cooldownTime)
536537
break;
537538

538539
// Type 2 (bomb) does not need to be triggered by a unit and despawns after casting its spell.
@@ -599,16 +600,14 @@ void GameObject::Update(uint32 diff)
599600
{
600601
case GAMEOBJECT_TYPE_DOOR:
601602
case GAMEOBJECT_TYPE_BUTTON:
602-
if (m_cooldownTime && (m_cooldownTime < time(NULL)))
603+
if (m_cooldownTime && GameTime::GetGameTimeMS() >= m_cooldownTime)
603604
ResetDoorOrButton();
604605
break;
605606
case GAMEOBJECT_TYPE_GOOBER:
606-
if (m_cooldownTime < time(NULL))
607+
if (GameTime::GetGameTimeMS() >= m_cooldownTime)
607608
{
608609
RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_IN_USE);
609-
610610
SetLootState(GO_JUST_DEACTIVATED);
611-
m_cooldownTime = 0;
612611
}
613612
break;
614613
case GAMEOBJECT_TYPE_CHEST:
@@ -641,7 +640,7 @@ void GameObject::Update(uint32 diff)
641640
CastSpell(target, goInfo->trap.spellId);
642641

643642
// Template value or 4 seconds
644-
m_cooldownTime = time(NULL) + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4));
643+
m_cooldownTime = GameTime::GetGameTimeMS() + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4)) * IN_MILLISECONDS;
645644

646645
if (goInfo->trap.type == 1)
647646
SetLootState(GO_JUST_DEACTIVATED);
@@ -1196,7 +1195,7 @@ void GameObject::UseDoorOrButton(uint32 time_to_restore, bool alternative /* = f
11961195
SwitchDoorOrButton(true, alternative);
11971196
SetLootState(GO_ACTIVATED, user);
11981197

1199-
m_cooldownTime = time_to_restore ? (time(NULL) + time_to_restore) : 0;
1198+
m_cooldownTime = GameTime::GetGameTimeMS() + time_to_restore;
12001199
}
12011200

12021201
void GameObject::SetGoArtKit(uint8 kit)
@@ -1254,10 +1253,10 @@ void GameObject::Use(Unit* user)
12541253
// If cooldown data present in template
12551254
if (uint32 cooldown = GetGOInfo()->GetCooldown())
12561255
{
1257-
if (m_cooldownTime > sWorld->GetGameTime())
1256+
if (GameTime::GetGameTimeMS() < m_cooldownTime)
12581257
return;
12591258

1260-
m_cooldownTime = sWorld->GetGameTime() + cooldown;
1259+
m_cooldownTime = GameTime::GetGameTimeMS() + cooldown * IN_MILLISECONDS;
12611260
}
12621261

12631262
switch (GetGoType())
@@ -1284,7 +1283,7 @@ void GameObject::Use(Unit* user)
12841283
if (goInfo->trap.spellId)
12851284
CastSpell(user, goInfo->trap.spellId);
12861285

1287-
m_cooldownTime = time(NULL) + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4)); // template or 4 seconds
1286+
m_cooldownTime = GameTime::GetGameTimeMS() + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4)) * IN_MILLISECONDS; // template or 4 seconds
12881287

12891288
if (goInfo->trap.type == 1) // Deactivate after trigger
12901289
SetLootState(GO_JUST_DEACTIVATED);
@@ -1431,7 +1430,7 @@ void GameObject::Use(Unit* user)
14311430
else
14321431
SetGoState(GO_STATE_ACTIVE);
14331432

1434-
m_cooldownTime = time(NULL) + info->GetAutoCloseTime();
1433+
m_cooldownTime = GameTime::GetGameTimeMS() + info->GetAutoCloseTime();
14351434

14361435
// cast this spell later if provided
14371436
spellId = info->goober.spellId;

src/server/game/Entities/GameObject/GameObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ struct GameObjectTemplate
520520
case GAMEOBJECT_TYPE_AREADAMAGE: autoCloseTime = areadamage.autoCloseTime; break;
521521
default: break;
522522
}
523-
return autoCloseTime / IN_MILLISECONDS; // prior to 3.0.3, conversion was / 0x10000;
523+
return autoCloseTime; // prior to 3.0.3, conversion was / 0x10000;
524524
}
525525

526526
uint32 GetLootId() const

src/server/game/Entities/Object/Object.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "BattlefieldMgr.h"
5353
#include "Battleground.h"
5454
#include "Chat.h"
55+
#include "GameTime.h"
5556

5657
Object::Object() : m_PackGUID(sizeof(uint64)+1)
5758
{
@@ -544,7 +545,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const
544545
*data << self->GetSpeed(MOVE_WALK);
545546

546547
//if (true) // Has time, controlled by bit just after HasTransport
547-
*data << uint32(getMSTime());
548+
*data << uint32(GameTime::GetGameTimeMS());
548549

549550
*data << self->GetSpeed(MOVE_TURN_RATE);
550551
data->WriteByteSeq(guid[6]);
@@ -659,7 +660,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const
659660
if (go && go->ToTransport())
660661
*data << uint32(go->GetGOValue()->Transport.PathProgress);
661662
else
662-
*data << uint32(getMSTime());
663+
*data << uint32(GameTime::GetGameTimeMS());
663664
}
664665
}
665666

0 commit comments

Comments
 (0)