Ensure that all actions are compared to fixed point in time (ie. world update start)

This commit is contained in:
Aokromes committed 2017-04-14 15:02:49 +02:00
1 parent 00babf222a
commit adae2fec26
43 files changed
+479 -185

No files matched your search

@@ -31,6 +31,7 @@
#include "Item.h"
#include "Language.h"
#include "Log.h"
#include "GameTime.h"
enum eAuctionHouse
{
@@ -591,7 +592,7 @@ bool AuctionHouseObject::RemoveAuction(AuctionEntry* auction)
void AuctionHouseObject::Update()
{
time_t curTime = sWorld->GetGameTime();
time_t curTime = GameTime::GetGameTime();
///- Handle expired auctions
// If storage is empty, no need to update. next == NULL in this case.
@@ -686,7 +687,7 @@ void AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player
int loc_idx = player->GetSession()->GetSessionDbLocaleIndex();
int locdbc_idx = player->GetSession()->GetSessionDbcLocale();
time_t curTime = sWorld->GetGameTime();
time_t curTime = GameTime::GetGameTime();
PlayerGetAllThrottleMap::const_iterator itr = GetAllThrottleMap.find(player->GetGUID());
time_t throttleTime = itr != GetAllThrottleMap.end() ? itr->second : curTime;
@@ -25,6 +25,7 @@
#include "AuctionHouseBot.h"
#include "AuctionHouseBotBuyer.h"
#include "AuctionHouseBotSeller.h"
#include "GameTime.h"
AuctionBotConfig* AuctionBotConfig::instance()
{
@@ -494,7 +495,7 @@ void AuctionHouseBot::Rebuild(bool all)
for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctionHouse->GetAuctionsBegin(); itr != auctionHouse->GetAuctionsEnd(); ++itr)
if (!itr->second->owner || sAuctionBotConfig->IsBotChar(itr->second->owner)) // ahbot auction
if (all || itr->second->bid == 0) // expire now auction if no bid or forced
itr->second->expire_time = sWorld->GetGameTime();
itr->second->expire_time = GameTime::GetGameTime();
}
}
@@ -36,6 +36,7 @@
#include "Util.h"
#include "WorldPacket.h"
#include "Transport.h"
#include "GameTime.h"
namespace Trinity
{
@@ -316,7 +317,7 @@ inline void Battleground::_ProcessOfflineQueue()
BattlegroundPlayerMap::iterator itr = m_Players.find(*(m_OfflineQueue.begin()));
if (itr != m_Players.end())
{
if (itr->second.OfflineRemoveTime <= sWorld->GetGameTime())
if (itr->second.OfflineRemoveTime <= GameTime::GetGameTime())
{
if (isBattleground() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_TRACK_DESERTERS) &&
(GetStatus() == STATUS_IN_PROGRESS || GetStatus() == STATUS_WAIT_JOIN))
@@ -1211,7 +1212,7 @@ void Battleground::EventPlayerLoggedOut(Player* player)
// player is correct pointer, it is checked in WorldSession::LogoutPlayer()
m_OfflineQueue.push_back(player->GetGUID());
m_Players[guid].OfflineRemoveTime = sWorld->GetGameTime() + MAX_OFFLINE_TIME;
m_Players[guid].OfflineRemoveTime = GameTime::GetGameTime() + MAX_OFFLINE_TIME;
if (GetStatus() == STATUS_IN_PROGRESS)
{
// drop flag and handle other cleanups
@@ -21,6 +21,7 @@
#include "BattlegroundMgr.h"
#include "BattlegroundQueue.h"
#include "Chat.h"
#include "GameTime.h"
#include "Group.h"
#include "Log.h"
#include "Language.h"
@@ -138,7 +139,7 @@ GroupQueueInfo* BattlegroundQueue::AddGroup(Player* leader, Group* grp, Battlegr
ginfo->ArenaTeamId = arenateamid;
ginfo->IsRated = isRated;
ginfo->IsInvitedToBGInstanceGUID = 0;
ginfo->JoinTime = getMSTime();
ginfo->JoinTime = GameTime::GetGameTimeMS();
ginfo->RemoveInviteTime = 0;
ginfo->Team = leader->GetTeam();
ginfo->ArenaTeamRating = ArenaRating;
@@ -156,7 +157,7 @@ GroupQueueInfo* BattlegroundQueue::AddGroup(Player* leader, Group* grp, Battlegr
index++;
TC_LOG_DEBUG("bg.battleground", "Adding Group to BattlegroundQueue bgTypeId : %u, bracket_id : %u, index : %u", BgTypeId, bracketId, index);
uint32 lastOnlineTime = getMSTime();
uint32 lastOnlineTime = GameTime::GetGameTimeMS();
//announce world (this don't need mutex)
if (isRated && sWorld->getBoolConfig(CONFIG_ARENA_QUEUE_ANNOUNCER_ENABLE))
@@ -233,7 +234,7 @@ GroupQueueInfo* BattlegroundQueue::AddGroup(Player* leader, Group* grp, Battlegr
void BattlegroundQueue::PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo* ginfo, BattlegroundBracketId bracket_id)
{
uint32 timeInQueue = getMSTimeDiff(ginfo->JoinTime, getMSTime());
uint32 timeInQueue = getMSTimeDiff(ginfo->JoinTime, GameTime::GetGameTimeMS());
uint8 team_index = TEAM_ALLIANCE; //default set to TEAM_ALLIANCE - or non rated arenas!
if (!ginfo->ArenaType)
{
@@ -445,7 +446,7 @@ bool BattlegroundQueue::InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg,
if (bg->isArena() && bg->isRated())
bg->SetArenaTeamIdForTeam(ginfo->Team, ginfo->ArenaTeamId);
ginfo->RemoveInviteTime = getMSTime() + INVITE_ACCEPT_WAIT_TIME;
ginfo->RemoveInviteTime = GameTime::GetGameTimeMS() + INVITE_ACCEPT_WAIT_TIME;
// loop through the players
for (std::map<ObjectGuid, PlayerQueueInfo*>::iterator itr = ginfo->Players.begin(); itr != ginfo->Players.end(); ++itr)
@@ -638,7 +639,7 @@ bool BattlegroundQueue::CheckPremadeMatch(BattlegroundBracketId bracket_id, uint
// this could be 2 cycles but i'm checking only first team in queue - it can cause problem -
// if first is invited to BG and seconds timer expired, but we can ignore it, because players have only 80 seconds to click to enter bg
// and when they click or after 80 seconds the queue info is removed from queue
uint32 time_before = getMSTime() - sWorld->getIntConfig(CONFIG_BATTLEGROUND_PREMADE_GROUP_WAIT_FOR_MATCH);
uint32 time_before = GameTime::GetGameTimeMS() - sWorld->getIntConfig(CONFIG_BATTLEGROUND_PREMADE_GROUP_WAIT_FOR_MATCH);
for (uint32 i = 0; i < BG_TEAMS_COUNT; i++)
{
if (!m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE + i].empty())
@@ -919,7 +920,7 @@ void BattlegroundQueue::BattlegroundQueueUpdate(uint32 /*diff*/, BattlegroundTyp
// the discard time is current_time - time_to_discard, teams that joined after that, will have their ratings taken into account
// else leave the discard time on 0, this way all ratings will be discarded
// this has to be signed value - when the server starts, this value would be negative and thus overflow
int32 discardTime = getMSTime() - sBattlegroundMgr->GetRatingDiscardTimer();
int32 discardTime = GameTime::GetGameTimeMS() - sBattlegroundMgr->GetRatingDiscardTimer();
// we need to find 2 teams which will play next game
GroupsQueueType::iterator itr_teams[BG_TEAMS_COUNT];
@@ -18,6 +18,7 @@
#include "BattlegroundSA.h"
#include "GameObject.h"
#include "GameTime.h"
#include "Language.h"
#include "ObjectMgr.h"
#include "Player.h"
@@ -985,11 +986,11 @@ void BattlegroundSA::UpdateDemolisherSpawns()
// Demolisher is not in list
if (DemoliserRespawnList.find(i) == DemoliserRespawnList.end())
{
DemoliserRespawnList[i] = getMSTime()+30000;
DemoliserRespawnList[i] = GameTime::GetGameTimeMS()+30000;
}
else
{
if (DemoliserRespawnList[i] < getMSTime())
if (DemoliserRespawnList[i] < GameTime::GetGameTimeMS())
{
Demolisher->Relocate(BG_SA_NpcSpawnlocs[i]);
Demolisher->Respawn();
@@ -26,6 +26,7 @@
#include "DatabaseEnv.h"
#include "Formulas.h"
#include "GameEventMgr.h"
#include "GameTime.h"
#include "GossipDef.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
@@ -2894,7 +2895,7 @@ void Creature::ReleaseFocus(Spell const* focusSpell, bool withDelay)
ClearUnitState(UNIT_STATE_CANNOT_TURN);
m_focusSpell = nullptr;
m_focusDelay = (!IsPet() && withDelay) ? getMSTime() : 0; // don't allow re-target right away to prevent visual bugs
m_focusDelay = (!IsPet() && withDelay) ? GameTime::GetGameTimeMS() : 0; // don't allow re-target right away to prevent visual bugs
}
void Creature::StartPickPocketRefillTimer()
@@ -21,6 +21,7 @@
#include "World.h"
#include "ObjectAccessor.h"
#include "DatabaseEnv.h"
#include "GameTime.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "ScriptMgr.h"
@@ -97,7 +98,7 @@ bool DynamicObject::CreateDynamicObject(ObjectGuid::LowType guidlow, Unit* caste
SetUInt32Value(DYNAMICOBJECT_BYTES, spell->SpellVisual[0] | (type << 28));
SetUInt32Value(DYNAMICOBJECT_SPELLID, spell->Id);
SetFloatValue(DYNAMICOBJECT_RADIUS, radius);
SetUInt32Value(DYNAMICOBJECT_CASTTIME, getMSTime());
SetUInt32Value(DYNAMICOBJECT_CASTTIME, GameTime::GetGameTimeMS());
if (IsWorldObject())
setActive(true); //must before add to map to be put in world container
@@ -21,6 +21,7 @@
#include "CellImpl.h"
#include "CreatureAISelector.h"
#include "GameObjectModel.h"
#include "GameTime.h"
#include "GridNotifiersImpl.h"
#include "Group.h"
#include "GroupMgr.h"
@@ -365,10 +366,10 @@ void GameObject::Update(uint32 diff)
// Bombs
if (goInfo->trap.type == 2)
// Hardcoded tooltip value
m_cooldownTime = time(NULL) + 10;
m_cooldownTime = GameTime::GetGameTimeMS() + 10 * IN_MILLISECONDS;
else if (Unit* owner = GetOwner())
if (owner->IsInCombat())
m_cooldownTime = time(NULL) + goInfo->trap.startDelay;
m_cooldownTime = GameTime::GetGameTimeMS() + goInfo->trap.startDelay * IN_MILLISECONDS;
SetLootState(GO_READY);
break;
@@ -532,7 +533,7 @@ void GameObject::Update(uint32 diff)
GameObjectTemplate const* goInfo = GetGOInfo();
if (goInfo->type == GAMEOBJECT_TYPE_TRAP)
{
if (m_cooldownTime >= time(NULL))
if (GameTime::GetGameTimeMS() < m_cooldownTime)
break;
// Type 2 (bomb) does not need to be triggered by a unit and despawns after casting its spell.
@@ -599,16 +600,14 @@ void GameObject::Update(uint32 diff)
{
case GAMEOBJECT_TYPE_DOOR:
case GAMEOBJECT_TYPE_BUTTON:
if (m_cooldownTime && (m_cooldownTime < time(NULL)))
if (m_cooldownTime && GameTime::GetGameTimeMS() >= m_cooldownTime)
ResetDoorOrButton();
break;
case GAMEOBJECT_TYPE_GOOBER:
if (m_cooldownTime < time(NULL))
if (GameTime::GetGameTimeMS() >= m_cooldownTime)
{
RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_IN_USE);
SetLootState(GO_JUST_DEACTIVATED);
m_cooldownTime = 0;
}
break;
case GAMEOBJECT_TYPE_CHEST:
@@ -641,7 +640,7 @@ void GameObject::Update(uint32 diff)
CastSpell(target, goInfo->trap.spellId);
// Template value or 4 seconds
m_cooldownTime = time(NULL) + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4));
m_cooldownTime = GameTime::GetGameTimeMS() + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4)) * IN_MILLISECONDS;
if (goInfo->trap.type == 1)
SetLootState(GO_JUST_DEACTIVATED);
@@ -1196,7 +1195,7 @@ void GameObject::UseDoorOrButton(uint32 time_to_restore, bool alternative /* = f
SwitchDoorOrButton(true, alternative);
SetLootState(GO_ACTIVATED, user);
m_cooldownTime = time_to_restore ? (time(NULL) + time_to_restore) : 0;
m_cooldownTime = GameTime::GetGameTimeMS() + time_to_restore;
}
void GameObject::SetGoArtKit(uint8 kit)
@@ -1254,10 +1253,10 @@ void GameObject::Use(Unit* user)
// If cooldown data present in template
if (uint32 cooldown = GetGOInfo()->GetCooldown())
{
if (m_cooldownTime > sWorld->GetGameTime())
if (GameTime::GetGameTimeMS() < m_cooldownTime)
return;
m_cooldownTime = sWorld->GetGameTime() + cooldown;
m_cooldownTime = GameTime::GetGameTimeMS() + cooldown * IN_MILLISECONDS;
}
switch (GetGoType())
@@ -1284,7 +1283,7 @@ void GameObject::Use(Unit* user)
if (goInfo->trap.spellId)
CastSpell(user, goInfo->trap.spellId);
m_cooldownTime = time(NULL) + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4)); // template or 4 seconds
m_cooldownTime = GameTime::GetGameTimeMS() + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4)) * IN_MILLISECONDS; // template or 4 seconds
if (goInfo->trap.type == 1) // Deactivate after trigger
SetLootState(GO_JUST_DEACTIVATED);
@@ -1431,7 +1430,7 @@ void GameObject::Use(Unit* user)
else
SetGoState(GO_STATE_ACTIVE);
m_cooldownTime = time(NULL) + info->GetAutoCloseTime();
m_cooldownTime = GameTime::GetGameTimeMS() + info->GetAutoCloseTime();
// cast this spell later if provided
spellId = info->goober.spellId;
@@ -520,7 +520,7 @@ struct GameObjectTemplate
case GAMEOBJECT_TYPE_AREADAMAGE: autoCloseTime = areadamage.autoCloseTime; break;
default: break;
}
return autoCloseTime / IN_MILLISECONDS; // prior to 3.0.3, conversion was / 0x10000;
return autoCloseTime; // prior to 3.0.3, conversion was / 0x10000;
}
uint32 GetLootId() const
+3 -2
View File
@@ -52,6 +52,7 @@
#include "BattlefieldMgr.h"
#include "Battleground.h"
#include "Chat.h"
#include "GameTime.h"
Object::Object() : m_PackGUID(sizeof(uint64)+1)
{
@@ -544,7 +545,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const
*data << self->GetSpeed(MOVE_WALK);
//if (true) // Has time, controlled by bit just after HasTransport
*data << uint32(getMSTime());
*data << uint32(GameTime::GetGameTimeMS());
*data << self->GetSpeed(MOVE_TURN_RATE);
data->WriteByteSeq(guid[6]);
@@ -659,7 +660,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const
if (go && go->ToTransport())
*data << uint32(go->GetGOValue()->Transport.PathProgress);
else
*data << uint32(getMSTime());
*data << uint32(GameTime::GetGameTimeMS());
}
}
+9 -8
View File
@@ -41,6 +41,7 @@
#include "DisableMgr.h"
#include "Formulas.h"
#include "GameEventMgr.h"
#include "GameTime.h"
#include "GossipDef.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
@@ -1226,7 +1227,7 @@ void Player::Update(uint32 p_time)
_cinematicMgr->m_cinematicDiff += p_time;
if (_cinematicMgr->m_activeCinematicCameraId != 0 && GetMSTimeDiffToNow(_cinematicMgr->m_lastCinematicCheck) > CINEMATIC_UPDATEDIFF)
{
_cinematicMgr->m_lastCinematicCheck = getMSTime();
_cinematicMgr->m_lastCinematicCheck = GameTime::GetGameTimeMS();
_cinematicMgr->UpdateCinematicLocation(p_time);
}
@@ -3981,7 +3982,7 @@ uint32 Player::GetNextResetTalentsCost() const
return 10*GOLD;
else
{
uint64 months = (sWorld->GetGameTime() - GetTalentResetTime())/MONTH;
uint64 months = (GameTime::GetGameTime() - GetTalentResetTime())/MONTH;
if (months > 0)
{
// This cost will be reduced by a rate of 5 gold per month
@@ -18603,10 +18604,10 @@ void Player::_LoadQuestStatus(PreparedQueryResult result)
{
AddTimedQuest(quest_id);
if (quest_time <= sWorld->GetGameTime())
if (quest_time <= GameTime::GetGameTime())
questStatusData.Timer = 1;
else
questStatusData.Timer = uint32((quest_time - sWorld->GetGameTime()) * IN_MILLISECONDS);
questStatusData.Timer = uint32((quest_time - GameTime::GetGameTime()) * IN_MILLISECONDS);
}
else
quest_time = 0;
@@ -20147,7 +20148,7 @@ void Player::_SaveQuestStatus(SQLTransaction& trans)
stmt->setUInt32(index++, statusItr->first);
stmt->setUInt8(index++, uint8(statusItr->second.Status));
stmt->setBool(index++, statusItr->second.Explored);
stmt->setUInt32(index++, uint32(statusItr->second.Timer / IN_MILLISECONDS+ sWorld->GetGameTime()));
stmt->setUInt32(index++, uint32(statusItr->second.Timer / IN_MILLISECONDS+ GameTime::GetGameTime()));
for (uint8 i = 0; i < 4; i++)
stmt->setUInt16(index++, statusItr->second.CreatureOrGOCount[i]);
@@ -23215,7 +23216,7 @@ void Player::SendInitialPacketsBeforeAddToMap()
SendEquipmentSetList();
data.Initialize(SMSG_LOGIN_SETTIMESPEED, 4 + 4 + 4);
data.AppendPackedTime(sWorld->GetGameTime());
data.AppendPackedTime(GameTime::GetGameTime());
data << float(0.01666667f); // game speed
data << uint32(0); // added in 3.1.2
GetSession()->SendPacket(&data);
@@ -26757,7 +26758,7 @@ void Player::ResetTimeSync()
{
m_timeSyncTimer = 0;
m_timeSyncClient = 0;
m_timeSyncServer = getMSTime();
m_timeSyncServer = GameTime::GetGameTimeMS();
}
void Player::SendTimeSync()
@@ -26770,7 +26771,7 @@ void Player::SendTimeSync()
// Schedule next sync in 10 sec
m_timeSyncTimer = 10000;
m_timeSyncServer = getMSTime();
m_timeSyncServer = GameTime::GetGameTimeMS();
if (m_timeSyncQueue.size() > 3)
TC_LOG_ERROR("network", "Not received CMSG_TIME_SYNC_RESP for over 30 seconds from player %u (%s), possible cheater", GetGUID().GetCounter(), GetName().c_str());
+1
View File
@@ -30,6 +30,7 @@
#include "CreatureGroups.h"
#include "Creature.h"
#include "Formulas.h"
#include "GameTime.h"
#include "GridNotifiersImpl.h"
#include "Group.h"
#include "InstanceSaveMgr.h"
-1
View File
@@ -226,7 +226,6 @@ bool SpellClickInfo::IsFitToRequirements(Unit const* clicker, Unit const* clicke
ObjectMgr::ObjectMgr():
_auctionId(1),
_equipmentSetGuid(1),
_itemTextId(1),
_mailId(1),
_hiPetNumber(1),
_voidItemId(1),
+2 -3
View File
@@ -1404,9 +1404,8 @@ class TC_GAME_API ObjectMgr
// first free id for selected id type
uint32 _auctionId;
uint64 _equipmentSetGuid;
uint32 _itemTextId;
uint32 _mailId;
uint32 _hiPetNumber;
std::atomic<uint32> _mailId;
std::atomic<uint32> _hiPetNumber;
uint64 _voidItemId;
uint32 _creatureSpawnId;
@@ -27,6 +27,7 @@
#include "BattlegroundMgr.h"
#include "Battleground.h"
#include "Chat.h"
#include "GameTime.h"
#include "Language.h"
#include "Log.h"
#include "Player.h"
@@ -659,7 +660,7 @@ void WorldSession::HandleBattlefieldStatusOpcode(WorldPacket & /*recvData*/)
continue;
// send status invited to Battleground
sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, GetPlayer(), i, STATUS_WAIT_JOIN, getMSTimeDiff(getMSTime(), ginfo.RemoveInviteTime), _player->GetBattlegroundQueueJoinTime(bgTypeId), arenaType);
sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, GetPlayer(), i, STATUS_WAIT_JOIN, getMSTimeDiff(GameTime::GetGameTimeMS(), ginfo.RemoveInviteTime), _player->GetBattlegroundQueueJoinTime(bgTypeId), arenaType);
SendPacket(&data);
}
else
@@ -24,6 +24,7 @@
#include "Chat.h"
#include "Common.h"
#include "DatabaseEnv.h"
#include "GameTime.h"
#include "Group.h"
#include "Guild.h"
#include "GuildFinderMgr.h"
@@ -953,7 +954,7 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder)
stmt->setUInt32(0, GetAccountId());
LoginDatabase.Execute(stmt);
pCurrChar->SetInGameTime(getMSTime());
pCurrChar->SetInGameTime(GameTime::GetGameTimeMS());
// announce group about member online (must be after add to player list to receive announce to self)
if (Group* group = pCurrChar->GetGroup())
+2 -1
View File
@@ -23,6 +23,7 @@
#include "Opcodes.h"
#include "Log.h"
#include "Player.h"
#include "GameTime.h"
#include "GossipDef.h"
#include "World.h"
#include "ObjectMgr.h"
@@ -1371,7 +1372,7 @@ void WorldSession::HandleTimeSyncResp(WorldPacket& recvData)
TC_LOG_DEBUG("network", "Time sync received: counter %u, client ticks %u, time since last sync %u", counter, clientTicks, clientTicks - _player->m_timeSyncClient);
uint32 ourTicks = clientTicks + (getMSTime() - _player->m_timeSyncServer);
uint32 ourTicks = clientTicks + (GameTime::GetGameTimeMS() - _player->m_timeSyncServer);
// diff should be small
TC_LOG_DEBUG("network", "Our ticks: %u, diff %u, latency %u", ourTicks, ourTicks - clientTicks, GetLatency());
+2 -1
View File
@@ -31,6 +31,7 @@
#include "ObjectMgr.h"
#include "MovementStructures.h"
#include "Vehicle.h"
#include "GameTime.h"
#define MOVEMENT_PACKET_TIME_DELAY 0
@@ -382,7 +383,7 @@ void WorldSession::HandleMovementOpcodes(WorldPacket& recvPacket)
plrMover->SetInWater(!plrMover->IsInWater() || plrMover->GetBaseMap()->IsUnderWater(movementInfo.pos.GetPositionX(), movementInfo.pos.GetPositionY(), movementInfo.pos.GetPositionZ()));
}
uint32 mstime = getMSTime();
uint32 mstime = GameTime::GetGameTimeMS();
/*----------------------*/
if (m_clientTimeDelay == 0)
m_clientTimeDelay = mstime - movementInfo.time;
+4 -3
View File
@@ -17,6 +17,7 @@
*/
#include "CellImpl.h"
#include "GameTime.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "GossipDef.h"
@@ -55,7 +56,7 @@ void Map::ScriptsStart(ScriptMapMap const& scripts, uint32 id, Object* source, O
sa.ownerGUID = ownerGUID;
sa.script = &iter->second;
m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(sWorld->GetGameTime() + iter->first), sa));
m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(GameTime::GetGameTime() + iter->first), sa));
if (iter->first == 0)
immedScript = true;
@@ -85,7 +86,7 @@ void Map::ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* sou
sa.ownerGUID = ownerGUID;
sa.script = &script;
m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(sWorld->GetGameTime() + delay), sa));
m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(GameTime::GetGameTime() + delay), sa));
sMapMgr->IncreaseScheduledScriptsCount();
@@ -285,7 +286,7 @@ void Map::ScriptsProcess()
///- Process overdue queued scripts
ScriptScheduleMap::iterator iter = m_scriptSchedule.begin();
// ok as multimap is a *sorted* associative container
while (!m_scriptSchedule.empty() && (iter->first <= sWorld->GetGameTime()))
while (!m_scriptSchedule.empty() && (iter->first <= GameTime::GetGameTime()))
{
ScriptAction const& step = iter->second;
+3 -2
View File
@@ -20,6 +20,7 @@
#include "DatabaseEnv.h"
#include "WorldPacket.h"
#include "WorldSession.h"
#include "GameTime.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "Opcodes.h"
@@ -2301,7 +2302,7 @@ void Spell::DoAllEffectOnTarget(TargetInfo* target)
if (unit->IsAlive() != target->alive)
return;
if (getState() == SPELL_STATE_DELAYED && !m_spellInfo->IsPositive() && (getMSTime() - target->timeDelay) <= unit->m_lastSanctuaryTime)
if (getState() == SPELL_STATE_DELAYED && !m_spellInfo->IsPositive() && (GameTime::GetGameTimeMS() - target->timeDelay) <= unit->m_lastSanctuaryTime)
return; // No missinfo in that case
// Get original caster (if exist) and calculate damage/healing from him data
@@ -4085,7 +4086,7 @@ void Spell::SendSpellGo()
data << uint32(m_spellInfo->Id); // spellId
data << uint32(castFlags); // cast flags
data << uint32(m_timer);
data << uint32(getMSTime()); // timestamp
data << uint32(GameTime::GetGameTimeMS()); // timestamp
WriteSpellGoTargets(&data);
+1 -1
View File
@@ -3730,7 +3730,7 @@ void Spell::EffectSanctuary(SpellEffIndex /*effIndex*/)
++itr;
}
unitTarget->m_lastSanctuaryTime = getMSTime();
unitTarget->m_lastSanctuaryTime = GameTime::GetGameTimeMS();
// Vanish allows to remove all threat and cast regular stealth so other spells can be used
if (m_caster->GetTypeId() == TYPEID_PLAYER
+11 -12
View File
@@ -21,7 +21,6 @@
#include "Player.h"
#include "SpellInfo.h"
#include "Spell.h"
#include "World.h"
#include "Opcodes.h"
SpellHistory::Clock::duration const SpellHistory::InfinityCooldownDelay = std::chrono::duration_cast<SpellHistory::Clock::duration>(std::chrono::seconds(MONTH));
@@ -136,7 +135,7 @@ void SpellHistory::SaveToDB(SQLTransaction& trans)
void SpellHistory::Update()
{
Clock::time_point now = Clock::now();
Clock::time_point now = GameTime::GetGameTimeSystemPoint();
for (auto itr = _categoryCooldowns.begin(); itr != _categoryCooldowns.end();)
{
if (itr->second->CategoryEnd < now)
@@ -195,7 +194,7 @@ bool SpellHistory::IsReady(SpellInfo const* spellInfo, uint32 itemId /*= 0*/, bo
template<>
void SpellHistory::WritePacket<Pet>(WorldPacket& packet) const
{
Clock::time_point now = Clock::now();
Clock::time_point now = GameTime::GetGameTimeSystemPoint();
uint8 cooldownsCount = _spellCooldowns.size();
packet << uint8(cooldownsCount);
@@ -232,7 +231,7 @@ void SpellHistory::WritePacket<Pet>(WorldPacket& packet) const
template<>
void SpellHistory::WritePacket<Player>(WorldPacket& packet) const
{
Clock::time_point now = Clock::now();
Clock::time_point now = GameTime::GetGameTimeSystemPoint();
packet << uint16(_spellCooldowns.size());
@@ -281,7 +280,7 @@ void SpellHistory::StartCooldown(SpellInfo const* spellInfo, uint32 itemId, Spel
GetCooldownDurations(spellInfo, itemId, &cooldown, &categoryId, &categoryCooldown);
Clock::time_point curTime = Clock::now();
Clock::time_point curTime = GameTime::GetGameTimeSystemPoint();
Clock::time_point catrecTime;
Clock::time_point recTime;
bool needsCooldownPacket = false;
@@ -428,7 +427,7 @@ void SpellHistory::ModifyCooldown(uint32 spellId, int32 cooldownModMs)
if (!cooldownModMs || itr == _spellCooldowns.end())
return;
Clock::time_point now = Clock::now();
Clock::time_point now = GameTime::GetGameTimeSystemPoint();
Clock::duration offset = std::chrono::duration_cast<Clock::duration>(std::chrono::milliseconds(cooldownModMs));
if (itr->second.CooldownEnd + offset > now)
itr->second.CooldownEnd += offset;
@@ -522,7 +521,7 @@ uint32 SpellHistory::GetRemainingCooldown(SpellInfo const* spellInfo) const
end = catItr->second->CategoryEnd;
}
Clock::time_point now = Clock::now();
Clock::time_point now = GameTime::GetGameTimeSystemPoint();
if (end < now)
return 0;
@@ -532,7 +531,7 @@ uint32 SpellHistory::GetRemainingCooldown(SpellInfo const* spellInfo) const
void SpellHistory::LockSpellSchool(SpellSchoolMask schoolMask, uint32 lockoutTime)
{
Clock::time_point now = Clock::now();
Clock::time_point now = GameTime::GetGameTimeSystemPoint();
Clock::time_point lockoutEnd = now + std::chrono::duration_cast<Clock::duration>(std::chrono::milliseconds(lockoutTime));
for (uint32 i = 0; i < MAX_SPELL_SCHOOL; ++i)
if (SpellSchoolMask(1 << i) & schoolMask)
@@ -589,7 +588,7 @@ void SpellHistory::LockSpellSchool(SpellSchoolMask schoolMask, uint32 lockoutTim
bool SpellHistory::IsSchoolLocked(SpellSchoolMask schoolMask) const
{
Clock::time_point now = Clock::now();
Clock::time_point now = GameTime::GetGameTimeSystemPoint();
for (uint32 i = 0; i < MAX_SPELL_SCHOOL; ++i)
if (SpellSchoolMask(1 << i) & schoolMask)
if (_schoolLockouts[i] > now)
@@ -601,12 +600,12 @@ bool SpellHistory::IsSchoolLocked(SpellSchoolMask schoolMask) const
bool SpellHistory::HasGlobalCooldown(SpellInfo const* spellInfo) const
{
auto itr = _globalCooldowns.find(spellInfo->StartRecoveryCategory);
return itr != _globalCooldowns.end() && itr->second > Clock::now();
return itr != _globalCooldowns.end() && itr->second > GameTime::GetGameTimeSystemPoint();
}
void SpellHistory::AddGlobalCooldown(SpellInfo const* spellInfo, uint32 duration)
{
_globalCooldowns[spellInfo->StartRecoveryCategory] = Clock::now() + std::chrono::duration_cast<Clock::duration>(std::chrono::milliseconds(duration));
_globalCooldowns[spellInfo->StartRecoveryCategory] = GameTime::GetGameTimeSystemPoint() + std::chrono::duration_cast<Clock::duration>(std::chrono::milliseconds(duration));
}
void SpellHistory::CancelGlobalCooldown(SpellInfo const* spellInfo)
@@ -750,7 +749,7 @@ void SpellHistory::RestoreCooldownStateAfterDuel()
for (auto const& c : _spellCooldowns)
{
Clock::time_point now = Clock::now();
Clock::time_point now = GameTime::GetGameTimeSystemPoint();
uint32 cooldownDuration = uint32(c.second.CooldownEnd > now ? std::chrono::duration_cast<std::chrono::milliseconds>(c.second.CooldownEnd - now).count() : 0);
// cooldownDuration must be between 0 and 10 minutes in order to avoid any visual bugs
+2 -2
View File
@@ -21,7 +21,7 @@
#include "SharedDefines.h"
#include "QueryResult.h"
#include "Transaction.h"
#include <chrono>
#include "GameTime.h"
#include <deque>
class Item;
@@ -75,7 +75,7 @@ public:
template<class Type, class Period>
void AddCooldown(uint32 spellId, uint32 itemId, std::chrono::duration<Type, Period> cooldownDuration)
{
Clock::time_point now = Clock::now();
Clock::time_point now = GameTime::GetGameTimeSystemPoint();
AddCooldown(spellId, itemId, now + std::chrono::duration_cast<Clock::duration>(cooldownDuration), 0, now);
}
+68
View File
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "GameTime.h"
#include "Timer.h"
namespace GameTime
{
time_t const StartTime = time(nullptr);
time_t GameTime = 0;
uint32 GameMSTime = 0;
std::chrono::system_clock::time_point GameTimeSystemPoint = std::chrono::system_clock::time_point::min();
std::chrono::steady_clock::time_point GameTimeSteadyPoint = std::chrono::steady_clock::time_point::min();
time_t GetStartTime()
{
return StartTime;
}
time_t GetGameTime()
{
return GameTime;
}
uint32 GetGameTimeMS()
{
return GameMSTime;
}
std::chrono::system_clock::time_point GetGameTimeSystemPoint()
{
return GameTimeSystemPoint;
}
std::chrono::steady_clock::time_point GetGameTimeSteadyPoint()
{
return GameTimeSteadyPoint;
}
uint32 GetUptime()
{
return uint32(GameTime - StartTime);
}
void UpdateGameTimers()
{
GameTime = time(nullptr);
GameMSTime = getMSTime();
GameTimeSystemPoint = std::chrono::system_clock::now();
GameTimeSteadyPoint = std::chrono::steady_clock::now();
}
}
+48
View File
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GAMETIME_H
#define __GAMETIME_H
#include "Define.h"
#include <chrono>
namespace GameTime
{
// Server start time
TC_GAME_API time_t GetStartTime();
// Current server time (unix) in seconds
TC_GAME_API time_t GetGameTime();
// Milliseconds since server start
TC_GAME_API uint32 GetGameTimeMS();
/// Current chrono system_clock time point
TC_GAME_API std::chrono::system_clock::time_point GetGameTimeSystemPoint();
/// Current chrono steady_clock time point
TC_GAME_API std::chrono::steady_clock::time_point GetGameTimeSteadyPoint();
/// Uptime (in secs)
TC_GAME_API uint32 GetUptime();
void UpdateGameTimers();
};
#endif
+135
View File
@@ -0,0 +1,135 @@
/*
* Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "UpdateTime.h"
#include "Timer.h"
#include "Config.h"
#include "Log.h"
// create instance
WorldUpdateTime sWorldUpdateTime;
UpdateTime::UpdateTime()
{
_averageUpdateTime = 0;
_totalUpdateTime = 0;
_updateTimeTableIndex = 0;
_maxUpdateTime = 0;
_maxUpdateTimeOfLastTable = 0;
_maxUpdateTimeOfCurrentTable = 0;
_updateTimeDataTable = { };
}
uint32 UpdateTime::GetAverageUpdateTime() const
{
return _averageUpdateTime;
}
uint32 UpdateTime::GetTimeWeightedAverageUpdateTime() const
{
uint32 sum = 0, weightsum = 0;
for (uint32 diff : _updateTimeDataTable)
{
sum += diff * diff;
weightsum += diff;
}
return sum / weightsum;
}
uint32 UpdateTime::GetMaxUpdateTime() const
{
return _maxUpdateTime;
}
uint32 UpdateTime::GetMaxUpdateTimeOfCurrentTable() const
{
return std::max(_maxUpdateTimeOfCurrentTable, _maxUpdateTimeOfLastTable);
}
uint32 UpdateTime::GetLastUpdateTime() const
{
return _updateTimeDataTable[_updateTimeTableIndex != 0 ? _updateTimeTableIndex - 1 : _updateTimeDataTable.size() - 1];
}
void UpdateTime::UpdateWithDiff(uint32 diff)
{
_totalUpdateTime = _totalUpdateTime - _updateTimeDataTable[_updateTimeTableIndex] + diff;
_updateTimeDataTable[_updateTimeTableIndex] = diff;
if (diff > _maxUpdateTime)
_maxUpdateTime = diff;
if (diff > _maxUpdateTimeOfCurrentTable)
_maxUpdateTimeOfCurrentTable = diff;
if (++_updateTimeTableIndex >= _updateTimeDataTable.size())
{
_updateTimeTableIndex = 0;
_maxUpdateTimeOfLastTable = _maxUpdateTimeOfCurrentTable;
_maxUpdateTimeOfCurrentTable = 0;
}
if (_updateTimeDataTable[_updateTimeDataTable.size() - 1])
_averageUpdateTime = _totalUpdateTime / _updateTimeDataTable.size();
else if (_updateTimeTableIndex)
_averageUpdateTime = _totalUpdateTime / _updateTimeTableIndex;
}
void UpdateTime::RecordUpdateTimeReset()
{
_recordedTime = getMSTime();
}
void UpdateTime::_RecordUpdateTimeDuration(std::string const& text, uint32 minUpdateTime)
{
uint32 thisTime = getMSTime();
uint32 diff = getMSTimeDiff(_recordedTime, thisTime);
if (diff > minUpdateTime)
TC_LOG_INFO("misc", "Recored Update Time of %s: %u.", text.c_str(), diff);
_recordedTime = thisTime;
}
void WorldUpdateTime::LoadFromConfig()
{
_recordUpdateTimeInverval = sConfigMgr->GetIntDefault("RecordUpdateTimeDiffInterval", 60000);
_recordUpdateTimeMin = sConfigMgr->GetIntDefault("MinRecordUpdateTimeDiff", 100);
}
void WorldUpdateTime::SetRecordUpdateTimeInterval(uint32 t)
{
_recordUpdateTimeInverval = t;
}
void WorldUpdateTime::RecordUpdateTime(uint32 gameTimeMs, uint32 diff, uint32 sessionCount)
{
if (_recordUpdateTimeInverval > 0 && diff > _recordUpdateTimeMin)
{
if (getMSTimeDiff(_lastRecordTime, gameTimeMs) > _recordUpdateTimeInverval)
{
TC_LOG_DEBUG("misc", "Update time diff: %u. Players online: %u.", GetAverageUpdateTime(), sessionCount);
_lastRecordTime = gameTimeMs;
}
}
}
void WorldUpdateTime::RecordUpdateTimeDuration(std::string const& text)
{
_RecordUpdateTimeDuration(text, _recordUpdateTimeMin);
}
+74
View File
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __UPDATETIME_H
#define __UPDATETIME_H
#include "Define.h"
#define AVG_DIFF_COUNT 500
class TC_GAME_API UpdateTime
{
using DiffTableArray = std::array<uint32, AVG_DIFF_COUNT>;
public:
uint32 GetAverageUpdateTime() const;
uint32 GetTimeWeightedAverageUpdateTime() const;
uint32 GetMaxUpdateTime() const;
uint32 GetMaxUpdateTimeOfCurrentTable() const;
uint32 GetLastUpdateTime() const;
void UpdateWithDiff(uint32 diff);
void RecordUpdateTimeReset();
protected:
UpdateTime();
void _RecordUpdateTimeDuration(std::string const& text, uint32 minUpdateTime);
private:
DiffTableArray _updateTimeDataTable;
uint32 _averageUpdateTime;
uint32 _totalUpdateTime;
uint32 _updateTimeTableIndex;
uint32 _maxUpdateTime;
uint32 _maxUpdateTimeOfLastTable;
uint32 _maxUpdateTimeOfCurrentTable;
uint32 _recordedTime;
};
class TC_GAME_API WorldUpdateTime : public UpdateTime
{
public:
WorldUpdateTime() : UpdateTime(), _recordUpdateTimeInverval(0), _recordUpdateTimeMin(0), _lastRecordTime(0) { }
void LoadFromConfig();
void SetRecordUpdateTimeInterval(uint32 t);
void RecordUpdateTime(uint32 gameTimeMs, uint32 diff, uint32 sessionCount);
void RecordUpdateTimeDuration(std::string const& text);
private:
uint32 _recordUpdateTimeInverval;
uint32 _recordUpdateTimeMin;
uint32 _lastRecordTime;
};
TC_GAME_API extern WorldUpdateTime sWorldUpdateTime;
#endif
+2 -2
View File
@@ -22,7 +22,7 @@
#include "Log.h"
#include "Opcodes.h"
#include "ByteBuffer.h"
#include "World.h"
#include "GameTime.h"
#include "Util.h"
#include "Warden.h"
#include "AccountMgr.h"
@@ -95,7 +95,7 @@ void Warden::Update()
{
if (_initialized)
{
uint32 currentTimestamp = getMSTime();
uint32 currentTimestamp = GameTime::GetGameTimeMS();
uint32 diff = currentTimestamp - _previousTimestamp;
_previousTimestamp = currentTimestamp;
+2 -2
View File
@@ -23,7 +23,7 @@
#include "Log.h"
#include "Opcodes.h"
#include "ByteBuffer.h"
#include "World.h"
#include "GameTime.h"
#include "Player.h"
#include "Util.h"
#include "WardenMac.h"
@@ -185,7 +185,7 @@ void WardenMac::HandleHashResult(ByteBuffer &buff)
_initialized = true;
_previousTimestamp = getMSTime();
_previousTimestamp = GameTime::GetGameTimeMS();
}
void WardenMac::RequestData()
+4 -4
View File
@@ -25,7 +25,7 @@
#include "Opcodes.h"
#include "ByteBuffer.h"
#include "Database/DatabaseEnv.h"
#include "World.h"
#include "GameTime.h"
#include "Player.h"
#include "Util.h"
#include "WardenWin.h"
@@ -166,7 +166,7 @@ void WardenWin::HandleHashResult(ByteBuffer &buff)
_initialized = true;
_previousTimestamp = getMSTime();
_previousTimestamp = GameTime::GetGameTimeMS();
}
void WardenWin::RequestData()
@@ -180,7 +180,7 @@ void WardenWin::RequestData()
if (_otherChecksTodo.empty())
_otherChecksTodo.assign(sWardenCheckMgr->OtherChecksIdPool.begin(), sWardenCheckMgr->OtherChecksIdPool.end());
_serverTicks = getMSTime();
_serverTicks = GameTime::GetGameTimeMS();
uint16 id;
uint8 type;
@@ -354,7 +354,7 @@ void WardenWin::HandleData(ByteBuffer &buff)
uint32 newClientTicks;
buff >> newClientTicks;
uint32 ticksNow = getMSTime();
uint32 ticksNow = GameTime::GetGameTimeMS();
uint32 ourTicks = newClientTicks + (ticksNow - _serverTicks);
TC_LOG_DEBUG("warden", "ServerTicks %u", ticksNow); // Now
+2 -2
View File
@@ -23,7 +23,7 @@
#include "Weather.h"
#include "WorldPacket.h"
#include "Player.h"
#include "World.h"
#include "GameTime.h"
#include "Log.h"
#include "Util.h"
#include "ScriptMgr.h"
@@ -92,7 +92,7 @@ bool Weather::ReGenerate()
//78 days between January 1st and March 20nd; 365/4=91 days by season
// season source http://aa.usno.navy.mil/data/docs/EarthSeasons.html
time_t gtime = sWorld->GetGameTime();
time_t gtime = GameTime::GetGameTime();
struct tm ltime;
localtime_r(&gtime, &ltime);
uint32 season = ((ltime.tm_yday - 78 + 365)/91)%4;
+38 -72
View File
@@ -69,6 +69,8 @@
#include "WorldSession.h"
#include "M2Stores.h"
#include "WhoListStorage.h"
#include "GameTime.h"
#include "UpdateTime.h"
TC_GAME_API std::atomic<bool> World::m_stopEvent(false);
TC_GAME_API uint8 World::m_ExitCode = SHUTDOWN_EXIT_CODE;
@@ -91,8 +93,7 @@ World::World()
m_allowMovement = true;
m_ShutdownMask = 0;
m_ShutdownTimer = 0;
m_gameTime = time(NULL);
m_startTime = m_gameTime;
m_maxActiveSessionCount = 0;
m_maxQueuedSessionCount = 0;
m_PlayerCount = 0;
@@ -109,10 +110,6 @@ World::World()
mail_timer = 0;
mail_timer_expires = 0;
m_updateTime = 0;
m_updateTimeSum = 0;
m_updateTimeCount = 0;
m_currentTime = 0;
m_isClosed = false;
@@ -411,6 +408,9 @@ void World::LoadConfigSettings(bool reload)
TC_LOG_INFO("server.loading", "Using %s DBC Locale", localeNames[m_defaultDbcLocale]);
// load update time related configs
sWorldUpdateTime.LoadFromConfig();
///- Read the player limit and the Message of the day from the config file
SetPlayerAmountLimit(sConfigMgr->GetIntDefault("PlayerLimit", 100));
SetMotd(sConfigMgr->GetStringDefault("Motd", "Welcome to a Trinity Core Server."));
@@ -1281,8 +1281,6 @@ void World::LoadConfigSettings(bool reload)
m_bool_configs[CONFIG_SHOW_KICK_IN_WORLD] = sConfigMgr->GetBoolDefault("ShowKickInWorld", false);
m_bool_configs[CONFIG_SHOW_MUTE_IN_WORLD] = sConfigMgr->GetBoolDefault("ShowMuteInWorld", false);
m_bool_configs[CONFIG_SHOW_BAN_IN_WORLD] = sConfigMgr->GetBoolDefault("ShowBanInWorld", false);
m_int_configs[CONFIG_INTERVAL_LOG_UPDATE] = sConfigMgr->GetIntDefault("RecordUpdateTimeDiffInterval", 60000);
m_int_configs[CONFIG_MIN_LOG_UPDATE] = sConfigMgr->GetIntDefault("MinRecordUpdateTimeDiff", 100);
m_int_configs[CONFIG_NUMTHREADS] = sConfigMgr->GetIntDefault("MapUpdate.Threads", 1);
m_int_configs[CONFIG_MAX_RESULTS_LOOKUP_COMMANDS] = sConfigMgr->GetIntDefault("Command.LookupMaxResults", 0);
@@ -1930,11 +1928,10 @@ void World::SetInitialWorldSettings()
///- Initialize game time and timers
TC_LOG_INFO("server.loading", "Initialize game time and timers");
m_gameTime = time(NULL);
m_startTime = m_gameTime;
GameTime::UpdateGameTimers();
LoginDatabase.PExecute("INSERT INTO uptime (realmid, starttime, uptime, revision) VALUES(%u, %u, 0, '%s')",
realm.Id.Realm, uint32(m_startTime), GitRevision::GetFullVersion()); // One-time query
realm.Id.Realm, uint32(GameTime::GetStartTime()), GitRevision::GetFullVersion()); // One-time query
m_timers[WUPDATE_WEATHERS].SetInterval(1*IN_MILLISECONDS);
m_timers[WUPDATE_AUCTIONS].SetInterval(MINUTE*IN_MILLISECONDS);
@@ -1964,7 +1961,8 @@ void World::SetInitialWorldSettings()
//one second is 1000 -(tested on win system)
/// @todo Get rid of magic numbers
tm localTm;
localtime_r(&m_gameTime, &localTm);
time_t gameTime = GameTime::GetGameTime();
localtime_r(&gameTime, &localTm);
mail_timer = ((((localTm.tm_hour + 20) % 24)* HOUR * IN_MILLISECONDS) / m_timers[WUPDATE_AUCTIONS].GetInterval());
//1440
mail_timer_expires = ((DAY * IN_MILLISECONDS) / (m_timers[WUPDATE_AUCTIONS].GetInterval()));
@@ -2068,28 +2066,6 @@ void World::SetInitialWorldSettings()
sLog->SetRealmId(realmId);
}
void World::ResetTimeDiffRecord()
{
if (m_updateTimeCount != 1)
return;
m_currentTime = getMSTime();
}
void World::RecordTimeDiff(std::string const& text)
{
if (m_updateTimeCount != 1)
return;
uint32 thisTime = getMSTime();
uint32 diff = getMSTimeDiff(m_currentTime, thisTime);
if (diff > m_int_configs[CONFIG_MIN_LOG_UPDATE])
TC_LOG_INFO("misc", "Difftime %s: %u.", text.c_str(), diff);
m_currentTime = thisTime;
}
void World::LoadAutobroadcasts()
{
uint32 oldMSTime = getMSTime();
@@ -2127,22 +2103,14 @@ void World::LoadAutobroadcasts()
/// Update the World !
void World::Update(uint32 diff)
{
m_updateTime = diff;
///- Update the game time and check for shutdown time
_UpdateGameTime();
time_t currentGameTime = GameTime::GetGameTime();
if (m_int_configs[CONFIG_INTERVAL_LOG_UPDATE] && diff > m_int_configs[CONFIG_MIN_LOG_UPDATE])
{
if (m_updateTimeSum > m_int_configs[CONFIG_INTERVAL_LOG_UPDATE])
{
TC_LOG_DEBUG("misc", "Update time diff: %u. Players online: %u.", m_updateTimeSum / m_updateTimeCount, GetActiveSessionCount());
m_updateTimeSum = m_updateTime;
m_updateTimeCount = 1;
}
else
{
m_updateTimeSum += m_updateTime;
++m_updateTimeCount;
}
}
sWorldUpdateTime.UpdateWithDiff(diff);
// Record update if recording set in log and diff is greater then minimum set in log
sWorldUpdateTime.RecordUpdateTime(GameTime::GetGameTimeMS(), diff, GetActiveSessionCount());
///- Update the different timers
for (int i = 0; i < WUPDATE_COUNT; ++i)
@@ -2160,31 +2128,28 @@ void World::Update(uint32 diff)
sWhoListStorageMgr->Update();
}
///- Update the game time and check for shutdown time
_UpdateGameTime();
/// Handle daily quests reset time
if (m_gameTime > m_NextDailyQuestReset)
if (currentGameTime > m_NextDailyQuestReset)
{
ResetDailyQuests();
InitDailyQuestResetTime(false);
}
/// Handle weekly quests reset time
if (m_gameTime > m_NextWeeklyQuestReset)
if (currentGameTime > m_NextWeeklyQuestReset)
ResetWeeklyQuests();
/// Handle monthly quests reset time
if (m_gameTime > m_NextMonthlyQuestReset)
if (currentGameTime > m_NextMonthlyQuestReset)
ResetMonthlyQuests();
if (m_gameTime > m_NextRandomBGReset)
if (currentGameTime > m_NextRandomBGReset)
ResetRandomBG();
if (m_gameTime > m_NextGuildReset)
if (currentGameTime > m_NextGuildReset)
ResetGuildCap();
if (m_gameTime > m_NextCurrencyReset)
if (currentGameTime > m_NextCurrencyReset)
ResetCurrencyWeekCap();
/// <ul><li> Handle auctions when the timer has passed
@@ -2226,9 +2191,9 @@ void World::Update(uint32 diff)
}
/// <li> Handle session updates when the timer has passed
ResetTimeDiffRecord();
sWorldUpdateTime.RecordUpdateTimeReset();
UpdateSessions(diff);
RecordTimeDiff("UpdateSessions");
sWorldUpdateTime.RecordUpdateTimeDuration("UpdateSessions");
/// <li> Handle weather updates when the timer has passed
if (m_timers[WUPDATE_WEATHERS].Passed())
@@ -2240,7 +2205,7 @@ void World::Update(uint32 diff)
/// <li> Update uptime table
if (m_timers[WUPDATE_UPTIME].Passed())
{
uint32 tmpDiff = uint32(m_gameTime - m_startTime);
uint32 tmpDiff = GameTime::GetUptime();
uint32 maxOnlinePlayers = GetMaxPlayerCount();
m_timers[WUPDATE_UPTIME].Reset();
@@ -2250,7 +2215,7 @@ void World::Update(uint32 diff)
stmt->setUInt32(0, tmpDiff);
stmt->setUInt16(1, uint16(maxOnlinePlayers));
stmt->setUInt32(2, realm.Id.Realm);
stmt->setUInt32(3, uint32(m_startTime));
stmt->setUInt32(3, uint32(GameTime::GetStartTime()));
LoginDatabase.Execute(stmt);
}
@@ -2274,9 +2239,9 @@ void World::Update(uint32 diff)
/// <li> Handle all other objects
///- Update objects when the timer has passed (maps, transport, creatures, ...)
ResetTimeDiffRecord();
sWorldUpdateTime.RecordUpdateTimeReset();();
sMapMgr->Update(diff);
RecordTimeDiff("UpdateMapMgr");
sWorldUpdateTime.RecordUpdateTimeDuration("UpdateMapMgr");
if (sWorld->getBoolConfig(CONFIG_AUTOBROADCAST))
{
@@ -2288,13 +2253,13 @@ void World::Update(uint32 diff)
}
sBattlegroundMgr->Update(diff);
RecordTimeDiff("UpdateBattlegroundMgr");
sWorldUpdateTime.RecordUpdateTimeDuration("UpdateBattlegroundMgr");
sOutdoorPvPMgr->Update(diff);
RecordTimeDiff("UpdateOutdoorPvPMgr");
sWorldUpdateTime.RecordUpdateTimeDuration("UpdateOutdoorPvPMgr");
sBattlefieldMgr->Update(diff);
RecordTimeDiff("BattlefieldMgr");
sWorldUpdateTime.RecordUpdateTimeDuration("BattlefieldMgr");
///- Delete all characters which have been deleted X days before
if (m_timers[WUPDATE_DELETECHARS].Passed())
@@ -2304,11 +2269,11 @@ void World::Update(uint32 diff)
}
sLFGMgr->Update(diff);
RecordTimeDiff("UpdateLFGMgr");
sWorldUpdateTime.RecordUpdateTimeDuration("UpdateLFGMgr");
// execute callbacks from sql queries that were queued recently
ProcessQueryCallbacks();
RecordTimeDiff("ProcessQueryCallbacks");
sWorldUpdateTime.RecordUpdateTimeDuration("ProcessQueryCallbacks");
///- Erase corpses once every 20 minutes
if (m_timers[WUPDATE_CORPSES].Passed())
@@ -2736,9 +2701,10 @@ bool World::RemoveBanCharacter(std::string const& name)
void World::_UpdateGameTime()
{
///- update the time
time_t thisTime = time(NULL);
uint32 elapsed = uint32(thisTime - m_gameTime);
m_gameTime = thisTime;
time_t lastGameTime = GameTime::GetGameTime();
GameTime::UpdateGameTimers();
uint32 elapsed = uint32(GameTime::GetGameTime() - lastGameTime);
///- if there is a shutdown timer
if (!IsStopped() && m_ShutdownTimer > 0 && elapsed > 0)
+1 -20
View File
@@ -328,8 +328,6 @@ enum WorldIntConfigs
CONFIG_PVP_TOKEN_MAP_TYPE,
CONFIG_PVP_TOKEN_ID,
CONFIG_PVP_TOKEN_COUNT,
CONFIG_INTERVAL_LOG_UPDATE,
CONFIG_MIN_LOG_UPDATE,
CONFIG_ENABLE_SINFO_LOGIN,
CONFIG_PLAYER_ALLOW_COMMANDS,
CONFIG_NUMTHREADS,
@@ -659,16 +657,6 @@ class TC_GAME_API World
/// Get the path where data (dbc, maps) are stored on disk
std::string const& GetDataPath() const { return m_dataPath; }
/// When server started?
time_t const& GetStartTime() const { return m_startTime; }
/// What time is it?
time_t const& GetGameTime() const { return m_gameTime; }
/// Uptime (in secs)
uint32 GetUptime() const { return uint32(m_gameTime - m_startTime); }
/// Update time
uint32 GetUpdateTime() const { return m_updateTime; }
void SetRecordDiffInterval(int32 t) { if (t >= 0) m_int_configs[CONFIG_INTERVAL_LOG_UPDATE] = (uint32)t; }
/// Next daily quests and random bg reset time
time_t GetNextDailyQuestsResetTime() const { return m_NextDailyQuestReset; }
time_t GetNextWeeklyQuestsResetTime() const { return m_NextWeeklyQuestReset; }
@@ -788,9 +776,6 @@ class TC_GAME_API World
void LoadDBVersion();
char const* GetDBVersion() const { return m_DBVersion.c_str(); }
void ResetTimeDiffRecord();
void RecordTimeDiff(std::string const& text);
void LoadAutobroadcasts();
void UpdateAreaDependentAuras();
@@ -817,6 +802,7 @@ class TC_GAME_API World
protected:
void _UpdateGameTime();
// callback for UpdateRealmCharacters
void _UpdateRealmCharCount(PreparedQueryResult resultCharCount);
@@ -845,14 +831,9 @@ class TC_GAME_API World
bool m_isClosed;
time_t m_startTime;
time_t m_gameTime;
IntervalTimer m_timers[WUPDATE_COUNT];
time_t mail_timer;
time_t mail_timer_expires;
uint32 m_updateTime, m_updateTimeSum;
uint32 m_updateTimeCount;
uint32 m_currentTime;
SessionMap m_sessions;
typedef std::unordered_map<uint32, time_t> DisconnectMap;
+5 -3
View File
@@ -30,6 +30,8 @@ EndScriptData */
#include "ScriptMgr.h"
#include "GitRevision.h"
#include "Util.h"
#include "GameTime.h"
#include "UpdateTime.h"
class server_commandscript : public CommandScript
{
@@ -108,8 +110,8 @@ public:
uint32 queuedClientsNum = sWorld->GetQueuedSessionCount();
uint32 maxActiveClientsNum = sWorld->GetMaxActiveSessionCount();
uint32 maxQueuedClientsNum = sWorld->GetMaxQueuedSessionCount();
std::string uptime = secsToTimeString(sWorld->GetUptime());
uint32 updateTime = sWorld->GetUpdateTime();
std::string uptime = secsToTimeString(GameTime::GetUptime());
uint32 updateTime = sWorldUpdateTime.GetLastUpdateTime();
handler->SendSysMessage(GitRevision::GetFullVersion());
handler->PSendSysMessage(LANG_CONNECTED_PLAYERS, playersNum, maxPlayersNum);
@@ -304,7 +306,7 @@ public:
if (newTime < 0)
return false;
sWorld->SetRecordDiffInterval(newTime);
sWorldUpdateTime.SetRecordUpdateTimeInterval(newTime);
printf("Record diff every %i ms\n", newTime);
return true;
+2 -1
View File
@@ -19,6 +19,7 @@
#include "GameObjectAI.h"
#include "CreatureAIImpl.h"
#include "GameEventMgr.h"
#include "GameTime.h"
enum FireworksShowTypeObjects
{
@@ -792,7 +793,7 @@ public:
{
_events.Update(diff);
time_t time = sWorld->GetGameTime();
time_t time = GameTime::GetGameTime();
tm localTm;
localtime_r(&time, &localTm);
@@ -1836,7 +1836,7 @@ class spell_icc_sprit_alarm : public SpellScriptLoader
}
if (GameObject* trap = GetCaster()->FindNearestGameObject(trapId, 5.0f))
trap->SetRespawnTime(trap->GetGOInfo()->GetAutoCloseTime());
trap->SetRespawnTime(trap->GetGOInfo()->GetAutoCloseTime() / IN_MILLISECONDS);
std::list<Creature*> wards;
GetCaster()->GetCreatureListWithEntryInGrid(wards, NPC_DEATHBOUND_WARD, 150.0f);
@@ -16,6 +16,7 @@
*/
#include "Player.h"
#include "GameTime.h"
#include "ScriptMgr.h"
#include "ScriptedCreature.h"
#include "SpellScript.h"
@@ -327,7 +328,7 @@ struct boss_four_horsemen_baseAI : public BossAI
}
Talk(SAY_DEATH);
_timeDied = getMSTime();
_timeDied = GameTime::GetGameTimeMS();
for (Horseman boss : horsemen)
{
if (Creature* cBoss = getHorsemanHandle(boss))
@@ -17,6 +17,7 @@
*/
#include "GameEventMgr.h"
#include "GameTime.h"
#include "ScriptMgr.h"
#include "ScriptedCreature.h"
#include "nexus.h"
@@ -167,7 +168,7 @@ public:
while (time[i] != 0)
++i;
time[i] = sWorld->GetGameTime();
time[i] = GameTime::GetGameTime();
if (i == 2 && (time[2] - time[1] < 5) && (time[1] - time[0] < 5))
++splitPersonality;
}
@@ -15,6 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "GameTime.h"
#include "ScriptMgr.h"
#include "ScriptedCreature.h"
#include "SpellScript.h"
@@ -194,7 +195,7 @@ class boss_ignis : public CreatureScript
me->RemoveAuraFromStack(SPELL_STRENGHT);
// Shattered Achievement
time_t secondKill = sWorld->GetGameTime();
time_t secondKill = GameTime::GetGameTime();
if ((secondKill - _firstConstructKill) < 5)
_shattered = true;
_firstConstructKill = secondKill;
+3 -2
View File
@@ -23,6 +23,7 @@
*/
#include "ScriptMgr.h"
#include "GameTime.h"
#include "Battleground.h"
#include "Cell.h"
#include "CellImpl.h"
@@ -3199,7 +3200,7 @@ class spell_gen_turkey_marker : public SpellScriptLoader
void OnApply(AuraEffect const* aurEff, AuraEffectHandleModes /*mode*/)
{
// store stack apply times, so we can pop them while they expire
_applyTimes.push_back(getMSTime());
_applyTimes.push_back(GameTime::GetGameTimeMS());
Unit* target = GetTarget();
// on stack 15 cast the achievement crediting spell
@@ -3213,7 +3214,7 @@ class spell_gen_turkey_marker : public SpellScriptLoader
return;
// pop stack if it expired for us
if (_applyTimes.front() + GetMaxDuration() < getMSTime())
if (_applyTimes.front() + GetMaxDuration() < GameTime::GetGameTimeMS())
ModStackAmount(-1, AURA_REMOVE_BY_EXPIRE);
}
@@ -35,6 +35,7 @@ at_brewfest
at_area_52_entrance
EndContentData */
#include "GameTime.h"
#include "ScriptMgr.h"
#include "ScriptedCreature.h"
#include "Player.h"
@@ -314,7 +315,7 @@ class AreaTrigger_at_brewfest : public AreaTriggerScript
{
uint32 triggerId = trigger->id;
// Second trigger happened too early after first, skip for now
if (sWorld->GetGameTime() - _triggerTimes[triggerId] < AREATRIGGER_TALK_COOLDOWN)
if (GameTime::GetGameTime() - _triggerTimes[triggerId] < AREATRIGGER_TALK_COOLDOWN)
return false;
switch (triggerId)
@@ -331,7 +332,7 @@ class AreaTrigger_at_brewfest : public AreaTriggerScript
break;
}
_triggerTimes[triggerId] = sWorld->GetGameTime();
_triggerTimes[triggerId] = GameTime::GetGameTime();
return false;
}
@@ -371,7 +372,7 @@ class AreaTrigger_at_area_52_entrance : public AreaTriggerScript
return false;
uint32 triggerId = trigger->id;
if (sWorld->GetGameTime() - _triggerTimes[trigger->id] < SUMMON_COOLDOWN)
if (GameTime::GetGameTime() - _triggerTimes[trigger->id] < SUMMON_COOLDOWN)
return false;
switch (triggerId)
@@ -400,7 +401,7 @@ class AreaTrigger_at_area_52_entrance : public AreaTriggerScript
player->SummonCreature(NPC_SPOTLIGHT, x, y, z, 0.0f, TEMPSUMMON_TIMED_DESPAWN, 5000);
player->AddAura(SPELL_A52_NEURALYZER, player);
_triggerTimes[trigger->id] = sWorld->GetGameTime();
_triggerTimes[trigger->id] = GameTime::GetGameTime();
return false;
}
+2 -1
View File
@@ -15,6 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "GameTime.h"
#include "ScriptMgr.h"
#include "Player.h"
#include "Pet.h"
@@ -103,7 +104,7 @@ class DuelResetScript : public PlayerScript
// remove cooldowns on spells that have < 10 min CD > 30 sec and has no onHold
player->GetSpellHistory()->ResetCooldowns([](SpellHistory::CooldownStorageType::iterator itr) -> bool
{
SpellHistory::Clock::time_point now = SpellHistory::Clock::now();
SpellHistory::Clock::time_point now = GameTime::GetGameTimeSystemPoint();
uint32 cooldownDuration = itr->second.CooldownEnd > now ? std::chrono::duration_cast<std::chrono::milliseconds>(itr->second.CooldownEnd - now).count() : 0;
SpellInfo const* spellInfo = sSpellMgr->AssertSpellInfo(itr->first);
return spellInfo->RecoveryTime < 10 * MINUTE * IN_MILLISECONDS
+2 -1
View File
@@ -53,6 +53,7 @@ EndContentData */
#include "Player.h"
#include "WorldSession.h"
#include "GameEventMgr.h"
#include "GameTime.h"
/*######
## go_cat_figurine
@@ -1573,7 +1574,7 @@ public:
{
if (eventId == GAME_EVENT_HOURLY_BELLS && start)
{
time_t time = sWorld->GetGameTime();
time_t time = GameTime::GetGameTime();
tm localTm;
localtime_r(&time, &localTm);
uint8 _rings = (localTm.tm_hour - 1) % 12 + 1;