From 1535f1a9e5044a2d9fb6c2799d3e36783097a091 Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Thu, 30 Oct 2008 21:04:51 +0300 Subject: [PATCH] Fixied crash at .pinfo command use from console. Also apply mangos code style to related code. --- src/game/Level2.cpp | 3 +- src/game/World.cpp | 87 ++++++++++++++++++++++++----------------------- src/game/WorldSession.cpp | 16 ++++----- 3 files changed, 54 insertions(+), 52 deletions(-) diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp index bb47d5f..fa2dbae 100644 --- a/src/game/Level2.cpp +++ b/src/game/Level2.cpp @@ -1794,7 +1794,8 @@ bool ChatHandler::HandlePInfoCommand(const char* args) else { accId = objmgr.GetPlayerAccountIdByGUID(targetGUID); - Player plr(m_session); // use current session for temporary load + WorldSession session(0,NULL,SEC_PLAYER,0,0,LOCALE_enUS); + Player plr(&session); // use fake session for temporary load plr.MinimalLoadFromDB(NULL, targetGUID); money = plr.GetMoney(); total_player_time = plr.GetTotalPlayedTime(); diff --git a/src/game/World.cpp b/src/game/World.cpp index c32c297..a8bc9a6 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -178,67 +178,67 @@ bool World::RemoveSession(uint32 id) void World::AddSession(WorldSession* s) { - addSessQueue.add(s); + addSessQueue.add(s); } void World::AddSession_ (WorldSession* s) { - ASSERT (s); + ASSERT (s); - //NOTE - Still there is race condition in WorldSession* being used in the Sockets + //NOTE - Still there is race condition in WorldSession* being used in the Sockets - ///- kick already loaded player with same account (if any) and remove session - ///- if player is in loading and want to load again, return - if (!RemoveSession (s->GetAccountId ())) + ///- kick already loaded player with same account (if any) and remove session + ///- if player is in loading and want to load again, return + if (!RemoveSession (s->GetAccountId ())) { - s->KickPlayer (); - m_kicked_sessions.insert (s); - return; + s->KickPlayer (); + m_kicked_sessions.insert (s); + return; } - WorldSession* old = m_sessions[s->GetAccountId ()]; - m_sessions[s->GetAccountId ()] = s; + WorldSession* old = m_sessions[s->GetAccountId ()]; + m_sessions[s->GetAccountId ()] = s; - // if session already exist, prepare to it deleting at next world update - // NOTE - KickPlayer() should be called on "old" in RemoveSession() - if (old) - m_kicked_sessions.insert (old); + // if session already exist, prepare to it deleting at next world update + // NOTE - KickPlayer() should be called on "old" in RemoveSession() + if (old) + m_kicked_sessions.insert (old); - uint32 Sessions = GetActiveAndQueuedSessionCount (); - uint32 pLimit = GetPlayerAmountLimit (); - uint32 QueueSize = GetQueueSize (); //number of players in the queue - bool inQueue = false; - //so we don't count the user trying to - //login as a session and queue the socket that we are using - --Sessions; + uint32 Sessions = GetActiveAndQueuedSessionCount (); + uint32 pLimit = GetPlayerAmountLimit (); + uint32 QueueSize = GetQueueSize (); //number of players in the queue + bool inQueue = false; + //so we don't count the user trying to + //login as a session and queue the socket that we are using + --Sessions; - if (pLimit > 0 && Sessions >= pLimit && s->GetSecurity () == SEC_PLAYER ) + if (pLimit > 0 && Sessions >= pLimit && s->GetSecurity () == SEC_PLAYER ) { - AddQueuedPlayer (s); - UpdateMaxSessionCounters (); - sLog.outDetail ("PlayerQueue: Account id %u is in Queue Position (%u).", s->GetAccountId (), ++QueueSize); - return; + AddQueuedPlayer (s); + UpdateMaxSessionCounters (); + sLog.outDetail ("PlayerQueue: Account id %u is in Queue Position (%u).", s->GetAccountId (), ++QueueSize); + return; } - WorldPacket packet(SMSG_AUTH_RESPONSE, 1 + 4 + 1 + 4 + 1); - packet << uint8 (AUTH_OK); - packet << uint32 (0); // unknown random value... - packet << uint8 (0); - packet << uint32 (0); - packet << uint8 (s->Expansion()); // 0 - normal, 1 - TBC, must be set in database manually for each account - s->SendPacket (&packet); + WorldPacket packet(SMSG_AUTH_RESPONSE, 1 + 4 + 1 + 4 + 1); + packet << uint8 (AUTH_OK); + packet << uint32 (0); // unknown random value... + packet << uint8 (0); + packet << uint32 (0); + packet << uint8 (s->Expansion()); // 0 - normal, 1 - TBC, must be set in database manually for each account + s->SendPacket (&packet); - UpdateMaxSessionCounters (); + UpdateMaxSessionCounters (); - // Updates the population - if (pLimit > 0) + // Updates the population + if (pLimit > 0) { - float popu = GetActiveSessionCount (); //updated number of users on the server - popu /= pLimit; - popu *= 2; - loginDatabase.PExecute ("UPDATE realmlist SET population = '%f' WHERE id = '%d'", popu, realmID); - sLog.outDetail ("Server Population (%f).", popu); + float popu = GetActiveSessionCount (); //updated number of users on the server + popu /= pLimit; + popu *= 2; + loginDatabase.PExecute ("UPDATE realmlist SET population = '%f' WHERE id = '%d'", popu, realmID); + sLog.outDetail ("Server Population (%f).", popu); } } @@ -2414,7 +2414,10 @@ void World::UpdateSessions( time_t diff ) ///- Delete kicked sessions at add new session for (std::set::iterator itr = m_kicked_sessions.begin(); itr != m_kicked_sessions.end(); ++itr) + { + RemoveQueuedPlayer (*itr); delete *itr; + } m_kicked_sessions.clear(); ///- Then send an update signal to remaining ones diff --git a/src/game/WorldSession.cpp b/src/game/WorldSession.cpp index 261d613..3018f1e 100644 --- a/src/game/WorldSession.cpp +++ b/src/game/WorldSession.cpp @@ -58,25 +58,23 @@ _logoutTime(0), m_playerLoading(false), m_playerLogout(false), m_playerRecentlyL WorldSession::~WorldSession() { ///- unload player if not unloaded - if(_player) - LogoutPlayer(true); + if (_player) + LogoutPlayer (true); /// - If have unclosed socket, close it - if (m_Socket) + if (m_Socket) { - m_Socket->CloseSocket (); - m_Socket->RemoveReference (); - m_Socket = NULL; + m_Socket->CloseSocket (); + m_Socket->RemoveReference (); + m_Socket = NULL; } ///- empty incoming packet queue while(!_recvQueue.empty()) { - WorldPacket *packet = _recvQueue.next(); + WorldPacket *packet = _recvQueue.next (); delete packet; } - - sWorld.RemoveQueuedPlayer(this); } void WorldSession::SizeError(WorldPacket const& packet, uint32 size) const -- 2.11.4.GIT