-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathChannel.cpp
More file actions
149 lines (119 loc) · 2.65 KB
/
Channel.cpp
File metadata and controls
149 lines (119 loc) · 2.65 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "Channel.hpp"
// constructors
Channel::Channel(): _name("unnammed channel") {}
Channel::~Channel() {std::cout << "Channel destructor for " << this->get_name() << "\n";}
Channel::Channel(const std::string &name): _name(name) {}
// getters
const std::string& Channel::get_name() const {return _name;}
const std::string& Channel::get_topic() const {return _topic;}
const std::set<User*>& Channel::get_members() const {return _members;}
const std::set<User*>& Channel::get_operators() const {return _operators;}
const std::set<User*>& Channel::get_invitees() const {return _invited_users;}
// setters
void Channel::add_member(User* user)
{
_members.insert(user);
}
void Channel::remove_member(User* user)
{
_members.erase(user);
_operators.erase(user);
}
bool Channel::is_member(User* user) const
{
return _members.find(user) != _members.end();
}
void Channel::set_topic(const std::string& topic)
{
_topic = topic;
}
// ops
void Channel::add_operator(User* user)
{
if (is_member(user))
_operators.insert(user);
}
void Channel::remove_operator(User* user)
{
_operators.erase(user);
}
bool Channel::is_operator(User* user) const
{
return _operators.find(user) != _operators.end();
}
// modes
void Channel::set_mode(char mode, bool value)
{
if (value == true)
_modes.insert(mode);
else
_modes.erase(mode);
}
bool Channel::get_mode(char mode) const
{
return _modes.find(mode) != _modes.end();
}
// for k mode
void Channel::set_key(const std::string &key)
{
_key = key;
set_mode('k', true);
}
void Channel::remove_key()
{
_key.clear();
set_mode('k', false);
}
const std::string &Channel::get_key() const
{
return _key;
}
// for l mode
void Channel::set_user_limit(size_t limit)
{
_userlimit = limit;
set_mode('l', true);
}
void Channel::remove_user_limit()
{
_userlimit = 0;
set_mode('l', false);
}
size_t Channel::get_user_limit() const
{
return _userlimit;
}
// return current channel modes as string
std::string Channel::str_modes() const
{
std::string ret = "+";
for (std::set<char>::const_iterator it = _modes.begin(); it != _modes.end(); ++it)
ret += *it;
return ret;
}
// invites
void Channel::add_invite(User *user)
{
_invited_users.insert(user);
}
bool Channel::is_invited(User *user) const
{
return _invited_users.find(user) != _invited_users.end();
}
void Channel::remove_invite(User *user)
{
_invited_users.erase(user);
}
/* const std::string &Channel::get_password() const
{
return _password;
}
void Channel::set_password(const std::string &password)
{
_password = password;
}
bool Channel::has_password() const
{
return !_password.empty();
}
*/