feat(Core/Time): remove inherited ACE Time (#3455)

Co-authored-by: Viste <viste02@gmail.com>
This commit is contained in:
Kargatum
2020-09-11 19:03:26 +07:00
committed by GitHub
parent 8b3621779e
commit e15a493927
20 changed files with 157 additions and 58 deletions

View File

@@ -428,7 +428,7 @@ bool AchievementCriteriaData::Meets(uint32 criteria_id, Player const* source, Un
{
time_t birthday_start = time_t(sWorld->getIntConfig(CONFIG_BIRTHDAY_TIME));
tm birthday_tm;
ACE_OS::localtime_r(&birthday_start, &birthday_tm);
localtime_r(&birthday_start, &birthday_tm);
// exactly N birthday
birthday_tm.tm_year += birthday_login.nth_birthday;

View File

@@ -27411,7 +27411,7 @@ void Player::_LoadBrewOfTheMonth(PreparedQueryResult result)
time_t curtime = time(nullptr);
tm localTime;
ACE_OS::localtime_r(&curtime, &localTime);
localtime_r(&curtime, &localTime);
uint16 month = uint16(localTime.tm_mon);
uint16 eventId = month;

View File

@@ -32,6 +32,8 @@
#include "PacketLog.h"
#include "ScriptMgr.h"
#include "AccountMgr.h"
#include <thread>
#ifdef ELUNA
#include "LuaEngine.h"
#endif
@@ -90,7 +92,7 @@ struct ClientPktHeader
#endif
WorldSocket::WorldSocket(void): WorldHandler(),
m_LastPingTime(ACE_Time_Value::zero), m_OverSpeedPings(0), m_Session(0),
m_LastPingTime(SystemTimePoint::min()), m_OverSpeedPings(0), m_Session(0),
m_RecvWPct(0), m_RecvPct(), m_Header(sizeof (ClientPktHeader)),
m_OutBuffer(0), m_OutBufferSize(65536), m_OutActive(false),
m_Seed(static_cast<uint32> (rand32()))
@@ -1021,9 +1023,9 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
// Sleep this Network thread for
uint32 sleepTime = sWorld->getIntConfig(CONFIG_SESSION_ADD_DELAY);
ACE_OS::sleep (ACE_Time_Value (0, sleepTime));
std::this_thread::sleep_for(Microseconds(sleepTime));
sWorld->AddSession (m_Session);
sWorld->AddSession(m_Session);
return 0;
}
@@ -1037,20 +1039,19 @@ int WorldSocket::HandlePing(WorldPacket& recvPacket)
recvPacket >> ping;
recvPacket >> latency;
if (m_LastPingTime == ACE_Time_Value::zero)
m_LastPingTime = ACE_OS::gettimeofday(); // for 1st ping
if (m_LastPingTime == SystemTimePoint::min())
m_LastPingTime = std::chrono::system_clock::now(); // for 1st ping
else
{
ACE_Time_Value cur_time = ACE_OS::gettimeofday();
ACE_Time_Value diff_time (cur_time);
diff_time -= m_LastPingTime;
m_LastPingTime = cur_time;
auto now = std::chrono::system_clock::now();
Seconds seconds = std::chrono::duration_cast<Seconds>(now - m_LastPingTime);
m_LastPingTime = now;
if (diff_time < ACE_Time_Value (27))
if (seconds.count() < 27)
{
++m_OverSpeedPings;
uint32 max_count = sWorld->getIntConfig (CONFIG_MAX_OVERSPEED_PINGS);
uint32 max_count = sWorld->getIntConfig(CONFIG_MAX_OVERSPEED_PINGS);
if (max_count && m_OverSpeedPings > max_count)
{

View File

@@ -13,7 +13,6 @@
#ifndef _WORLDSOCKET_H
#define _WORLDSOCKET_H
#include <ace/Basic_Types.h>
#include <ace/Synch_Traits.h>
#include <ace/Svc_Handler.h>
#include <ace/SOCK_Stream.h>
@@ -28,6 +27,7 @@
#include "Common.h"
#include "AuthCrypt.h"
#include "Duration.h"
class ACE_Message_Block;
class WorldPacket;
@@ -151,7 +151,7 @@ class WorldSocket : public WorldHandler
private:
/// Time in which the last ping was received
ACE_Time_Value m_LastPingTime;
SystemTimePoint m_LastPingTime;
/// Keep track of over-speed pings, to prevent ping flood.
uint32 m_OverSpeedPings;

View File

@@ -84,7 +84,7 @@ bool Weather::ReGenerate()
// season source http://aa.usno.navy.mil/data/docs/EarthSeasons.html
time_t gtime = sWorld->GetGameTime();
struct tm ltime;
ACE_OS::localtime_r(&gtime, &ltime);
localtime_r(&gtime, &ltime);
uint32 season = ((ltime.tm_yday - 78 + 365)/91)%4;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)

View File

@@ -2838,7 +2838,7 @@ time_t World::GetNextTimeWithDayAndHour(int8 dayOfWeek, int8 hour)
hour = 0;
time_t curr = time(nullptr);
tm localTm;
ACE_OS::localtime_r(&curr, &localTm);
localtime_r(&curr, &localTm);
localTm.tm_hour = hour;
localTm.tm_min = 0;
localTm.tm_sec = 0;
@@ -2859,7 +2859,7 @@ time_t World::GetNextTimeWithMonthAndHour(int8 month, int8 hour)
hour = 0;
time_t curr = time(nullptr);
tm localTm;
ACE_OS::localtime_r(&curr, &localTm);
localtime_r(&curr, &localTm);
localTm.tm_mday = 1;
localTm.tm_hour = hour;
localTm.tm_min = 0;

View File

@@ -460,7 +460,7 @@ public:
{
time_t timeBan = time_t(fields2[0].GetUInt32());
tm tmBan;
ACE_OS::localtime_r(&timeBan, &tmBan);
localtime_r(&timeBan, &tmBan);
if (fields2[0].GetUInt32() == fields2[1].GetUInt32())
{
@@ -472,7 +472,7 @@ public:
{
time_t timeUnban = time_t(fields2[1].GetUInt32());
tm tmUnban;
ACE_OS::localtime_r(&timeUnban, &tmUnban);
localtime_r(&timeUnban, &tmUnban);
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
accountName.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
tmUnban.tm_year%100, tmUnban.tm_mon+1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
@@ -549,7 +549,7 @@ public:
{
time_t timeBan = time_t(banFields[0].GetUInt32());
tm tmBan;
ACE_OS::localtime_r(&timeBan, &tmBan);
localtime_r(&timeBan, &tmBan);
if (banFields[0].GetUInt32() == banFields[1].GetUInt32())
{
@@ -561,7 +561,7 @@ public:
{
time_t timeUnban = time_t(banFields[1].GetUInt32());
tm tmUnban;
ACE_OS::localtime_r(&timeUnban, &tmUnban);
localtime_r(&timeUnban, &tmUnban);
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
char_name.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
tmUnban.tm_year%100, tmUnban.tm_mon+1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
@@ -630,7 +630,7 @@ public:
Field* fields = result->Fetch();
time_t timeBan = time_t(fields[1].GetUInt32());
tm tmBan;
ACE_OS::localtime_r(&timeBan, &tmBan);
localtime_r(&timeBan, &tmBan);
if (fields[1].GetUInt32() == fields[2].GetUInt32())
{
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
@@ -641,7 +641,7 @@ public:
{
time_t timeUnban = time_t(fields[2].GetUInt32());
tm tmUnban;
ACE_OS::localtime_r(&timeUnban, &tmUnban);
localtime_r(&timeUnban, &tmUnban);
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
fields[0].GetCString(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
tmUnban.tm_year%100, tmUnban.tm_mon+1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,

View File

@@ -224,7 +224,7 @@ public:
char createdDateStr[20];
time_t createdDate = guild->GetCreatedDate();
tm localTm;
ACE_OS::localtime_r(&createdDate, &localTm);
localtime_r(&createdDate, &localTm);
strftime(createdDateStr, 20, "%Y-%m-%d %H:%M:%S", &localTm);
handler->PSendSysMessage(LANG_GUILD_INFO_CREATION_DATE, createdDateStr); // Creation Date

View File

@@ -2370,7 +2370,7 @@ public:
char buffer[80];
// set it to string
ACE_OS::localtime_r(&sqlTime, &timeInfo);
localtime_r(&sqlTime, &timeInfo);
strftime(buffer, sizeof(buffer), "%Y-%m-%d %I:%M%p", &timeInfo);
handler->PSendSysMessage(LANG_COMMAND_MUTEHISTORY_OUTPUT, buffer, fields[1].GetUInt32(), fields[2].GetCString(), fields[3].GetCString());

View File

@@ -846,7 +846,7 @@ public:
{
time_t curtime = time(nullptr);
tm strDate;
ACE_OS::localtime_r(&curtime, &strDate);
localtime_r(&curtime, &strDate);
if (strDate.tm_min == 0 || strDate.tm_min == 30)
return true;

View File

@@ -110,7 +110,7 @@ public:
{
time_t curtime = time(nullptr);
tm strdate;
ACE_OS::localtime_r(&curtime, &strdate);
localtime_r(&curtime, &strdate);
if (!preWarning && strdate.tm_hour == 13 && strdate.tm_min == 55)
{
@@ -255,7 +255,7 @@ public:
{
time_t curtime = time(nullptr);
tm strdate;
ACE_OS::localtime_r(&curtime, &strdate);
localtime_r(&curtime, &strdate);
if (!startWarning && strdate.tm_hour == 14 && strdate.tm_min == 0)
{
sCreatureTextMgr->SendChat(me, RIGGLE_SAY_START, 0, CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, TEXT_RANGE_ZONE);

View File

@@ -15,9 +15,11 @@
#include "Log.h"
#include "RASocket.h"
#include "Util.h"
#include "Duration.h"
#include "World.h"
#include "SHA1.h"
#include "ServerMotd.h"
#include <thread>
RASocket::RASocket()
{
@@ -49,7 +51,7 @@ int RASocket::handle_close(ACE_HANDLE /*handle*/, ACE_Reactor_Mask /*mask*/)
// RASocket::commandfinished to be completed. Calling destroy() before the latter function ends
// will lead to using a freed pointer -> crash.
while (_commandExecuting)
ACE_OS::sleep(1);
std::this_thread::sleep_for(1s);
destroy();
return 0;