-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChannel.cpp
108 lines (95 loc) · 2.27 KB
/
Channel.cpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "includes/Server.hpp"
#include "includes/Channel.hpp"
#include "includes/Numeric.hpp"
Channel::Channel(std::string name, Client *client)
{
this->name = name;
this->topic = "";
this->operators.push_back(client);
this->clients.push_back(client);
}
Channel::~Channel()
{
}
std::string Channel::getName() const
{
return (this->name);
}
std::string Channel::getTopic() const
{
return (this->topic);
}
std::vector<Client *> &Channel::getClients()
{
return (this->clients);
}
std::vector<Client *> &Channel::getOperators()
{
return (this->operators);
}
void Channel::setTopic(std::string topic)
{
this->topic = topic;
}
void Channel::addClient(Client *client)
{
this->clients.push_back(client);
}
void Channel::removeClient(Client *client)
{
std::vector<Client *>::iterator it;
for (it = this->clients.begin(); it != this->clients.end(); it++)
{
if ((*it)->getClientFd() == client->getClientFd())
{
this->clients.erase(it);
return;
}
}
if (isClientOperator(client))
removeOperator(client);
}
bool Channel::isClientInChannel(Client *client)
{
std::vector<Client *>::iterator it;
for (it = this->clients.begin(); it != this->clients.end(); it++)
{
if ((*it)->getClientFd() == client->getClientFd())
return (true);
}
return (false);
}
bool Channel::isClientOperator(Client *client)
{
std::vector<Client *>::iterator it;
for (it = this->operators.begin(); it != this->operators.end(); it++)
{
if ((*it) == client)
return (true);
}
return (false);
}
void Channel::sendMessageToChannel(Server &server, Client *client, std::string message)
{
std::vector<Client *>::iterator it;
for (it = this->clients.begin(); it != this->clients.end(); it++)
{
server.messageToClient(client, *it, message);
}
}
void Channel::addOperator(Client *client)
{
this->operators.push_back(client);
}
void Channel::removeOperator(Client *client)
{
std::vector<Client *>::iterator it;
for (it = this->operators.begin(); it != this->operators.end(); it++)
{
if ((*it)->getClientFd() == client->getClientFd())
{
this->operators.erase(it);
return;
}
}
}