feat(Core/Time): Implement saparated manager for game time (#8630)

This commit is contained in:
Kargatum
2022-01-24 17:55:00 +07:00
committed by GitHub
parent 12da792a90
commit 8b7df23f06
129 changed files with 1147 additions and 817 deletions

View File

@@ -26,6 +26,7 @@ EndScriptData */
#include "BanMgr.h"
#include "CharacterCache.h"
#include "Chat.h"
#include "GameTime.h"
#include "Language.h"
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
@@ -305,7 +306,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().count()))
active = true;
bool permanent = (fields[1].GetUInt64() == uint64(0));
std::string banTime = permanent ? handler->GetAcoreString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].GetUInt64(), true);
@@ -353,7 +354,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().count()))
active = true;
bool permanent = (fields[1].GetUInt32() == uint32(0));
std::string banTime = permanent ? handler->GetAcoreString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].GetUInt64(), true);

View File

@@ -24,6 +24,7 @@
#include "Chat.h"
#include "GameEventMgr.h"
#include "GameTime.h"
#include "Language.h"
#include "Player.h"
#include "ScriptMgr.h"
@@ -116,8 +117,8 @@ public:
std::string endTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.end));
uint32 delay = sGameEventMgr->NextCheck(eventId);
time_t nextTime = time(nullptr) + delay;
std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? Acore::Time::TimeToTimestampStr(Seconds(time(nullptr) + delay)) : "-";
time_t nextTime = GameTime::GetGameTime().count() + delay;
std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? Acore::Time::TimeToTimestampStr(Seconds(nextTime)) : "-";
std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE, true);
std::string lengthStr = secsToTimeString(eventData.length * MINUTE, true);

View File

@@ -25,6 +25,7 @@ EndScriptData */
#include "Chat.h"
#include "GameEventMgr.h"
#include "GameObject.h"
#include "GameTime.h"
#include "Language.h"
#include "MapMgr.h"
#include "ObjectMgr.h"
@@ -280,7 +281,7 @@ public:
if (target)
{
int32 curRespawnDelay = int32(target->GetRespawnTimeEx() - time(nullptr));
int32 curRespawnDelay = int32(target->GetRespawnTimeEx() - GameTime::GetGameTime().count());
if (curRespawnDelay < 0)
curRespawnDelay = 0;

View File

@@ -23,6 +23,7 @@
EndScriptData */
#include "Chat.h"
#include "GameTime.h"
#include "Group.h"
#include "InstanceSaveMgr.h"
#include "InstanceScript.h"
@@ -73,7 +74,7 @@ public:
{
InstanceSave const* save = bind.save;
uint32 resetTime = bind.extended ? save->GetExtendedResetTime() : save->GetResetTime();
uint32 ttr = (resetTime >= time(nullptr) ? resetTime - time(nullptr) : 0);
uint32 ttr = (resetTime >= GameTime::GetGameTime().count() ? resetTime - GameTime::GetGameTime().count() : 0);
std::string timeleft = secsToTimeString(ttr);
handler->PSendSysMessage("map: %d, inst: %d, perm: %s, diff: %d, canReset: %s, TTR: %s%s",
mapId, save->GetInstanceId(), bind.perm ? "yes" : "no", save->GetDifficulty(), save->CanReset() ? "yes" : "no", timeleft.c_str(), (bind.extended ? " (extended)" : ""));
@@ -111,7 +112,7 @@ public:
if (itr->first != player->GetMapId() && (!mapId || mapId == itr->first) && (!difficultyArg || difficultyArg == 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().count() ? resetTime - GameTime::GetGameTime().count() : 0);
std::string timeleft = secsToTimeString(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->GetGUID(), itr->first, Difficulty(i), true, player);

View File

@@ -22,6 +22,7 @@
#include "CharacterCache.h"
#include "Chat.h"
#include "GameGraveyard.h"
#include "GameTime.h"
#include "GridNotifiers.h"
#include "Group.h"
#include "GuildMgr.h"
@@ -2131,13 +2132,13 @@ 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->GetAcoreString(LANG_PERMANENTLY), bannedBy.c_str());
handler->PSendSysMessage(LANG_PINFO_BANNED, banType.c_str(), banReason.c_str(), banTime > 0 ? secsToTimeString(banTime - GameTime::GetGameTime().count(), true).c_str() : handler->GetAcoreString(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().count(), true).c_str(), muteBy.c_str());
}
// Output V. LANG_PINFO_ACC_ACCOUNT
@@ -2409,7 +2410,7 @@ public:
if (target)
{
// Target is online, mute will be in effect right away.
int64 muteTime = time(nullptr) + notSpeakTime * MINUTE;
int64 muteTime = GameTime::GetGameTime().count() + notSpeakTime * MINUTE;
target->GetSession()->m_muteTime = muteTime;
stmt->setInt64(0, muteTime);
std::string nameLink = handler->playerLink(player->GetName());

View File

@@ -25,6 +25,7 @@ EndScriptData */
#include "Chat.h"
#include "CreatureAI.h"
#include "CreatureGroups.h"
#include "GameTime.h"
#include "Language.h"
#include "ObjectMgr.h"
#include "Pet.h"
@@ -605,7 +606,7 @@ public:
id3 = cData->id3;
}
int64 curRespawnDelay = target->GetRespawnTimeEx() - time(nullptr);
int64 curRespawnDelay = target->GetRespawnTimeEx() - GameTime::GetGameTime().count();
if (curRespawnDelay < 0)
curRespawnDelay = 0;
std::string curRespawnDelayStr = secsToTimeString(uint64(curRespawnDelay), true);

View File

@@ -23,6 +23,7 @@ Category: commandscripts
EndScriptData */
#include "Chat.h"
#include "GameTime.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ReputationMgr.h"
@@ -379,7 +380,7 @@ public:
// fill mail
MailDraft draft(quest->GetTitle(), std::string());
for (auto itr : questItems)
for (auto const& itr : questItems)
{
if (Item* item = Item::CreateItem(itr.first, itr.second))
{
@@ -615,7 +616,7 @@ public:
// fill mail
MailDraft draft(quest->GetTitle(), "This quest has been manually rewarded to you. This mail contains your quest rewards.");
for (auto itr : questRewardItems)
for (auto const& itr : questRewardItems)
{
if (!itr.first || !itr.second)
{
@@ -652,7 +653,7 @@ public:
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHARACTER_DAILYQUESTSTATUS);
stmt->setUInt32(0, guid);
stmt->setUInt32(1, entry);
stmt->setUInt64(2, time(nullptr));
stmt->setUInt64(2, GameTime::GetGameTime().count());
trans->Append(stmt);
}
else if (quest->IsWeekly())

View File

@@ -22,9 +22,9 @@
Category: commandscripts
EndScriptData */
#include "AvgDiffTracker.h"
#include "Chat.h"
#include "Config.h"
#include "GameTime.h"
#include "GitRevision.h"
#include "Language.h"
#include "ModuleMgr.h"
@@ -34,6 +34,7 @@
#include "ScriptMgr.h"
#include "ServerMotd.h"
#include "StringConvert.h"
#include "UpdateTime.h"
#include "VMapFactory.h"
#include "VMapMgr2.h"
#include <boost/version.hpp>
@@ -77,7 +78,6 @@ public:
static ChatCommandTable serverSetCommandTable =
{
{ "difftime", HandleServerSetDiffTimeCommand, SEC_CONSOLE, Console::Yes },
{ "loglevel", HandleServerSetLogLevelCommand, SEC_CONSOLE, Console::Yes },
{ "motd", HandleServerSetMotdCommand, SEC_ADMINISTRATOR, Console::Yes },
{ "closed", HandleServerSetClosedCommand, SEC_CONSOLE, Console::Yes },
@@ -238,23 +238,16 @@ public:
uint32 activeSessionCount = sWorld->GetActiveSessionCount();
uint32 queuedSessionCount = sWorld->GetQueuedSessionCount();
uint32 connPeak = sWorld->GetMaxActiveSessionCount();
std::string uptime = secsToTimeString(sWorld->GetUptime()).append(".");
uint32 updateTime = sWorld->GetUpdateTime();
uint32 avgUpdateTime = avgDiffTracker.getAverage();
handler->PSendSysMessage("%s", GitRevision::GetFullVersion());
if (!queuedSessionCount)
handler->PSendSysMessage("Connected players: %u. Characters in world: %u.", activeSessionCount, playerCount);
else
handler->PSendSysMessage("Connected players: %u. Characters in world: %u. Queue: %u.", activeSessionCount, playerCount, queuedSessionCount);
handler->PSendSysMessage("Connection peak: %u.", connPeak);
handler->PSendSysMessage(LANG_UPTIME, uptime.c_str());
handler->PSendSysMessage("Update time diff: %ums, average: %ums.", updateTime, avgUpdateTime);
if (handler->GetSession())
if (Player* p = handler->GetSession()->GetPlayer())
if (p->IsDeveloper())
handler->PSendSysMessage("DEV wavg: %ums, nsmax: %ums, nsavg: %ums. LFG avg: %ums, max: %ums.", avgDiffTracker.getTimeWeightedAverage(), devDiffTracker.getMax(), devDiffTracker.getAverage(), lfgDiffTracker.getAverage(), lfgDiffTracker.getMax());
handler->PSendSysMessage("Connection peak: %u.", connPeak);
handler->PSendSysMessage(LANG_UPTIME, secsToTimeString(GameTime::GetUptime().count()).c_str());
handler->PSendSysMessage("Update time diff: %ums, average: %ums.", sWorldUpdateTime.GetLastUpdateTime(), sWorldUpdateTime.GetAverageUpdateTime());
//! Can't use sWorld->ShutdownMsg here in case of console command
if (sWorld->IsShuttingDown())
@@ -439,18 +432,6 @@ public:
sLog->SetLogLevel(name, level, isLogger);
return true;
}
// set diff time record interval
static bool HandleServerSetDiffTimeCommand(ChatHandler* /*handler*/, int32 newTime)
{
if (newTime < 0)
return false;
sWorld->SetRecordDiffInterval(newTime);
printf("Record diff every %u ms\n", newTime);
return true;
}
};
void AddSC_server_commandscript()