feat(core): Ensure that all actions are compared to fixed point in time (#1236) (#1458)

i.e. world update start
This commit is contained in:
Viste(Кирилл)
2019-02-14 21:22:17 +03:00
committed by Francesco Borzì
parent 1b7522ff0e
commit 51b8773528
108 changed files with 933 additions and 509 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);

View File

@@ -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());

View File

@@ -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);

View File

@@ -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;