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)));
|
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)
|
public static string secsToTimeString(ulong timeInSecs, bool shortText = false, bool hoursOnly = false)
|
||||||
{
|
{
|
||||||
ulong secs = timeInSecs % Minute;
|
ulong secs = timeInSecs % Minute;
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ namespace Game.Maps
|
|||||||
}
|
}
|
||||||
|
|
||||||
// load the global respawn times for raid/heroic instances
|
// 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");
|
result = DB.Characters.Query("SELECT mapid, difficulty, resettime FROM instance_reset");
|
||||||
if (!result.IsEmpty())
|
if (!result.IsEmpty())
|
||||||
{
|
{
|
||||||
@@ -241,7 +241,7 @@ namespace Game.Maps
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update the reset time if the hour in the configs changes
|
// 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)
|
if (oldresettime != newresettime)
|
||||||
{
|
{
|
||||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_GLOBAL_INSTANCE_RESETTIME);
|
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_GLOBAL_INSTANCE_RESETTIME);
|
||||||
@@ -277,7 +277,7 @@ namespace Game.Maps
|
|||||||
if (t == 0)
|
if (t == 0)
|
||||||
{
|
{
|
||||||
// initialize the reset time
|
// initialize the reset time
|
||||||
t = today + period + diff;
|
t = Time.GetLocalHourTimestamp(today + period, resetHour);
|
||||||
|
|
||||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_GLOBAL_INSTANCE_RESETTIME);
|
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_GLOBAL_INSTANCE_RESETTIME);
|
||||||
stmt.AddValue(0, mapid);
|
stmt.AddValue(0, mapid);
|
||||||
@@ -290,8 +290,8 @@ namespace Game.Maps
|
|||||||
{
|
{
|
||||||
// assume that expired instances have already been cleaned
|
// assume that expired instances have already been cleaned
|
||||||
// calculate the next reset time
|
// calculate the next reset time
|
||||||
t = (t / Time.Day) * Time.Day;
|
long day = (t / Time.Day) * Time.Day;
|
||||||
t += ((today - t) / period + 1) * period + diff;
|
t = Time.GetLocalHourTimestamp(day + ((today - day) / period + 1) * period, resetHour);
|
||||||
|
|
||||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_GLOBAL_INSTANCE_RESETTIME);
|
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_GLOBAL_INSTANCE_RESETTIME);
|
||||||
stmt.AddValue(0, t);
|
stmt.AddValue(0, t);
|
||||||
@@ -327,12 +327,12 @@ namespace Game.Maps
|
|||||||
return 0;
|
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);
|
long period = (uint)(((mapDiff.GetRaidDuration() * WorldConfig.GetFloatValue(WorldCfg.RateInstanceResetTime)) / Time.Day) * Time.Day);
|
||||||
if (period < Time.Day)
|
if (period < Time.Day)
|
||||||
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)
|
public void ScheduleReset(bool add, long time, InstResetEvent Event)
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ namespace Game
|
|||||||
Global.ScriptMgr.OnOpenStateChange(!val);
|
Global.ScriptMgr.OnOpenStateChange(!val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadDBAllowedSecurityLevel()
|
public void LoadDBAllowedSecurityLevel()
|
||||||
{
|
{
|
||||||
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_REALMLIST_SECURITY_LEVEL);
|
PreparedStatement stmt = DB.Login.GetPreparedStatement(LoginStatements.SEL_REALMLIST_SECURITY_LEVEL);
|
||||||
stmt.AddValue(0, (int)_realm.Id.Index);
|
stmt.AddValue(0, (int)_realm.Id.Index);
|
||||||
@@ -90,7 +90,7 @@ namespace Game
|
|||||||
SetPlayerSecurityLimit((AccountTypes)result.Read<byte>(0));
|
SetPlayerSecurityLimit((AccountTypes)result.Read<byte>(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetPlayerSecurityLimit(AccountTypes _sec)
|
public void SetPlayerSecurityLimit(AccountTypes _sec)
|
||||||
{
|
{
|
||||||
AccountTypes sec = _sec < AccountTypes.Console ? _sec : AccountTypes.Player;
|
AccountTypes sec = _sec < AccountTypes.Console ? _sec : AccountTypes.Player;
|
||||||
bool update = sec > m_allowedSecurityLevel;
|
bool update = sec > m_allowedSecurityLevel;
|
||||||
@@ -121,11 +121,11 @@ namespace Game
|
|||||||
long today = (gameTime / Time.Day) * Time.Day;
|
long today = (gameTime / Time.Day) * Time.Day;
|
||||||
|
|
||||||
// Check if our window to restart today has passed. 5 mins until quiet time
|
// 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;
|
today += Time.Day;
|
||||||
|
|
||||||
// Schedule restart for 30 minutes before quiet time, or as long as we have
|
// 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;
|
_guidWarn = true;
|
||||||
SendGuidWarning();
|
SendGuidWarning();
|
||||||
|
|||||||
@@ -34,9 +34,10 @@ namespace Scripts.World
|
|||||||
|
|
||||||
bool IsXPBoostActive()
|
bool IsXPBoostActive()
|
||||||
{
|
{
|
||||||
var now = Time.UnixTimeToDateTime(GameTime.GetGameTime());
|
long time = GameTime.GetGameTime();
|
||||||
|
var localTm = Time.UnixTimeToDateTime(time);
|
||||||
uint weekdayMaskBoosted = WorldConfig.GetUIntValue(WorldCfg.XpBoostDaymask);
|
uint weekdayMaskBoosted = WorldConfig.GetUIntValue(WorldCfg.XpBoostDaymask);
|
||||||
uint weekdayMask = (1u << now.Day);
|
uint weekdayMask = 1u << localTm.Day;
|
||||||
bool currentDayBoosted = (weekdayMask & weekdayMaskBoosted) != 0;
|
bool currentDayBoosted = (weekdayMask & weekdayMaskBoosted) != 0;
|
||||||
return currentDayBoosted;
|
return currentDayBoosted;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user