aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGiacomo Pozzoni <giacomopoz@gmail.com>2019-07-19 21:24:56 +0200
committerGitHub <noreply@github.com>2019-07-19 21:24:56 +0200
commitaeddd417c460c43d885cb89ceaa6e051c44b1d27 (patch)
tree589e76b3c39940dec7e8db8240224220d4893090 /src
parentfbd0fe26ee239f7cf80004d771b96df3f9ae1274 (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
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 53365373eb4..3b9917611aa 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 193981e31ae..125442865c5 100644
--- a/src/common/Utilities/Util.h
+++ b/src/common/Utilities/Util.h
@@ -59,6 +59,8 @@ TC_COMMON_API int32 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 461bd562fd6..debeb26b198 100644
--- a/src/server/game/Instances/InstanceSaveMgr.cpp
+++ b/src/server/game/Instances/InstanceSaveMgr.cpp
@@ -346,7 +346,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
@@ -369,7 +369,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)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GLOBAL_INSTANCE_RESETTIME);
@@ -403,7 +403,7 @@ void InstanceSaveManager::LoadResetTimes()
if (!t)
{
// initialize the reset time
- t = today + period + diff;
+ t = GetLocalHourTimestamp(today + period, resetHour);
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_GLOBAL_INSTANCE_RESETTIME);
stmt->setUInt16(0, uint16(mapid));
@@ -416,8 +416,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);
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GLOBAL_INSTANCE_RESETTIME);
stmt->setUInt64(0, uint64(t));
@@ -451,12 +451,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->resetTime * 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 c511c85f0d4..d719442f9f7 100644
--- a/src/server/game/World/World.cpp
+++ b/src/server/game/World/World.cpp
@@ -230,11 +230,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 df03dab4a81..9d73e5afadf 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;
}