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
This commit is contained in:
Giacomo Pozzoni
2019-07-19 21:24:56 +02:00
committed by GitHub
parent fbd0fe26ee
commit aeddd417c4
5 changed files with 37 additions and 13 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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)

View File

@@ -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();

View File

@@ -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;
}