mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
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 aeddd417c4)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user