Core/Calendar: Add some additional validation when creating events

Port From (https://github.com/TrinityCore/TrinityCore/commit/562c567b1e0c878f0632994a79bcfbfd4a962504)
This commit is contained in:
hondacrx
2022-01-04 20:40:30 -05:00
parent 7f053ea099
commit 4b08dc2756
6 changed files with 222 additions and 33 deletions
+34 -1
View File
@@ -1072,9 +1072,12 @@ namespace Game
InitQuestResetTimes();
CheckScheduledResetTimes();
Log.outInfo(LogFilter.ServerLoading, "Calculate random Battlegroundreset time...");
Log.outInfo(LogFilter.ServerLoading, "Calculate random battleground reset time...");
InitRandomBGResetTime();
Log.outInfo(LogFilter.ServerLoading, "Calculate deletion of old calendar events time...");
InitCalendarOldEventsDeletionTime();
Log.outInfo(LogFilter.ServerLoading, "Calculate Guild cap reset time...");
InitGuildResetTime();
@@ -1310,6 +1313,9 @@ namespace Game
if (currentGameTime > m_NextRandomBGReset)
ResetRandomBG();
if (currentGameTime > m_NextCalendarOldEventsDeletionTime)
CalendarDeleteOldEvents();
if (currentGameTime > m_NextGuildReset)
ResetGuildCap();
@@ -2114,6 +2120,23 @@ namespace Game
SetWorldState(WorldStates.BGDailyResetTime, (ulong)m_NextRandomBGReset);
}
void InitCalendarOldEventsDeletionTime()
{
long now = GameTime.GetGameTime();
long nextDeletionTime = Time.GetLocalHourTimestamp(now, WorldConfig.GetUIntValue(WorldCfg.CalendarDeleteOldEventsHour));
long currentDeletionTime = GetWorldState(WorldStates.DailyCalendarDeletionOldEventsTime);
// If the reset time saved in the worldstate is before now it means the server was offline when the reset was supposed to occur.
// In this case we set the reset time in the past and next world update will do the reset and schedule next one in the future.
if (currentDeletionTime < now)
m_NextCalendarOldEventsDeletionTime = nextDeletionTime - Time.Day;
else
m_NextCalendarOldEventsDeletionTime = nextDeletionTime;
if (currentDeletionTime == 0)
SetWorldState(WorldStates.DailyCalendarDeletionOldEventsTime, (ulong)m_NextCalendarOldEventsDeletionTime);
}
void InitGuildResetTime()
{
long gtime = GetWorldState(WorldStates.GuildDailyResetTime);
@@ -2193,6 +2216,15 @@ namespace Game
SetWorldState(WorldStates.BGDailyResetTime, (ulong)m_NextRandomBGReset);
}
void CalendarDeleteOldEvents()
{
Log.outInfo(LogFilter.Misc, "Calendar deletion of old events.");
m_NextCalendarOldEventsDeletionTime = m_NextCalendarOldEventsDeletionTime + Time.Day;
SetWorldState(WorldStates.DailyCalendarDeletionOldEventsTime, (ulong)m_NextCalendarOldEventsDeletionTime);
Global.CalendarMgr.DeleteOldEvents();
}
void ResetGuildCap()
{
m_NextGuildReset += Time.Day;
@@ -2489,6 +2521,7 @@ namespace Game
long m_NextWeeklyQuestReset;
long m_NextMonthlyQuestReset;
long m_NextRandomBGReset;
long m_NextCalendarOldEventsDeletionTime;
long m_NextGuildReset;
long m_NextCurrencyReset;
+7
View File
@@ -890,6 +890,10 @@ namespace Game
public uint GetRecruiterId() { return recruiterId; }
public bool IsARecruiter() { return isRecruiter; }
// Packets cooldown
public long GetCalendarEventCreationCooldown() { return _calendarEventCreationCooldown; }
public void SetCalendarEventCreationCooldown(long cooldown) { _calendarEventCreationCooldown = cooldown; }
// Battle Pets
public BattlePetMgr GetBattlePetMgr() { return _battlePetMgr; }
public CollectionMgr GetCollectionMgr() { return _collectionMgr; }
@@ -967,6 +971,9 @@ namespace Game
ConnectToKey _instanceConnectKey;
// Packets cooldown
long _calendarEventCreationCooldown;
BattlePetMgr _battlePetMgr;
Task<SQLQueryHolder<AccountInfoQueryLoad>> _realmAccountLoginCallback;