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
 
std::map< uint32, AccountPlayHistory_accountsPlayHistory
 
DisconnectMap _disconnects
 
Queue _queuedPlayer
 
uint32 _playerLimit
 
uint32 _maxActiveSessionCount
 
uint32 _maxQueuedSessionCount
 
uint32 _playerCount
 
uint32 _maxPlayerCount
 
uint32 _accountsPlayHistoryPruneTimer
 

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;
42}
uint32 _accountsPlayHistoryPruneTimer
Definition WorldSessionMgr.h:115
uint32 _playerLimit
Definition WorldSessionMgr.h:110
uint32 _maxActiveSessionCount
Definition WorldSessionMgr.h:111
uint32 _maxQueuedSessionCount
Definition WorldSessionMgr.h:112
uint32 _playerCount
Definition WorldSessionMgr.h:113
uint32 _maxPlayerCount
Definition WorldSessionMgr.h:114

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

◆ ~WorldSessionMgr()

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

References _offlineSessions, and _sessions.

Member Function Documentation

◆ AddQueuedPlayer()

void WorldSessionMgr::AddQueuedPlayer ( WorldSession session)
248{
249 session->SetInQueue(true);
250 _queuedPlayer.push_back(session);
251
252 // The 1st SMSG_AUTH_RESPONSE needs to contain other info too.
253 session->SendAuthResponse(AUTH_WAIT_QUEUE, false, GetQueuePos(session));
254}
@ AUTH_WAIT_QUEUE
Definition SharedDefines.h:3599
Queue _queuedPlayer
Definition WorldSessionMgr.h:108
int32 GetQueuePos(WorldSession *session)
Definition WorldSessionMgr.cpp:304
void SetInQueue(bool state)
Session in auth.queue currently.
Definition WorldSession.h:500
void SendAuthResponse(uint8 code, bool shortForm, uint32 queuePos=0)
Definition AuthHandler.cpp:23

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

Referenced by AddSession_().

◆ AddSession()

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

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

◆ AddSession_()

void WorldSessionMgr::AddSession_ ( WorldSession session)
private
316{
317 ASSERT(session);
318
319 // kick existing session with same account (if any)
320 // if character on old session is being loaded, then return
321 if (!KickSession(session->GetAccountId()))
322 {
323 session->KickPlayer("kick existing session with same account");
324 delete session; // session not added yet in session list, so not listed in queue
325 return;
326 }
327
328 SessionMap::const_iterator old = _sessions.find(session->GetAccountId());
329 if (old != _sessions.end())
330 {
331 WorldSession* oldSession = old->second;
332
333 if (!RemoveQueuedPlayer(oldSession) && sWorld->getIntConfig(CONFIG_INTERVAL_DISCONNECT_TOLERANCE))
334 _disconnects[session->GetAccountId()] = GameTime::GetGameTime().count();
335
336 // don't allow resetting consecutive play time on double login to same account
337 session->SetPreviousPlayedTime(old->second->GetConsecutivePlayTime(GameTime::GetGameTime()));
338
339 // pussywizard:
340 if (oldSession->HandleSocketClosed())
341 {
342 // there should be no offline session if current one is logged onto a character
343 SessionMap::iterator iter;
344 if ((iter = _offlineSessions.find(oldSession->GetAccountId())) != _offlineSessions.end())
345 {
346 WorldSession* tmp = iter->second;
347 _offlineSessions.erase(iter);
348 delete tmp;
349 }
350 oldSession->SetOfflineTime(GameTime::GetGameTime().count());
351 _offlineSessions[oldSession->GetAccountId()] = oldSession;
352 }
353 else
354 {
355 delete oldSession;
356 }
357 }
358 else
359 {
360 auto itr = _accountsPlayHistory.find(session->GetAccountId());
361 if (itr != _accountsPlayHistory.end())
362 {
363 // carry consecutive play time only if the offline gap was under the reset window
364 if ((GameTime::GetGameTime() - itr->second.logoutTime) < PLAY_TIME_LIMIT_FULL)
365 session->SetPreviousPlayedTime(itr->second.playedTime);
366
367 // entry consumed on login; erase so _accountsPlayHistory cannot grow unbounded
368 _accountsPlayHistory.erase(itr);
369 }
370 }
371
372 _sessions[session->GetAccountId()] = session;
373
375 uint32 pLimit = GetPlayerAmountLimit();
376
377 // don't count this session when checking player limit
378 --Sessions;
379
380 // Trial accounts do not get account-flag queue priority. RBAC_PERM_SKIP_QUEUE is still honored
381 // since it can be granted intentionally to specific accounts.
382 bool trialQueueRestricted = sWorld->getBoolConfig(CONFIG_TRIAL_RESTRICTION_QUEUE) && session->IsTrialAccount();
383 bool canSkipQueue = session->HasPermission(rbac::RBAC_PERM_SKIP_QUEUE) || (!trialQueueRestricted && session->CanSkipQueue());
384
385 if (pLimit > 0 && Sessions >= pLimit && !canSkipQueue && !HasRecentlyDisconnected(session))
386 {
387 AddQueuedPlayer(session);
389 return;
390 }
391
392 session->InitializeSession();
393
395}
std::uint32_t uint32
Definition Define.h:107
#define ASSERT
Definition Errors.h:68
@ CONFIG_TRIAL_RESTRICTION_QUEUE
Definition WorldConfig.h:517
@ CONFIG_INTERVAL_DISCONNECT_TOLERANCE
Definition WorldConfig.h:172
bool KickSession(uint32 id)
Remove a given session.
Definition WorldSessionMgr.cpp:203
void UpdateMaxSessionCounters()
Get the number of current active sessions.
Definition WorldSessionMgr.cpp:419
DisconnectMap _disconnects
Definition WorldSessionMgr.h:105
uint32 GetPlayerAmountLimit() const
Definition WorldSessionMgr.h:80
bool HasRecentlyDisconnected(WorldSession *session)
Definition WorldSessionMgr.cpp:397
std::map< uint32, AccountPlayHistory > _accountsPlayHistory
Definition WorldSessionMgr.h:102
uint32 GetActiveAndQueuedSessionCount() const
Definition WorldSessionMgr.h:69
void AddQueuedPlayer(WorldSession *session)
Definition WorldSessionMgr.cpp:247
bool RemoveQueuedPlayer(WorldSession *session)
Definition WorldSessionMgr.cpp:256
Player session in the World.
Definition WorldSession.h:409
void SetOfflineTime(uint32 time)
Definition WorldSession.h:1188
void SetPreviousPlayedTime(Seconds playedTime)
Definition WorldSession.h:508
bool HasPermission(uint32 permissionId)
Definition WorldSession.cpp:1671
bool HandleSocketClosed()
Definition WorldSession.cpp:618
uint32 GetAccountId() const
Definition WorldSession.h:479
bool IsTrialAccount() const
Definition WorldSession.cpp:220
void KickPlayer(bool setKicked=true)
Definition WorldSession.h:528
void InitializeSession()
Definition WorldSession.cpp:1553
bool CanSkipQueue() const
Definition WorldSession.h:468
constexpr Seconds PLAY_TIME_LIMIT_FULL
Definition WorldSession.h:296
#define sWorld
Definition World.h:318
Seconds GetGameTime()
Definition GameTime.cpp:38
@ RBAC_PERM_SKIP_QUEUE
Definition RBAC.h:53

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

Referenced by UpdateSessions().

◆ DecreasePlayerCount()

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

References _playerCount.

◆ DoForAllOnlinePlayers()

void WorldSessionMgr::DoForAllOnlinePlayers ( std::function< void(Player *)>  exec)
475{
476 std::shared_lock lock(*HashMapHolder<Player>::GetLock());
477 for (auto const& it : ObjectAccessor::GetPlayers())
478 {
479 if (Player* player = it.second)
480 {
481 if (!player->IsInWorld())
482 {
483 continue;
484 }
485
486 exec(player);
487 }
488 }
489}
Definition ObjectAccessor.h:41
Definition Player.h:1086
Definition ObjectAccessor.h:61
HashMapHolder< Player >::MapType const & GetPlayers()
Definition ObjectAccessor.cpp:99

References ObjectAccessor::GetPlayers().

◆ FindOfflineSession()

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

References _offlineSessions.

◆ FindOfflineSessionForCharacterGUID()

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

References _offlineSessions.

◆ FindSession()

WorldSession * WorldSessionMgr::FindSession ( uint32  id) const

Find a session by its id.

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

References _sessions.

◆ GetActiveAndQueuedSessionCount()

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

References _sessions.

Referenced by AddSession_().

◆ GetActiveSessionCount()

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

References _queuedPlayer, and _sessions.

Referenced by RemoveQueuedPlayer().

◆ GetAllSessions()

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

References _sessions.

◆ GetMaxActiveSessionCount()

uint32 WorldSessionMgr::GetMaxActiveSessionCount ( ) const
inline

◆ GetMaxPlayerCount()

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

References _maxPlayerCount.

◆ GetMaxQueuedSessionCount()

uint32 WorldSessionMgr::GetMaxQueuedSessionCount ( ) const
inline

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

73{ return _maxQueuedSessionCount; }

References _maxQueuedSessionCount.

◆ GetPlayerAmountLimit()

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

References _playerLimit.

Referenced by AddSession_(), and RemoveQueuedPlayer().

◆ GetPlayerCount()

uint32 WorldSessionMgr::GetPlayerCount ( ) const
inline

Get number of players.

76{ return _playerCount; }

References _playerCount.

◆ GetQueuedSessionCount()

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

References _queuedPlayer.

◆ GetQueuePos()

int32 WorldSessionMgr::GetQueuePos ( WorldSession session)
305{
306 uint32 position = 1;
307
308 for (Queue::const_iterator iter = _queuedPlayer.begin(); iter != _queuedPlayer.end(); ++iter, ++position)
309 if ((*iter) == session)
310 return position;
311
312 return 0;
313}

References _queuedPlayer.

Referenced by AddQueuedPlayer().

◆ HasRecentlyDisconnected()

bool WorldSessionMgr::HasRecentlyDisconnected ( WorldSession session)
398{
399 if (!session)
400 return false;
401
402 if (uint32 tolerance = sWorld->getIntConfig(CONFIG_INTERVAL_DISCONNECT_TOLERANCE))
403 {
404 for (DisconnectMap::iterator i = _disconnects.begin(); i != _disconnects.end();)
405 {
406 if ((GameTime::GetGameTime().count() - i->second) < tolerance)
407 {
408 if (i->first == session->GetAccountId())
409 return true;
410 ++i;
411 }
412 else
413 _disconnects.erase(i++);
414 }
415 }
416 return false;
417}

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.

84 {
87 }

References _maxPlayerCount, and _playerCount.

◆ Instance()

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

◆ KickAll()

void WorldSessionMgr::KickAll ( )

Kick (and save) all players.

221{
222 _queuedPlayer.clear(); // prevent send queue update packet and login queued sessions
223
224 // session not removed at kick and will removed in next update tick
225 for (SessionMap::const_iterator itr = _sessions.begin(); itr != _sessions.end(); ++itr)
226 itr->second->KickPlayer("KickAll sessions");
227
228 // pussywizard: kick offline sessions
229 for (SessionMap::const_iterator itr = _offlineSessions.begin(); itr != _offlineSessions.end(); ++itr)
230 itr->second->KickPlayer("KickAll offline sessions");
231}

References _offlineSessions, _queuedPlayer, and _sessions.

◆ KickAllLess()

void WorldSessionMgr::KickAllLess ( AccountTypes  sec)

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

235{
236 // session not removed at kick and will removed in next update tick
237 for (SessionMap::const_iterator itr = _sessions.begin(); itr != _sessions.end(); ++itr)
238 if (itr->second->GetSecurity() < sec)
239 itr->second->KickPlayer("KickAllLess");
240}

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
204{
206 SessionMap::const_iterator itr = _sessions.find(id);
207
208 if (itr != _sessions.end() && itr->second)
209 {
210 if (itr->second->PlayerLoading())
211 return false;
212
213 itr->second->KickPlayer("KickSession", false);
214 }
215
216 return true;
217}

References _sessions, and WorldSession::KickPlayer().

Referenced by AddSession_().

◆ RemoveQueuedPlayer()

bool WorldSessionMgr::RemoveQueuedPlayer ( WorldSession session)
257{
258 uint32 sessions = GetActiveSessionCount();
259
260 uint32 position = 1;
261 Queue::iterator iter = _queuedPlayer.begin();
262
263 // search to remove and count skipped positions
264 bool found = false;
265
266 for (; iter != _queuedPlayer.end(); ++iter, ++position)
267 {
268 if (*iter == session)
269 {
270 session->SetInQueue(false);
271 session->ResetTimeOutTime(false);
272 iter = _queuedPlayer.erase(iter);
273 found = true;
274 break;
275 }
276 }
277
278 // if session not queued then it was an active session
279 if (!found)
280 {
281 ASSERT(sessions > 0);
282 --sessions;
283 }
284
285 // accept first in queue
286 if ((!GetPlayerAmountLimit() || sessions < GetPlayerAmountLimit()) && !_queuedPlayer.empty())
287 {
288 WorldSession* pop_sess = _queuedPlayer.front();
289 pop_sess->InitializeSession();
290 _queuedPlayer.pop_front();
291
292 // update iter to point first queued socket or end() if queue is empty now
293 iter = _queuedPlayer.begin();
294 position = 1;
295 }
296
297 // update queue position from iter to end()
298 for (; iter != _queuedPlayer.end(); ++iter, ++position)
299 (*iter)->SendAuthWaitQueue(position);
300
301 return found;
302}
uint32 GetActiveSessionCount() const
Definition WorldSessionMgr.h:70
void ResetTimeOutTime(bool onlyActive)
Definition WorldSession.h:638

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)

444{
445 SessionMap::iterator itr;
446 for (itr = _sessions.begin(); itr != _sessions.end(); ++itr)
447 {
448 if (itr->second &&
449 itr->second->GetPlayer() &&
450 itr->second->GetPlayer()->IsInWorld() &&
451 itr->second != self &&
453 (teamId == TEAM_NEUTRAL || itr->second->GetPlayer()->GetTeamId() == teamId))
454 {
455 itr->second->SendPacket(packet);
456 }
457 }
458}
@ 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)

427{
428 SessionMap::const_iterator itr;
429 for (itr = _sessions.begin(); itr != _sessions.end(); ++itr)
430 {
431 if (itr->second &&
432 itr->second->GetPlayer() &&
433 itr->second->GetPlayer()->IsInWorld() &&
434 itr->second != self &&
435 (teamId == TEAM_NEUTRAL || itr->second->GetPlayer()->GetTeamId() == teamId))
436 {
437 itr->second->SendPacket(packet);
438 }
439 }
440}

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)

462{
464 chatServerMessage.MessageID = int32(messageID);
465 if (messageID <= SERVER_MSG_STRING)
466 chatServerMessage.StringParam = stringParam;
467
468 if (player)
469 player->SendDirectMessage(chatServerMessage.Write());
470 else
471 SendGlobalMessage(chatServerMessage.Write());
472}
std::int32_t int32
Definition Define.h:103
@ SERVER_MSG_STRING
Definition IWorld.h:57
void SendDirectMessage(WorldPacket const *data) const
Definition Player.cpp:5852
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:426

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.

79{ _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
94{
95 // Drop play-history entries past the reset window so the map stays bounded even for
96 // accounts that disconnect and never reconnect (login only erases their own entry).
99 {
101 Seconds const now = GameTime::GetGameTime();
102 for (auto itr = _accountsPlayHistory.begin(); itr != _accountsPlayHistory.end();)
103 {
104 if ((now - itr->second.logoutTime) >= PLAY_TIME_LIMIT_FULL)
105 itr = _accountsPlayHistory.erase(itr);
106 else
107 ++itr;
108 }
109 }
110
111 {
112 METRIC_DETAILED_NO_THRESHOLD_TIMER("world_update_time",
113 METRIC_TAG("type", "Add sessions"),
114 METRIC_TAG("parent_type", "Update sessions"));
115
117 WorldSession* sess = nullptr;
118 while (_addSessQueue.next(sess))
119 {
120 AddSession_(sess);
121 }
122 }
123
125 for (SessionMap::iterator itr = _sessions.begin(), next; itr != _sessions.end(); itr = next)
126 {
127 next = itr;
128 ++next;
129
131 WorldSession* pSession = itr->second;
132 WorldSessionFilter updater(pSession);
133
134 // pussywizard:
135 if (pSession->HandleSocketClosed())
136 {
137 Seconds const now = GameTime::GetGameTime();
138
139 if (pSession->IsAffectedByCAIS())
140 {
141 // a reconnect builds a fresh session and carries time from _accountsPlayHistory, so persist it
142 // here at socket-close time rather than during offline cleanup (which runs ~60s later)
144 history.playedTime = pSession->GetConsecutivePlayTime(now);
145 history.logoutTime = now;
146 }
147
148 if (!RemoveQueuedPlayer(pSession) && sWorld->getIntConfig(CONFIG_INTERVAL_DISCONNECT_TOLERANCE))
149 _disconnects[pSession->GetAccountId()] = now.count();
150 _sessions.erase(itr);
151 // there should be no offline session if current one is logged onto a character
152 SessionMap::iterator iter;
153 if ((iter = _offlineSessions.find(pSession->GetAccountId())) != _offlineSessions.end())
154 {
155 WorldSession* tmp = iter->second;
156 _offlineSessions.erase(iter);
157 delete tmp;
158 }
159 pSession->SetOfflineTime(now.count());
160 _offlineSessions[pSession->GetAccountId()] = pSession;
161 continue;
162 }
163
164 [[maybe_unused]] uint32 currentSessionId = itr->first;
165 METRIC_DETAILED_TIMER("world_update_sessions_time", METRIC_TAG("account_id", std::to_string(currentSessionId)));
166
167 if (!pSession->Update(diff, updater))
168 {
169 Seconds const now = GameTime::GetGameTime();
170
171 if (pSession->IsAffectedByCAIS())
172 {
174 history.playedTime = pSession->GetConsecutivePlayTime(now);
175 history.logoutTime = now;
176 }
177
178 if (!RemoveQueuedPlayer(pSession) && sWorld->getIntConfig(CONFIG_INTERVAL_DISCONNECT_TOLERANCE))
179 _disconnects[pSession->GetAccountId()] = now.count();
180 _sessions.erase(itr);
181 delete pSession;
182 }
183 }
184
185 // pussywizard:
186 if (_offlineSessions.empty())
187 return;
188 uint32 currTime = GameTime::GetGameTime().count();
189 for (SessionMap::iterator itr = _offlineSessions.begin(), next; itr != _offlineSessions.end(); itr = next)
190 {
191 next = itr;
192 ++next;
193 WorldSession* pSession = itr->second;
194 if (!pSession->GetPlayer() || pSession->GetOfflineTime() + 60 < currTime || pSession->IsKicked())
195 {
196 _offlineSessions.erase(itr);
197 delete pSession;
198 }
199 }
200}
constexpr auto IN_MILLISECONDS
Definition Common.h:53
constexpr auto MINUTE
Definition Common.h:47
std::chrono::seconds Seconds
Seconds shorthand typedef.
Definition Duration.h:30
#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:336
void AddSession_(WorldSession *session)
Definition WorldSessionMgr.cpp:315
bool Update(uint32 diff, PacketFilter &updater)
Update the WorldSession (triggered by World update)
Definition WorldSession.cpp:378
uint32 GetOfflineTime() const
Definition WorldSession.h:1189
Player * GetPlayer() const
Definition WorldSession.h:480
bool IsAffectedByCAIS() const
Definition WorldSession.cpp:235
Seconds GetConsecutivePlayTime(Seconds now) const
Definition WorldSession.h:506
bool IsKicked() const
Definition WorldSession.h:1190
Definition WorldSessionMgr.h:35
Seconds logoutTime
Definition WorldSessionMgr.h:36
Seconds playedTime
Definition WorldSessionMgr.h:37

References _accountsPlayHistory, _accountsPlayHistoryPruneTimer, _addSessQueue, _disconnects, _offlineSessions, _sessions, AddSession_(), CONFIG_INTERVAL_DISCONNECT_TOLERANCE, WorldSession::GetAccountId(), WorldSession::GetConsecutivePlayTime(), GameTime::GetGameTime(), WorldSession::GetOfflineTime(), WorldSession::GetPlayer(), WorldSession::HandleSocketClosed(), IN_MILLISECONDS, WorldSession::IsAffectedByCAIS(), WorldSession::IsKicked(), AccountPlayHistory::logoutTime, METRIC_DETAILED_NO_THRESHOLD_TIMER, METRIC_DETAILED_TIMER, METRIC_TAG, MINUTE, LockedQueue< T, StorageType >::next(), PLAY_TIME_LIMIT_FULL, AccountPlayHistory::playedTime, RemoveQueuedPlayer(), WorldSession::SetOfflineTime(), sWorld, and WorldSession::Update().

Member Data Documentation

◆ _accountsPlayHistory

std::map<uint32 , AccountPlayHistory> WorldSessionMgr::_accountsPlayHistory
private

Referenced by AddSession_(), and UpdateSessions().

◆ _accountsPlayHistoryPruneTimer

uint32 WorldSessionMgr::_accountsPlayHistoryPruneTimer
private

Referenced by UpdateSessions(), and WorldSessionMgr().

◆ _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: