This commit is contained in:
Kbz-8
2024-01-23 13:16:52 +01:00
parent 2cda614d92
commit 8042d3db6f
11 changed files with 93 additions and 44 deletions

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 10:36:21 by maldavid #+# #+# */
/* Updated: 2024/01/22 20:06:36 by maldavid ### ########.fr */
/* Updated: 2024/01/23 11:01:06 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,9 +14,32 @@
namespace irc
{
Channel::Channel(const std::string& name) : _name(name)
{
Channel::Channel(const std::string& name) : _name(name) {}
void Channel::addClient(unstd::SharedPtr<Client> client)
{
if(!_clients.insert(client).second) // client already in coco channel
return;
for(std::set<unstd::SharedPtr<Client> >::iterator it = _clients.begin(); it != _clients.end(); ++it)
{
const_cast<unstd::SharedPtr<irc::Client>&>(*it)->sendMsg(client->getNickName(), "JOIN", _name);
}
}
bool Channel::removeClient(unstd::SharedPtr<Client> client)
{
return _clients.erase(client);
}
void Channel::handleMessage(const std::string& msg, unstd::SharedPtr<Client> client) const
{
const std::string sender = client ? client->getNickName() : "";
for(std::set<unstd::SharedPtr<Client> >::iterator it = _clients.begin(); it != _clients.end(); ++it)
{
if(client == *it)
continue;
const_cast<unstd::SharedPtr<irc::Client>&>(*it)->sendMsg(sender, "PRIVMSG " + _name, msg);
}
}
void Channel::setTopic(unstd::SharedPtr<Client> client, const std::string& new_topic)