-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_manager.cpp
More file actions
33 lines (32 loc) · 862 Bytes
/
client_manager.cpp
File metadata and controls
33 lines (32 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "client_manager.hpp"
#include <algorithm>
client_manager* client_manager::instance = NULL;
client_manager::client_manager() {}
client_manager* client_manager::get_instance()
{
if (instance == NULL)
instance = new client_manager();
return instance;
}
void client_manager::add_client(client_state* cptr)
{
this->clients.push_back(cptr);
}
void client_manager::delete_client(client_state *cptr)
{
auto idx = std::find(this->clients.begin(), this->clients.end(), cptr);
this->clients.erase(idx);
}
void client_manager::broadcast(client_state* except, void* msg, size_t msglen)
{
for (auto i = this->clients.begin() ; i != this->clients.end(); ++i)
{
if (*i == except || (!(*i)->is_ready()))
continue;
(*i)->send(msg, msglen);
}
}
client_manager::~client_manager()
{
instance = NULL;
}