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

@@ -1,9 +1,22 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
* Copyright (C) 2021+ WarheadCore <https://github.com/WarheadCore>
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 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 Affero 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 "TOTP.h"
#include "Timer.h"
#include <openssl/evp.h>
#include <openssl/hmac.h>
@@ -34,7 +47,7 @@ static constexpr uint32 HMAC_RESULT_SIZE = 20;
/*static*/ bool Acore::Crypto::TOTP::ValidateToken(Secret const& secret, uint32 token)
{
time_t now = time(nullptr);
time_t now = GetEpochTime().count();
return (
(token == GenerateToken(secret, now - TOTP_INTERVAL)) ||
(token == GenerateToken(secret, now)) ||

View File

@@ -19,7 +19,7 @@
#include "Log.h"
#include "LogMessage.h"
#include "StringConvert.h"
#include "Util.h"
#include "Timer.h"
#include <algorithm>
AppenderFile::AppenderFile(uint8 id, std::string const& name, LogLevel level, AppenderFlags flags, std::vector<std::string_view> const& args) :
@@ -127,7 +127,7 @@ FILE* AppenderFile::OpenFile(std::string const& filename, std::string const& mod
CloseFile();
std::string newName(fullName);
newName.push_back('.');
newName.append(LogMessage::getTimeStr(time(nullptr)));
newName.append(LogMessage::getTimeStr(GetEpochTime()));
std::replace(newName.begin(), newName.end(), ':', '-');
rename(fullName.c_str(), newName.c_str()); // no error handling... if we couldn't make a backup, just ignore
}

View File

@@ -20,18 +20,18 @@
#include "Timer.h"
LogMessage::LogMessage(LogLevel _level, std::string const& _type, std::string&& _text)
: level(_level), type(_type), text(std::forward<std::string>(_text)), mtime(time(nullptr))
: level(_level), type(_type), text(std::forward<std::string>(_text)), mtime(GetEpochTime())
{
}
LogMessage::LogMessage(LogLevel _level, std::string const& _type, std::string&& _text, std::string&& _param1)
: level(_level), type(_type), text(std::forward<std::string>(_text)), param1(std::forward<std::string>(_param1)), mtime(time(nullptr))
: level(_level), type(_type), text(std::forward<std::string>(_text)), param1(std::forward<std::string>(_param1)), mtime(GetEpochTime())
{
}
std::string LogMessage::getTimeStr(time_t time)
std::string LogMessage::getTimeStr(Seconds time)
{
return Acore::Time::TimeToTimestampStr(Seconds(time), "%Y-%m-%d %X");
return Acore::Time::TimeToTimestampStr(time, "%Y-%m-%d %X");
}
std::string LogMessage::getTimeStr() const

View File

@@ -19,8 +19,8 @@
#define LogMessage_h__
#include "Define.h"
#include "Duration.h"
#include "LogCommon.h"
#include <ctime>
#include <string>
struct LogMessage
@@ -31,7 +31,7 @@ struct LogMessage
LogMessage(LogMessage const& /*other*/) = delete;
LogMessage& operator=(LogMessage const& /*other*/) = delete;
static std::string getTimeStr(time_t time);
static std::string getTimeStr(Seconds time);
std::string getTimeStr() const;
LogLevel const level;
@@ -39,7 +39,7 @@ struct LogMessage
std::string const text;
std::string prefix;
std::string param1;
time_t mtime;
Seconds mtime;
///@ Returns size of the log message content in bytes
uint32 Size() const

View File

@@ -16,8 +16,8 @@
*/
#include "SFMTRand.h"
#include "Timer.h"
#include <array>
#include <ctime>
#include <functional>
#include <random>
@@ -69,7 +69,7 @@ SFMTRand::SFMTRand()
}
else
{
sfmt_init_gen_rand(&_state, uint32(time(nullptr)));
sfmt_init_gen_rand(&_state, uint32(GetEpochTime().count()));
}
}

View File

@@ -76,7 +76,7 @@ inline TimePoint GetApplicationStartTime()
{
using namespace std::chrono;
static const steady_clock::time_point ApplicationStartTime = steady_clock::now();
static const TimePoint ApplicationStartTime = steady_clock::now();
return ApplicationStartTime;
}