YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
ClientManager.cpp
Go to the documentation of this file.
1
#include "
YAPOG/System/Network/IPacket.hpp
"
2
3
#include "
Server/ClientManager.hpp
"
4
#include "
Server/ClientSession.hpp
"
5
6
namespace
yse
7
{
8
const
yap::Time
ClientManager::DEFAULT_RECEPTION_SLEEP_DELAY
=
9
yap::Time
(0.05f);
10
11
ClientManager::ClientManager
()
12
:
clients_
()
13
,
clientsMutex_
()
14
, receptionThread_ ([this] () {
HandleReception
(); })
15
,
receptionIsActive_
(
false
)
16
{
17
}
18
19
ClientManager::~ClientManager
()
20
{
21
for
(
ClientSession
* client :
clients_
)
22
delete
client;
23
}
24
25
void
ClientManager::AddClient
(
ClientSession
* client)
26
{
27
{
28
yap::Lock
lock (
clientsMutex_
);
29
clients_
.
Add
(client);
30
}
31
}
32
33
void
ClientManager::RemoveClient
(
ClientSession
* client)
34
{
35
{
36
yap::Lock
lock (
clientsMutex_
);
37
clients_
.
Remove
(client);
38
}
39
}
40
41
void
ClientManager::LaunchReception
()
42
{
43
receptionIsActive_
=
true
;
44
receptionThread_
.
Launch
();
45
}
46
47
void
ClientManager::Refresh
()
48
{
49
{
50
yap::Lock
lock (
clientsMutex_
);
51
52
for
(
ClientSession
* client :
clients_
)
53
client->Refresh ();
54
}
55
}
56
57
void
ClientManager::Dispose
()
58
{
59
receptionIsActive_
=
false
;
60
}
61
62
void
ClientManager::ServerTick
(
const
yap::Time
& dt)
63
{
64
{
65
yap::Lock
lock (
clientsMutex_
);
66
67
for
(
ClientSession
* client :
clients_
)
68
client->ServerTick (dt);
69
}
70
}
71
72
void
ClientManager::HandleReception
()
73
{
74
while
(
receptionIsActive_
)
75
{
76
yap::Thread::Sleep
(
DEFAULT_RECEPTION_SLEEP_DELAY
);
77
78
{
79
yap::Lock
lock (
clientsMutex_
);
80
81
for
(
ClientSession
* client :
clients_
)
82
client->HandleReception ();
83
}
84
}
85
}
86
}
// namespace yse
YAPOG.Server
src
Server
ClientManager.cpp
Generated on Mon Sep 17 2012 22:24:22 for YAPOG by
1.8.1.1