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