patates
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/21 10:36:21 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/24 12:52:25 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/24 15:34:53 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -16,28 +16,20 @@
|
||||
|
||||
namespace irc
|
||||
{
|
||||
typedef std::set<unstd::SharedPtr<Client> >::iterator client_it;
|
||||
|
||||
Channel::Channel(const std::string& name) : _name(name) {}
|
||||
|
||||
void Channel::addClient(unstd::SharedPtr<Client> client)
|
||||
{
|
||||
if (!_clients.insert(client).second)
|
||||
{
|
||||
client->sendCode(ERR_USERONCHANNEL, "You are already in the 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);
|
||||
}
|
||||
void Channel::addClient(unstd::SharedPtr<Client> client, bool op)
|
||||
{
|
||||
if (!_clients.insert(client).second)
|
||||
if(!_clients.insert(client).second)
|
||||
{
|
||||
client->sendCode(ERR_USERONCHANNEL, "You are already in the channel");
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
if (op)
|
||||
if(op)
|
||||
_operators.insert(client);
|
||||
for(std::set<unstd::SharedPtr<Client> >::iterator it = _clients.begin(); it != _clients.end(); ++it)
|
||||
for(client_it it = _clients.begin(); it != _clients.end(); ++it)
|
||||
const_cast<unstd::SharedPtr<irc::Client>&>(*it)->sendMsg(client->getNickName(), "JOIN", _name);
|
||||
}
|
||||
|
||||
@@ -46,14 +38,14 @@ namespace irc
|
||||
return _clients.erase(client);
|
||||
}
|
||||
|
||||
void Channel::handleMessage(const std::string& msg, unstd::SharedPtr<Client> client) const
|
||||
void Channel::handleMessage(const std::string& msg, unstd::SharedPtr<Client> client, bool notice) const
|
||||
{
|
||||
const std::string sender = client ? client->getNickName() : "";
|
||||
for(std::set<unstd::SharedPtr<Client> >::iterator it = _clients.begin(); it != _clients.end(); ++it)
|
||||
for(client_it it = _clients.begin(); it != _clients.end(); ++it)
|
||||
{
|
||||
if(client == *it)
|
||||
continue;
|
||||
const_cast<unstd::SharedPtr<irc::Client>&>(*it)->sendMsg(sender, "PRIVMSG " + _name, msg);
|
||||
const_cast<unstd::SharedPtr<irc::Client>&>(*it)->sendMsg(sender, (notice ? "NOTICE " : "PRIVMSG ") + _name, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user