Created
December 25, 2015 12:55
-
-
Save kotishe/807eabbc1617c8a55e18 to your computer and use it in GitHub Desktop.
Move uptime table to auth for better compatibility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HG changeset patch | |
# User kotishe <[email protected]> | |
# Date 1451047887 -10800 | |
# Fri Dec 25 15:51:27 2015 +0300 | |
# Node ID 92afa47d8dbd7e0269f6d09940da57c4c67bb4bf | |
# Parent 1cacfd0d872062c4b6d43fc2a61ed7f568885902 | |
Move uptime table to auth for better compatibility | |
diff --git a/sql/realmd.sql b/sql/realmd.sql | |
--- a/sql/realmd.sql | |
+++ b/sql/realmd.sql | |
@@ -121,6 +121,16 @@ | |
INSERT INTO `realmlist` VALUES (1,'OregonCore','127.0.0.1',8085,0,0,1,0,0,'8606'); | |
+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 'Trinitycore', | |
+ PRIMARY KEY (`realmid`,`starttime`) | |
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Uptime system'; | |
+ | |
-- | |
-- EOF | |
-- | |
\ No newline at end of file | |
diff --git a/sql/updates/realmd/3128_uptime.sql b/sql/updates/realmd/3128_uptime.sql | |
new file mode 100644 | |
--- /dev/null | |
+++ b/sql/updates/realmd/3128_uptime.sql | |
@@ -0,0 +1,9 @@ | |
+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 'DefaultCore', | |
+ PRIMARY KEY (`realmid`,`starttime`) | |
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Uptime system'; | |
\ No newline at end of file | |
diff --git a/sql/updates/world/3128_uptime.sql b/sql/updates/world/3128_uptime.sql | |
new file mode 100644 | |
--- /dev/null | |
+++ b/sql/updates/world/3128_uptime.sql | |
@@ -0,0 +1,1 @@ | |
+DROP TABLE IF EXISTS `uptime`; | |
\ No newline at end of file | |
diff --git a/src/game/Player.cpp b/src/game/Player.cpp | |
--- a/src/game/Player.cpp | |
+++ b/src/game/Player.cpp | |
@@ -432,6 +432,8 @@ | |
m_isActive = true; | |
+ sWorld.IncreasePlayerCount(); | |
+ | |
_activeCheats = CHEAT_NONE; | |
m_ControlledByPlayer = true; | |
@@ -1518,8 +1520,8 @@ | |
{ | |
ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_AFK); | |
- // afk player not allowed in battleground | |
- if (isAFK() && InBattleGround() && !InArena()) | |
+ // afk player not allowed in battleground | |
+ if (isAFK() && InBattleGround() && !InArena()) | |
LeaveBattleground(); | |
} | |
@@ -1530,13 +1532,13 @@ | |
uint8 Player::GetChatTag() const | |
{ | |
- uint8 tag = CHAT_TAG_NONE; | |
- | |
- if (isGMChat()) | |
- tag |= CHAT_TAG_GM; | |
- if (isDND()) | |
- tag |= CHAT_TAG_DND; | |
- if (isAFK()) | |
+ uint8 tag = CHAT_TAG_NONE; | |
+ | |
+ if (isGMChat()) | |
+ tag |= CHAT_TAG_GM; | |
+ if (isDND()) | |
+ tag |= CHAT_TAG_DND; | |
+ if (isAFK()) | |
tag |= CHAT_TAG_AFK; | |
return tag; | |
@@ -1805,9 +1807,9 @@ | |
return true; | |
} | |
-bool Player::TeleportTo(WorldLocation const &loc, uint32 options /*= 0*/) | |
-{ | |
- return TeleportTo(loc.GetMapId(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ(), loc.GetOrientation(), options); | |
+bool Player::TeleportTo(WorldLocation const &loc, uint32 options /*= 0*/) | |
+{ | |
+ return TeleportTo(loc.GetMapId(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ(), loc.GetOrientation(), options); | |
} | |
WorldLocation Player::GetStartPosition() const | |
@@ -2152,22 +2154,22 @@ | |
} | |
} | |
-bool Player::CanInteractWithQuestGiver(Object* questGiver) | |
-{ | |
- switch (questGiver->GetTypeId()) | |
- { | |
- case TYPEID_UNIT: | |
- return GetNPCIfCanInteractWith(questGiver->GetGUID(), UNIT_NPC_FLAG_QUESTGIVER) != NULL; | |
- case TYPEID_GAMEOBJECT: | |
- return GetGameObjectIfCanInteractWith(questGiver->GetGUID(), GAMEOBJECT_TYPE_QUESTGIVER) != NULL; | |
- case TYPEID_PLAYER: | |
- return IsAlive() && questGiver->ToPlayer()->IsAlive(); | |
- case TYPEID_ITEM: | |
- return IsAlive(); | |
- default: | |
- break; | |
- } | |
- return false; | |
+bool Player::CanInteractWithQuestGiver(Object* questGiver) | |
+{ | |
+ switch (questGiver->GetTypeId()) | |
+ { | |
+ case TYPEID_UNIT: | |
+ return GetNPCIfCanInteractWith(questGiver->GetGUID(), UNIT_NPC_FLAG_QUESTGIVER) != NULL; | |
+ case TYPEID_GAMEOBJECT: | |
+ return GetGameObjectIfCanInteractWith(questGiver->GetGUID(), GAMEOBJECT_TYPE_QUESTGIVER) != NULL; | |
+ case TYPEID_PLAYER: | |
+ return IsAlive() && questGiver->ToPlayer()->IsAlive(); | |
+ case TYPEID_ITEM: | |
+ return IsAlive(); | |
+ default: | |
+ break; | |
+ } | |
+ return false; | |
} | |
Creature* Player::GetNPCIfCanInteractWith(uint64 guid, uint32 npcflagmask) | |
@@ -2516,7 +2518,7 @@ | |
//update level, max level of skills | |
m_Played_time[PLAYED_TIME_LEVEL] = 0; // Level Played Time reset | |
- | |
+ | |
SetLevel(level); | |
UpdateSkillsForLevel(); | |
@@ -13654,9 +13656,9 @@ | |
return true; | |
// each-from-all exclusive group (< 0) | |
- // given a group with 2+ quests, and one of those has a branch that is not restricted by the group, return true | |
- if (qInfo->GetPrevQuestId() != 0 && qPrevInfo->GetNextQuestId() != qInfo->GetPrevQuestId()) | |
- return true; | |
+ // given a group with 2+ quests, and one of those has a branch that is not restricted by the group, return true | |
+ if (qInfo->GetPrevQuestId() != 0 && qPrevInfo->GetNextQuestId() != qInfo->GetPrevQuestId()) | |
+ return true; | |
// can be start if only all quests in prev quest exclusive group completed and rewarded | |
ObjectMgr::ExclusiveQuestGroups::iterator iter = sObjectMgr.mExclusiveQuestGroups.lower_bound(qPrevInfo->GetExclusiveGroup()); | |
@@ -13693,9 +13695,9 @@ | |
return true; | |
// each-from-all exclusive group (< 0) | |
- // given a group with 2+ quests, and one of those has a branch that is not restricted by the group, return true | |
- if (qInfo->GetPrevQuestId() != 0 && qPrevInfo->GetNextQuestId() != abs(qInfo->GetPrevQuestId())) | |
- return true; | |
+ // given a group with 2+ quests, and one of those has a branch that is not restricted by the group, return true | |
+ if (qInfo->GetPrevQuestId() != 0 && qPrevInfo->GetNextQuestId() != abs(qInfo->GetPrevQuestId())) | |
+ return true; | |
// can be start if only all quests in prev quest exclusive group active | |
ObjectMgr::ExclusiveQuestGroups::iterator iter = sObjectMgr.mExclusiveQuestGroups.lower_bound(qPrevInfo->GetExclusiveGroup()); | |
@@ -16308,7 +16310,7 @@ | |
bind.save = save; | |
bind.perm = permanent; | |
- | |
+ | |
#ifdef OREGON_DEBUG | |
if (!load) | |
DEBUG_LOG("Player::BindToInstance: %s(%d) is now bound to map %d, instance %d, difficulty %d", GetName(), GetGUIDLow(), save->GetMapId(), save->GetInstanceId(), save->GetDifficulty()); | |
@@ -17772,7 +17774,7 @@ | |
data << uint8(0); // cooldowns count | |
GetSession()->SendPacket(&data); | |
- | |
+ | |
charm->SendHealthUpdateDueToCharm(this); | |
} | |
@@ -17831,7 +17833,7 @@ | |
data << uint8(0); // cooldowns count | |
GetSession()->SendPacket(&data); | |
- | |
+ | |
charm->SendHealthUpdateDueToCharm(this); | |
} | |
@@ -20063,13 +20065,13 @@ | |
GetSession()->SendPacket(&packet); | |
} | |
-void Player::SetSummonPoint(uint32 mapid, float x, float y, float z) | |
-{ | |
- m_summon_expire = time(NULL) + MAX_PLAYER_SUMMON_DELAY; | |
- m_summon_mapid = mapid; | |
- m_summon_x = x; | |
- m_summon_y = y; | |
- m_summon_z = z; | |
+void Player::SetSummonPoint(uint32 mapid, float x, float y, float z) | |
+{ | |
+ m_summon_expire = time(NULL) + MAX_PLAYER_SUMMON_DELAY; | |
+ m_summon_mapid = mapid; | |
+ m_summon_x = x; | |
+ m_summon_y = y; | |
+ m_summon_z = z; | |
} | |
void Player::SummonIfPossible(bool agree) | |
@@ -20846,7 +20848,7 @@ | |
if (damageperc > 0) | |
{ | |
uint32 damage = (uint32)(damageperc * GetMaxHealth() * sWorld.getRate(RATE_DAMAGE_FALL)); | |
- | |
+ | |
if (GetCommandStatus(CHEAT_GOD)) | |
damage = 0; | |
diff --git a/src/game/World.cpp b/src/game/World.cpp | |
--- a/src/game/World.cpp | |
+++ b/src/game/World.cpp | |
@@ -97,6 +97,8 @@ | |
m_startTime = m_gameTime; | |
m_maxActiveSessionCount = 0; | |
m_maxQueuedSessionCount = 0; | |
+ m_PlayerCount = 0; | |
+ m_MaxPlayerCount = 0; | |
m_resultQueue = NULL; | |
m_NextDailyQuestReset = 0; | |
m_scheduledScripts = 0; | |
@@ -1188,7 +1190,7 @@ | |
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, | |
NULL, | |
dwLastError, | |
- MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), | |
+ MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), | |
lpBuffer, | |
sizeof(lpBuffer)-1, | |
NULL); | |
@@ -1208,7 +1210,7 @@ | |
else | |
sLog.outFatal("Can't open %s: %s", path.c_str(), strerror(errno)); | |
#endif | |
- | |
+ | |
std::sort(files.begin(), files.end()); | |
for (size_t j = 0; j < files.size(); ++j) | |
@@ -1217,7 +1219,7 @@ | |
char name[PATH_MAX]; | |
if (sscanf(files[j].c_str(), "%u_%s.sql", &revision, name) != 2 || currentRev >= revision) | |
continue; | |
- | |
+ | |
label.str(""); | |
label << "Applying " << files[j].c_str() << " (" << j << '/' << files.size() << ')'; | |
sConsole.SetLoadingLabel(label.str().c_str()); | |
@@ -1616,16 +1618,8 @@ | |
m_gameTime = time(NULL); | |
m_startTime = m_gameTime; | |
- tm local; | |
- time_t curr; | |
- time(&curr); | |
- local = *(localtime(&curr)); // dereference and assign | |
- char isoDate[128]; | |
- sprintf(isoDate, "%04d-%02d-%02d %02d:%02d:%02d", | |
- local.tm_year + 1900, local.tm_mon + 1, local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec); | |
- | |
- WorldDatabase.PExecute("INSERT INTO uptime (startstring, starttime, uptime) VALUES('%s', " UI64FMTD ", 0)", | |
- isoDate, uint64(m_startTime)); | |
+ 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_AUTOBROADCAST].SetInterval(m_configs[CONFIG_AUTOBROADCAST_TIMER]); | |
m_timers[WUPDATE_OBJECTS].SetInterval(IN_MILLISECONDS / 2); | |
@@ -1946,11 +1940,12 @@ | |
// Update uptime table | |
if (m_timers[WUPDATE_UPTIME].Passed()) | |
{ | |
- uint32 tmpDiff = (m_gameTime - m_startTime); | |
- uint32 maxClientsNum = sWorld.GetMaxActiveSessionCount(); | |
+ uint32 tmpDiff = uint32(m_gameTime - m_startTime); | |
+ uint32 maxOnlinePlayers = GetMaxPlayerCount(); | |
m_timers[WUPDATE_UPTIME].Reset(); | |
- WorldDatabase.PExecute("UPDATE uptime SET uptime = %d, maxplayers = %d WHERE starttime = " UI64FMTD, tmpDiff, maxClientsNum, uint64(m_startTime)); | |
+ | |
+ LoginDatabase.PExecute("UPDATE uptime SET uptime = %u, maxplayers = %u WHERE realmid = %u AND starttime = %u", tmpDiff, uint16(maxOnlinePlayers), realmID, uint32(m_startTime)); | |
} | |
// Clean logs table | |
diff --git a/src/game/World.h b/src/game/World.h | |
--- a/src/game/World.h | |
+++ b/src/game/World.h | |
@@ -451,7 +451,6 @@ | |
OpcodePenalty penalty; //!< What should happen if the threshold per interval is passed. | |
}; | |
-typedef UNORDERED_MAP<uint32, WorldSession*> SessionMap; | |
// The World | |
class World | |
@@ -466,30 +465,25 @@ | |
void AddSession(WorldSession* s); | |
void SendAutoBroadcast(); | |
bool RemoveSession(uint32 id); | |
- // Get the number of current active sessions | |
+ /// Get the number of current active sessions | |
void UpdateMaxSessionCounters(); | |
- const SessionMap& GetAllSessions() const { return m_sessions; } | |
- uint32 GetActiveAndQueuedSessionCount() const | |
+ uint32 GetActiveAndQueuedSessionCount() const { return uint32(m_sessions.size()); } | |
+ uint32 GetActiveSessionCount() const { return uint32(m_sessions.size() - m_QueuedPlayer.size()); } | |
+ uint32 GetQueuedSessionCount() const { return uint32(m_QueuedPlayer.size()); } | |
+ /// Get the maximum number of parallel sessions on the server since last reboot | |
+ uint32 GetMaxQueuedSessionCount() const { return m_maxQueuedSessionCount; } | |
+ uint32 GetMaxActiveSessionCount() const { return m_maxActiveSessionCount; } | |
+ /// Get number of players | |
+ inline uint32 GetPlayerCount() const { return m_PlayerCount; } | |
+ inline uint32 GetMaxPlayerCount() const { return m_MaxPlayerCount; } | |
+ /// Increase/Decrease number of players | |
+ inline void IncreasePlayerCount() | |
{ | |
- return m_sessions.size(); | |
+ m_PlayerCount++; | |
+ m_MaxPlayerCount = std::max(m_MaxPlayerCount, m_PlayerCount); | |
} | |
- uint32 GetActiveSessionCount() const | |
- { | |
- return m_sessions.size() - m_QueuedPlayer.size(); | |
- } | |
- uint32 GetQueuedSessionCount() const | |
- { | |
- return m_QueuedPlayer.size(); | |
- } | |
- // Get the maximum number of parallel sessions on the server since last reboot | |
- uint32 GetMaxQueuedSessionCount() const | |
- { | |
- return m_maxQueuedSessionCount; | |
- } | |
- uint32 GetMaxActiveSessionCount() const | |
- { | |
- return m_maxActiveSessionCount; | |
- } | |
+ inline void DecreasePlayerCount() { m_PlayerCount--; } | |
+ | |
Player* FindPlayerInZone(uint32 zone); | |
Weather* FindWeather(uint32 id) const; | |
@@ -820,12 +814,14 @@ | |
typedef UNORDERED_MAP<uint32, Weather*> WeatherMap; | |
WeatherMap m_weathers; | |
- | |
+ typedef UNORDERED_MAP<uint32, WorldSession*> SessionMap; | |
SessionMap m_sessions; | |
typedef UNORDERED_MAP<uint32, time_t> DisconnectMap; | |
DisconnectMap m_disconnects; | |
uint32 m_maxActiveSessionCount; | |
uint32 m_maxQueuedSessionCount; | |
+ uint32 m_PlayerCount; | |
+ uint32 m_MaxPlayerCount; | |
std::string m_newCharString; | |
diff --git a/src/game/WorldSession.cpp b/src/game/WorldSession.cpp | |
--- a/src/game/WorldSession.cpp | |
+++ b/src/game/WorldSession.cpp | |
@@ -469,6 +469,8 @@ | |
//No SQL injection as AccountId is uint32 | |
CharacterDatabase.PExecute("UPDATE characters SET online = 0 WHERE account = '%u'", | |
GetAccountId()); | |
+ | |
+ sWorld.DecreasePlayerCount(); | |
sLog.outDebug("SESSION: Sent SMSG_LOGOUT_COMPLETE Message"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment