From 29f4a1e090338bc033ebdecb0d71ee45cde6f66f Mon Sep 17 00:00:00 2001 From: neltharionorg Date: Tue, 5 Dec 2017 02:57:42 +0400 Subject: [PATCH] Import uptime table and feature from TC (#717) --- .../rev_1511238042597856200.sql | 11 +++++++ .../Database/Implementation/LoginDatabase.cpp | 1 + .../Database/Implementation/LoginDatabase.h | 1 + src/game/World/World.cpp | 31 ++++++++++++++++++- src/game/World/World.h | 1 + 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 data/sql/updates/pending_db_auth/rev_1511238042597856200.sql diff --git a/data/sql/updates/pending_db_auth/rev_1511238042597856200.sql b/data/sql/updates/pending_db_auth/rev_1511238042597856200.sql new file mode 100644 index 000000000..e9811213a --- /dev/null +++ b/data/sql/updates/pending_db_auth/rev_1511238042597856200.sql @@ -0,0 +1,11 @@ +INSERT INTO version_db_auth (`sql_rev`) VALUES ('1511238042597856200'); +DROP TABLE IF EXISTS `uptime`; + +CREATE TABLE `uptime` ( + `realmid` int(10) unsigned NOT NULL, + `starttime` int(10) unsigned NOT NULL DEFAULT '0', + `uptime` int(10) unsigned NOT NULL DEFAULT '0', + `maxplayers` smallint(5) unsigned NOT NULL DEFAULT '0', + `revision` varchar(255) NOT NULL DEFAULT 'AzerothCore', + PRIMARY KEY (`realmid`,`starttime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Uptime system'; \ No newline at end of file diff --git a/modules/worldengine/nucleus/src/Database/Implementation/LoginDatabase.cpp b/modules/worldengine/nucleus/src/Database/Implementation/LoginDatabase.cpp index 2f24eb49e..66d1755c7 100644 --- a/modules/worldengine/nucleus/src/Database/Implementation/LoginDatabase.cpp +++ b/modules/worldengine/nucleus/src/Database/Implementation/LoginDatabase.cpp @@ -57,6 +57,7 @@ void LoginDatabaseConnection::DoPrepareStatements() PrepareStatement(LOGIN_UPD_MUTE_TIME_LOGIN, "UPDATE account SET mutetime = ? WHERE id = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_UPD_LAST_IP, "UPDATE account SET last_ip = ? WHERE username = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_UPD_ACCOUNT_ONLINE, "UPDATE account SET online = online | (1<<(?-1)) WHERE id = ?", CONNECTION_ASYNC); + PrepareStatement(LOGIN_UPD_UPTIME_PLAYERS, "UPDATE uptime SET uptime = ?, maxplayers = ? WHERE realmid = ? AND starttime = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_DEL_OLD_LOGS, "DELETE FROM logs WHERE (time + ?) < ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_DEL_ACCOUNT_ACCESS, "DELETE FROM account_access WHERE id = ?", CONNECTION_ASYNC); PrepareStatement(LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM, "DELETE FROM account_access WHERE id = ? AND (RealmID = ? OR RealmID = -1)", CONNECTION_ASYNC); diff --git a/modules/worldengine/nucleus/src/Database/Implementation/LoginDatabase.h b/modules/worldengine/nucleus/src/Database/Implementation/LoginDatabase.h index d745d44c8..0bde70d16 100644 --- a/modules/worldengine/nucleus/src/Database/Implementation/LoginDatabase.h +++ b/modules/worldengine/nucleus/src/Database/Implementation/LoginDatabase.h @@ -77,6 +77,7 @@ enum LoginDatabaseStatements LOGIN_UPD_MUTE_TIME_LOGIN, LOGIN_UPD_LAST_IP, LOGIN_UPD_ACCOUNT_ONLINE, + LOGIN_UPD_UPTIME_PLAYERS, LOGIN_DEL_OLD_LOGS, LOGIN_DEL_ACCOUNT_ACCESS, LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM, diff --git a/src/game/World/World.cpp b/src/game/World/World.cpp index e2d204c48..5e9c2392b 100644 --- a/src/game/World/World.cpp +++ b/src/game/World/World.cpp @@ -910,6 +910,12 @@ void World::LoadConfigSettings(bool reload) m_int_configs[CONFIG_UPTIME_UPDATE] = 1; } + if (reload) + { + m_timers[WUPDATE_UPTIME].SetInterval(m_int_configs[CONFIG_UPTIME_UPDATE]*MINUTE*IN_MILLISECONDS); + m_timers[WUPDATE_UPTIME].Reset(); + } + // log db cleanup interval m_int_configs[CONFIG_LOGDB_CLEARINTERVAL] = sConfigMgr->GetIntDefault("LogDB.Opt.ClearInterval", 10); if (int32(m_int_configs[CONFIG_LOGDB_CLEARINTERVAL]) <= 0) @@ -1760,11 +1766,16 @@ void World::SetInitialWorldSettings() m_gameTime = time(NULL); m_startTime = m_gameTime; + LoginDatabase.PExecute("INSERT INTO uptime (realmid, starttime, uptime, revision) VALUES(%u, %u, 0, '%s')", + realmID, uint32(m_startTime), _FULLVERSION); // One-time query + m_timers[WUPDATE_WEATHERS].SetInterval(1*IN_MILLISECONDS); m_timers[WUPDATE_AUCTIONS].SetInterval(MINUTE*IN_MILLISECONDS); m_timers[WUPDATE_AUCTIONS].SetCurrent(MINUTE*IN_MILLISECONDS); + m_timers[WUPDATE_UPTIME].SetInterval(m_int_configs[CONFIG_UPTIME_UPDATE]*MINUTE*IN_MILLISECONDS); + //Update "uptime" table based on configuration entry in minutes. m_timers[WUPDATE_CORPSES].SetInterval(20 * MINUTE * IN_MILLISECONDS); //erase corpses every 20 minutes @@ -2085,7 +2096,25 @@ void World::Update(uint32 diff) // execute callbacks from sql queries that were queued recently ProcessQueryCallbacks(); - + + ///
  • Update uptime table + if (m_timers[WUPDATE_UPTIME].Passed()) + { + uint32 tmpDiff = uint32(m_gameTime - m_startTime); + uint32 maxOnlinePlayers = GetMaxPlayerCount(); + + m_timers[WUPDATE_UPTIME].Reset(); + + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_UPTIME_PLAYERS); + + stmt->setUInt32(0, tmpDiff); + stmt->setUInt16(1, uint16(maxOnlinePlayers)); + stmt->setUInt32(2, realmID); + stmt->setUInt32(3, uint32(m_startTime)); + + LoginDatabase.Execute(stmt); + } + ///- Erase corpses once every 20 minutes if (m_timers[WUPDATE_CORPSES].Passed()) { diff --git a/src/game/World/World.h b/src/game/World/World.h index 96eecf073..58a14dd4d 100644 --- a/src/game/World/World.h +++ b/src/game/World/World.h @@ -60,6 +60,7 @@ enum WorldTimers { WUPDATE_AUCTIONS, WUPDATE_WEATHERS, + WUPDATE_UPTIME, WUPDATE_CORPSES, WUPDATE_EVENTS, WUPDATE_CLEANDB,