Core/Misc: Handle timezones for hour-specific events specifieds in worldserver.conf
Port From (https://github.com/TrinityCore/TrinityCore/commit/493fe066f6b107a9f356d693c5d37d878d3a63eb)
This commit is contained in:
@@ -120,6 +120,19 @@ public static class Time
|
||||
return DateTimeToUnixTime((DateTime.Now.Date + new TimeSpan(months + days, hours, 0)));
|
||||
}
|
||||
|
||||
public static long GetLocalHourTimestamp(long time, uint hour, bool onlyAfterTime = true)
|
||||
{
|
||||
DateTime timeLocal = UnixTimeToDateTime(time);
|
||||
timeLocal = new DateTime(timeLocal.Year, timeLocal.Month, timeLocal.Day, 0, 0, 0, timeLocal.Kind);
|
||||
long midnightLocal = DateTimeToUnixTime(timeLocal);
|
||||
long hourLocal = midnightLocal + hour * Hour;
|
||||
|
||||
if (onlyAfterTime && hourLocal < time)
|
||||
hourLocal += Day;
|
||||
|
||||
return hourLocal;
|
||||
}
|
||||
|
||||
public static string secsToTimeString(ulong timeInSecs, bool shortText = false, bool hoursOnly = false)
|
||||
{
|
||||
ulong secs = timeInSecs % Minute;
|
||||
|
||||
@@ -219,7 +219,7 @@ namespace Game.Maps
|
||||
}
|
||||
|
||||
// load the global respawn times for raid/heroic instances
|
||||
uint diff = (uint)(WorldConfig.GetIntValue(WorldCfg.InstanceResetTimeHour) * Time.Hour);
|
||||
uint resetHour = WorldConfig.GetUIntValue(WorldCfg.InstanceResetTimeHour);
|
||||
result = DB.Characters.Query("SELECT mapid, difficulty, resettime FROM instance_reset");
|
||||
if (!result.IsEmpty())
|
||||
{
|
||||
@@ -241,7 +241,7 @@ namespace Game.Maps
|
||||
}
|
||||
|
||||
// update the reset time if the hour in the configs changes
|
||||
long newresettime = (oldresettime / Time.Day) * Time.Day + diff;
|
||||
long newresettime = Time.GetLocalHourTimestamp(oldresettime, resetHour, false);
|
||||
if (oldresettime != newresettime)
|
||||
{
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_GLOBAL_INSTANCE_RESETTIME);
|
||||
@@ -277,7 +277,7 @@ namespace Game.Maps
|
||||
if (t == 0)
|
||||
{
|
||||
// initialize the reset time
|
||||
t = today + period + diff;
|
||||
t = Time.GetLocalHourTimestamp(today + period, resetHour);
|
||||
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_GLOBAL_INSTANCE_RESETTIME);
|
||||
stmt.AddValue(0, mapid);
|
||||
@@ -290,8 +290,8 @@ namespace Game.Maps
|
||||
{
|
||||
// assume that expired instances have already been cleaned
|
||||
// calculate the next reset time
|
||||
t = (t / Time.Day) * Time.Day;
|
||||
t += ((today - t) / period + 1) * period + diff;
|
||||
long day = (t / Time.Day) * Time.Day;
|
||||
t = Time.GetLocalHourTimestamp(day + ((today - day) / period + 1) * period, resetHour);
|
||||
|
||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_GLOBAL_INSTANCE_RESETTIME);
|
||||
stmt.AddValue(0, t);
|
||||
@@ -327,12 +327,12 @@ namespace Game.Maps
|
||||
return 0;
|
||||
}
|
||||
|
||||
long diff = WorldConfig.GetIntValue(WorldCfg.InstanceResetTimeHour) * Time.Hour;
|
||||
long resetHour = WorldConfig.GetIntValue(WorldCfg.InstanceResetTimeHour);
|
||||
long period = (uint)(((mapDiff.GetRaidDuration() * WorldConfig.GetFloatValue(WorldCfg.RateInstanceResetTime)) / Time.Day) * Time.Day);
|
||||
if (period < Time.Day)
|
||||
period = Time.Day;
|
||||
|
||||
return ((resetTime + Time.Minute) / Time.Day * Time.Day) + period + diff;
|
||||
return Time.GetLocalHourTimestamp(((resetTime + Time.Minute) / Time.Day * Time.Day) + period, (uint)resetHour);
|
||||
}
|
||||
|
||||
public void ScheduleReset(bool add, long time, InstResetEvent Event)
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace Game
|
||||
Global.ScriptMgr.OnOpenStateChange(!val);
|
||||
}
|
||||
|
||||
void LoadDBAllowedSecurityLevel()
|
||||
public void LoadDBAllowedSecurityLevel()
|
||||
{
|
||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_REALMLIST_SECURITY_LEVEL);
|
||||
stmt.AddValue(0, (int)_realm.Id.Index);
|
||||
@@ -90,7 +90,7 @@ namespace Game
|
||||
SetPlayerSecurityLimit((AccountTypes)result.Read<byte>(0));
|
||||
}
|
||||
|
||||
void SetPlayerSecurityLimit(AccountTypes _sec)
|
||||
public void SetPlayerSecurityLimit(AccountTypes _sec)
|
||||
{
|
||||
AccountTypes sec = _sec < AccountTypes.Console ? _sec : AccountTypes.Player;
|
||||
bool update = sec > m_allowedSecurityLevel;
|
||||
@@ -121,11 +121,11 @@ namespace Game
|
||||
long today = (gameTime / Time.Day) * Time.Day;
|
||||
|
||||
// Check if our window to restart today has passed. 5 mins until quiet time
|
||||
while (gameTime >= (today + (WorldConfig.GetIntValue(WorldCfg.RespawnRestartQuietTime) * Time.Hour) - 1810))
|
||||
while (gameTime >= Time.GetLocalHourTimestamp(today, WorldConfig.GetUIntValue(WorldCfg.RespawnRestartQuietTime)) - 1810)
|
||||
today += Time.Day;
|
||||
|
||||
// Schedule restart for 30 minutes before quiet time, or as long as we have
|
||||
_warnShutdownTime = today + (WorldConfig.GetIntValue(WorldCfg.RespawnRestartQuietTime) * Time.Hour) - 1800;
|
||||
_warnShutdownTime = Time.GetLocalHourTimestamp(today, WorldConfig.GetUIntValue(WorldCfg.RespawnRestartQuietTime)) - 1800;
|
||||
|
||||
_guidWarn = true;
|
||||
SendGuidWarning();
|
||||
|
||||
@@ -34,9 +34,10 @@ namespace Scripts.World
|
||||
|
||||
bool IsXPBoostActive()
|
||||
{
|
||||
var now = Time.UnixTimeToDateTime(GameTime.GetGameTime());
|
||||
long time = GameTime.GetGameTime();
|
||||
var localTm = Time.UnixTimeToDateTime(time);
|
||||
uint weekdayMaskBoosted = WorldConfig.GetUIntValue(WorldCfg.XpBoostDaymask);
|
||||
uint weekdayMask = (1u << now.Day);
|
||||
uint weekdayMask = 1u << localTm.Day;
|
||||
bool currentDayBoosted = (weekdayMask & weekdayMaskBoosted) != 0;
|
||||
return currentDayBoosted;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user