This commit is contained in:
2024-01-29 19:57:36 +01:00
parent de2cafe2cd
commit fbcb5873bb
3 changed files with 25 additions and 25 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/26 02:08:19 by vvaas ### ########.fr */
/* Updated: 2024/01/29 18:31:14 by vvaas ### ########.fr */
/* */
/******************************************************************************/

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 10:36:21 by maldavid #+# #+# */
/* Updated: 2024/01/29 19:43:33 by maldavid ### ########.fr */
/* Updated: 2024/01/29 19:57:34 by vvaas ### ########.fr */
/* */
/******************************************************************************/
@@ -43,20 +43,16 @@ namespace irc
for (it = _clients.begin(); it != _clients.end(); ++it)
{
if (const_cast<unstd::SharedPtr<irc::Client>&>(*it)->getNickName() == clientname)
_operators.insert(const_cast<unstd::SharedPtr<irc::Client>&>(*it));
{
if (mode)
_operators.insert(const_cast<unstd::SharedPtr<irc::Client>&>(*it));
else
_operators.erase(const_cast<unstd::SharedPtr<irc::Client>&>(*it));
break ;
}
}
if (it == _clients.end())
client->sendCode(ERR_USERNOTINCHANNEL, "User not in channel");
else
{
std::string out;
if (mode)
out = clientname + ": +o";
else
out = clientname + ": -o";
for (it = _clients.begin(); it != _clients.end(); ++it)
const_cast<unstd::SharedPtr<irc::Client>&>(*it)->sendMsg(client->getNickName(), "MODE", out);
}
}
bool Channel::removeClient(unstd::SharedPtr<Client> client)
@@ -125,6 +121,8 @@ namespace irc
modes += 'k';
if (_channel_size != -1)
modes += 'l';
if (modes.size() < 2)
return ;
client->sendCode(RPL_CHANNELMODEIS, modes);
}
void Channel::changeMode(unstd::SharedPtr<class Client> client, const Message& msg)
@@ -155,18 +153,19 @@ namespace irc
case 'o':
if (isOp(client) && modevalue)
ModOperator(client, msg.getTokens()[3], modevalue);
else
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 (static_cast<int>(getNumberOfClients()) > std::atoi(msg.getTokens()[3].c_str()))
return ;
if (!modevalue)
{
_channel_size = -1;
break ;
}
if (modevalue)
_channel_size = std::atoi(msg.getTokens()[3].c_str());
if (!modevalue)
_channel_size = -1;
}
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/22 17:31:06 by maldavid #+# #+# */
/* Updated: 2024/01/29 17:06:16 by vvaas ### ########.fr */
/* Updated: 2024/01/29 17:12:21 by vvaas ### ########.fr */
/* */
/******************************************************************************/
@@ -409,7 +409,6 @@ namespace irc
void Server::handleMode(unstd::SharedPtr<class Client> client, const Message& msg)
{
logs::report(log_message, "Mode requested");
irc::Channel *chan;
if(msg.getTokens().size() < 2)
return ;
@@ -423,14 +422,16 @@ namespace irc
return ;
}
logs::report(log_message, "Mode parsing ok");
channel_it it;
for(it = _channels.begin(); it != _channels.end() && it->getName() != msg.getTokens()[1]; ++it);
if(it == _channels.end())
chan = getChannelByName(msg.getTokens()[1]);
if(chan == NULL)
{
client->sendCode(ERR_NOSUCHCHANNEL, "No such channel");
if(getChannelByName(msg.getTokens()[1]) && !it->isOp(client))
return ;
}
if(!chan->isOp(client))
client->sendCode(ERR_CHANOPRIVSNEEDED, "You need operator privileges to execute this command");
if(msg.getTokens()[2][0] != '-' && msg.getTokens()[2][0] != '+')
return ;
it->changeMode(client, msg);
chan->changeMode(client, msg);
}
}