je suis aigri

This commit is contained in:
Kbz-8
2024-01-30 17:35:50 +01:00
parent 64fb3e539d
commit b90087188f
5 changed files with 73 additions and 63 deletions

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 10:34:25 by maldavid #+# #+# */
/* Updated: 2024/01/29 20:04:19 by vvaas ### ########.fr */
/* Updated: 2024/01/30 17:23:28 by maldavid ### ########.fr */
/* */
/******************************************************************************/
@@ -42,7 +42,7 @@ namespace irc
inline std::size_t getNumberOfClients() const { return _clients.size(); }
inline int getChannelSize() const { return _channel_size; }
void ModOperator(unstd::SharedPtr<class Client> client, const std::string &clientname, bool mode);
void modOperator(unstd::SharedPtr<class Client> client, const std::string &clientname, bool mode);
inline bool removeOperator(unstd::SharedPtr<Client> op) { return _operators.erase(op); }
void changeMode(unstd::SharedPtr<class Client> client, const Message& msg);
bool isOp(unstd::SharedPtr<Client> client) const;

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/22 09:45:10 by maldavid #+# #+# */
/* Updated: 2024/01/30 01:37:03 by vvaas ### ########.fr */
/* Updated: 2024/01/30 17:34:11 by maldavid ### ########.fr */
/* */
/******************************************************************************/
@@ -18,4 +18,5 @@
#define MAX_USERS 20
#define NULL_SOCKET -1
#define LEGAL_CHARACTER "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789{}[]\\|^`-_"
#endif

View File

@@ -6,12 +6,13 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 10:36:21 by maldavid #+# #+# */
/* Updated: 2024/01/29 23:47:14 by vvaas ### ########.fr */
/* Updated: 2024/01/30 17:33:40 by maldavid ### ########.fr */
/* */
/******************************************************************************/
#include <channel.hpp>
#include <logs.hpp>
#include <cerrno>
#include <errorscode.hpp>
#include <cstdlib>
#include <unstd/string.hpp>
@@ -37,7 +38,7 @@ namespace irc
sendWho(client);
}
void Channel::ModOperator(unstd::SharedPtr<class Client> client, const std::string &clientname, bool mode)
void Channel::modOperator(unstd::SharedPtr<class Client> client, const std::string& clientname, bool mode)
{
client_it it;
logs::report(log_message, "mode operator, mode = %d", mode);
@@ -53,9 +54,9 @@ namespace irc
}
if(it == _clients.end())
client->sendCode(ERR_USERNOTINCHANNEL, "User not in channel");
return;
}
else
{
for(it = _operators.begin(); it != _operators.end(); ++it)
{
logs::report(log_message, "nickname %s, clientname : %s", const_cast<unstd::SharedPtr<irc::Client>&>(*it)->getNickName().c_str(), clientname.c_str());
@@ -69,7 +70,6 @@ namespace irc
if(it == _operators.end())
client->sendCode(ERR_USERNOTINCHANNEL, "User not in channel");
}
}
bool Channel::removeClient(unstd::SharedPtr<Client> client)
{
@@ -125,6 +125,7 @@ namespace irc
for(client_it it = _clients.begin(); it != _clients.end(); ++it)
const_cast<unstd::SharedPtr<irc::Client>&>(*it)->sendMsg(client->getNickName(), out, modes);
}
void Channel::showModes(unstd::SharedPtr<Client> client)
{
std::string modes = " +";
@@ -141,38 +142,39 @@ namespace irc
return ;
client->sendCode(RPL_CHANNELMODEIS, modes);
}
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 :)
logs::report(log_message, "tokensize : %d, mode : %c, modevalue %d", msg.getTokens().size(), msg.getTokens()[2][1], modevalue);
switch(msg.getTokens()[2][1])
{
case 'i':
_invite_only = modevalue;
break;
case 't':
_topic_op_restrict = modevalue;
break;
case 'i': _invite_only = modevalue; break;
case 't': _topic_op_restrict = modevalue; break;
case 'k':
{
if(modevalue && msg.getTokens().size() == 4)
{
logs::report(log_message, "%s password set as %s", getName().c_str(), msg.getTokens()[3].c_str());
_password = msg.getTokens()[3];
logs::report(log_message, "%s password set as %s", _name.c_str(), msg.getArgs()[2].c_str());
_password = msg.getArgs()[2];
}
else if(msg.getTokens().size() < 4)
{
_password = "";
logs::report(log_message, "password removed on %s", getName().c_str());
_password.clear();
logs::report(log_message, "password removed on %s", _name.c_str());
}
break;
}
case 'o':
{
if(isOp(client))
ModOperator(client, msg.getTokens()[3], modevalue);
modOperator(client, msg.getTokens()[3], modevalue);
else if(!isOp(client))
client->sendCode(ERR_CHANOPRIVSNEEDED, "You need to be operator to execute this command");
break;
}
case 'l':
{
if(msg.getTokens().size() < 3 && modevalue)
return;
if(!modevalue)
@@ -181,11 +183,18 @@ namespace irc
break;
}
if(modevalue)
_channel_size = std::atoi(msg.getTokens()[3].c_str());
{
char* end;
long tmp = std::strtol(msg.getArgs()[2].c_str(), &end, 10);
if(errno == ERANGE || *end != 0 || tmp < 0)
logs::report(log_error, "invalid channel size");
else
_channel_size = tmp;
}
break;
default :
client->sendCode(":yipirc " ERR_UNKNOWNMODE " @", getName().c_str(), "Unknown mode");
return ;
}
default : client->sendCode(":yipirc " ERR_UNKNOWNMODE " @", getName().c_str(), "Unknown mode"); return;
}
logs::report(log_message, "%s MODES : i:%d t:%d k:%s l:%d", getName().c_str(), _invite_only, _topic_op_restrict, _password.c_str(), _channel_size);
showModesModify(client, msg);

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/20 09:27:04 by maldavid #+# #+# */
/* Updated: 2024/01/30 17:16:04 by vvaas ### ########.fr */
/* Updated: 2024/01/30 17:35:22 by maldavid ### ########.fr */
/* */
/******************************************************************************/

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/22 17:31:06 by maldavid #+# #+# */
/* Updated: 2024/01/30 17:15:46 by vvaas ### ########.fr */
/* Updated: 2024/01/30 17:35:15 by maldavid ### ########.fr */
/* */
/******************************************************************************/