Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
WorldSocketSessionState.h
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#ifndef SF_WORLDSOCKETSESSIONSTATE_H
7#define SF_WORLDSOCKETSESSIONSTATE_H
8
10
11#include <utility>
12
13class WorldSession;
14
16{
17public:
19
20 bool Attach(WorldSession* session)
21 {
22 if (!session)
23 return false;
24
25 GuardType guard(_lock);
26 if (_session)
27 return false;
28
29 _session = session;
30 return true;
31 }
32
33 bool Detach(WorldSession* session)
34 {
35 if (!session)
36 return false;
37
38 GuardType guard(_lock);
39 if (_session != session)
40 return false;
41
42 _session = nullptr;
43 return true;
44 }
45
46 bool HasSession() const
47 {
48 GuardType guard(_lock);
49 return _session != nullptr;
50 }
51
52 template<class Callback>
53 auto WithSession(Callback&& callback) const -> decltype(callback(static_cast<WorldSession*>(nullptr)))
54 {
55 GuardType guard(_lock);
56 return callback(_session);
57 }
58
59private:
61 typedef std::lock_guard<LockType> GuardType;
62
63 mutable LockType _lock;
65};
66
67#endif
Player session in the World.
std::lock_guard< LockType > GuardType
bool Detach(WorldSession *session)
auto WithSession(Callback &&callback) const -> decltype(callback(static_cast< WorldSession * >(nullptr)))
bool Attach(WorldSession *session)