summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/Configuration/Config.cpp2
-rw-r--r--src/common/Logging/Log.cpp16
-rw-r--r--src/common/Logging/LogMessage.cpp6
-rw-r--r--src/common/Utilities/Duration.h76
-rw-r--r--src/common/Utilities/StringFormat.cpp19
-rw-r--r--src/common/Utilities/StringFormat.h23
-rw-r--r--src/common/Utilities/Timer.cpp442
-rw-r--r--src/common/Utilities/Timer.h85
-rw-r--r--src/common/Utilities/Util.cpp77
-rw-r--r--src/common/Utilities/Util.h7
-rw-r--r--src/server/game/Achievements/AchievementMgr.cpp4
-rw-r--r--src/server/game/Entities/Player/Player.cpp18
-rw-r--r--src/server/game/Entities/Player/Player.h2
-rw-r--r--src/server/game/Entities/Player/PlayerSettings.cpp4
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp2
-rw-r--r--src/server/game/Events/GameEventMgr.cpp5
-rw-r--r--src/server/game/Guilds/Guild.h2
-rw-r--r--src/server/game/Handlers/BankHandler.cpp2
-rw-r--r--src/server/game/Scripting/ScriptDefines/CommandScript.cpp2
-rw-r--r--src/server/game/Scripting/ScriptDefines/GlobalScript.cpp2
-rw-r--r--src/server/game/Scripting/ScriptDefines/OutdoorPvPScript.cpp2
-rw-r--r--src/server/game/Scripting/ScriptMgr.cpp6
-rw-r--r--src/server/game/Server/Packets/AllPackets.h10
-rw-r--r--src/server/game/Server/Packets/BankPackets.h2
-rw-r--r--src/server/game/Server/Packets/ChatPackets.h2
-rw-r--r--src/server/game/Server/Packets/GuildPackets.h4
-rw-r--r--src/server/game/Server/Packets/TotemPackets.h2
-rw-r--r--src/server/game/Server/Protocol/Opcodes.cpp2
-rw-r--r--src/server/game/Weather/Weather.cpp7
-rw-r--r--src/server/game/Weather/WeatherMgr.cpp2
-rw-r--r--src/server/game/World/IWorld.h2
-rw-r--r--src/server/game/World/World.cpp69
-rw-r--r--src/server/game/World/World.h3
-rw-r--r--src/server/scripts/Commands/cs_ban.cpp24
-rw-r--r--src/server/scripts/Commands/cs_character.cpp3
-rw-r--r--src/server/scripts/Commands/cs_event.cpp7
-rw-r--r--src/server/scripts/Commands/cs_gear.cpp2
-rw-r--r--src/server/scripts/Commands/cs_group.cpp2
-rw-r--r--src/server/scripts/Commands/cs_guild.cpp9
-rw-r--r--src/server/scripts/Commands/cs_inventory.cpp2
-rw-r--r--src/server/scripts/Commands/cs_item.cpp4
-rw-r--r--src/server/scripts/Commands/cs_misc.cpp14
-rw-r--r--src/server/scripts/Commands/cs_pet.cpp4
-rw-r--r--src/server/scripts/Commands/cs_send.cpp2
-rw-r--r--src/server/scripts/Commands/cs_tele.cpp2
-rw-r--r--src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_eviscerator.cpp4
-rw-r--r--src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_hedrum.cpp4
-rw-r--r--src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_okthor.cpp4
-rw-r--r--src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/boss_mor_grayhoof.cpp2
-rw-r--r--src/server/scripts/EasternKingdoms/Scholomance/boss_kormok.cpp2
-rw-r--r--src/server/scripts/EasternKingdoms/Stratholme/boss_jarien_and_sothos.cpp2
-rw-r--r--src/server/scripts/EasternKingdoms/zone_elwynn_forest.cpp8
-rw-r--r--src/server/scripts/EasternKingdoms/zone_ghostlands.cpp2
-rw-r--r--src/server/scripts/Events/brewfest.cpp6
-rw-r--r--src/server/scripts/Kalimdor/DireMaul/boss_isalien.cpp2
-rw-r--r--src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_ouro.cpp2
-rw-r--r--src/server/scripts/World/go_scripts.cpp5
-rw-r--r--src/server/scripts/World/npcs_special.cpp10
-rw-r--r--src/server/shared/Packets/ByteBuffer.cpp4
-rw-r--r--src/tools/map_extractor/loadlib/loadlib.h30
60 files changed, 731 insertions, 340 deletions
diff --git a/src/common/Configuration/Config.cpp b/src/common/Configuration/Config.cpp
index a37ebcfe4e..cccbdc9879 100644
--- a/src/common/Configuration/Config.cpp
+++ b/src/common/Configuration/Config.cpp
@@ -19,8 +19,8 @@
#include "Log.h"
#include "StringConvert.h"
#include "StringFormat.h"
-#include "Util.h"
#include "Tokenize.h"
+#include "Util.h"
#include <fstream>
#include <mutex>
#include <unordered_map>
diff --git a/src/common/Logging/Log.cpp b/src/common/Logging/Log.cpp
index 05a5d63671..7b4980cfe0 100644
--- a/src/common/Logging/Log.cpp
+++ b/src/common/Logging/Log.cpp
@@ -24,8 +24,8 @@
#include "LogOperation.h"
#include "Logger.h"
#include "StringConvert.h"
+#include "Timer.h"
#include "Tokenize.h"
-#include "Util.h"
#include <chrono>
#include <sstream>
@@ -275,19 +275,7 @@ Logger const* Log::GetLoggerByType(std::string const& type) const
std::string Log::GetTimestampStr()
{
- time_t tt = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
-
- std::tm aTm;
- localtime_r(&tt, &aTm);
-
- // YYYY year
- // MM month (2 digits 01-12)
- // DD day (2 digits 01-31)
- // HH hour (2 digits 00-23)
- // MM minutes (2 digits 00-59)
- // SS seconds (2 digits 00-59)
- return Acore::StringFormat("%04d-%02d-%02d_%02d-%02d-%02d",
- aTm.tm_year + 1900, aTm.tm_mon + 1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec);
+ return Acore::Time::TimeToTimestampStr(GetEpochTime(), "%Y-%m-%d_%H_%M_%S");
}
bool Log::SetLogLevel(std::string const& name, int32 newLeveli, bool isLogger /* = true */)
diff --git a/src/common/Logging/LogMessage.cpp b/src/common/Logging/LogMessage.cpp
index 4a0cf3a0bd..28f8e82ba5 100644
--- a/src/common/Logging/LogMessage.cpp
+++ b/src/common/Logging/LogMessage.cpp
@@ -17,7 +17,7 @@
#include "LogMessage.h"
#include "StringFormat.h"
-#include "Util.h"
+#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))
@@ -31,9 +31,7 @@ LogMessage::LogMessage(LogLevel _level, std::string const& _type, std::string&&
std::string LogMessage::getTimeStr(time_t time)
{
- tm aTm;
- localtime_r(&time, &aTm);
- return Acore::StringFormat("%04d-%02d-%02d_%02d:%02d:%02d", aTm.tm_year + 1900, aTm.tm_mon + 1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec);
+ return Acore::Time::TimeToTimestampStr(Seconds(time), "%Y-%m-%d %X");
}
std::string LogMessage::getTimeStr() const
diff --git a/src/common/Utilities/Duration.h b/src/common/Utilities/Duration.h
index 0749b34254..9ddb1a68a1 100644
--- a/src/common/Utilities/Duration.h
+++ b/src/common/Utilities/Duration.h
@@ -1,6 +1,18 @@
/*
- * Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
- * Copyright (C) 2008-2020 TrinityCore <http://www.trinitycore.org/>
+ * 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/>.
*/
#ifndef _DURATION_H_
@@ -9,25 +21,71 @@
#include <chrono>
/// Microseconds shorthand typedef.
-typedef std::chrono::microseconds Microseconds;
+using Microseconds = std::chrono::microseconds;
/// Milliseconds shorthand typedef.
-typedef std::chrono::milliseconds Milliseconds;
+using Milliseconds = std::chrono::milliseconds;
/// Seconds shorthand typedef.
-typedef std::chrono::seconds Seconds;
+using Seconds = std::chrono::seconds;
/// Minutes shorthand typedef.
-typedef std::chrono::minutes Minutes;
+using Minutes = std::chrono::minutes;
/// Hours shorthand typedef.
-typedef std::chrono::hours Hours;
+using Hours = std::chrono::hours;
+
+#if __cplusplus > 201703L
+/// Days shorthand typedef.
+using Days = std::chrono::days;
+
+/// Weeks shorthand typedef.
+using Weeks = std::chrono::weeks;
+
+/// Years shorthand typedef.
+using Years = std::chrono::years;
+
+/// Months shorthand typedef.
+using Months = std::chrono::months;
+#else
+/// Days shorthand typedef. (delete after start support c++20)
+using Days = std::chrono::duration<int, std::ratio_multiply<std::ratio<24>, Hours::period>>;
+
+/// Weeks shorthand typedef. (delete after start support c++20)
+using Weeks = std::chrono::duration<int, std::ratio_multiply<std::ratio<7>, Days::period>>;
+
+/// Years shorthand typedef. (delete after start support c++20)
+using Years = std::chrono::duration<int, std::ratio_multiply<std::ratio<146097, 400>, Days::period>>;
+
+/// Months shorthand typedef. (delete after start support c++20)
+using Months = std::chrono::duration<int, std::ratio_divide<Years::period, std::ratio<12>>>;
+#endif
/// time_point shorthand typedefs
-typedef std::chrono::steady_clock::time_point TimePoint;
-typedef std::chrono::system_clock::time_point SystemTimePoint;
+using TimePoint = std::chrono::steady_clock::time_point;
+using SystemTimePoint = std::chrono::system_clock::time_point;
/// Makes std::chrono_literals globally available.
using namespace std::chrono_literals;
+constexpr Days operator""_days(unsigned long long days)
+{
+ return Days(days);
+}
+
+constexpr Weeks operator""_weeks(unsigned long long weeks)
+{
+ return Weeks(weeks);
+}
+
+constexpr Years operator""_years(unsigned long long years)
+{
+ return Years(years);
+}
+
+constexpr Months operator""_months(unsigned long long months)
+{
+ return Months(months);
+}
+
#endif
diff --git a/src/common/Utilities/StringFormat.cpp b/src/common/Utilities/StringFormat.cpp
index 0d8ca27491..83e2d2a468 100644
--- a/src/common/Utilities/StringFormat.cpp
+++ b/src/common/Utilities/StringFormat.cpp
@@ -16,10 +16,11 @@
*/
#include "StringFormat.h"
+#include "Define.h"
#include <locale>
template<class Str>
-Str Acore::String::Trim(const Str& s, const std::locale& loc /*= std::locale()*/)
+AC_COMMON_API Str Acore::String::Trim(const Str& s, const std::locale& loc /*= std::locale()*/)
{
typename Str::const_iterator first = s.begin();
typename Str::const_iterator end = s.end();
@@ -49,5 +50,19 @@ Str Acore::String::Trim(const Str& s, const std::locale& loc /*= std::locale()*/
return s;
}
+std::string Acore::String::TrimRightInPlace(std::string& str)
+{
+ int pos = int(str.size()) - 1;
+
+ while (pos >= 0 && std::isspace(str[pos]))
+ {
+ --pos;
+ }
+
+ str.resize(static_cast<std::basic_string<char, std::char_traits<char>, std::allocator<char>>::size_type>(pos) + 1);
+
+ return str;
+}
+
// Template Trim
-template std::string Acore::String::Trim<std::string>(const std::string& s, const std::locale& loc /*= std::locale()*/);
+template AC_COMMON_API std::string Acore::String::Trim<std::string>(const std::string& s, const std::locale& loc /*= std::locale()*/);
diff --git a/src/common/Utilities/StringFormat.h b/src/common/Utilities/StringFormat.h
index b8176ed219..e7f6fab3e0 100644
--- a/src/common/Utilities/StringFormat.h
+++ b/src/common/Utilities/StringFormat.h
@@ -1,13 +1,24 @@
/*
- * 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>
- * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
+ * 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/>.
*/
#ifndef _STRING_FORMAT_H_
#define _STRING_FORMAT_H_
+#include "Define.h"
#include <fmt/core.h>
#include <fmt/printf.h>
@@ -58,7 +69,9 @@ namespace Acore
namespace Acore::String
{
template<class Str>
- Str Trim(const Str& s, const std::locale& loc = std::locale());
+ AC_COMMON_API Str Trim(const Str& s, const std::locale& loc = std::locale());
+
+ AC_COMMON_API std::string TrimRightInPlace(std::string& str);
}
#endif
diff --git a/src/common/Utilities/Timer.cpp b/src/common/Utilities/Timer.cpp
new file mode 100644
index 0000000000..e7cb691a1c
--- /dev/null
+++ b/src/common/Utilities/Timer.cpp
@@ -0,0 +1,442 @@
+/*
+ * 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 "Timer.h"
+#include "StringFormat.h"
+#include <iomanip>
+#include <sstream>
+
+namespace Acore::TimeDiff // in us
+{
+ constexpr uint64 MILLISECONDS = 1000;
+ constexpr uint64 SECONDS = 1000 * MILLISECONDS;
+ constexpr uint64 MINUTES = 60 * SECONDS;
+ constexpr uint64 HOURS = 60 * MINUTES;
+ constexpr uint64 DAYS = 24 * HOURS;
+}
+
+template<>
+AC_COMMON_API uint32 Acore::Time::TimeStringTo<Seconds>(std::string_view timestring)
+{
+ uint32 secs = 0;
+ uint32 buffer = 0;
+ uint32 multiplier = 0;
+
+ for (char itr : timestring)
+ {
+ if (isdigit(itr))
+ {
+ buffer *= 10;
+ buffer += itr - '0';
+ }
+ else
+ {
+ switch (itr)
+ {
+ case 'd':
+ multiplier = DAY;
+ break;
+ case 'h':
+ multiplier = HOUR;
+ break;
+ case 'm':
+ multiplier = MINUTE;
+ break;
+ case 's':
+ multiplier = 1;
+ break;
+ default:
+ return 0; // bad format
+ }
+
+ buffer *= multiplier;
+ secs += buffer;
+ buffer = 0;
+ }
+ }
+
+ return secs;
+}
+
+template<>
+AC_COMMON_API std::string Acore::Time::ToTimeString<Microseconds>(uint64 durationTime, TimeOutput timeOutput /*= TimeOutput::Seconds*/, TimeFormat timeFormat /*= TimeFormat::ShortText*/)
+{
+ uint64 microsecs = durationTime % 1000;
+ uint64 millisecs = (durationTime / TimeDiff::MILLISECONDS) % 1000;
+ uint64 secs = (durationTime / TimeDiff::SECONDS) % 60;
+ uint64 minutes = (durationTime / TimeDiff::MINUTES) % 60;
+ uint64 hours = (durationTime / TimeDiff::HOURS) % 24;
+ uint64 days = durationTime / TimeDiff::DAYS;
+
+ if (timeFormat == TimeFormat::Numeric)
+ {
+ if (days)
+ {
+ return Acore::StringFormatFmt("{}:{:02}:{:02}:{:02}:{:02}:{:02}", days, hours, minutes, secs, millisecs);
+ }
+ else if (hours)
+ {
+ return Acore::StringFormatFmt("{}:{:02}:{:02}:{:02}:{:02}", hours, minutes, secs, millisecs);
+ }
+ else if (minutes)
+ {
+ return Acore::StringFormatFmt("{}:{:02}:{:02}:{:02}", minutes, secs, millisecs);
+ }
+ else if (secs)
+ {
+ return Acore::StringFormatFmt("{}:{:02}:{:02}", secs, millisecs);
+ }
+ else if (millisecs)
+ {
+ return Acore::StringFormatFmt("{}:{:02}", millisecs);
+ }
+ else // microsecs
+ {
+ return Acore::StringFormatFmt("{}", microsecs);
+ }
+ }
+
+ std::ostringstream ss;
+ std::string stringTime;
+
+ auto GetStringFormat = [&](uint32 timeType, std::string_view shortText, std::string_view fullText1, std::string_view fullText)
+ {
+ ss << timeType;
+
+ switch (timeFormat)
+ {
+ case TimeFormat::ShortText:
+ ss << shortText;
+ break;
+ case TimeFormat::FullText:
+ ss << (timeType == 1 ? fullText1 : fullText);
+ break;
+ default:
+ ss << "<Unknown time format>";
+ }
+ };
+
+ if (days)
+ {
+ GetStringFormat(days, "d ", " Day ", " Days ");
+ }
+
+ if (timeOutput == TimeOutput::Days)
+ {
+ stringTime = ss.str();
+ }
+
+ if (hours)
+ {
+ GetStringFormat(hours, "h ", " Hour ", " Hours ");
+ }
+
+ if (timeOutput == TimeOutput::Hours)
+ {
+ stringTime = ss.str();
+ }
+
+ if (minutes)
+ {
+ GetStringFormat(minutes, "m ", " Minute ", " Minutes ");
+ }
+
+ if (timeOutput == TimeOutput::Minutes)
+ {
+ stringTime = ss.str();
+ }
+
+ if (secs)
+ {
+ GetStringFormat(secs, "s ", " Second ", " Seconds ");
+ }
+
+ if (timeOutput == TimeOutput::Seconds)
+ {
+ stringTime = ss.str();
+ }
+
+ if (millisecs)
+ {
+ GetStringFormat(millisecs, "ms ", " Millisecond ", " Milliseconds ");
+ }
+
+ if (timeOutput == TimeOutput::Milliseconds)
+ {
+ stringTime = ss.str();
+ }
+
+ if (microsecs)
+ {
+ GetStringFormat(microsecs, "us ", " Microsecond ", " Microseconds ");
+ }
+
+ if (timeOutput == TimeOutput::Microseconds)
+ {
+ stringTime = ss.str();
+ }
+
+ return Acore::String::TrimRightInPlace(stringTime);
+}
+
+template<>
+AC_COMMON_API std::string Acore::Time::ToTimeString<Milliseconds>(uint64 durationTime, TimeOutput timeOutput /*= TimeOutput::Seconds*/, TimeFormat timeFormat /*= TimeFormat::ShortText*/)
+{
+ return ToTimeString<Microseconds>(durationTime * TimeDiff::MILLISECONDS, timeOutput, timeFormat);
+}
+
+template<>
+AC_COMMON_API std::string Acore::Time::ToTimeString<Seconds>(uint64 durationTime, TimeOutput timeOutput /*= TimeOutput::Seconds*/, TimeFormat timeFormat /*= TimeFormat::ShortText*/)
+{
+ return ToTimeString<Microseconds>(durationTime * TimeDiff::SECONDS, timeOutput, timeFormat);
+}
+
+template<>
+AC_COMMON_API std::string Acore::Time::ToTimeString<Minutes>(uint64 durationTime, TimeOutput timeOutput /*= TimeOutput::Seconds*/, TimeFormat timeFormat /*= TimeFormat::ShortText*/)
+{
+ return ToTimeString<Microseconds>(durationTime * TimeDiff::MINUTES, timeOutput, timeFormat);
+}
+
+template<>
+AC_COMMON_API std::string Acore::Time::ToTimeString<Seconds>(std::string_view durationTime, TimeOutput timeOutput /*= TimeOutput::Seconds*/, TimeFormat timeFormat /*= TimeFormat::ShortText*/)
+{
+ return ToTimeString<Seconds>(TimeStringTo<Seconds>(durationTime), timeOutput, timeFormat);
+}
+
+std::string Acore::Time::ToTimeString(Microseconds durationTime, TimeOutput timeOutput /*= TimeOutput::Seconds*/, TimeFormat timeFormat /*= TimeFormat::ShortText*/)
+{
+ return ToTimeString<Microseconds>(durationTime.count(), timeOutput, timeFormat);
+}
+
+#if AC_PLATFORM == AC_PLATFORM_WINDOWS
+struct tm* localtime_r(time_t const* time, struct tm* result)
+{
+ localtime_s(result, time);
+ return result;
+}
+#endif
+
+std::tm Acore::Time::TimeBreakdown(time_t time /*= 0*/)
+{
+ if (!time)
+ {
+ time = GetEpochTime().count();
+ }
+
+ std::tm timeLocal;
+ localtime_r(&time, &timeLocal);
+ return timeLocal;
+}
+
+time_t Acore::Time::LocalTimeToUTCTime(time_t time)
+{
+#if AC_PLATFORM == AC_PLATFORM_WINDOWS
+ return time + _timezone;
+#else
+ return time + timezone;
+#endif
+}
+
+time_t Acore::Time::GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime)
+{
+ tm timeLocal = TimeBreakdown(time);
+ timeLocal.tm_hour = 0;
+ timeLocal.tm_min = 0;
+ timeLocal.tm_sec = 0;
+
+ time_t midnightLocal = mktime(&timeLocal);
+ time_t hourLocal = midnightLocal + hour * HOUR;
+
+ if (onlyAfterTime && hourLocal <= time)
+ {
+ hourLocal += DAY;
+ }
+
+ return hourLocal;
+}
+
+std::string Acore::Time::TimeToTimestampStr(Seconds time /*= 0s*/, std::string_view fmt /*= {}*/)
+{
+ std::stringstream ss;
+ std::string format{ fmt };
+ time_t t = time.count();
+
+ if (format.empty())
+ {
+ format = "%Y-%m-%d %X";
+ }
+
+ ss << std::put_time(std::localtime(&t), format.c_str());
+ return ss.str();
+}
+
+std::string Acore::Time::TimeToHumanReadable(Seconds time /*= 0s*/, std::string_view fmt /*= {}*/)
+{
+ std::stringstream ss;
+ std::string format{ fmt };
+ time_t t = time.count();
+
+ if (format.empty())
+ {
+ format = "%a %b %d %Y %X";
+ }
+
+ ss << std::put_time(std::localtime(&t), format.c_str());
+ return ss.str();
+}
+
+time_t Acore::Time::GetNextTimeWithDayAndHour(int8 dayOfWeek, int8 hour)
+{
+ if (hour < 0 || hour > 23)
+ {
+ hour = 0;
+ }
+
+ tm localTm = TimeBreakdown();
+ localTm.tm_hour = hour;
+ localTm.tm_min = 0;
+ localTm.tm_sec = 0;
+
+ if (dayOfWeek < 0 || dayOfWeek > 6)
+ {
+ dayOfWeek = (localTm.tm_wday + 1) % 7;
+ }
+
+ uint32 add;
+
+ if (localTm.tm_wday >= dayOfWeek)
+ {
+ add = (7 - (localTm.tm_wday - dayOfWeek)) * DAY;
+ }
+ else
+ {
+ add = (dayOfWeek - localTm.tm_wday) * DAY;
+ }
+
+ return mktime(&localTm) + add;
+}
+
+time_t Acore::Time::GetNextTimeWithMonthAndHour(int8 month, int8 hour)
+{
+ if (hour < 0 || hour > 23)
+ {
+ hour = 0;
+ }
+
+ tm localTm = TimeBreakdown();
+ localTm.tm_mday = 1;
+ localTm.tm_hour = hour;
+ localTm.tm_min = 0;
+ localTm.tm_sec = 0;
+
+ if (month < 0 || month > 11)
+ {
+ month = (localTm.tm_mon + 1) % 12;
+
+ if (!month)
+ {
+ localTm.tm_year += 1;
+ }
+ }
+ else if (localTm.tm_mon >= month)
+ {
+ localTm.tm_year += 1;
+ }
+
+ localTm.tm_mon = month;
+ return mktime(&localTm);
+}
+
+uint32 Acore::Time::GetSeconds(Seconds time /*= 0s*/)
+{
+ if (time == 0s)
+ {
+ time = GetEpochTime();
+ }
+
+ return TimeBreakdown(time.count()).tm_sec;
+}
+
+uint32 Acore::Time::GetMinutes(Seconds time /*= 0s*/)
+{
+ if (time == 0s)
+ {
+ time = GetEpochTime();
+ }
+
+ return TimeBreakdown(time.count()).tm_min;
+}
+
+uint32 Acore::Time::GetHours(Seconds time /*= 0s*/)
+{
+ if (time == 0s)
+ {
+ time = GetEpochTime();
+ }
+
+ return TimeBreakdown(time.count()).tm_hour;
+}
+
+uint32 Acore::Time::GetDayInWeek(Seconds time /*= 0s*/)
+{
+ if (time == 0s)
+ {
+ time = GetEpochTime();
+ }
+
+ return TimeBreakdown(time.count()).tm_wday;
+}
+
+uint32 Acore::Time::GetDayInMonth(Seconds time /*= 0s*/)
+{
+ if (time == 0s)
+ {
+ time = GetEpochTime();
+ }
+
+ return TimeBreakdown(time.count()).tm_mday;
+}
+
+uint32 Acore::Time::GetDayInYear(Seconds time /*= 0s*/)
+{
+ if (time == 0s)
+ {
+ time = GetEpochTime();
+ }
+
+ return TimeBreakdown(time.count()).tm_yday;
+}
+
+uint32 Acore::Time::GetMonth(Seconds time /*= 0s*/)
+{
+ if (time == 0s)
+ {
+ time = GetEpochTime();
+ }
+
+ return TimeBreakdown(time.count()).tm_mon;
+}
+
+uint32 Acore::Time::GetYear(Seconds time /*= 0s*/)
+{
+ if (time == 0s)
+ {
+ time = GetEpochTime();
+ }
+
+ return TimeBreakdown(time.count()).tm_year;
+}
diff --git a/src/common/Utilities/Timer.h b/src/common/Utilities/Timer.h
index e61f0fd5e5..5e2d190599 100644
--- a/src/common/Utilities/Timer.h
+++ b/src/common/Utilities/Timer.h
@@ -21,6 +21,57 @@
#include "Common.h"
#include "Duration.h"
+enum class TimeFormat : uint8
+{
+ FullText, // 1 Days 2 Hours 3 Minutes 4 Seconds 5 Milliseconds
+ ShortText, // 1d 2h 3m 4s 5ms
+ Numeric // 1:2:3:4:5
+};
+
+enum class TimeOutput : uint8
+{
+ Days, // 1d
+ Hours, // 1d 2h
+ Minutes, // 1d 2h 3m
+ Seconds, // 1d 2h 3m 4s
+ Milliseconds, // 1d 2h 3m 4s 5ms
+ Microseconds // 1d 2h 3m 4s 5ms 6us
+};
+
+namespace Acore::Time
+{
+ template <class T>
+ AC_COMMON_API uint32 TimeStringTo(std::string_view timeString);
+
+ template<class T>
+ AC_COMMON_API std::string ToTimeString(uint64 durationTime, TimeOutput timeOutput = TimeOutput::Seconds, TimeFormat timeFormat = TimeFormat::ShortText);
+
+ template<class T>
+ AC_COMMON_API std::string ToTimeString(std::string_view durationTime, TimeOutput timeOutput = TimeOutput::Seconds, TimeFormat timeFormat = TimeFormat::ShortText);
+
+ AC_COMMON_API std::string ToTimeString(Microseconds durationTime, TimeOutput timeOutput = TimeOutput::Seconds, TimeFormat timeFormat = TimeFormat::ShortText);
+
+ AC_COMMON_API time_t LocalTimeToUTCTime(time_t time);
+ AC_COMMON_API time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime = true);
+ AC_COMMON_API std::tm TimeBreakdown(time_t t = 0);
+ AC_COMMON_API std::string TimeToTimestampStr(Seconds time = 0s, std::string_view fmt = {});
+ AC_COMMON_API std::string TimeToHumanReadable(Seconds time = 0s, std::string_view fmt = {});
+
+ AC_COMMON_API time_t GetNextTimeWithDayAndHour(int8 dayOfWeek, int8 hour); // int8 dayOfWeek: 0 (sunday) to 6 (saturday)
+ AC_COMMON_API time_t GetNextTimeWithMonthAndHour(int8 month, int8 hour); // int8 month: 0 (january) to 11 (december)
+
+ AC_COMMON_API uint32 GetSeconds(Seconds time = 0s); // seconds after the minute - [0, 60]
+ AC_COMMON_API uint32 GetMinutes(Seconds time = 0s); // minutes after the hour - [0, 59]
+ AC_COMMON_API uint32 GetHours(Seconds time = 0s); // hours since midnight - [0, 23]
+ AC_COMMON_API uint32 GetDayInWeek(Seconds time = 0s); // days since Sunday - [0, 6]
+ AC_COMMON_API uint32 GetDayInMonth(Seconds time = 0s); // day of the month - [1, 31]
+ AC_COMMON_API uint32 GetDayInYear(Seconds time = 0s); // days since January 1 - [0, 365]
+ AC_COMMON_API uint32 GetMonth(Seconds time = 0s); // months since January - [0, 11]
+ AC_COMMON_API uint32 GetYear(Seconds time = 0s); // years since 1900
+}
+
+AC_COMMON_API struct tm* localtime_r(time_t const* time, struct tm* result);
+
inline TimePoint GetApplicationStartTime()
{
using namespace std::chrono;
@@ -30,6 +81,25 @@ inline TimePoint GetApplicationStartTime()
return ApplicationStartTime;
}
+inline Milliseconds GetTimeMS()
+{
+ using namespace std::chrono;
+
+ return duration_cast<milliseconds>(steady_clock::now() - GetApplicationStartTime());
+}
+
+inline Milliseconds GetMSTimeDiff(Milliseconds oldMSTime, Milliseconds newMSTime)
+{
+ if (oldMSTime > newMSTime)
+ {
+ return oldMSTime - newMSTime;
+ }
+ else
+ {
+ return newMSTime - oldMSTime;
+ }
+}
+
inline uint32 getMSTime()
{
using namespace std::chrono;
@@ -63,12 +133,21 @@ inline uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
return getMSTimeDiff(oldMSTime, getMSTime());
}
+inline Milliseconds GetMSTimeDiffToNow(Milliseconds oldMSTime)
+{
+ return GetMSTimeDiff(oldMSTime, GetTimeMS());
+}
+
+inline Seconds GetEpochTime()
+{
+ using namespace std::chrono;
+ return duration_cast<Seconds>(system_clock::now().time_since_epoch());
+}
+
struct IntervalTimer
{
public:
- IntervalTimer()
-
- = default;
+ IntervalTimer() = default;
void Update(time_t diff)
{
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp
index dc8348452f..cf7a1e3e9b 100644
--- a/src/common/Utilities/Util.cpp
+++ b/src/common/Utilities/Util.cpp
@@ -69,53 +69,6 @@ Tokenizer::Tokenizer(const std::string& src, const char sep, uint32 vectorReserv
}
}
-#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
-struct tm* localtime_r(time_t const* time, struct tm* result)
-{
- localtime_s(result, time);
- return result;
-}
-#endif
-
-tm TimeBreakdown(time_t time)
-{
- tm timeLocal;
- localtime_r(&time, &timeLocal);
- return timeLocal;
-}
-
-time_t LocalTimeToUTCTime(time_t time)
-{
-#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
- return time + _timezone;
-#elif defined(__FreeBSD__)
- struct tm tm;
-
- gmtime_r(&time, &tm);
- tm.tm_isdst = -1;
- return mktime(&tm);
-#else
- return time + timezone;
-#endif
-}
-
-time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime)
-{
- tm timeLocal = TimeBreakdown(time);
- timeLocal.tm_hour = 0;
- timeLocal.tm_min = 0;
- timeLocal.tm_sec = 0;
- time_t midnightLocal = mktime(&timeLocal);
- time_t hourLocal = midnightLocal + hour * HOUR;
-
- if (onlyAfterTime && hourLocal <= time)
- {
- hourLocal += DAY;
- }
-
- return hourLocal;
-}
-
void stripLineInvisibleChars(std::string& str)
{
static std::string const invChars = " \t\7\n";
@@ -288,36 +241,6 @@ uint32 TimeStringToSecs(const std::string& timestring)
return secs;
}
-std::string TimeToTimestampStr(time_t t)
-{
- tm aTm;
- localtime_r(&t, &aTm);
- // YYYY year
- // MM month (2 digits 01-12)
- // DD day (2 digits 01-31)
- // HH hour (2 digits 00-23)
- // MM minutes (2 digits 00-59)
- // SS seconds (2 digits 00-59)
- char buf[20];
- int ret = snprintf(buf, 20, "%04d-%02d-%02d_%02d-%02d-%02d", aTm.tm_year + 1900, aTm.tm_mon + 1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec);
-
- if (ret < 0)
- {
- return std::string("ERROR");
- }
-
- return std::string(buf);
-}
-
-std::string TimeToHumanReadable(time_t t)
-{
- tm time;
- localtime_r(&t, &time);
- char buf[30];
- strftime(buf, 30, "%c", &time);
- return std::string(buf);
-}
-
/// Check if the string is a valid ip address representation
bool IsIPAddress(char const* ipaddress)
{
diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h
index 10092f4b37..ae9ba126ca 100644
--- a/src/common/Utilities/Util.h
+++ b/src/common/Utilities/Util.h
@@ -68,19 +68,12 @@ private:
StorageType m_storage;
};
-struct tm* localtime_r(time_t const* time, struct tm* result);
-time_t LocalTimeToUTCTime(time_t time);
-time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime = true);
-tm TimeBreakdown(time_t t);
-
void stripLineInvisibleChars(std::string& src);
AC_COMMON_API Optional<int32> MoneyStringToMoney(std::string_view moneyString);
std::string secsToTimeString(uint64 timeInSecs, bool shortText = false);
uint32 TimeStringToSecs(const std::string& timestring);
-std::string TimeToTimestampStr(time_t t);
-std::string TimeToHumanReadable(time_t t);
inline void ApplyPercentModFloatVar(float& var, float val, bool apply)
{
diff --git a/src/server/game/Achievements/AchievementMgr.cpp b/src/server/game/Achievements/AchievementMgr.cpp
index 94228f9762..469344f04e 100644
--- a/src/server/game/Achievements/AchievementMgr.cpp
+++ b/src/server/game/Achievements/AchievementMgr.cpp
@@ -417,9 +417,7 @@ bool AchievementCriteriaData::Meets(uint32 criteria_id, Player const* source, Un
return source->GetMapId() == map_id.mapId;
case ACHIEVEMENT_CRITERIA_DATA_TYPE_NTH_BIRTHDAY:
{
- time_t birthday_start = time_t(sWorld->getIntConfig(CONFIG_BIRTHDAY_TIME));
- tm birthday_tm;
- localtime_r(&birthday_start, &birthday_tm);
+ tm birthday_tm = Acore::Time::TimeBreakdown(sWorld->getIntConfig(CONFIG_BIRTHDAY_TIME));
// exactly N birthday
birthday_tm.tm_year += birthday_login.nth_birthday;
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 3f3726f312..dca0c6a64f 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -15,6 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "Player.h"
#include "AccountMgr.h"
#include "AchievementMgr.h"
#include "ArenaSpectator.h"
@@ -31,11 +32,11 @@
#include "CharacterCache.h"
#include "CharacterDatabaseCleaner.h"
#include "Chat.h"
-#include "Config.h"
+#include "CombatLogPackets.h"
#include "Common.h"
#include "ConditionMgr.h"
+#include "Config.h"
#include "CreatureAI.h"
-#include "CombatLogPackets.h"
#include "DatabaseEnv.h"
#include "DisableMgr.h"
#include "Formulas.h"
@@ -50,8 +51,8 @@
#include "GuildMgr.h"
#include "InstanceSaveMgr.h"
#include "InstanceScript.h"
-#include "Language.h"
#include "LFGMgr.h"
+#include "Language.h"
#include "Log.h"
#include "LootItemStorage.h"
#include "MapMgr.h"
@@ -62,11 +63,10 @@
#include "OutdoorPvPMgr.h"
#include "Pet.h"
#include "PetitionMgr.h"
-#include "Player.h"
-#include "QuestDef.h"
#include "QueryHolder.h"
-#include "ReputationMgr.h"
+#include "QuestDef.h"
#include "Realm.h"
+#include "ReputationMgr.h"
#include "ScriptMgr.h"
#include "SocialMgr.h"
#include "Spell.h"
@@ -15172,11 +15172,7 @@ void Player::_LoadBrewOfTheMonth(PreparedQueryResult result)
lastEventId = fields[0].GetUInt32();
}
- time_t curtime = time(nullptr);
- tm localTime;
- localtime_r(&curtime, &localTime);
-
- uint16 month = uint16(localTime.tm_mon);
+ uint16 month = static_cast<uint16>(Acore::Time::GetMonth());
uint16 eventId = month;
if (eventId < 9)
eventId += 3;
diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h
index 6f92ec732b..5355c7f51b 100644
--- a/src/server/game/Entities/Player/Player.h
+++ b/src/server/game/Entities/Player/Player.h
@@ -21,8 +21,8 @@
#include "ArenaTeam.h"
#include "Battleground.h"
#include "CharacterCache.h"
-#include "DatabaseEnvFwd.h"
#include "DBCStores.h"
+#include "DatabaseEnvFwd.h"
#include "GroupReference.h"
#include "InstanceSaveMgr.h"
#include "Item.h"
diff --git a/src/server/game/Entities/Player/PlayerSettings.cpp b/src/server/game/Entities/Player/PlayerSettings.cpp
index 117ea67160..acd82dcd79 100644
--- a/src/server/game/Entities/Player/PlayerSettings.cpp
+++ b/src/server/game/Entities/Player/PlayerSettings.cpp
@@ -15,9 +15,9 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "Tokenize.h"
-#include "StringConvert.h"
#include "Player.h"
+#include "StringConvert.h"
+#include "Tokenize.h"
/*********************************************************/
/*** PLAYER SETTINGS SYSTEM ***/
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index af7239de20..5334c4cb1c 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -40,9 +40,9 @@
#include "InstanceScript.h"
#include "Log.h"
#include "MapMgr.h"
-#include "MovementGenerator.h"
#include "MoveSpline.h"
#include "MoveSplineInit.h"
+#include "MovementGenerator.h"
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "Opcodes.h"
diff --git a/src/server/game/Events/GameEventMgr.cpp b/src/server/game/Events/GameEventMgr.cpp
index 2d4acc183b..d5b363a77e 100644
--- a/src/server/game/Events/GameEventMgr.cpp
+++ b/src/server/game/Events/GameEventMgr.cpp
@@ -1849,7 +1849,7 @@ void GameEventMgr::SetHolidayEventTime(GameEventData& event)
tm timeInfo;
if (singleDate)
{
- localtime_r(&curTime, &timeInfo);
+ timeInfo = Acore::Time::TimeBreakdown(curTime);
timeInfo.tm_year -= 1; // First try last year (event active through New Year)
}
else
@@ -1873,8 +1873,7 @@ void GameEventMgr::SetHolidayEventTime(GameEventData& event)
}
else if (singleDate)
{
- tm tmCopy;
- localtime_r(&curTime, &tmCopy);
+ tm tmCopy = Acore::Time::TimeBreakdown(curTime);
int year = tmCopy.tm_year; // This year
tmCopy = timeInfo;
tmCopy.tm_year = year;
diff --git a/src/server/game/Guilds/Guild.h b/src/server/game/Guilds/Guild.h
index 44337611bf..2d40407dda 100644
--- a/src/server/game/Guilds/Guild.h
+++ b/src/server/game/Guilds/Guild.h
@@ -20,8 +20,8 @@
#include "Item.h"
#include "ObjectMgr.h"
-#include "Player.h"
#include "Optional.h"
+#include "Player.h"
#include "World.h"
#include "WorldPacket.h"
#include <set>
diff --git a/src/server/game/Handlers/BankHandler.cpp b/src/server/game/Handlers/BankHandler.cpp
index 946ae532ac..42f487ba84 100644
--- a/src/server/game/Handlers/BankHandler.cpp
+++ b/src/server/game/Handlers/BankHandler.cpp
@@ -16,8 +16,8 @@
*/
#include "BankPackets.h"
-#include "Item.h"
#include "DBCStores.h"
+#include "Item.h"
#include "Log.h"
#include "Opcodes.h"
#include "Player.h"
diff --git a/src/server/game/Scripting/ScriptDefines/CommandScript.cpp b/src/server/game/Scripting/ScriptDefines/CommandScript.cpp
index 7cd4e3728f..e0b7c0afc8 100644
--- a/src/server/game/Scripting/ScriptDefines/CommandScript.cpp
+++ b/src/server/game/Scripting/ScriptDefines/CommandScript.cpp
@@ -15,8 +15,8 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "ScriptMgr.h"
#include "Chat.h"
+#include "ScriptMgr.h"
Acore::ChatCommands::ChatCommandTable ScriptMgr::GetChatCommands()
{
diff --git a/src/server/game/Scripting/ScriptDefines/GlobalScript.cpp b/src/server/game/Scripting/ScriptDefines/GlobalScript.cpp
index 5909687644..2f63c82f64 100644
--- a/src/server/game/Scripting/ScriptDefines/GlobalScript.cpp
+++ b/src/server/game/Scripting/ScriptDefines/GlobalScript.cpp
@@ -15,9 +15,9 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "Player.h"
#include "ScriptMgr.h"
#include "ScriptMgrMacros.h"
-#include "Player.h"
void ScriptMgr::OnGlobalItemDelFromDB(CharacterDatabaseTransaction trans, ObjectGuid::LowType itemGuid)
{
diff --git a/src/server/game/Scripting/ScriptDefines/OutdoorPvPScript.cpp b/src/server/game/Scripting/ScriptDefines/OutdoorPvPScript.cpp
index c1332abb17..f0c4ea871b 100644
--- a/src/server/game/Scripting/ScriptDefines/OutdoorPvPScript.cpp
+++ b/src/server/game/Scripting/ScriptDefines/OutdoorPvPScript.cpp
@@ -15,8 +15,8 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "ScriptMgr.h"
#include "OutdoorPvPMgr.h"
+#include "ScriptMgr.h"
OutdoorPvP* ScriptMgr::CreateOutdoorPvP(OutdoorPvPData const* data)
{
diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp
index 361e2ef5f9..f26d017fbd 100644
--- a/src/server/game/Scripting/ScriptMgr.cpp
+++ b/src/server/game/Scripting/ScriptMgr.cpp
@@ -16,11 +16,11 @@
*/
#include "ScriptMgr.h"
+#include "InstanceScript.h"
+#include "ScriptSystem.h"
+#include "SmartAI.h"
#include "SpellMgr.h"
#include "UnitAI.h"
-#include "SmartAI.h"
-#include "ScriptSystem.h"
-#include "InstanceScript.h"
namespace
{
diff --git a/src/server/game/Server/Packets/AllPackets.h b/src/server/game/Server/Packets/AllPackets.h
index 598fcb0349..694037e2b8 100644
--- a/src/server/game/Server/Packets/AllPackets.h
+++ b/src/server/game/Server/Packets/AllPackets.h
@@ -18,13 +18,13 @@
#ifndef AllPackets_h__
#define AllPackets_h__
-#include "CombatLogPackets.h"
-#include "ChatPackets.h"
+#include "BankPackets.h"
#include "CharacterPackets.h"
+#include "ChatPackets.h"
+#include "CombatLogPackets.h"
+#include "GuildPackets.h"
#include "MiscPackets.h"
-#include "WorldStatePackets.h"
#include "TotemPackets.h"
-#include "BankPackets.h"
-#include "GuildPackets.h"
+#include "WorldStatePackets.h"
#endif // AllPackets_h__
diff --git a/src/server/game/Server/Packets/BankPackets.h b/src/server/game/Server/Packets/BankPackets.h
index e7b21b2837..707680579a 100644
--- a/src/server/game/Server/Packets/BankPackets.h
+++ b/src/server/game/Server/Packets/BankPackets.h
@@ -18,8 +18,8 @@
#ifndef BankPackets_h__
#define BankPackets_h__
-#include "Packet.h"
#include "ObjectGuid.h"
+#include "Packet.h"
namespace WorldPackets
{
diff --git a/src/server/game/Server/Packets/ChatPackets.h b/src/server/game/Server/Packets/ChatPackets.h
index 2643189010..aec83b167c 100644
--- a/src/server/game/Server/Packets/ChatPackets.h
+++ b/src/server/game/Server/Packets/ChatPackets.h
@@ -18,8 +18,8 @@
#ifndef ChatPackets_h__
#define ChatPackets_h__
-#include "Packet.h"
#include "ObjectGuid.h"
+#include "Packet.h"
namespace WorldPackets
{
diff --git a/src/server/game/Server/Packets/GuildPackets.h b/src/server/game/Server/Packets/GuildPackets.h
index 8d57839c3a..ee68324af7 100644
--- a/src/server/game/Server/Packets/GuildPackets.h
+++ b/src/server/game/Server/Packets/GuildPackets.h
@@ -17,12 +17,12 @@
#ifndef GuildPackets_h__
#define GuildPackets_h__
-#include "Packet.h"
#include "Guild.h"
#include "ObjectGuid.h"
+#include "Packet.h"
#include "PacketUtilities.h"
-#include <boost/container/static_vector.hpp>
#include <array>
+#include <boost/container/static_vector.hpp>
namespace WorldPackets
{
diff --git a/src/server/game/Server/Packets/TotemPackets.h b/src/server/game/Server/Packets/TotemPackets.h
index 69cb03311f..98e559562b 100644
--- a/src/server/game/Server/Packets/TotemPackets.h
+++ b/src/server/game/Server/Packets/TotemPackets.h
@@ -18,8 +18,8 @@
#ifndef TotemPackets_h__
#define TotemPackets_h__
-#include "Packet.h"
#include "ObjectGuid.h"
+#include "Packet.h"
namespace WorldPackets
{
diff --git a/src/server/game/Server/Protocol/Opcodes.cpp b/src/server/game/Server/Protocol/Opcodes.cpp
index a38394839d..dfcf2c3ab5 100644
--- a/src/server/game/Server/Protocol/Opcodes.cpp
+++ b/src/server/game/Server/Protocol/Opcodes.cpp
@@ -17,10 +17,10 @@
#include "Opcodes.h"
#include "Log.h"
+#include "Packets/AllPackets.h"
#include "WorldSession.h"
#include <iomanip>
#include <sstream>
-#include "Packets/AllPackets.h"
template<class PacketClass, void(WorldSession::* HandlerFunction)(PacketClass&)>
class PacketHandler : public ClientOpcodeHandler
diff --git a/src/server/game/Weather/Weather.cpp b/src/server/game/Weather/Weather.cpp
index f588b85b23..5c59580fbe 100644
--- a/src/server/game/Weather/Weather.cpp
+++ b/src/server/game/Weather/Weather.cpp
@@ -20,12 +20,12 @@
*/
#include "Weather.h"
+#include "MiscPackets.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "Util.h"
#include "World.h"
#include "WorldPacket.h"
-#include "MiscPackets.h"
/// Create the Weather object
Weather::Weather(uint32 zone, WeatherData const* weatherChances)
@@ -89,10 +89,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();
- struct tm ltime;
- localtime_r(&gtime, &ltime);
- uint32 season = ((ltime.tm_yday - 78 + 365) / 91) % 4;
+ uint32 season = ((Acore::Time::GetDayInYear() - 78 + 365) / 91) % 4;
static char const* seasonName[WEATHER_SEASONS] = { "spring", "summer", "fall", "winter" };
LOG_DEBUG("weather", "Generating a change in %s weather for zone %u.", seasonName[season], m_zone);
diff --git a/src/server/game/Weather/WeatherMgr.cpp b/src/server/game/Weather/WeatherMgr.cpp
index c39bb043f2..0728b69dbb 100644
--- a/src/server/game/Weather/WeatherMgr.cpp
+++ b/src/server/game/Weather/WeatherMgr.cpp
@@ -21,12 +21,12 @@
#include "WeatherMgr.h"
#include "Log.h"
+#include "MiscPackets.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "Weather.h"
#include "WorldPacket.h"
#include "WorldSession.h"
-#include "MiscPackets.h"
#include <memory>
namespace WeatherMgr
diff --git a/src/server/game/World/IWorld.h b/src/server/game/World/IWorld.h
index 6cd79cbeb1..2bfb3fb696 100644
--- a/src/server/game/World/IWorld.h
+++ b/src/server/game/World/IWorld.h
@@ -587,8 +587,6 @@ public:
[[nodiscard]] virtual uint32 GetCleaningFlags() const = 0;
virtual void SetCleaningFlags(uint32 flags) = 0;
virtual void ResetEventSeasonalQuests(uint16 event_id) = 0;
- virtual time_t GetNextTimeWithDayAndHour(int8 dayOfWeek, int8 hour) = 0;
- virtual time_t GetNextTimeWithMonthAndHour(int8 month, int8 hour) = 0;
[[nodiscard]] virtual std::string const& GetRealmName() const = 0;
virtual void SetRealmName(std::string name) = 0;
virtual void RemoveOldCorpses() = 0;
diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp
index 90f52aed24..6133e53f9c 100644
--- a/src/server/game/World/World.cpp
+++ b/src/server/game/World/World.cpp
@@ -75,6 +75,7 @@
#include "SkillExtraItems.h"
#include "SmartAI.h"
#include "SpellMgr.h"
+#include "TaskScheduler.h"
#include "TicketMgr.h"
#include "Transport.h"
#include "TransportMgr.h"
@@ -89,7 +90,6 @@
#include "WhoListCacheMgr.h"
#include "WorldPacket.h"
#include "WorldSession.h"
-#include "TaskScheduler.h"
#include <boost/asio/ip/address.hpp>
#include <cmath>
@@ -3044,55 +3044,10 @@ void World::_UpdateRealmCharCount(PreparedQueryResult resultCharCount)
}
}
-// int8 dayOfWeek: 0 (sunday) to 6 (saturday)
-time_t World::GetNextTimeWithDayAndHour(int8 dayOfWeek, int8 hour)
-{
- if (hour < 0 || hour > 23)
- hour = 0;
- time_t curr = time(nullptr);
- tm localTm;
- localtime_r(&curr, &localTm);
- localTm.tm_hour = hour;
- localTm.tm_min = 0;
- localTm.tm_sec = 0;
- uint32 add;
- if (dayOfWeek < 0 || dayOfWeek > 6)
- dayOfWeek = (localTm.tm_wday + 1) % 7;
- if (localTm.tm_wday >= dayOfWeek)
- add = (7 - (localTm.tm_wday - dayOfWeek)) * DAY;
- else
- add = (dayOfWeek - localTm.tm_wday) * DAY;
- return mktime(&localTm) + add;
-}
-
-// int8 month: 0 (january) to 11 (december)
-time_t World::GetNextTimeWithMonthAndHour(int8 month, int8 hour)
-{
- if (hour < 0 || hour > 23)
- hour = 0;
- time_t curr = time(nullptr);
- tm localTm;
- localtime_r(&curr, &localTm);
- localTm.tm_mday = 1;
- localTm.tm_hour = hour;
- localTm.tm_min = 0;
- localTm.tm_sec = 0;
- if (month < 0 || month > 11)
- {
- month = (localTm.tm_mon + 1) % 12;
- if (month == 0)
- localTm.tm_year += 1;
- }
- else if (localTm.tm_mon >= month)
- localTm.tm_year += 1;
- localTm.tm_mon = month;
- return mktime(&localTm);
-}
-
void World::InitWeeklyQuestResetTime()
{
time_t wstime = time_t(sWorld->getWorldState(WS_WEEKLY_QUEST_RESET_TIME));
- m_NextWeeklyQuestReset = wstime ? wstime : GetNextTimeWithDayAndHour(4, 6);
+ m_NextWeeklyQuestReset = wstime ? wstime : Acore::Time::GetNextTimeWithDayAndHour(4, 6);
if (!wstime)
sWorld->setWorldState(WS_WEEKLY_QUEST_RESET_TIME, uint64(m_NextWeeklyQuestReset));
}
@@ -3100,7 +3055,7 @@ void World::InitWeeklyQuestResetTime()
void World::InitDailyQuestResetTime()
{
time_t wstime = time_t(sWorld->getWorldState(WS_DAILY_QUEST_RESET_TIME));
- m_NextDailyQuestReset = wstime ? wstime : GetNextTimeWithDayAndHour(-1, 6);
+ m_NextDailyQuestReset = wstime ? wstime : Acore::Time::GetNextTimeWithDayAndHour(-1, 6);
if (!wstime)
sWorld->setWorldState(WS_DAILY_QUEST_RESET_TIME, uint64(m_NextDailyQuestReset));
}
@@ -3108,7 +3063,7 @@ void World::InitDailyQuestResetTime()
void World::InitMonthlyQuestResetTime()
{
time_t wstime = time_t(sWorld->getWorldState(WS_MONTHLY_QUEST_RESET_TIME));
- m_NextMonthlyQuestReset = wstime ? wstime : GetNextTimeWithMonthAndHour(-1, 6);
+ m_NextMonthlyQuestReset = wstime ? wstime : Acore::Time::GetNextTimeWithMonthAndHour(-1, 6);
if (!wstime)
sWorld->setWorldState(WS_MONTHLY_QUEST_RESET_TIME, uint64(m_NextMonthlyQuestReset));
}
@@ -3116,7 +3071,7 @@ void World::InitMonthlyQuestResetTime()
void World::InitRandomBGResetTime()
{
time_t wstime = time_t(sWorld->getWorldState(WS_BG_DAILY_RESET_TIME));
- m_NextRandomBGReset = wstime ? wstime : GetNextTimeWithDayAndHour(-1, 6);
+ m_NextRandomBGReset = wstime ? wstime : Acore::Time::GetNextTimeWithDayAndHour(-1, 6);
if (!wstime)
sWorld->setWorldState(WS_BG_DAILY_RESET_TIME, uint64(m_NextRandomBGReset));
}
@@ -3125,7 +3080,7 @@ void World::InitCalendarOldEventsDeletionTime()
{
time_t now = time(nullptr);
time_t currentDeletionTime = getWorldState(WS_DAILY_CALENDAR_DELETION_OLD_EVENTS_TIME);
- time_t nextDeletionTime = currentDeletionTime ? currentDeletionTime : GetNextTimeWithDayAndHour(-1, getIntConfig(CONFIG_CALENDAR_DELETE_OLD_EVENTS_HOUR));
+ time_t nextDeletionTime = currentDeletionTime ? currentDeletionTime : Acore::Time::GetNextTimeWithDayAndHour(-1, getIntConfig(CONFIG_CALENDAR_DELETE_OLD_EVENTS_HOUR));
// If the reset time saved in the worldstate is before now it means the server was offline when the reset was supposed to occur.
// In this case we set the reset time in the past and next world update will do the reset and schedule next one in the future.
@@ -3141,7 +3096,7 @@ void World::InitCalendarOldEventsDeletionTime()
void World::InitGuildResetTime()
{
time_t wstime = time_t(getWorldState(WS_GUILD_DAILY_RESET_TIME));
- m_NextGuildReset = wstime ? wstime : GetNextTimeWithDayAndHour(-1, 6);
+ m_NextGuildReset = wstime ? wstime : Acore::Time::GetNextTimeWithDayAndHour(-1, 6);
if (!wstime)
sWorld->setWorldState(WS_GUILD_DAILY_RESET_TIME, uint64(m_NextGuildReset));
}
@@ -3155,7 +3110,7 @@ void World::ResetDailyQuests()
if (itr->second->GetPlayer())
itr->second->GetPlayer()->ResetDailyQuestStatus();
- m_NextDailyQuestReset = GetNextTimeWithDayAndHour(-1, 6);
+ m_NextDailyQuestReset = Acore::Time::GetNextTimeWithDayAndHour(-1, 6);
sWorld->setWorldState(WS_DAILY_QUEST_RESET_TIME, uint64(m_NextDailyQuestReset));
// change available dailies
@@ -3190,7 +3145,7 @@ void World::ResetWeeklyQuests()
if (itr->second->GetPlayer())
itr->second->GetPlayer()->ResetWeeklyQuestStatus();
- m_NextWeeklyQuestReset = GetNextTimeWithDayAndHour(4, 6);
+ m_NextWeeklyQuestReset = Acore::Time::GetNextTimeWithDayAndHour(4, 6);
sWorld->setWorldState(WS_WEEKLY_QUEST_RESET_TIME, uint64(m_NextWeeklyQuestReset));
// change available weeklies
@@ -3208,7 +3163,7 @@ void World::ResetMonthlyQuests()
if (itr->second->GetPlayer())
itr->second->GetPlayer()->ResetMonthlyQuestStatus();
- m_NextMonthlyQuestReset = GetNextTimeWithMonthAndHour(-1, 6);
+ m_NextMonthlyQuestReset = Acore::Time::GetNextTimeWithMonthAndHour(-1, 6);
sWorld->setWorldState(WS_MONTHLY_QUEST_RESET_TIME, uint64(m_NextMonthlyQuestReset));
}
@@ -3234,7 +3189,7 @@ void World::ResetRandomBG()
if (itr->second->GetPlayer())
itr->second->GetPlayer()->SetRandomWinner(false);
- m_NextRandomBGReset = GetNextTimeWithDayAndHour(-1, 6);
+ m_NextRandomBGReset = Acore::Time::GetNextTimeWithDayAndHour(-1, 6);
sWorld->setWorldState(WS_BG_DAILY_RESET_TIME, uint64(m_NextRandomBGReset));
}
@@ -3251,7 +3206,7 @@ void World::ResetGuildCap()
{
LOG_INFO("server.worldserver", "Guild Daily Cap reset.");
- m_NextGuildReset = GetNextTimeWithDayAndHour(-1, 6);
+ m_NextGuildReset = Acore::Time::GetNextTimeWithDayAndHour(-1, 6);
sWorld->setWorldState(WS_GUILD_DAILY_RESET_TIME, uint64(m_NextGuildReset));
sGuildMgr->ResetTimes();
diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h
index 82ccdd11b0..9b2d91ab2a 100644
--- a/src/server/game/World/World.h
+++ b/src/server/game/World/World.h
@@ -365,9 +365,6 @@ public:
void SetCleaningFlags(uint32 flags) override { m_CleaningFlags = flags; }
void ResetEventSeasonalQuests(uint16 event_id) override;
- time_t GetNextTimeWithDayAndHour(int8 dayOfWeek, int8 hour) override; // pussywizard
- time_t GetNextTimeWithMonthAndHour(int8 month, int8 hour) override; // pussywizard
-
[[nodiscard]] std::string const& GetRealmName() const override { return _realmName; } // pussywizard
void SetRealmName(std::string name) override { _realmName = name; } // pussywizard
diff --git a/src/server/scripts/Commands/cs_ban.cpp b/src/server/scripts/Commands/cs_ban.cpp
index 064224ccef..849287da11 100644
--- a/src/server/scripts/Commands/cs_ban.cpp
+++ b/src/server/scripts/Commands/cs_ban.cpp
@@ -474,9 +474,7 @@ public:
Field* fields2 = banInfo->Fetch();
do
{
- time_t timeBan = time_t(fields2[0].GetUInt32());
- tm tmBan;
- localtime_r(&timeBan, &tmBan);
+ tm tmBan = Acore::Time::TimeBreakdown(fields2[0].GetUInt32());
if (fields2[0].GetUInt32() == fields2[1].GetUInt32())
{
@@ -486,9 +484,7 @@ public:
}
else
{
- time_t timeUnban = time_t(fields2[1].GetUInt32());
- tm tmUnban;
- localtime_r(&timeUnban, &tmUnban);
+ tm tmUnban = Acore::Time::TimeBreakdown(fields2[1].GetUInt32());
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,
@@ -562,9 +558,7 @@ public:
Field* banFields = banInfo->Fetch();
do
{
- time_t timeBan = time_t(banFields[0].GetUInt32());
- tm tmBan;
- localtime_r(&timeBan, &tmBan);
+ tm tmBan = Acore::Time::TimeBreakdown(banFields[0].GetUInt32());
if (banFields[0].GetUInt32() == banFields[1].GetUInt32())
{
@@ -574,9 +568,7 @@ public:
}
else
{
- time_t timeUnban = time_t(banFields[1].GetUInt32());
- tm tmUnban;
- localtime_r(&timeUnban, &tmUnban);
+ tm tmUnban = Acore::Time::TimeBreakdown(banFields[1].GetUInt32());
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,
@@ -640,9 +632,7 @@ public:
{
handler->SendSysMessage("-------------------------------------------------------------------------------");
Field* fields = result->Fetch();
- time_t timeBan = time_t(fields[1].GetUInt32());
- tm tmBan;
- localtime_r(&timeBan, &tmBan);
+ tm tmBan = Acore::Time::TimeBreakdown(fields[1].GetUInt32());
if (fields[1].GetUInt32() == fields[2].GetUInt32())
{
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
@@ -651,9 +641,7 @@ public:
}
else
{
- time_t timeUnban = time_t(fields[2].GetUInt32());
- tm tmUnban;
- localtime_r(&timeUnban, &tmUnban);
+ tm tmUnban = Acore::Time::TimeBreakdown(fields[2].GetUInt32());
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,
diff --git a/src/server/scripts/Commands/cs_character.cpp b/src/server/scripts/Commands/cs_character.cpp
index 8348fb0aff..9563b572cf 100644
--- a/src/server/scripts/Commands/cs_character.cpp
+++ b/src/server/scripts/Commands/cs_character.cpp
@@ -33,6 +33,7 @@ EndScriptData */
#include "PlayerDump.h"
#include "ReputationMgr.h"
#include "ScriptMgr.h"
+#include "Timer.h"
#include "World.h"
#include "WorldSession.h"
@@ -182,7 +183,7 @@ public:
for (DeletedInfoList::const_iterator itr = foundList.begin(); itr != foundList.end(); ++itr)
{
- std::string dateStr = TimeToTimestampStr(itr->deleteDate);
+ std::string dateStr = Acore::Time::TimeToTimestampStr(Seconds(itr->deleteDate));
if (!handler->GetSession())
handler->PSendSysMessage(LANG_CHARACTER_DELETED_LIST_LINE_CONSOLE,
diff --git a/src/server/scripts/Commands/cs_event.cpp b/src/server/scripts/Commands/cs_event.cpp
index 3c4949e51a..4dc64ce1a7 100644
--- a/src/server/scripts/Commands/cs_event.cpp
+++ b/src/server/scripts/Commands/cs_event.cpp
@@ -27,6 +27,7 @@
#include "Language.h"
#include "Player.h"
#include "ScriptMgr.h"
+#include "Timer.h"
using namespace Acore::ChatCommands;
@@ -111,12 +112,12 @@ public:
bool active = activeEvents.find(eventId) != activeEvents.end();
char const* activeStr = active ? handler->GetAcoreString(LANG_ACTIVE) : "";
- std::string startTimeStr = TimeToTimestampStr(eventData.start);
- std::string endTimeStr = TimeToTimestampStr(eventData.end);
+ std::string startTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.start));
+ 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 ? TimeToTimestampStr(time(nullptr) + delay) : "-";
+ std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? Acore::Time::TimeToTimestampStr(Seconds(time(nullptr) + delay)) : "-";
std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE, true);
std::string lengthStr = secsToTimeString(eventData.length * MINUTE, true);
diff --git a/src/server/scripts/Commands/cs_gear.cpp b/src/server/scripts/Commands/cs_gear.cpp
index d3783e9ff4..df53b59657 100644
--- a/src/server/scripts/Commands/cs_gear.cpp
+++ b/src/server/scripts/Commands/cs_gear.cpp
@@ -15,11 +15,11 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "ScriptMgr.h"
#include "Chat.h"
#include "Language.h"
#include "Log.h"
#include "Player.h"
+#include "ScriptMgr.h"
#include "WorldSession.h"
using namespace Acore::ChatCommands;
diff --git a/src/server/scripts/Commands/cs_group.cpp b/src/server/scripts/Commands/cs_group.cpp
index d7c192be9a..e2553dd22c 100644
--- a/src/server/scripts/Commands/cs_group.cpp
+++ b/src/server/scripts/Commands/cs_group.cpp
@@ -15,12 +15,12 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "ScriptMgr.h"
#include "Chat.h"
#include "DatabaseEnv.h"
#include "GroupMgr.h"
#include "Language.h"
#include "Player.h"
+#include "ScriptMgr.h"
using namespace Acore::ChatCommands;
diff --git a/src/server/scripts/Commands/cs_guild.cpp b/src/server/scripts/Commands/cs_guild.cpp
index 44222a890e..f89b819918 100644
--- a/src/server/scripts/Commands/cs_guild.cpp
+++ b/src/server/scripts/Commands/cs_guild.cpp
@@ -231,14 +231,7 @@ public:
handler->PSendSysMessage(LANG_GUILD_INFO_GUILD_MASTER, guildMasterName.c_str(), guild->GetLeaderGUID().GetCounter()); // Guild Master
}
- // Format creation date
- char createdDateStr[20];
- time_t createdDate = guild->GetCreatedDate();
- tm 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
+ handler->PSendSysMessage(LANG_GUILD_INFO_CREATION_DATE, Acore::Time::TimeToHumanReadable(Seconds(guild->GetCreatedDate())).c_str()); // Creation Date
handler->PSendSysMessage(LANG_GUILD_INFO_MEMBER_COUNT, guild->GetMemberCount()); // Number of Members
handler->PSendSysMessage(LANG_GUILD_INFO_BANK_GOLD, guild->GetTotalBankMoney() / 100 / 100); // Bank Gold (in gold coins)
handler->PSendSysMessage(LANG_GUILD_INFO_MOTD, guild->GetMOTD().c_str()); // Message of the day
diff --git a/src/server/scripts/Commands/cs_inventory.cpp b/src/server/scripts/Commands/cs_inventory.cpp
index b5040f5ca9..649fe310cc 100644
--- a/src/server/scripts/Commands/cs_inventory.cpp
+++ b/src/server/scripts/Commands/cs_inventory.cpp
@@ -15,10 +15,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "ScriptMgr.h"
#include "Chat.h"
#include "Language.h"
#include "Player.h"
+#include "ScriptMgr.h"
#include "WorldSession.h"
constexpr std::array<const char*, MAX_ITEM_SUBCLASS_CONTAINER> bagSpecsToString =
diff --git a/src/server/scripts/Commands/cs_item.cpp b/src/server/scripts/Commands/cs_item.cpp
index a248121bd6..248b4a186e 100644
--- a/src/server/scripts/Commands/cs_item.cpp
+++ b/src/server/scripts/Commands/cs_item.cpp
@@ -23,12 +23,12 @@ Category: commandscripts
EndScriptData */
#include "Chat.h"
-#include "DatabaseEnv.h"
#include "DBCStores.h"
+#include "DatabaseEnv.h"
+#include "Language.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ScriptMgr.h"
-#include "Language.h"
using namespace Acore::ChatCommands;
diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp
index da19d40a06..de1722e075 100644
--- a/src/server/scripts/Commands/cs_misc.cpp
+++ b/src/server/scripts/Commands/cs_misc.cpp
@@ -39,8 +39,8 @@
#include "ScriptMgr.h"
#include "SpellAuras.h"
#include "TargetedMovementGenerator.h"
-#include "WeatherMgr.h"
#include "Tokenize.h"
+#include "WeatherMgr.h"
// TODO: this import is not necessary for compilation and marked as unused by the IDE
// however, for some reasons removing it would cause a damn linking issue
@@ -2556,17 +2556,7 @@ public:
do
{
Field* fields = result->Fetch();
-
- // we have to manually set the string for mutedate
- time_t sqlTime = fields[0].GetUInt32();
- tm timeInfo;
- char buffer[80];
-
- // set it to string
- 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());
+ handler->PSendSysMessage(LANG_COMMAND_MUTEHISTORY_OUTPUT, Acore::Time::TimeToHumanReadable(Seconds(fields[0].GetUInt32())).c_str(), fields[1].GetUInt32(), fields[2].GetCString(), fields[3].GetCString());
} while (result->NextRow());
return true;
diff --git a/src/server/scripts/Commands/cs_pet.cpp b/src/server/scripts/Commands/cs_pet.cpp
index 0863eec746..45e922b671 100644
--- a/src/server/scripts/Commands/cs_pet.cpp
+++ b/src/server/scripts/Commands/cs_pet.cpp
@@ -15,15 +15,15 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "ScriptMgr.h"
#include "Chat.h"
#include "Language.h"
#include "Log.h"
#include "ObjectMgr.h"
#include "Pet.h"
#include "Player.h"
-#include "SpellMgr.h"
+#include "ScriptMgr.h"
#include "SpellInfo.h"
+#include "SpellMgr.h"
#include "WorldSession.h"
using namespace Acore::ChatCommands;
diff --git a/src/server/scripts/Commands/cs_send.cpp b/src/server/scripts/Commands/cs_send.cpp
index bf15904bbb..65133672b5 100644
--- a/src/server/scripts/Commands/cs_send.cpp
+++ b/src/server/scripts/Commands/cs_send.cpp
@@ -15,7 +15,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "ScriptMgr.h"
#include "Chat.h"
#include "DatabaseEnv.h"
#include "Item.h"
@@ -24,6 +23,7 @@
#include "ObjectMgr.h"
#include "Pet.h"
#include "Player.h"
+#include "ScriptMgr.h"
#include "Tokenize.h"
using namespace Acore::ChatCommands;
diff --git a/src/server/scripts/Commands/cs_tele.cpp b/src/server/scripts/Commands/cs_tele.cpp
index 22ce06da48..f8ebdaf80b 100644
--- a/src/server/scripts/Commands/cs_tele.cpp
+++ b/src/server/scripts/Commands/cs_tele.cpp
@@ -23,8 +23,8 @@ Category: commandscripts
EndScriptData */
#include "Chat.h"
-#include "DatabaseEnv.h"
#include "DBCStores.h"
+#include "DatabaseEnv.h"
#include "Group.h"
#include "Language.h"
#include "MapMgr.h"
diff --git a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_eviscerator.cpp b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_eviscerator.cpp
index 6790e20699..5146adac18 100644
--- a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_eviscerator.cpp
+++ b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_eviscerator.cpp
@@ -15,9 +15,9 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "blackrock_depths.h"
-#include "ScriptedCreature.h"
#include "ScriptMgr.h"
+#include "ScriptedCreature.h"
+#include "blackrock_depths.h"
enum Spells
{
diff --git a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_hedrum.cpp b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_hedrum.cpp
index 0ab186a031..a7f384f47f 100644
--- a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_hedrum.cpp
+++ b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_hedrum.cpp
@@ -15,9 +15,9 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "blackrock_depths.h"
-#include "ScriptedCreature.h"
#include "ScriptMgr.h"
+#include "ScriptedCreature.h"
+#include "blackrock_depths.h"
enum Spells
{
diff --git a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_okthor.cpp b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_okthor.cpp
index e96eec3f02..38018f279a 100644
--- a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_okthor.cpp
+++ b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/boss_okthor.cpp
@@ -15,9 +15,9 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "blackrock_depths.h"
-#include "ScriptedCreature.h"
#include "ScriptMgr.h"
+#include "ScriptedCreature.h"
+#include "blackrock_depths.h"
enum Spells
{
diff --git a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/boss_mor_grayhoof.cpp b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/boss_mor_grayhoof.cpp
index 49c100befe..8687387ab6 100644
--- a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/boss_mor_grayhoof.cpp
+++ b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/boss_mor_grayhoof.cpp
@@ -17,8 +17,8 @@
#include "ScriptMgr.h"
#include "ScriptedCreature.h"
-#include "blackrock_spire.h"
#include "TaskScheduler.h"
+#include "blackrock_spire.h"
enum Texts
{
diff --git a/src/server/scripts/EasternKingdoms/Scholomance/boss_kormok.cpp b/src/server/scripts/EasternKingdoms/Scholomance/boss_kormok.cpp
index f4699217db..7396158806 100644
--- a/src/server/scripts/EasternKingdoms/Scholomance/boss_kormok.cpp
+++ b/src/server/scripts/EasternKingdoms/Scholomance/boss_kormok.cpp
@@ -16,10 +16,10 @@
*/
#include "ScriptMgr.h"
-#include "scholomance.h"
#include "ScriptedCreature.h"
#include "SpellScript.h"
#include "TaskScheduler.h"
+#include "scholomance.h"
enum Spells
{
diff --git a/src/server/scripts/EasternKingdoms/Stratholme/boss_jarien_and_sothos.cpp b/src/server/scripts/EasternKingdoms/Stratholme/boss_jarien_and_sothos.cpp
index c890bb1449..933dee3b30 100644
--- a/src/server/scripts/EasternKingdoms/Stratholme/boss_jarien_and_sothos.cpp
+++ b/src/server/scripts/EasternKingdoms/Stratholme/boss_jarien_and_sothos.cpp
@@ -17,8 +17,8 @@
#include "ScriptMgr.h"
#include "ScriptedCreature.h"
-#include "stratholme.h"
#include "TaskScheduler.h"
+#include "stratholme.h"
enum Texts
{
diff --git a/src/server/scripts/EasternKingdoms/zone_elwynn_forest.cpp b/src/server/scripts/EasternKingdoms/zone_elwynn_forest.cpp
index 35c3874bad..081f7b8370 100644
--- a/src/server/scripts/EasternKingdoms/zone_elwynn_forest.cpp
+++ b/src/server/scripts/EasternKingdoms/zone_elwynn_forest.cpp
@@ -17,12 +17,12 @@
#include "Common.h"
#include "CreatureGroups.h"
-#include "ScriptedCreature.h"
-#include "ScriptedEscortAI.h"
-#include "ScriptMgr.h"
+#include "GameEventMgr.h"
#include "MotionMaster.h"
#include "ObjectAccessor.h"
-#include "GameEventMgr.h"
+#include "ScriptMgr.h"
+#include "ScriptedCreature.h"
+#include "ScriptedEscortAI.h"
enum COG_Paths
{
diff --git a/src/server/scripts/EasternKingdoms/zone_ghostlands.cpp b/src/server/scripts/EasternKingdoms/zone_ghostlands.cpp
index 02bfc34b98..091e089089 100644
--- a/src/server/scripts/EasternKingdoms/zone_ghostlands.cpp
+++ b/src/server/scripts/EasternKingdoms/zone_ghostlands.cpp
@@ -15,12 +15,12 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "ObjectGuid.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "ScriptedCreature.h"
#include "ScriptedEscortAI.h"
#include "ScriptedGossip.h"
-#include "ObjectGuid.h"
/*######
## npc_ranger_lilatha
diff --git a/src/server/scripts/Events/brewfest.cpp b/src/server/scripts/Events/brewfest.cpp
index c1ed017222..55b46485e4 100644
--- a/src/server/scripts/Events/brewfest.cpp
+++ b/src/server/scripts/Events/brewfest.cpp
@@ -532,11 +532,9 @@ struct npc_dark_iron_attack_generator : public ScriptedAI
bool AllowStart()
{
- time_t curtime = time(nullptr);
- tm strDate;
- localtime_r(&curtime, &strDate);
+ auto minutes = Acore::Time::GetMinutes();
- if (strDate.tm_min == 0 || strDate.tm_min == 30)
+ if (!minutes || minutes == 30)
return true;
return false;
diff --git a/src/server/scripts/Kalimdor/DireMaul/boss_isalien.cpp b/src/server/scripts/Kalimdor/DireMaul/boss_isalien.cpp
index 0a0d61fe50..feba8988ed 100644
--- a/src/server/scripts/Kalimdor/DireMaul/boss_isalien.cpp
+++ b/src/server/scripts/Kalimdor/DireMaul/boss_isalien.cpp
@@ -17,8 +17,8 @@
#include "ScriptMgr.h"
#include "ScriptedCreature.h"
-#include "dire_maul.h"
#include "TaskScheduler.h"
+#include "dire_maul.h"
enum Texts
{
diff --git a/src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_ouro.cpp b/src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_ouro.cpp
index 0effad174c..a3955255ab 100644
--- a/src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_ouro.cpp
+++ b/src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_ouro.cpp
@@ -22,8 +22,8 @@ SDComment: No model for submerging. Currently just invisible.
SDCategory: Temple of Ahn'Qiraj
EndScriptData */
-#include "ScriptedCreature.h"
#include "ScriptMgr.h"
+#include "ScriptedCreature.h"
#include "temple_of_ahnqiraj.h"
enum Spells
diff --git a/src/server/scripts/World/go_scripts.cpp b/src/server/scripts/World/go_scripts.cpp
index 8ac5ce9975..95a7c806da 100644
--- a/src/server/scripts/World/go_scripts.cpp
+++ b/src/server/scripts/World/go_scripts.cpp
@@ -1890,11 +1890,8 @@ public:
{
case EVENT_TIME:
{
- // Get how many times it should ring
- time_t t = time(nullptr);
- tm local_tm;
tzset(); // set timezone for localtime_r() -> fix issues due to daylight time
- localtime_r(&t, &local_tm);
+ tm local_tm = Acore::Time::TimeBreakdown();
uint8 _rings = (local_tm.tm_hour) % 12;
_rings = (_rings == 0) ? 12 : _rings; // 00:00 and 12:00
diff --git a/src/server/scripts/World/npcs_special.cpp b/src/server/scripts/World/npcs_special.cpp
index 451635a910..5b71ad17b4 100644
--- a/src/server/scripts/World/npcs_special.cpp
+++ b/src/server/scripts/World/npcs_special.cpp
@@ -119,9 +119,7 @@ public:
{
case EVENT_CLEARWATER_ANNOUNCE:
{
- time_t curtime = time(nullptr);
- tm strdate;
- localtime_r(&curtime, &strdate);
+ tm strdate = Acore::Time::TimeBreakdown();
if (!preWarning && strdate.tm_hour == 13 && strdate.tm_min == 55)
{
@@ -268,14 +266,14 @@ public:
{
case EVENT_RIGGLE_ANNOUNCE:
{
- time_t curtime = time(nullptr);
- tm strdate;
- localtime_r(&curtime, &strdate);
+ tm strdate = Acore::Time::TimeBreakdown();
+
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);
startWarning = true;
}
+
if (!finishWarning && strdate.tm_hour == 16 && strdate.tm_min == 0)
{
sCreatureTextMgr->SendChat(me, RIGGLE_SAY_END, 0, CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, TEXT_RANGE_ZONE);
diff --git a/src/server/shared/Packets/ByteBuffer.cpp b/src/server/shared/Packets/ByteBuffer.cpp
index 85850f3c14..9834ac7b04 100644
--- a/src/server/shared/Packets/ByteBuffer.cpp
+++ b/src/server/shared/Packets/ByteBuffer.cpp
@@ -19,6 +19,7 @@
#include "Errors.h"
#include "Log.h"
#include "MessageBuffer.h"
+#include "Timer.h"
#include "Util.h"
#include <ctime>
#include <sstream>
@@ -136,8 +137,7 @@ void ByteBuffer::append(uint8 const* src, size_t cnt)
void ByteBuffer::AppendPackedTime(time_t time)
{
- tm lt;
- localtime_r(&time, &lt);
+ tm lt = Acore::Time::TimeBreakdown(time);
append<uint32>((lt.tm_year - 100) << 24 | lt.tm_mon << 20 | (lt.tm_mday - 1) << 14 | lt.tm_wday << 11 | lt.tm_hour << 6 | lt.tm_min);
}
diff --git a/src/tools/map_extractor/loadlib/loadlib.h b/src/tools/map_extractor/loadlib/loadlib.h
index 2502a75cf8..f8259d9acc 100644
--- a/src/tools/map_extractor/loadlib/loadlib.h
+++ b/src/tools/map_extractor/loadlib/loadlib.h
@@ -18,35 +18,10 @@
#ifndef LOAD_LIB_H
#define LOAD_LIB_H
+#include "Define.h"
#include <string>
-#ifdef _WIN32
-typedef __int64 int64;
-typedef __int32 int32;
-typedef __int16 int16;
-typedef __int8 int8;
-typedef unsigned __int64 uint64;
-typedef unsigned __int32 uint32;
-typedef unsigned __int16 uint16;
-typedef unsigned __int8 uint8;
-#else
-#include <cstdint>
-#ifndef uint64_t
-#ifdef __linux__
-#include <linux/types.h>
-#endif
-#endif
-typedef int64_t int64;
-typedef int32_t int32;
-typedef int16_t int16;
-typedef int8_t int8;
-typedef uint64_t uint64;
-typedef uint32_t uint32;
-typedef uint16_t uint16;
-typedef uint8_t uint8;
-#endif
-
-#define FILE_FORMAT_VERSION 18
+constexpr auto FILE_FORMAT_VERSION = 18;
union u_map_fcc
{
@@ -83,4 +58,5 @@ public:
bool loadFile(std::string const& filename, bool log = true);
virtual void free();
};
+
#endif