forked from zoovely/IRC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChannel.cpp
More file actions
106 lines (93 loc) · 2.34 KB
/
Channel.cpp
File metadata and controls
106 lines (93 loc) · 2.34 KB
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
#include <algorithm>
#include <iostream>
#include "Channel.hpp"
Channel::Channel(const Client& client, std::string name)
:_name(name)
{
_users.insert(std::make_pair<const Client&, int>(client, OPER));
return ;
}
const std::string Channel::getName(void) const {
return _name;
}
bool Channel::checkAuth(const Client& client) const {
if (_users.find(client) != _users.end())
{
if (_users.find(client)->second == OPER)
return (true);
else
return (false);
}
return (false);
}
bool Channel::checkClient(std::string nick) {
for (_it = _users.begin(); _it != _users.end(); _it++) {
if (_it->first.getNick() == nick)
return (true);
}
return (false);
}
void Channel::addUser(const Client& client)
{
_users.insert(std::make_pair<const Client&, int>(client, NORMAL));
return ;
}
void Channel::delUser(const Client &client) {
_users.erase(_users.find(client));
return ;
}
int Channel::delByNick(std::string nick) {
for (_it = _users.begin(); _it != _users.end(); _it++)
{
if (_it->first.getNick() == nick) {
_it = _users.erase(_it);
return (1);
}
}
return (0);
}
int Channel::getUserSize( void ) const {
return _users.size();
}
std::string Channel::getUsersNames(void) {
std::string msg;
_it = _users.begin();
for (_it = _users.begin(); _it != _users.end(); _it++) {
if(_it->second == OPER)
msg += "@";
msg += _it->first.getNick();
msg += " ";
}
return (msg);
}
std::vector<int> Channel::getFds(int senderFd) const {
std::vector <int> fds;
std::map<const Client&, int>::const_iterator it;
for (it = _users.begin(); it != _users.end(); it++)
{
if (it->first.getFd() == senderFd)
continue;
fds.push_back(it->first.getFd());
}
return (fds);
}
void Channel::opUser(std::string nick) {
for (_it = _users.begin(); _it != _users.end(); _it++) {
if (_it->first.getNick() == nick)
{
_it->second = OPER;
return ;
}
}
return ;
}
void Channel::deopUser(std::string nick) {
for (_it = _users.begin(); _it != _users.end(); _it++) {
if (_it->first.getNick() == nick)
{
_it->second = NORMAL;
return ;
}
}
return ;
}