diff --git a/sql/characters.sql b/sql/characters.sql index 5fd59fcd8..2ab6fc47f 100644 --- a/sql/characters.sql +++ b/sql/characters.sql @@ -21,7 +21,7 @@ DROP TABLE IF EXISTS `character_db_version`; CREATE TABLE `character_db_version` ( - `required_9686_01_characters_character_queststatus_weekly` bit(1) default NULL + `required_9687_01_characters_character_queststatus_daily` bit(1) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Last applied sql update to DB'; -- @@ -702,7 +702,6 @@ DROP TABLE IF EXISTS `character_queststatus_daily`; CREATE TABLE `character_queststatus_daily` ( `guid` int(11) unsigned NOT NULL default '0' COMMENT 'Global Unique Identifier', `quest` int(11) unsigned NOT NULL default '0' COMMENT 'Quest Identifier', - `time` bigint(20) unsigned NOT NULL default '0', PRIMARY KEY (`guid`,`quest`), KEY `idx_guid` (`guid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='Player System'; @@ -1583,6 +1582,7 @@ UNLOCK TABLES; DROP TABLE IF EXISTS `saved_variables`; CREATE TABLE `saved_variables` ( `NextArenaPointDistributionTime` bigint(40) UNSIGNED NOT NULL DEFAULT '0', + `NextDailyQuestResetTime` bigint(40) unsigned NOT NULL default '0', `NextWeeklyQuestResetTime` bigint(40) unsigned NOT NULL default '0' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Variable Saves'; diff --git a/sql/updates/9687_01_characters_character_queststatus_daily.sql b/sql/updates/9687_01_characters_character_queststatus_daily.sql new file mode 100644 index 000000000..66d192896 --- /dev/null +++ b/sql/updates/9687_01_characters_character_queststatus_daily.sql @@ -0,0 +1,8 @@ +ALTER TABLE character_db_version CHANGE COLUMN required_9686_01_characters_character_queststatus_weekly required_9687_01_characters_character_queststatus_daily bit; + +ALTER TABLE `character_queststatus_daily` + DROP COLUMN `time`; + +ALTER TABLE `saved_variables` + ADD COLUMN `NextDailyQuestResetTime` bigint(40) unsigned NOT NULL default '0' AFTER `NextArenaPointDistributionTime`; + diff --git a/sql/updates/Makefile.am b/sql/updates/Makefile.am index c1b91703d..1de7371e3 100644 --- a/sql/updates/Makefile.am +++ b/sql/updates/Makefile.am @@ -104,6 +104,7 @@ pkgdata_DATA = \ 9663_01_mangos_mangos_string.sql \ 9680_01_characters_character_stats.sql \ 9686_01_characters_character_queststatus_weekly.sql \ + 9687_01_characters_character_queststatus_daily.sql \ README ## Additional files to include when running 'make dist' @@ -188,4 +189,5 @@ EXTRA_DIST = \ 9663_01_mangos_mangos_string.sql \ 9680_01_characters_character_stats.sql \ 9686_01_characters_character_queststatus_weekly.sql \ + 9687_01_characters_character_queststatus_daily.sql \ README diff --git a/src/game/CharacterHandler.cpp b/src/game/CharacterHandler.cpp index 978223662..93070a9b6 100644 --- a/src/game/CharacterHandler.cpp +++ b/src/game/CharacterHandler.cpp @@ -78,7 +78,7 @@ bool LoginQueryHolder::Initialize() res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADAURAS, "SELECT caster_guid,spell,effect_index,stackcount,amount,maxduration,remaintime,remaincharges FROM character_aura WHERE guid = '%u'", GUID_LOPART(m_guid)); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADSPELLS, "SELECT spell,active,disabled FROM character_spell WHERE guid = '%u'", GUID_LOPART(m_guid)); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADQUESTSTATUS, "SELECT quest,status,rewarded,explored,timer,mobcount1,mobcount2,mobcount3,mobcount4,itemcount1,itemcount2,itemcount3,itemcount4 FROM character_queststatus WHERE guid = '%u'", GUID_LOPART(m_guid)); - res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADDAILYQUESTSTATUS,"SELECT quest,time FROM character_queststatus_daily WHERE guid = '%u'", GUID_LOPART(m_guid)); + res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADDAILYQUESTSTATUS,"SELECT quest FROM character_queststatus_daily WHERE guid = '%u'", GUID_LOPART(m_guid)); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADWEKLYQUESTSTATUS,"SELECT quest FROM character_queststatus_weekly WHERE guid = '%u'", GUID_LOPART(m_guid)); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADREPUTATION, "SELECT faction,standing,flags FROM character_reputation WHERE guid = '%u'", GUID_LOPART(m_guid)); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADINVENTORY, "SELECT data,bag,slot,item,item_template FROM character_inventory JOIN item_instance ON character_inventory.item = item_instance.guid WHERE character_inventory.guid = '%u' ORDER BY bag,slot", GUID_LOPART(m_guid)); diff --git a/src/game/Player.cpp b/src/game/Player.cpp index d2f343a6c..8e396d398 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -390,7 +390,7 @@ Player::Player (WorldSession *session): Unit(), m_achievementMgr(this), m_reputa m_currentBuybackSlot = BUYBACK_SLOT_START; m_DailyQuestChanged = false; - m_lastDailyQuestTime = 0; + m_WeeklyQuestChanged = false; for (int i=0; i MAX_LEVEL) setConfig(CONFIG_UINT32_QUEST_HIGH_LEVEL_HIDE_DIFF, MAX_LEVEL); + setConfigMinMax(CONFIG_UINT32_QUEST_DAILY_RESET_HOUR, "Quests.Daily.ResetHour", 6, 0, 23); + setConfigMinMax(CONFIG_UINT32_QUEST_WEEKLY_RESET_WEEK_DAY, "Quests.Weekly.ResetWeekDay", 3, 0, 6); + setConfigMinMax(CONFIG_UINT32_QUEST_WEEKLY_RESET_HOUR, "Quests.Weekly.ResetHour", 6, 0 , 23); + setConfig(CONFIG_BOOL_DETECT_POS_COLLISION, "DetectPosCollision", true); setConfig(CONFIG_BOOL_RESTRICTED_LFG_CHANNEL, "Channel.RestrictedLfg", true); @@ -1888,60 +1892,65 @@ void World::InitWeeklyQuestResetTime() { QueryResult * result = CharacterDatabase.Query("SELECT NextWeeklyQuestResetTime FROM saved_variables"); if (!result) - { - m_NextWeeklyQuestReset = time_t(m_gameTime + WEEK); - CharacterDatabase.PExecute("INSERT INTO saved_variables (NextWeeklyQuestResetTime) VALUES ('"UI64FMTD"')", uint64(m_NextWeeklyQuestReset)); - } + m_NextWeeklyQuestReset = time_t(time(NULL)); // game time not yet init else - { m_NextWeeklyQuestReset = time_t((*result)[0].GetUInt64()); - // move to just before if need - time_t cur = time(NULL); - if(m_NextWeeklyQuestReset < cur) - m_NextWeeklyQuestReset += WEEK * ((cur - m_NextWeeklyQuestReset) / WEEK); + // generate time by config + time_t curTime = time(NULL); + tm localTm = *localtime(&curTime); + int week_day_offset = localTm.tm_wday - int(getConfig(CONFIG_UINT32_QUEST_WEEKLY_RESET_WEEK_DAY)); + + // current week reset time + localTm.tm_hour = getConfig(CONFIG_UINT32_QUEST_WEEKLY_RESET_HOUR); + localTm.tm_min = 0; + localTm.tm_sec = 0; + time_t nextWeekResetTime = mktime(&localTm); + nextWeekResetTime -= week_day_offset * DAY; // move time to proper day + + // next reset time before current moment + if (curTime >= nextWeekResetTime) + nextWeekResetTime += WEEK; + + // normalize reset time + m_NextWeeklyQuestReset = m_NextWeeklyQuestReset < curTime ? nextWeekResetTime - WEEK : nextWeekResetTime; + + if (!result) + CharacterDatabase.PExecute("INSERT INTO saved_variables (NextWeeklyQuestResetTime) VALUES ('"UI64FMTD"')", uint64(m_NextWeeklyQuestReset)); + else delete result; - } } void World::InitDailyQuestResetTime() { - time_t mostRecentQuestTime; - - QueryResult* result = CharacterDatabase.Query("SELECT MAX(time) FROM character_queststatus_daily"); - if(result) - { - Field *fields = result->Fetch(); - - mostRecentQuestTime = (time_t)fields[0].GetUInt64(); - delete result; - } + QueryResult * result = CharacterDatabase.Query("SELECT NextDailyQuestResetTime FROM saved_variables"); + if (!result) + m_NextDailyQuestReset = time_t(time(NULL)); // game time not yet init else - mostRecentQuestTime = 0; + m_NextWeeklyQuestReset = time_t((*result)[0].GetUInt64()); - // client built-in time for reset is 6:00 AM - // FIX ME: client not show day start time + // generate time by config time_t curTime = time(NULL); tm localTm = *localtime(&curTime); - localTm.tm_hour = 6; + localTm.tm_hour = getConfig(CONFIG_UINT32_QUEST_DAILY_RESET_HOUR); localTm.tm_min = 0; localTm.tm_sec = 0; // current day reset time - time_t curDayResetTime = mktime(&localTm); + time_t nextDayResetTime = mktime(&localTm); - // last reset time before current moment - time_t resetTime = (curTime < curDayResetTime) ? curDayResetTime - DAY : curDayResetTime; + // next reset time before current moment + if (curTime >= nextDayResetTime) + nextDayResetTime += DAY; - // need reset (if we have quest time before last reset time (not processed by some reason) - if(mostRecentQuestTime && mostRecentQuestTime <= resetTime) - m_NextDailyQuestReset = mostRecentQuestTime; + // normalize reset time + m_NextDailyQuestReset = m_NextDailyQuestReset < curTime ? nextDayResetTime - DAY : nextDayResetTime; + + if (!result) + CharacterDatabase.PExecute("INSERT INTO saved_variables (NextDailyQuestResetTime) VALUES ('"UI64FMTD"')", uint64(m_NextDailyQuestReset)); else - { - // plan next reset time - m_NextDailyQuestReset = (curTime >= curDayResetTime) ? curDayResetTime + DAY : curDayResetTime; - } + delete result; } void World::ResetDailyQuests() diff --git a/src/game/World.h b/src/game/World.h index 0bbf492f6..a4e4f6f9d 100644 --- a/src/game/World.h +++ b/src/game/World.h @@ -148,6 +148,9 @@ enum eConfigUInt32Values CONFIG_UINT32_WORLD_BOSS_LEVEL_DIFF, CONFIG_UINT32_QUEST_LOW_LEVEL_HIDE_DIFF, CONFIG_UINT32_QUEST_HIGH_LEVEL_HIDE_DIFF, + CONFIG_UINT32_QUEST_DAILY_RESET_HOUR, + CONFIG_UINT32_QUEST_WEEKLY_RESET_WEEK_DAY, + CONFIG_UINT32_QUEST_WEEKLY_RESET_HOUR, CONFIG_UINT32_CHAT_STRICT_LINK_CHECKING_SEVERITY, CONFIG_UINT32_CHAT_STRICT_LINK_CHECKING_KICK, CONFIG_UINT32_CORPSE_DECAY_NORMAL, diff --git a/src/mangosd/mangosd.conf.dist.in b/src/mangosd/mangosd.conf.dist.in index 2ad2a2f3a..5d4053f19 100644 --- a/src/mangosd/mangosd.conf.dist.in +++ b/src/mangosd/mangosd.conf.dist.in @@ -558,6 +558,18 @@ LogColors = "" # Default: 7 # -1 (show all available quests marks) # +# Quests.Daily.ResetHour +# Hour when daily quests reset (0..23) +# Default: 6 +# +# Quests.Weekly.ResetWeekDay +# Week day when daily quests reset (0..6) 0 == Sunday +# Default: 3 +# +# Quests.Weekly.ResetHour +# Hour in one from weekly days when weekly quests reset (0..23) +# Default: 6 +# # Guild.EventLogRecordsCount # Count of guild event log records stored in guild_eventlog table # Increase to store more guild events in table, minimum is 100 @@ -685,6 +697,9 @@ Instance.ResetTimeHour = 4 Instance.UnloadDelay = 1800000 Quests.LowLevelHideDiff = 4 Quests.HighLevelHideDiff = 7 +Quests.Daily.ResetHour = 6 +Quests.Weekly.ResetWeekDay = 3 +Quests.Weekly.ResetHour = 6 Guild.EventLogRecordsCount = 100 Guild.BankEventLogRecordsCount = 25 TimerBar.Fatigue.GMLevel = 4 diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 45443aea0..d3fa365df 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "9686" + #define REVISION_NR "9687" #endif // __REVISION_NR_H__ diff --git a/src/shared/revision_sql.h b/src/shared/revision_sql.h index b7b6295b0..7f943d0f6 100644 --- a/src/shared/revision_sql.h +++ b/src/shared/revision_sql.h @@ -1,6 +1,6 @@ #ifndef __REVISION_SQL_H__ #define __REVISION_SQL_H__ - #define REVISION_DB_CHARACTERS "required_9686_01_characters_character_queststatus_weekly" + #define REVISION_DB_CHARACTERS "required_9687_01_characters_character_queststatus_daily" #define REVISION_DB_MANGOS "required_9663_01_mangos_mangos_string" #define REVISION_DB_REALMD "required_9010_01_realmd_realmlist" #endif // __REVISION_SQL_H__