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)
 
bool SendZoneMessage (uint32 zone, WorldPacket const *packet, WorldSession *self=nullptr, TeamId teamId=TEAM_NEUTRAL)
 Send a packet to all players (or players selected team) in the zone (except self if mentioned)
 
void SendZoneText (uint32 zone, std::string text, WorldSession *self=nullptr, TeamId teamId=TEAM_NEUTRAL)
 Send a System Message to all players in the zone (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 ( )
34{
35 _playerLimit = 0;
38 _playerCount = 0;
40}
uint32 _playerLimit
Definition WorldSessionMgr.h:103
uint32 _maxActiveSessionCount
Definition WorldSessionMgr.h:104
uint32 _maxQueuedSessionCount
Definition WorldSessionMgr.h:105
uint32 _playerCount
Definition WorldSessionMgr.h:106
uint32 _maxPlayerCount
Definition WorldSessionMgr.h:107

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

◆ ~WorldSessionMgr()

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

References _offlineSessions, and _sessions.

Member Function Documentation

◆ AddQueuedPlayer()

void WorldSessionMgr::AddQueuedPlayer ( WorldSession session)
210{
211 session->SetInQueue(true);
212 _queuedPlayer.push_back(session);
213
214 // The 1st SMSG_AUTH_RESPONSE needs to contain other info too.
215 session->SendAuthResponse(AUTH_WAIT_QUEUE, false, GetQueuePos(session));
216}
@ AUTH_WAIT_QUEUE
Definition SharedDefines.h:3350
Queue _queuedPlayer
Definition WorldSessionMgr.h:101
int32 GetQueuePos(WorldSession *session)
Definition WorldSessionMgr.cpp:266
void SetInQueue(bool state)
Session in auth.queue currently.
Definition WorldSession.h:396
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)
205{
206 _addSessQueue.add(session);
207}
void add(const T &item)
Adds an item to the back of the queue.
Definition LockedQueue.h:52
LockedQueue< WorldSession * > _addSessQueue
Definition WorldSessionMgr.h:91

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

◆ AddSession_()

void WorldSessionMgr::AddSession_ ( WorldSession session)
private
278{
279 ASSERT(session);
280
281 // kick existing session with same account (if any)
282 // if character on old session is being loaded, then return
283 if (!KickSession(session->GetAccountId()))
284 {
285 session->KickPlayer("kick existing session with same account");
286 delete session; // session not added yet in session list, so not listed in queue
287 return;
288 }
289
290 SessionMap::const_iterator old = _sessions.find(session->GetAccountId());
291 if (old != _sessions.end())
292 {
293 WorldSession* oldSession = old->second;
294
295 if (!RemoveQueuedPlayer(oldSession) && sWorld->getIntConfig(CONFIG_INTERVAL_DISCONNECT_TOLERANCE))
296 _disconnects[session->GetAccountId()] = GameTime::GetGameTime().count();
297
298 // pussywizard:
299 if (oldSession->HandleSocketClosed())
300 {
301 // there should be no offline session if current one is logged onto a character
302 SessionMap::iterator iter;
303 if ((iter = _offlineSessions.find(oldSession->GetAccountId())) != _offlineSessions.end())
304 {
305 WorldSession* tmp = iter->second;
306 _offlineSessions.erase(iter);
307 delete tmp;
308 }
309 oldSession->SetOfflineTime(GameTime::GetGameTime().count());
310 _offlineSessions[oldSession->GetAccountId()] = oldSession;
311 }
312 else
313 {
314 delete oldSession;
315 }
316 }
317
318 _sessions[session->GetAccountId()] = session;
319
321 uint32 pLimit = GetPlayerAmountLimit();
322
323 // don't count this session when checking player limit
324 --Sessions;
325
326 if (pLimit > 0 && Sessions >= pLimit && AccountMgr::IsPlayerAccount(session->GetSecurity()) && !session->CanSkipQueue() && !HasRecentlyDisconnected(session))
327 {
328 AddQueuedPlayer(session);
330 return;
331 }
332
333 session->InitializeSession();
334
336}
std::uint32_t uint32
Definition Define.h:107
#define ASSERT
Definition Errors.h:68
@ CONFIG_INTERVAL_DISCONNECT_TOLERANCE
Definition IWorld.h:212
bool KickSession(uint32 id)
Remove a given session.
Definition WorldSessionMgr.cpp:165
void UpdateMaxSessionCounters()
Get the number of current active sessions.
Definition WorldSessionMgr.cpp:360
DisconnectMap _disconnects
Definition WorldSessionMgr.h:98
uint32 GetPlayerAmountLimit() const
Definition WorldSessionMgr.h:72
bool HasRecentlyDisconnected(WorldSession *session)
Definition WorldSessionMgr.cpp:338
uint32 GetActiveAndQueuedSessionCount() const
Definition WorldSessionMgr.h:61
void AddQueuedPlayer(WorldSession *session)
Definition WorldSessionMgr.cpp:209
bool RemoveQueuedPlayer(WorldSession *session)
Definition WorldSessionMgr.cpp:218
Player session in the World.
Definition WorldSession.h:330
void SetOfflineTime(uint32 time)
Definition WorldSession.h:1077
AccountTypes GetSecurity() const
Definition WorldSession.h:373
bool HandleSocketClosed()
Definition WorldSession.cpp:537
uint32 GetAccountId() const
Definition WorldSession.h:375
void KickPlayer(bool setKicked=true)
Definition WorldSession.h:414
void InitializeSession()
Definition WorldSession.cpp:1448
bool CanSkipQueue() const
Definition WorldSession.h:374
#define sWorld
Definition World.h:363
bool IsPlayerAccount(uint32 gmlevel)
Definition AccountMgr.cpp:305
Seconds GetGameTime()
Definition GameTime.cpp:38

References _disconnects, _offlineSessions, _sessions, AddQueuedPlayer(), ASSERT, WorldSession::CanSkipQueue(), CONFIG_INTERVAL_DISCONNECT_TOLERANCE, WorldSession::GetAccountId(), GetActiveAndQueuedSessionCount(), GameTime::GetGameTime(), GetPlayerAmountLimit(), WorldSession::GetSecurity(), WorldSession::HandleSocketClosed(), HasRecentlyDisconnected(), WorldSession::InitializeSession(), AccountMgr::IsPlayerAccount(), WorldSession::KickPlayer(), KickSession(), 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)
447{
448 std::shared_lock lock(*HashMapHolder<Player>::GetLock());
449 for (auto const& it : ObjectAccessor::GetPlayers())
450 {
451 if (Player* player = it.second)
452 {
453 if (!player->IsInWorld())
454 {
455 continue;
456 }
457
458 exec(player);
459 }
460 }
461}
Definition ObjectAccessor.h:41
Definition Player.h:1081
Definition ObjectAccessor.h:61
HashMapHolder< Player >::MapType const & GetPlayers()
Definition ObjectAccessor.cpp:75

References ObjectAccessor::GetPlayers().

◆ FindOfflineSession()

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

References _offlineSessions.

◆ FindOfflineSessionForCharacterGUID()

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

References _offlineSessions.

◆ FindSession()

WorldSession * WorldSessionMgr::FindSession ( uint32  id) const

Find a session by its id.

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

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)
267{
268 uint32 position = 1;
269
270 for (Queue::const_iterator iter = _queuedPlayer.begin(); iter != _queuedPlayer.end(); ++iter, ++position)
271 if ((*iter) == session)
272 return position;
273
274 return 0;
275}

References _queuedPlayer.

Referenced by AddQueuedPlayer().

◆ HasRecentlyDisconnected()

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

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
28{
29 static WorldSessionMgr instance;
30 return &instance;
31}
Definition WorldSessionMgr.h:33

◆ KickAll()

void WorldSessionMgr::KickAll ( )

Kick (and save) all players.

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

References _offlineSessions, _queuedPlayer, and _sessions.

◆ KickAllLess()

void WorldSessionMgr::KickAllLess ( AccountTypes  sec)

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

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

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
166{
168 SessionMap::const_iterator itr = _sessions.find(id);
169
170 if (itr != _sessions.end() && itr->second)
171 {
172 if (itr->second->PlayerLoading())
173 return false;
174
175 itr->second->KickPlayer("KickSession", false);
176 }
177
178 return true;
179}

References _sessions, and WorldSession::KickPlayer().

Referenced by AddSession_().

◆ RemoveQueuedPlayer()

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

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)

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

References _sessions, AccountMgr::IsPlayerAccount(), 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)

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

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)

426{
428 chatServerMessage.MessageID = int32(messageID);
429 if (messageID <= SERVER_MSG_STRING)
430 chatServerMessage.StringParam = stringParam;
431
432 if (player)
433 player->SendDirectMessage(chatServerMessage.Write());
434 else
435 SendGlobalMessage(chatServerMessage.Write());
436}
std::int32_t int32
Definition Define.h:103
@ SERVER_MSG_STRING
Definition IWorld.h:56
void SendDirectMessage(WorldPacket const *data) const
Definition Player.cpp:5733
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:367

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

◆ SendZoneMessage()

bool WorldSessionMgr::SendZoneMessage ( uint32  zone,
WorldPacket const *  packet,
WorldSession self = nullptr,
TeamId  teamId = TEAM_NEUTRAL 
)

Send a packet to all players (or players selected team) in the zone (except self if mentioned)

403{
404 bool foundPlayerToSend = false;
405 SessionMap::const_iterator itr;
406
407 for (itr = _sessions.begin(); itr != _sessions.end(); ++itr)
408 {
409 if (itr->second &&
410 itr->second->GetPlayer() &&
411 itr->second->GetPlayer()->IsInWorld() &&
412 itr->second->GetPlayer()->GetZoneId() == zone &&
413 itr->second != self &&
414 (teamId == TEAM_NEUTRAL || itr->second->GetPlayer()->GetTeamId() == teamId))
415 {
416 itr->second->SendPacket(packet);
417 foundPlayerToSend = true;
418 }
419 }
420
421 return foundPlayerToSend;
422}

References _sessions, and TEAM_NEUTRAL.

Referenced by SendZoneText().

◆ SendZoneText()

void WorldSessionMgr::SendZoneText ( uint32  zone,
std::string  text,
WorldSession self = nullptr,
TeamId  teamId = TEAM_NEUTRAL 
)

Send a System Message to all players in the zone (except self if mentioned)

440{
441 WorldPacket data;
442 ChatHandler::BuildChatPacket(data, CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, text.c_str());
443 SendZoneMessage(zone, &data, self, teamId);
444}
@ CHAT_MSG_SYSTEM
Definition SharedDefines.h:3152
@ LANG_UNIVERSAL
Definition SharedDefines.h:735
static std::size_t BuildChatPacket(WorldPacket &data, ChatMsg chatType, Language language, ObjectGuid senderGUID, ObjectGuid receiverGUID, std::string_view message, uint8 chatTag, std::string const &senderName="", std::string const &receiverName="", uint32 achievementId=0, bool gmMessage=false, std::string const &channelName="")
Definition Chat.cpp:265
Definition WorldPacket.h:26
bool SendZoneMessage(uint32 zone, WorldPacket const *packet, WorldSession *self=nullptr, TeamId teamId=TEAM_NEUTRAL)
Send a packet to all players (or players selected team) in the zone (except self if mentioned)
Definition WorldSessionMgr.cpp:402

References ChatHandler::BuildChatPacket(), CHAT_MSG_SYSTEM, LANG_UNIVERSAL, and SendZoneMessage().

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

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: