AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
WorldSessionMgr Class Reference

#include "WorldSessionMgr.h"

Public Types

typedef std::unordered_map< uint32, WorldSession * > SessionMap
 

Public Member Functions

 WorldSessionMgr ()
 
 ~WorldSessionMgr ()
 
WorldSessionFindSession (uint32 id) const
 Find a session by its id.
 
WorldSessionFindOfflineSession (uint32 id) const
 
WorldSessionFindOfflineSessionForCharacterGUID (ObjectGuid::LowType guidLow) const
 
void UpdateSessions (uint32 const diff)
 
bool KickSession (uint32 id)
 Remove a given session.
 
void KickAll ()
 Kick (and save) all players.
 
void KickAllLess (AccountTypes sec)
 Kick (and save) all players with security level less sec
 
void AddSession (WorldSession *session)
 
void AddQueuedPlayer (WorldSession *session)
 
bool RemoveQueuedPlayer (WorldSession *session)
 
int32 GetQueuePos (WorldSession *session)
 
bool HasRecentlyDisconnected (WorldSession *session)
 
SessionMap const & GetAllSessions () const
 
void UpdateMaxSessionCounters ()
 Get the number of current active sessions.
 
uint32 GetActiveAndQueuedSessionCount () const
 
uint32 GetActiveSessionCount () const
 
uint32 GetQueuedSessionCount () const
 
uint32 GetMaxQueuedSessionCount () const
 Get the maximum number of parallel sessions on the server since last reboot.
 
uint32 GetMaxActiveSessionCount () const
 
uint32 GetPlayerCount () const
 Get number of players.
 
uint32 GetMaxPlayerCount () const
 
void SetPlayerAmountLimit (uint32 limit)
 Active session server limit.
 
uint32 GetPlayerAmountLimit () const
 
void IncreasePlayerCount ()
 Increase/Decrease number of players.
 
void DecreasePlayerCount ()
 
void SendGlobalMessage (WorldPacket const *packet, WorldSession *self=nullptr, TeamId teamId=TEAM_NEUTRAL)
 Send a packet to all players (except self if mentioned)
 
void SendGlobalGMMessage (WorldPacket const *packet, WorldSession *self=nullptr, TeamId teamId=TEAM_NEUTRAL)
 Send a packet to all GMs (except self if mentioned)
 
void SendServerMessage (ServerMessageType messageID, std::string stringParam="", Player *player=nullptr)
 Send a server message to the user(s)
 
void DoForAllOnlinePlayers (std::function< void(Player *)> exec)
 

Static Public Member Functions

static WorldSessionMgrInstance ()
 

Private Types

typedef std::unordered_map< uint32, time_t > DisconnectMap
 
typedef std::list< WorldSession * > Queue
 

Private Member Functions

void AddSession_ (WorldSession *session)
 

Private Attributes

LockedQueue< WorldSession * > _addSessQueue
 
SessionMap _sessions
 
SessionMap _offlineSessions
 
DisconnectMap _disconnects
 
Queue _queuedPlayer
 
uint32 _playerLimit
 
uint32 _maxActiveSessionCount
 
uint32 _maxQueuedSessionCount
 
uint32 _playerCount
 
uint32 _maxPlayerCount
 

Detailed Description

Member Typedef Documentation

◆ DisconnectMap

typedef std::unordered_map<uint32, time_t> WorldSessionMgr::DisconnectMap
private

◆ Queue

typedef std::list<WorldSession*> WorldSessionMgr::Queue
private

◆ SessionMap

typedef std::unordered_map<uint32, WorldSession*> WorldSessionMgr::SessionMap

Constructor & Destructor Documentation

◆ WorldSessionMgr()

WorldSessionMgr::WorldSessionMgr ( )
35{
36 _playerLimit = 0;
39 _playerCount = 0;
41}
uint32 _playerLimit
Definition WorldSessionMgr.h:101
uint32 _maxActiveSessionCount
Definition WorldSessionMgr.h:102
uint32 _maxQueuedSessionCount
Definition WorldSessionMgr.h:103
uint32 _playerCount
Definition WorldSessionMgr.h:104
uint32 _maxPlayerCount
Definition WorldSessionMgr.h:105

References _maxActiveSessionCount, _maxPlayerCount, _maxQueuedSessionCount, _playerCount, and _playerLimit.

◆ ~WorldSessionMgr()

WorldSessionMgr::~WorldSessionMgr ( )
  • Empty the kicked session set
44{
46 while (!_sessions.empty())
47 {
48 // not remove from queue, prevent loading new sessions
49 delete _sessions.begin()->second;
50 _sessions.erase(_sessions.begin());
51 }
52
53 while (!_offlineSessions.empty())
54 {
55 delete _offlineSessions.begin()->second;
57 }
58}
SessionMap _sessions
Definition WorldSessionMgr.h:92
SessionMap _offlineSessions
Definition WorldSessionMgr.h:93

References _offlineSessions, and _sessions.

Member Function Documentation

◆ AddQueuedPlayer()

void WorldSessionMgr::AddQueuedPlayer ( WorldSession session)
211{
212 session->SetInQueue(true);
213 _queuedPlayer.push_back(session);
214
215 // The 1st SMSG_AUTH_RESPONSE needs to contain other info too.
216 session->SendAuthResponse(AUTH_WAIT_QUEUE, false, GetQueuePos(session));
217}
@ AUTH_WAIT_QUEUE
Definition SharedDefines.h:3599
Queue _queuedPlayer
Definition WorldSessionMgr.h:99
int32 GetQueuePos(WorldSession *session)
Definition WorldSessionMgr.cpp:267
void SetInQueue(bool state)
Session in auth.queue currently.
Definition WorldSession.h:474
void SendAuthResponse(uint8 code, bool shortForm, uint32 queuePos=0)
Definition AuthHandler.cpp:22

References _queuedPlayer, AUTH_WAIT_QUEUE, GetQueuePos(), WorldSession::SendAuthResponse(), and WorldSession::SetInQueue().

Referenced by AddSession_().

◆ AddSession()

void WorldSessionMgr::AddSession ( WorldSession session)
206{
207 _addSessQueue.add(session);
208}
void add(const T &item)
Adds an item to the back of the queue.
Definition LockedQueue.h:52
LockedQueue< WorldSession * > _addSessQueue
Definition WorldSessionMgr.h:89

References _addSessQueue, and LockedQueue< T, StorageType >::add().

◆ AddSession_()

void WorldSessionMgr::AddSession_ ( WorldSession session)
private
279{
280 ASSERT(session);
281
282 // kick existing session with same account (if any)
283 // if character on old session is being loaded, then return
284 if (!KickSession(session->GetAccountId()))
285 {
286 session->KickPlayer("kick existing session with same account");
287 delete session; // session not added yet in session list, so not listed in queue
288 return;
289 }
290
291 SessionMap::const_iterator old = _sessions.find(session->GetAccountId());
292 if (old != _sessions.end())
293 {
294 WorldSession* oldSession = old->second;
295
296 if (!RemoveQueuedPlayer(oldSession) && sWorld->getIntConfig(CONFIG_INTERVAL_DISCONNECT_TOLERANCE))
297 _disconnects[session->GetAccountId()] = GameTime::GetGameTime().count();
298
299 // pussywizard:
300 if (oldSession->HandleSocketClosed())
301 {
302 // there should be no offline session if current one is logged onto a character
303 SessionMap::iterator iter;
304 if ((iter = _offlineSessions.find(oldSession->GetAccountId())) != _offlineSessions.end())
305 {
306 WorldSession* tmp = iter->second;
307 _offlineSessions.erase(iter);
308 delete tmp;
309 }
310 oldSession->SetOfflineTime(GameTime::GetGameTime().count());
311 _offlineSessions[oldSession->GetAccountId()] = oldSession;
312 }
313 else
314 {
315 delete oldSession;
316 }
317 }
318
319 _sessions[session->GetAccountId()] = session;
320
322 uint32 pLimit = GetPlayerAmountLimit();
323
324 // don't count this session when checking player limit
325 --Sessions;
326
327 if (pLimit > 0 && Sessions >= pLimit && !session->HasPermission(rbac::RBAC_PERM_SKIP_QUEUE) && !session->CanSkipQueue() && !HasRecentlyDisconnected(session))
328 {
329 AddQueuedPlayer(session);
331 return;
332 }
333
334 session->InitializeSession();
335
337}
std::uint32_t uint32
Definition Define.h:107
#define ASSERT
Definition Errors.h:68
@ CONFIG_INTERVAL_DISCONNECT_TOLERANCE
Definition WorldConfig.h:166
bool KickSession(uint32 id)
Remove a given session.
Definition WorldSessionMgr.cpp:166
void UpdateMaxSessionCounters()
Get the number of current active sessions.
Definition WorldSessionMgr.cpp:361
DisconnectMap _disconnects
Definition WorldSessionMgr.h:96
uint32 GetPlayerAmountLimit() const
Definition WorldSessionMgr.h:72
bool HasRecentlyDisconnected(WorldSession *session)
Definition WorldSessionMgr.cpp:339
uint32 GetActiveAndQueuedSessionCount() const
Definition WorldSessionMgr.h:61
void AddQueuedPlayer(WorldSession *session)
Definition WorldSessionMgr.cpp:210
bool RemoveQueuedPlayer(WorldSession *session)
Definition WorldSessionMgr.cpp:219
Player session in the World.
Definition WorldSession.h:384
void SetOfflineTime(uint32 time)
Definition WorldSession.h:1152
bool HasPermission(uint32 permissionId)
Definition WorldSession.cpp:1551
bool HandleSocketClosed()
Definition WorldSession.cpp:596
uint32 GetAccountId() const
Definition WorldSession.h:453
void KickPlayer(bool setKicked=true)
Definition WorldSession.h:492
void InitializeSession()
Definition WorldSession.cpp:1481
bool CanSkipQueue() const
Definition WorldSession.h:442
#define sWorld
Definition World.h:317
Seconds GetGameTime()
Definition GameTime.cpp:38
@ RBAC_PERM_SKIP_QUEUE
Definition RBAC.h:53

References _disconnects, _offlineSessions, _sessions, AddQueuedPlayer(), ASSERT, WorldSession::CanSkipQueue(), CONFIG_INTERVAL_DISCONNECT_TOLERANCE, WorldSession::GetAccountId(), GetActiveAndQueuedSessionCount(), GameTime::GetGameTime(), GetPlayerAmountLimit(), WorldSession::HandleSocketClosed(), WorldSession::HasPermission(), HasRecentlyDisconnected(), WorldSession::InitializeSession(), WorldSession::KickPlayer(), KickSession(), rbac::RBAC_PERM_SKIP_QUEUE, RemoveQueuedPlayer(), WorldSession::SetOfflineTime(), sWorld, and UpdateMaxSessionCounters().

Referenced by UpdateSessions().

◆ DecreasePlayerCount()

void WorldSessionMgr::DecreasePlayerCount ( )
inline
80{ _playerCount--; }

References _playerCount.

◆ DoForAllOnlinePlayers()

void WorldSessionMgr::DoForAllOnlinePlayers ( std::function< void(Player *)>  exec)
417{
418 std::shared_lock lock(*HashMapHolder<Player>::GetLock());
419 for (auto const& it : ObjectAccessor::GetPlayers())
420 {
421 if (Player* player = it.second)
422 {
423 if (!player->IsInWorld())
424 {
425 continue;
426 }
427
428 exec(player);
429 }
430 }
431}
Definition ObjectAccessor.h:41
Definition Player.h:1084
Definition ObjectAccessor.h:61
HashMapHolder< Player >::MapType const & GetPlayers()
Definition ObjectAccessor.cpp:75

References ObjectAccessor::GetPlayers().

◆ FindOfflineSession()

WorldSession * WorldSessionMgr::FindOfflineSession ( uint32  id) const
72{
73 SessionMap::const_iterator itr = _offlineSessions.find(id);
74 if (itr != _offlineSessions.end())
75 return itr->second;
76 else
77 return nullptr;
78}

References _offlineSessions.

◆ FindOfflineSessionForCharacterGUID()

WorldSession * WorldSessionMgr::FindOfflineSessionForCharacterGUID ( ObjectGuid::LowType  guidLow) const
81{
82 if (_offlineSessions.empty())
83 return nullptr;
84
85 for (SessionMap::const_iterator itr = _offlineSessions.begin(); itr != _offlineSessions.end(); ++itr)
86 if (itr->second->GetGuidLow() == guidLow)
87 return itr->second;
88
89 return nullptr;
90}

References _offlineSessions.

◆ FindSession()

WorldSession * WorldSessionMgr::FindSession ( uint32  id) const

Find a session by its id.

62{
63 SessionMap::const_iterator itr = _sessions.find(id);
64
65 if (itr != _sessions.end())
66 return itr->second; // also can return nullptr for kicked session
67 else
68 return nullptr;
69}

References _sessions.

◆ GetActiveAndQueuedSessionCount()

uint32 WorldSessionMgr::GetActiveAndQueuedSessionCount ( ) const
inline
61{ return _sessions.size(); }

References _sessions.

Referenced by AddSession_().

◆ GetActiveSessionCount()

uint32 WorldSessionMgr::GetActiveSessionCount ( ) const
inline
62{ return _sessions.size() - _queuedPlayer.size(); }

References _queuedPlayer, and _sessions.

Referenced by RemoveQueuedPlayer().

◆ GetAllSessions()

SessionMap const & WorldSessionMgr::GetAllSessions ( ) const
inline
57{ return _sessions; }

References _sessions.

◆ GetMaxActiveSessionCount()

uint32 WorldSessionMgr::GetMaxActiveSessionCount ( ) const
inline

◆ GetMaxPlayerCount()

uint32 WorldSessionMgr::GetMaxPlayerCount ( ) const
inline
69{ return _maxPlayerCount; }

References _maxPlayerCount.

◆ GetMaxQueuedSessionCount()

uint32 WorldSessionMgr::GetMaxQueuedSessionCount ( ) const
inline

Get the maximum number of parallel sessions on the server since last reboot.

65{ return _maxQueuedSessionCount; }

References _maxQueuedSessionCount.

◆ GetPlayerAmountLimit()

uint32 WorldSessionMgr::GetPlayerAmountLimit ( ) const
inline
72{ return _playerLimit; }

References _playerLimit.

Referenced by AddSession_(), and RemoveQueuedPlayer().

◆ GetPlayerCount()

uint32 WorldSessionMgr::GetPlayerCount ( ) const
inline

Get number of players.

68{ return _playerCount; }

References _playerCount.

◆ GetQueuedSessionCount()

uint32 WorldSessionMgr::GetQueuedSessionCount ( ) const
inline
63{ return _queuedPlayer.size(); }

References _queuedPlayer.

◆ GetQueuePos()

int32 WorldSessionMgr::GetQueuePos ( WorldSession session)
268{
269 uint32 position = 1;
270
271 for (Queue::const_iterator iter = _queuedPlayer.begin(); iter != _queuedPlayer.end(); ++iter, ++position)
272 if ((*iter) == session)
273 return position;
274
275 return 0;
276}

References _queuedPlayer.

Referenced by AddQueuedPlayer().

◆ HasRecentlyDisconnected()

bool WorldSessionMgr::HasRecentlyDisconnected ( WorldSession session)
340{
341 if (!session)
342 return false;
343
344 if (uint32 tolerance = sWorld->getIntConfig(CONFIG_INTERVAL_DISCONNECT_TOLERANCE))
345 {
346 for (DisconnectMap::iterator i = _disconnects.begin(); i != _disconnects.end();)
347 {
348 if ((GameTime::GetGameTime().count() - i->second) < tolerance)
349 {
350 if (i->first == session->GetAccountId())
351 return true;
352 ++i;
353 }
354 else
355 _disconnects.erase(i++);
356 }
357 }
358 return false;
359}

References _disconnects, CONFIG_INTERVAL_DISCONNECT_TOLERANCE, WorldSession::GetAccountId(), GameTime::GetGameTime(), and sWorld.

Referenced by AddSession_().

◆ IncreasePlayerCount()

void WorldSessionMgr::IncreasePlayerCount ( )
inline

Increase/Decrease number of players.

76 {
79 }

References _maxPlayerCount, and _playerCount.

◆ Instance()

WorldSessionMgr * WorldSessionMgr::Instance ( )
static
29{
30 static WorldSessionMgr instance;
31 return &instance;
32}
Definition WorldSessionMgr.h:33

◆ KickAll()

void WorldSessionMgr::KickAll ( )

Kick (and save) all players.

184{
185 _queuedPlayer.clear(); // prevent send queue update packet and login queued sessions
186
187 // session not removed at kick and will removed in next update tick
188 for (SessionMap::const_iterator itr = _sessions.begin(); itr != _sessions.end(); ++itr)
189 itr->second->KickPlayer("KickAll sessions");
190
191 // pussywizard: kick offline sessions
192 for (SessionMap::const_iterator itr = _offlineSessions.begin(); itr != _offlineSessions.end(); ++itr)
193 itr->second->KickPlayer("KickAll offline sessions");
194}

References _offlineSessions, _queuedPlayer, and _sessions.

◆ KickAllLess()

void WorldSessionMgr::KickAllLess ( AccountTypes  sec)

Kick (and save) all players with security level less sec

198{
199 // session not removed at kick and will removed in next update tick
200 for (SessionMap::const_iterator itr = _sessions.begin(); itr != _sessions.end(); ++itr)
201 if (itr->second->GetSecurity() < sec)
202 itr->second->KickPlayer("KickAllLess");
203}

References _sessions.

◆ KickSession()

bool WorldSessionMgr::KickSession ( uint32  id)

Remove a given session.

  • Find the session, kick the user, but we can't delete session at this moment to prevent iterator invalidation
167{
169 SessionMap::const_iterator itr = _sessions.find(id);
170
171 if (itr != _sessions.end() && itr->second)
172 {
173 if (itr->second->PlayerLoading())
174 return false;
175
176 itr->second->KickPlayer("KickSession", false);
177 }
178
179 return true;
180}

References _sessions, and WorldSession::KickPlayer().

Referenced by AddSession_().

◆ RemoveQueuedPlayer()

bool WorldSessionMgr::RemoveQueuedPlayer ( WorldSession session)
220{
221 uint32 sessions = GetActiveSessionCount();
222
223 uint32 position = 1;
224 Queue::iterator iter = _queuedPlayer.begin();
225
226 // search to remove and count skipped positions
227 bool found = false;
228
229 for (; iter != _queuedPlayer.end(); ++iter, ++position)
230 {
231 if (*iter == session)
232 {
233 session->SetInQueue(false);
234 session->ResetTimeOutTime(false);
235 iter = _queuedPlayer.erase(iter);
236 found = true;
237 break;
238 }
239 }
240
241 // if session not queued then it was an active session
242 if (!found)
243 {
244 ASSERT(sessions > 0);
245 --sessions;
246 }
247
248 // accept first in queue
249 if ((!GetPlayerAmountLimit() || sessions < GetPlayerAmountLimit()) && !_queuedPlayer.empty())
250 {
251 WorldSession* pop_sess = _queuedPlayer.front();
252 pop_sess->InitializeSession();
253 _queuedPlayer.pop_front();
254
255 // update iter to point first queued socket or end() if queue is empty now
256 iter = _queuedPlayer.begin();
257 position = 1;
258 }
259
260 // update queue position from iter to end()
261 for (; iter != _queuedPlayer.end(); ++iter, ++position)
262 (*iter)->SendAuthWaitQueue(position);
263
264 return found;
265}
uint32 GetActiveSessionCount() const
Definition WorldSessionMgr.h:62
void ResetTimeOutTime(bool onlyActive)
Definition WorldSession.h:604

References _queuedPlayer, ASSERT, GetActiveSessionCount(), GetPlayerAmountLimit(), WorldSession::InitializeSession(), WorldSession::ResetTimeOutTime(), and WorldSession::SetInQueue().

Referenced by AddSession_(), and UpdateSessions().

◆ SendGlobalGMMessage()

void WorldSessionMgr::SendGlobalGMMessage ( WorldPacket const *  packet,
WorldSession self = nullptr,
TeamId  teamId = TEAM_NEUTRAL 
)

Send a packet to all GMs (except self if mentioned)

386{
387 SessionMap::iterator itr;
388 for (itr = _sessions.begin(); itr != _sessions.end(); ++itr)
389 {
390 if (itr->second &&
391 itr->second->GetPlayer() &&
392 itr->second->GetPlayer()->IsInWorld() &&
393 itr->second != self &&
395 (teamId == TEAM_NEUTRAL || itr->second->GetPlayer()->GetTeamId() == teamId))
396 {
397 itr->second->SendPacket(packet);
398 }
399 }
400}
@ TEAM_NEUTRAL
Definition SharedDefines.h:750
@ RBAC_PERM_RECEIVE_GLOBAL_GM_TEXTMESSAGE
Definition RBAC.h:95

References _sessions, WorldSession::HasPermission(), rbac::RBAC_PERM_RECEIVE_GLOBAL_GM_TEXTMESSAGE, and TEAM_NEUTRAL.

◆ SendGlobalMessage()

void WorldSessionMgr::SendGlobalMessage ( WorldPacket const *  packet,
WorldSession self = nullptr,
TeamId  teamId = TEAM_NEUTRAL 
)

Send a packet to all players (except self if mentioned)

369{
370 SessionMap::const_iterator itr;
371 for (itr = _sessions.begin(); itr != _sessions.end(); ++itr)
372 {
373 if (itr->second &&
374 itr->second->GetPlayer() &&
375 itr->second->GetPlayer()->IsInWorld() &&
376 itr->second != self &&
377 (teamId == TEAM_NEUTRAL || itr->second->GetPlayer()->GetTeamId() == teamId))
378 {
379 itr->second->SendPacket(packet);
380 }
381 }
382}

References _sessions, and TEAM_NEUTRAL.

Referenced by SendServerMessage().

◆ SendServerMessage()

void WorldSessionMgr::SendServerMessage ( ServerMessageType  messageID,
std::string  stringParam = "",
Player player = nullptr 
)

Send a server message to the user(s)

404{
406 chatServerMessage.MessageID = int32(messageID);
407 if (messageID <= SERVER_MSG_STRING)
408 chatServerMessage.StringParam = stringParam;
409
410 if (player)
411 player->SendDirectMessage(chatServerMessage.Write());
412 else
413 SendGlobalMessage(chatServerMessage.Write());
414}
std::int32_t int32
Definition Define.h:103
@ SERVER_MSG_STRING
Definition IWorld.h:57
void SendDirectMessage(WorldPacket const *data) const
Definition Player.cpp:5692
Definition ChatPackets.h:50
std::string StringParam
Definition ChatPackets.h:57
WorldPacket const * Write() override
Definition ChatPackets.cpp:33
int32 MessageID
Definition ChatPackets.h:56
void SendGlobalMessage(WorldPacket const *packet, WorldSession *self=nullptr, TeamId teamId=TEAM_NEUTRAL)
Send a packet to all players (except self if mentioned)
Definition WorldSessionMgr.cpp:368

References WorldPackets::Chat::ChatServerMessage::MessageID, Player::SendDirectMessage(), SendGlobalMessage(), SERVER_MSG_STRING, WorldPackets::Chat::ChatServerMessage::StringParam, and WorldPackets::Chat::ChatServerMessage::Write().

◆ SetPlayerAmountLimit()

void WorldSessionMgr::SetPlayerAmountLimit ( uint32  limit)
inline

Active session server limit.

71{ _playerLimit = limit; }

References _playerLimit.

◆ UpdateMaxSessionCounters()

void WorldSessionMgr::UpdateMaxSessionCounters ( )

Get the number of current active sessions.

References _maxActiveSessionCount, _maxQueuedSessionCount, _queuedPlayer, and _sessions.

Referenced by AddSession_().

◆ UpdateSessions()

void WorldSessionMgr::UpdateSessions ( uint32 const  diff)
  • Add new sessions
  • Then send an update signal to remaining ones
  • and remove not active sessions from the list
93{
94 {
95 METRIC_DETAILED_NO_THRESHOLD_TIMER("world_update_time",
96 METRIC_TAG("type", "Add sessions"),
97 METRIC_TAG("parent_type", "Update sessions"));
98
100 WorldSession* sess = nullptr;
101 while (_addSessQueue.next(sess))
102 {
103 AddSession_(sess);
104 }
105 }
106
108 for (SessionMap::iterator itr = _sessions.begin(), next; itr != _sessions.end(); itr = next)
109 {
110 next = itr;
111 ++next;
112
114 WorldSession* pSession = itr->second;
115 WorldSessionFilter updater(pSession);
116
117 // pussywizard:
118 if (pSession->HandleSocketClosed())
119 {
120 if (!RemoveQueuedPlayer(pSession) && sWorld->getIntConfig(CONFIG_INTERVAL_DISCONNECT_TOLERANCE))
121 _disconnects[pSession->GetAccountId()] = GameTime::GetGameTime().count();
122 _sessions.erase(itr);
123 // there should be no offline session if current one is logged onto a character
124 SessionMap::iterator iter;
125 if ((iter = _offlineSessions.find(pSession->GetAccountId())) != _offlineSessions.end())
126 {
127 WorldSession* tmp = iter->second;
128 _offlineSessions.erase(iter);
129 delete tmp;
130 }
131 pSession->SetOfflineTime(GameTime::GetGameTime().count());
132 _offlineSessions[pSession->GetAccountId()] = pSession;
133 continue;
134 }
135
136 [[maybe_unused]] uint32 currentSessionId = itr->first;
137 METRIC_DETAILED_TIMER("world_update_sessions_time", METRIC_TAG("account_id", std::to_string(currentSessionId)));
138
139 if (!pSession->Update(diff, updater))
140 {
141 if (!RemoveQueuedPlayer(pSession) && sWorld->getIntConfig(CONFIG_INTERVAL_DISCONNECT_TOLERANCE))
142 _disconnects[pSession->GetAccountId()] = GameTime::GetGameTime().count();
143 _sessions.erase(itr);
144 delete pSession;
145 }
146 }
147
148 // pussywizard:
149 if (_offlineSessions.empty())
150 return;
151 uint32 currTime = GameTime::GetGameTime().count();
152 for (SessionMap::iterator itr = _offlineSessions.begin(), next; itr != _offlineSessions.end(); itr = next)
153 {
154 next = itr;
155 ++next;
156 WorldSession* pSession = itr->second;
157 if (!pSession->GetPlayer() || pSession->GetOfflineTime() + 60 < currTime || pSession->IsKicked())
158 {
159 _offlineSessions.erase(itr);
160 delete pSession;
161 }
162 }
163}
#define METRIC_DETAILED_TIMER(category,...)
Definition Metric.h:223
#define METRIC_DETAILED_NO_THRESHOLD_TIMER(category,...)
Definition Metric.h:224
#define METRIC_TAG(name, value)
Definition Metric.h:163
bool next(T &result)
Gets the next item in the queue and removes it.
Definition LockedQueue.h:77
Definition WorldSession.h:311
void AddSession_(WorldSession *session)
Definition WorldSessionMgr.cpp:278
bool Update(uint32 diff, PacketFilter &updater)
Update the WorldSession (triggered by World update)
Definition WorldSession.cpp:362
uint32 GetOfflineTime() const
Definition WorldSession.h:1153
Player * GetPlayer() const
Definition WorldSession.h:454
bool IsKicked() const
Definition WorldSession.h:1154

References _addSessQueue, _disconnects, _offlineSessions, _sessions, AddSession_(), CONFIG_INTERVAL_DISCONNECT_TOLERANCE, WorldSession::GetAccountId(), GameTime::GetGameTime(), WorldSession::GetOfflineTime(), WorldSession::GetPlayer(), WorldSession::HandleSocketClosed(), WorldSession::IsKicked(), METRIC_DETAILED_NO_THRESHOLD_TIMER, METRIC_DETAILED_TIMER, METRIC_TAG, LockedQueue< T, StorageType >::next(), RemoveQueuedPlayer(), WorldSession::SetOfflineTime(), sWorld, and WorldSession::Update().

Member Data Documentation

◆ _addSessQueue

LockedQueue<WorldSession*> WorldSessionMgr::_addSessQueue
private

Referenced by AddSession(), and UpdateSessions().

◆ _disconnects

DisconnectMap WorldSessionMgr::_disconnects
private

◆ _maxActiveSessionCount

uint32 WorldSessionMgr::_maxActiveSessionCount
private

◆ _maxPlayerCount

uint32 WorldSessionMgr::_maxPlayerCount
private

◆ _maxQueuedSessionCount

uint32 WorldSessionMgr::_maxQueuedSessionCount
private

◆ _offlineSessions

◆ _playerCount

uint32 WorldSessionMgr::_playerCount
private

◆ _playerLimit

uint32 WorldSessionMgr::_playerLimit
private

◆ _queuedPlayer

◆ _sessions


The documentation for this class was generated from the following files: