oh merde...
This commit is contained in:
@@ -6,19 +6,20 @@
|
||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/21 10:36:21 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/24 15:34:53 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/25 02:33:59 by vvaas ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
#include <channel.hpp>
|
||||
#include <logs.hpp>
|
||||
#include <errorscode.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
namespace irc
|
||||
{
|
||||
typedef std::set<unstd::SharedPtr<Client> >::iterator client_it;
|
||||
|
||||
Channel::Channel(const std::string& name) : _name(name) {}
|
||||
Channel::Channel(const std::string& name) : _name(name), _channel_size(-1) {}
|
||||
|
||||
void Channel::addClient(unstd::SharedPtr<Client> client, bool op)
|
||||
{
|
||||
@@ -32,10 +33,14 @@ namespace irc
|
||||
for(client_it 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);
|
||||
if (!_clients.erase(client))
|
||||
return (false);
|
||||
for (client_it it = _clients.begin(); it != _clients.end(); ++it)
|
||||
const_cast<unstd::SharedPtr<irc::Client>&>(*it)->sendMsg(client->getNickName(), "PART", _name);
|
||||
client->sendMsg(client->getNickName(), "PART", _name);
|
||||
return (true);
|
||||
}
|
||||
|
||||
void Channel::handleMessage(const std::string& msg, unstd::SharedPtr<Client> client, bool notice) const
|
||||
@@ -49,9 +54,41 @@ namespace irc
|
||||
}
|
||||
}
|
||||
|
||||
void Channel::changeMode(unstd::SharedPtr<class Client> client, const Message& msg)
|
||||
{
|
||||
bool modevalue = (msg.getTokens()[2][0] != '-');
|
||||
// attention on est sur un truc solidement MERDIQUE, a toucher a tes propres risques (je suis proche du nervous breakdown) gl hf :)
|
||||
switch (msg.getTokens()[2][1])
|
||||
{
|
||||
case 'i':
|
||||
_invite_only = modevalue;
|
||||
break;
|
||||
case 't':
|
||||
_topic_op_restrict = modevalue;
|
||||
break;
|
||||
case 'k':
|
||||
logs::report(log_message, "%s password set as %s", getName().c_str(), msg.getTokens()[3].c_str());
|
||||
_password = msg.getTokens()[3];
|
||||
break;
|
||||
case 'o':
|
||||
if (isOp(client))
|
||||
modevalue = !modevalue; // todo sa me clc :(
|
||||
else
|
||||
client->sendCode(ERR_CHANOPRIVSNEEDED, "You need to be operator to execute this command");
|
||||
break;
|
||||
case 'l':
|
||||
if (static_cast<int>(getNumberOfClients()) > std::atoi(msg.getTokens()[3].c_str()))
|
||||
return ;
|
||||
if (modevalue)
|
||||
_channel_size = std::atoi(msg.getTokens()[3].c_str());
|
||||
if (!modevalue)
|
||||
_channel_size = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void Channel::setTopic(unstd::SharedPtr<Client> client, const std::string& new_topic)
|
||||
{
|
||||
if(_topic_op_restrict && _operators.find(client) == _operators.end() )
|
||||
if(_topic_op_restrict && !isOp(client))
|
||||
{
|
||||
client->sendCode(ERR_CHANOPRIVSNEEDED, "You need operator privileges");
|
||||
return ;
|
||||
@@ -59,5 +96,14 @@ namespace irc
|
||||
_topic = new_topic;
|
||||
}
|
||||
|
||||
bool Channel::isOp(unstd::SharedPtr<Client> client)
|
||||
{
|
||||
for (client_it it = _clients.begin(); it != _clients.end(); ++it)
|
||||
{
|
||||
if (const_cast<unstd::SharedPtr<irc::Client>&>(*it)->getNickName() == client->getNickName())
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
Channel::~Channel() {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user