IRC SERVER
The goal of this project is to make you write your own IRC server.
|
Go to the documentation of this file.
30 std::string _password;
33 std::vector<Message *> _messages;
34 long long int _user_limit;
38 std::vector<ChannelMode> _modes;
39 std::vector<std::string> _ban_masks;
40 std::vector<Client *> _invite_list;
46 std::vector<std::pair<Client *, ClientMode> >
_clients;
49 Channel(std::string &name, std::string &password)
52 _created_at = time(0);
53 if (password.size() > 0)
61 throw std::runtime_error(
"Creator is already assigned");
153 std::string stringModes =
"";
154 for (std::vector<ChannelMode>::const_iterator it = _modes.begin();
155 it != _modes.end(); ++it)
161 return (stringModes);
166 return (_user_limit);
174 std::vector<Client *> clients;
185 std::vector<Client *> clients = this->
getClients();
187 return (std::find(clients.begin(), clients.end(), client) != clients.end());
192 return (_creator == client);
215 for (std::vector<std::string>::iterator it = _ban_masks.begin();
216 it != _ban_masks.end(); ++it)
227 return (std::find(_invite_list.begin(), _invite_list.end(), client) !=
245 std::vector<Client *>::iterator it =
256 std::vector<Client *>::iterator it =
267 std::vector<Client *>::iterator it =
281 if (std::find(_invite_list.begin(), _invite_list.end(), client) ==
283 this->_invite_list.push_back(client);
288 std::vector<Client *>::iterator it =
289 std::find(_invite_list.begin(), _invite_list.end(), client);
290 if (it != _invite_list.end())
291 _invite_list.erase(it);
296 if (std::find(_ban_masks.begin(), _ban_masks.end(), mask) == _ban_masks.end())
297 this->_ban_masks.push_back(mask);
302 std::vector<std::string>::iterator it =
303 std::find(_ban_masks.begin(), _ban_masks.end(), mask);
304 if (it != _ban_masks.end())
305 _ban_masks.erase(it);
314 for (
size_t i = 0; i < _modes.size(); i++)
333 std::cout <<
"MODE: " << mode << std::endl;
339 return std::find(this->_modes.begin(), this->_modes.end(), mode) !=
346 this->_modes.push_back(mode);
351 std::vector<ChannelMode>::iterator it = std::find(_modes.begin(), _modes.end(), mode);
352 if (it != _modes.end())
358 if (this->
isOpe(client))
367 std::vector<Client *> related_channels_clients =
getClients();
368 for (
size_t j = 0; j < related_channels_clients.size(); j++)
370 if (related_channels_clients[j] == client)
372 if (
isOpe(related_channels_clients[j]))
386 std::vector<Client *> clients = this->
getClients();
387 for (
size_t i = 0; i < clients.size(); i++)
389 clients[i]->message(message);
void removeInvite(Client *client)
Definition: Channel.hpp:286
void setPassword(std::string passwd)
Definition: Channel.hpp:71
Definition: Channel.hpp:26
char getIdentifier(ChannelMode _mode)
Definition: Channel.hpp:112
std::string & getName(void)
Definition: Channel.hpp:82
std::vector< ChannelMode > getModes(void)
Definition: Channel.hpp:107
bool isSecret(void)
Definition: Channel.hpp:237
ClientMode
Definition: Channel.hpp:20
bool isOpe(Client *client)
Definition: Channel.hpp:195
bool isInvited(Client *client)
Definition: Channel.hpp:225
Channel(std::string &name, std::string &password)
Definition: Channel.hpp:49
@ CHANNEL_MODE_OPERATOR
Definition: Channel.hpp:17
ChannelMode
Definition: Channel.hpp:6
void kick(Client *client)
Definition: Channel.hpp:265
std::string & getTopic(void)
Definition: Channel.hpp:87
const std::string getNick(void) const
Definition: Client.hpp:142
@ CHANNEL_MODE_TOPIC_SETTABLE_BY_CHANNEL_OPERATOR_ONLY
Definition: Channel.hpp:12
std::string getClientRoleString(Client *client)
Definition: Channel.hpp:356
const std::string getHost(void) const
Definition: Client.hpp:157
@ CHANNEL_MODE_SECRET
Definition: Channel.hpp:9
bool isVoice(Client *client)
Definition: Channel.hpp:207
time_t getCreatedAt(void)
Definition: Channel.hpp:97
@ CHANNEL_MODE_KEY
Definition: Channel.hpp:15
std::string getStringModes(void)
Definition: Channel.hpp:151
void removeMode(ChannelMode mode)
Definition: Channel.hpp:349
void invite(Client *client)
Definition: Channel.hpp:279
@ CLIENT_MODE_OPERATOR
Definition: Channel.hpp:23
void addBanMask(std::string mask)
Definition: Channel.hpp:294
std::vector< Client * > _voice_clients
Definition: Channel.hpp:44
std::vector< std::pair< Client *, ClientMode > > _clients
Definition: Channel.hpp:46
void setCreator(Client *creator)
Definition: Channel.hpp:58
@ CHANNEL_MODE_MODERATED
Definition: Channel.hpp:11
std::vector< Client * > _normal_clients
Definition: Channel.hpp:43
@ CHANNEL_MODE_PRIVATE
Definition: Channel.hpp:8
bool isInviteOnly(void)
Definition: Channel.hpp:231
Client * getCreator(void)
Definition: Channel.hpp:92
const std::string getUsername(void) const
Definition: Client.hpp:147
std::string & getPassword(void)
Definition: Channel.hpp:77
@ CHANNEL_MODE_CANT_SENT_MESSAGES_OUTSIDE
Definition: Channel.hpp:13
bool isBanned(Client *client)
Definition: Channel.hpp:213
bool isOwner(Client *client)
Definition: Channel.hpp:190
@ CHANNEL_MODE_BAN_MASK
Definition: Channel.hpp:14
#define MAX_CLIENTS_PER_CHANNEL
Definition: config.hpp:10
void removeClientFromChannel(Client *client)
Definition: Channel.hpp:365
bool hasKey(void)
Definition: Channel.hpp:399
void removeBanMask(std::string mask)
Definition: Channel.hpp:300
void removeOpe(Client *client)
Definition: Channel.hpp:254
void setUserLimit(size_t limit)
Definition: Channel.hpp:168
std::string getModeString(void)
Definition: Channel.hpp:311
void broadcastMessage(std::string message)
Definition: Channel.hpp:384
ChannelMode getMode(void)
Definition: Channel.hpp:102
std::vector< Client * > getClients(void) const
Definition: Channel.hpp:172
std::vector< Client * > _ope_clients
Definition: Channel.hpp:45
bool joined(Client *client)
Definition: Channel.hpp:183
size_t getUserLimit(void)
Definition: Channel.hpp:164
@ CHANNEL_MODE_USER_LIMIT
Definition: Channel.hpp:16
void setTopic(std::string &topic)
Definition: Channel.hpp:66
bool isNormal(Client *client)
Definition: Channel.hpp:201
Definition: Client.hpp:22
@ CLIENT_MODE_VOICE
Definition: Channel.hpp:22
bool hasMode(ChannelMode mode)
Definition: Channel.hpp:337
bool isModerated(void)
Definition: Channel.hpp:393
@ CHANNEL_MODE_INVITE_ONLY
Definition: Channel.hpp:10
void addOpe(Client *client)
Definition: Channel.hpp:243
void addMode(ChannelMode mode)
Definition: Channel.hpp:343