forked from InfpRC/INFPRC
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChannel.cpp
More file actions
145 lines (116 loc) · 2.53 KB
/
Copy pathChannel.cpp
File metadata and controls
145 lines (116 loc) · 2.53 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
#include "Channel.hpp"
Channel::Channel(std::string const &name): _name(name), _topic(""), _limit(-1), _invite_only(false), _topic_only(true), _created(time(NULL)) {
}
Channel::~Channel() {}
void Channel::setName(std::string const &name) {
_name = name;
}
void Channel::setKey(std::string const &key) {
_key = key;
}
void Channel::setLimit(int limit) {
_limit = limit;
}
void Channel::setInviteOnly(bool invite_only) {
_invite_only = invite_only;
}
void Channel::setTopicOnly(bool topic_only) {
_topic_only = topic_only;
}
void Channel::setTopic(std::string const &topic, std::string author) {
_topic = topic;
_topic_created = time(NULL);
_topic_author = author;
}
void Channel::inviteClient(int fd) {
_invited.insert(fd);
}
void Channel::delInvitedClient(int fd) {
_invited.erase(fd);
}
void Channel::addClient(int fd, int chanops) {
_clients[fd] = chanops;
}
void Channel::delClient(int fd) {
_clients.erase(fd);
}
void Channel::addOperator(int fd) {
_clients[fd] = CHAN_OPR;
}
void Channel::delOperator(int fd) {
_clients[fd] = CHAN_MEM;
}
std::string const &Channel::getName() const {
return _name;
}
std::string const &Channel::getTopic() const {
return _topic;
}
std::string const &Channel::getKey() const {
return _key;
}
int Channel::getLimit() const {
return _limit;
}
bool Channel::getInviteOnly() const {
return _invite_only;
}
bool Channel::getTopicOnly() const {
return _topic_only;
}
size_t Channel::getClientNum() {
return _clients.size();
}
std::map<int, int> &Channel::getClients() {
return _clients;
}
std::vector<int> Channel::getClientsFd() {
std::vector<int> fds;
for (std::map<int, int>::iterator it = _clients.begin(); it != _clients.end(); it++) {
fds.push_back(it->first);
}
return fds;
}
std::string Channel::getCreated() {
std::stringstream ss;
ss << _created;
return ss.str();
}
std::string Channel::getTopicCreated() {
std::stringstream ss;
ss << _topic_created;
return ss.str();
}
std::string Channel::getTopicAuthor() {
return _topic_author;
}
int Channel::isInvited(int fd) {
if (_invited.find(fd) != _invited.end()) {
return 1;
}
return 0;
}
std::string Channel::getModeList() {
std::string mode_list;
if (_invite_only) {
mode_list.append("i");
}
if (_topic_only) {
mode_list.append("t");
}
if (_limit >= 0) {
mode_list.append("l");
}
if (!_key.empty()) {
mode_list.append("k");
}
if (_limit >= 0) {
mode_list.append(" ");
mode_list.append(std::to_string(_limit));
}
if (!_key.empty()) {
mode_list.append(" ");
mode_list.append(_key);
}
return mode_list;
}