/******************************************************************************/ /* */ /* ::: :::::::: */ /* channel.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: vvaas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/21 10:36:21 by maldavid #+# #+# */ /* Updated: 2024/01/23 17:10:16 by vvaas ### ########.fr */ /* */ /******************************************************************************/ #include #include #include namespace irc { Channel::Channel(const std::string& name) : _name(name) {} void Channel::addClient(unstd::SharedPtr client) { for (std::set >::iterator it = _clients.begin(); it != _clients.end(); ++it) { if (const_cast&>(*it)->getNickName() == client->getNickName()) { logs::report(log_message, "%s is already is channel for", client->getNickName().c_str()); return ; } } _clients.insert(client); for(std::set >::iterator it = _clients.begin(); it != _clients.end(); ++it) { const_cast&>(*it)->sendMsg(client->getNickName(), "JOIN", _name); logs::report(log_message, "%s has been sent a JOIN message", const_cast&>(*it)->getNickName().c_str()); } } bool Channel::removeClient(unstd::SharedPtr client) { return _clients.erase(client); } void Channel::handleMessage(const std::string& msg, unstd::SharedPtr client) const { const std::string sender = client ? client->getNickName() : ""; for(std::set >::iterator it = _clients.begin(); it != _clients.end(); ++it) { if(client == *it) continue; const_cast&>(*it)->sendMsg(sender, "PRIVMSG " + _name, msg); } } void Channel::setTopic(unstd::SharedPtr client, const std::string& new_topic) { if(_topic_op_restrict && _operators.find(client) == _operators.end()) { // send error code to user } _topic = new_topic; } Channel::~Channel() {} }