fix(Calendar/Packets): add additional validation when creating events (#2799)

This commit is contained in:
Nefertumm
2020-03-28 18:47:53 -03:00
committed by GitHub
parent 1411336dcb
commit bb6047248a
8 changed files with 250 additions and 63 deletions

View File

@@ -111,6 +111,7 @@ World::World()
m_NextWeeklyQuestReset = 0;
m_NextMonthlyQuestReset = 0;
m_NextRandomBGReset = 0;
m_NextCalendarOldEventsDeletionTime = 0;
m_NextGuildReset = 0;
m_defaultDbcLocale = LOCALE_enUS;
@@ -1071,6 +1072,13 @@ void World::LoadConfigSettings(bool reload)
m_int_configs[CONFIG_RANDOM_BG_RESET_HOUR] = 6;
}
m_int_configs[CONFIG_CALENDAR_DELETE_OLD_EVENTS_HOUR] = sConfigMgr->GetIntDefault("Calendar.DeleteOldEventsHour", 6);
if (m_int_configs[CONFIG_CALENDAR_DELETE_OLD_EVENTS_HOUR] > 23)
{
sLog->outError("Calendar.DeleteOldEventsHour (%i) can't be load. Set to 6.", m_int_configs[CONFIG_CALENDAR_DELETE_OLD_EVENTS_HOUR]);
m_int_configs[CONFIG_CALENDAR_DELETE_OLD_EVENTS_HOUR] = 6;
}
m_int_configs[CONFIG_GUILD_RESET_HOUR] = sConfigMgr->GetIntDefault("Guild.ResetHour", 6);
if (m_int_configs[CONFIG_GUILD_RESET_HOUR] > 23)
{
@@ -1964,6 +1972,9 @@ void World::SetInitialWorldSettings()
sLog->outString("Calculate random battleground reset time..." );
InitRandomBGResetTime();
sLog->outString("Calculate deletion of old calendar events time...");
InitCalendarOldEventsDeletionTime();
sLog->outString("Calculate Guild cap reset time...");
InitGuildResetTime();
@@ -2165,6 +2176,9 @@ void World::Update(uint32 diff)
if (m_gameTime > m_NextRandomBGReset)
ResetRandomBG();
if (m_gameTime > m_NextCalendarOldEventsDeletionTime)
CalendarDeleteOldEvents();
if (m_gameTime > m_NextGuildReset)
ResetGuildCap();
@@ -2882,6 +2896,23 @@ void World::InitRandomBGResetTime()
sWorld->setWorldState(WS_BG_DAILY_RESET_TIME, uint64(m_NextRandomBGReset));
}
void World::InitCalendarOldEventsDeletionTime()
{
time_t now = time(nullptr);
time_t currentDeletionTime = getWorldState(WS_DAILY_CALENDAR_DELETION_OLD_EVENTS_TIME);
time_t nextDeletionTime = currentDeletionTime ? currentDeletionTime : GetNextTimeWithDayAndHour(-1, getIntConfig(CONFIG_CALENDAR_DELETE_OLD_EVENTS_HOUR));
// 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 - DAY;
else
m_NextCalendarOldEventsDeletionTime = nextDeletionTime;
if (!currentDeletionTime)
sWorld->setWorldState(WS_DAILY_CALENDAR_DELETION_OLD_EVENTS_TIME, uint64(m_NextCalendarOldEventsDeletionTime));
}
void World::InitGuildResetTime()
{
time_t wstime = time_t(getWorldState(WS_GUILD_DAILY_RESET_TIME));
@@ -2984,6 +3015,15 @@ void World::ResetRandomBG()
sWorld->setWorldState(WS_BG_DAILY_RESET_TIME, uint64(m_NextRandomBGReset));
}
void World::CalendarDeleteOldEvents()
{
sLog->outString("Calendar deletion of old events.");
m_NextCalendarOldEventsDeletionTime = time_t(m_NextCalendarOldEventsDeletionTime + DAY);
sWorld->setWorldState(WS_DAILY_CALENDAR_DELETION_OLD_EVENTS_TIME, uint64(m_NextCalendarOldEventsDeletionTime));
sCalendarMgr->DeleteOldEvents();
}
void World::ResetGuildCap()
{
sLog->outString("Guild Daily Cap reset.");

View File

@@ -316,6 +316,7 @@ enum WorldIntConfigs
CONFIG_GUILD_BANK_EVENT_LOG_COUNT,
CONFIG_MIN_LEVEL_STAT_SAVE,
CONFIG_RANDOM_BG_RESET_HOUR,
CONFIG_CALENDAR_DELETE_OLD_EVENTS_HOUR,
CONFIG_GUILD_RESET_HOUR,
CONFIG_CHARDELETE_KEEP_DAYS,
CONFIG_CHARDELETE_METHOD,
@@ -493,13 +494,14 @@ enum RealmZone
enum WorldStates
{
WS_ARENA_DISTRIBUTION_TIME = 20001, // Next arena distribution time
WS_WEEKLY_QUEST_RESET_TIME = 20002, // Next weekly reset time
WS_BG_DAILY_RESET_TIME = 20003, // Next daily BG reset time
WS_CLEANING_FLAGS = 20004, // Cleaning Flags
WS_DAILY_QUEST_RESET_TIME = 20005, // Next daily reset time
WS_GUILD_DAILY_RESET_TIME = 20006, // Next guild cap reset time
WS_MONTHLY_QUEST_RESET_TIME = 20007, // Next monthly reset time
WS_ARENA_DISTRIBUTION_TIME = 20001, // Next arena distribution time
WS_WEEKLY_QUEST_RESET_TIME = 20002, // Next weekly reset time
WS_BG_DAILY_RESET_TIME = 20003, // Next daily BG reset time
WS_CLEANING_FLAGS = 20004, // Cleaning Flags
WS_DAILY_QUEST_RESET_TIME = 20005, // Next daily reset time
WS_GUILD_DAILY_RESET_TIME = 20006, // Next guild cap reset time
WS_MONTHLY_QUEST_RESET_TIME = 20007, // Next monthly reset time
WS_DAILY_CALENDAR_DELETION_OLD_EVENTS_TIME = 20008 // Next daily calendar deletions of old events time
};
/// Storage class for commands issued for delayed execution
@@ -812,11 +814,13 @@ class World
void InitWeeklyQuestResetTime();
void InitMonthlyQuestResetTime();
void InitRandomBGResetTime();
void InitCalendarOldEventsDeletionTime();
void InitGuildResetTime();
void ResetDailyQuests();
void ResetWeeklyQuests();
void ResetMonthlyQuests();
void ResetRandomBG();
void CalendarDeleteOldEvents();
void ResetGuildCap();
private:
static ACE_Atomic_Op<ACE_Thread_Mutex, bool> m_stopEvent;
@@ -879,6 +883,7 @@ class World
time_t m_NextWeeklyQuestReset;
time_t m_NextMonthlyQuestReset;
time_t m_NextRandomBGReset;
time_t m_NextCalendarOldEventsDeletionTime;
time_t m_NextGuildReset;
//Player Queue