aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGiacomo Pozzoni <giacomopoz@gmail.com>2019-07-19 21:24:56 +0200
committerShauren <shauren.trinity@gmail.com>2021-12-16 22:35:44 +0100
commit493fe066f6b107a9f356d693c5d37d878d3a63eb (patch)
tree3039d6c3a031f716a6a8f369181a92828380df63 /src
parent53c41b28216dd75309ea918e9c8a5387a7a2cf5d (diff)
Core/Misc: Handle timezones for hour-specific events specifieds in worldserver.conf (#23540)
* Core/Misc: Handle timezones for hour-specific events specifieds in worldserver.conf * Handle Respawn.RestartQuietTime too * Handle XP.Boost.Daymask too * Core/Misc: Code cleanup * Core/Misc: Code cleanup * Update Util.cpp * Update boosted_xp.cpp (cherry picked from commit aeddd417c460c43d885cb89ceaa6e051c44b1d27)
Diffstat (limited to 'src')
-rw-r--r--src/common/Utilities/Util.cpp22
-rw-r--r--src/common/Utilities/Util.h2
-rw-r--r--src/server/game/Instances/InstanceSaveMgr.cpp14
-rw-r--r--src/server/game/World/World.cpp4
-rw-r--r--src/server/scripts/World/boosted_xp.cpp8
5 files changed, 37 insertions, 13 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp
index 5123636f6a0..4b8c206c9ff 100644
--- a/src/common/Utilities/Util.cpp
+++ b/src/common/Utilities/Util.cpp
@@ -77,6 +77,13 @@ struct tm* localtime_r(time_t const* time, struct tm *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__))
@@ -86,6 +93,21 @@ time_t LocalTimeToUTCTime(time_t time)
#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;
+}
+
std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
{
uint64 secs = timeInSecs % MINUTE;
diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h
index 1ed9c344765..2c06cb936e6 100644
--- a/src/common/Utilities/Util.h
+++ b/src/common/Utilities/Util.h
@@ -60,6 +60,8 @@ TC_COMMON_API int64 MoneyStringToMoney(std::string const& moneyString);
TC_COMMON_API struct tm* localtime_r(time_t const* time, struct tm *result);
TC_COMMON_API time_t LocalTimeToUTCTime(time_t time);
+TC_COMMON_API time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime = true);
+TC_COMMON_API tm TimeBreakdown(time_t t);
TC_COMMON_API std::string secsToTimeString(uint64 timeInSecs, bool shortText = false, bool hoursOnly = false);
TC_COMMON_API uint32 TimeStringToSecs(std::string const& timestring);
diff --git a/src/server/game/Instances/InstanceSaveMgr.cpp b/src/server/game/Instances/InstanceSaveMgr.cpp
index 741a3e98697..adaa84c631d 100644
--- a/src/server/game/Instances/InstanceSaveMgr.cpp
+++ b/src/server/game/Instances/InstanceSaveMgr.cpp
@@ -358,7 +358,7 @@ void InstanceSaveManager::LoadResetTimes()
}
// load the global respawn times for raid/heroic instances
- uint32 diff = sWorld->getIntConfig(CONFIG_INSTANCE_RESET_TIME_HOUR) * HOUR;
+ uint32 resetHour = sWorld->getIntConfig(CONFIG_INSTANCE_RESET_TIME_HOUR);
if (QueryResult result = CharacterDatabase.Query("SELECT mapid, difficulty, resettime FROM instance_reset"))
{
do
@@ -381,7 +381,7 @@ void InstanceSaveManager::LoadResetTimes()
}
// update the reset time if the hour in the configs changes
- uint64 newresettime = (oldresettime / DAY) * DAY + diff;
+ uint64 newresettime = GetLocalHourTimestamp(oldresettime, resetHour, false);
if (oldresettime != newresettime)
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GLOBAL_INSTANCE_RESETTIME);
@@ -417,7 +417,7 @@ void InstanceSaveManager::LoadResetTimes()
if (!t)
{
// initialize the reset time
- t = today + period + diff;
+ t = GetLocalHourTimestamp(today + period, resetHour);
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_GLOBAL_INSTANCE_RESETTIME);
stmt->setUInt16(0, uint16(mapid));
@@ -430,8 +430,8 @@ void InstanceSaveManager::LoadResetTimes()
{
// assume that expired instances have already been cleaned
// calculate the next reset time
- t = (t / DAY) * DAY;
- t += ((today - t) / period + 1) * period + diff;
+ time_t day = (t / DAY) * DAY;
+ t = GetLocalHourTimestamp(day + ((today - day) / period + 1) * period, resetHour);
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GLOBAL_INSTANCE_RESETTIME);
stmt->setInt64(0, t);
@@ -466,12 +466,12 @@ time_t InstanceSaveManager::GetSubsequentResetTime(uint32 mapid, Difficulty diff
return 0;
}
- time_t diff = sWorld->getIntConfig(CONFIG_INSTANCE_RESET_TIME_HOUR) * HOUR;
+ time_t resetHour = sWorld->getIntConfig(CONFIG_INSTANCE_RESET_TIME_HOUR);
time_t period = uint32(((mapDiff->GetRaidDuration() * sWorld->getRate(RATE_INSTANCE_RESET_TIME)) / DAY) * DAY);
if (period < DAY)
period = DAY;
- return ((resetTime + MINUTE) / DAY * DAY) + period + diff;
+ return GetLocalHourTimestamp(((resetTime + MINUTE) / DAY * DAY) + period, resetHour);
}
void InstanceSaveManager::SetResetTimeFor(uint32 mapid, Difficulty d, time_t t)
diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp
index 97311508ebb..87b8ad5a3ec 100644
--- a/src/server/game/World/World.cpp
+++ b/src/server/game/World/World.cpp
@@ -258,11 +258,11 @@ void World::TriggerGuidWarning()
time_t today = (gameTime / DAY) * DAY;
// Check if our window to restart today has passed. 5 mins until quiet time
- while (gameTime >= (today + (getIntConfig(CONFIG_RESPAWN_RESTARTQUIETTIME) * HOUR) - 1810))
+ while (gameTime >= GetLocalHourTimestamp(today, getIntConfig(CONFIG_RESPAWN_RESTARTQUIETTIME)) - 1810)
today += DAY;
// Schedule restart for 30 minutes before quiet time, or as long as we have
- _warnShutdownTime = today + (getIntConfig(CONFIG_RESPAWN_RESTARTQUIETTIME) * HOUR) - 1800;
+ _warnShutdownTime = GetLocalHourTimestamp(today, getIntConfig(CONFIG_RESPAWN_RESTARTQUIETTIME)) - 1800;
_guidWarn = true;
SendGuidWarning();
diff --git a/src/server/scripts/World/boosted_xp.cpp b/src/server/scripts/World/boosted_xp.cpp
index d65a1b812c2..240dc4b34f7 100644
--- a/src/server/scripts/World/boosted_xp.cpp
+++ b/src/server/scripts/World/boosted_xp.cpp
@@ -17,17 +17,17 @@
#include "GameTime.h"
#include "ScriptMgr.h"
+#include "Util.h"
#include "World.h"
-#include <boost/date_time/posix_time/posix_time.hpp>
-
namespace
{
bool IsXPBoostActive()
{
- auto now = boost::posix_time::to_tm(boost::posix_time::from_time_t(GameTime::GetGameTime()));
+ time_t time = GameTime::GetGameTime();
+ tm localTm = TimeBreakdown(time);
uint32 weekdayMaskBoosted = sWorld->getIntConfig(CONFIG_XP_BOOST_DAYMASK);
- uint32 weekdayMask = (1 << now.tm_wday);
+ uint32 weekdayMask = (1 << localTm.tm_wday);
bool currentDayBoosted = (weekdayMask & weekdayMaskBoosted) != 0;
return currentDayBoosted;
}