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:36:21 by maldavid #+# #+# */
|
/* Created: 2024/01/21 10:36:21 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/29 21:08:18 by vvaas ### ########.fr */
|
/* Updated: 2024/01/29 22:08:11 by vvaas ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@@ -40,19 +40,35 @@ namespace irc
|
|||||||
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;
|
client_it it;
|
||||||
for (it = _clients.begin(); it != _clients.end(); ++it)
|
logs::report(log_message, "mode operator, mode = %d", mode);
|
||||||
|
if (mode)
|
||||||
{
|
{
|
||||||
if (const_cast<unstd::SharedPtr<irc::Client>&>(*it)->getNickName() == clientname)
|
for (it = _clients.begin(); it != _clients.end(); ++it)
|
||||||
{
|
{
|
||||||
if (mode)
|
if (const_cast<unstd::SharedPtr<irc::Client>&>(*it)->getNickName() == clientname)
|
||||||
|
{
|
||||||
_operators.insert(const_cast<unstd::SharedPtr<irc::Client>&>(*it));
|
_operators.insert(const_cast<unstd::SharedPtr<irc::Client>&>(*it));
|
||||||
else
|
break ;
|
||||||
_operators.erase(const_cast<unstd::SharedPtr<irc::Client>&>(*it));
|
}
|
||||||
break ;
|
|
||||||
}
|
}
|
||||||
|
if (it == _clients.end())
|
||||||
|
client->sendCode(ERR_USERNOTINCHANNEL, "User not in channel");
|
||||||
|
}
|
||||||
|
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());
|
||||||
|
if (const_cast<unstd::SharedPtr<irc::Client>&>(*it)->getNickName() == clientname)
|
||||||
|
{
|
||||||
|
logs::report(log_message, "found %s to erase", const_cast<unstd::SharedPtr<irc::Client>&>(*it)->getNickName().c_str());
|
||||||
|
_operators.erase(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (it == _operators.end())
|
||||||
|
client->sendCode(ERR_USERNOTINCHANNEL, "User not in channel");
|
||||||
}
|
}
|
||||||
if (it == _clients.end())
|
|
||||||
client->sendCode(ERR_USERNOTINCHANNEL, "User not in channel");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Channel::removeClient(unstd::SharedPtr<Client> client)
|
bool Channel::removeClient(unstd::SharedPtr<Client> client)
|
||||||
@@ -151,7 +167,7 @@ namespace irc
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
if (isOp(client) && modevalue)
|
if (isOp(client))
|
||||||
ModOperator(client, msg.getTokens()[3], modevalue);
|
ModOperator(client, msg.getTokens()[3], modevalue);
|
||||||
else if (!isOp(client))
|
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");
|
||||||
@@ -232,12 +248,12 @@ namespace irc
|
|||||||
}
|
}
|
||||||
if(!hasClient(target))
|
if(!hasClient(target))
|
||||||
{
|
{
|
||||||
op->sendCode(ERR_USERNOTINCHANNEL, const_cast<std::string&>(target->getNickName()) + ' ' + _name + " they aren't on that channel");
|
op->sendCodeInChannel(ERR_USERNOTINCHANNEL, *this, "they aren't on that channel");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!isOp(op))
|
if(!isOp(op))
|
||||||
{
|
{
|
||||||
op->sendCode(ERR_CHANOPRIVSNEEDED, const_cast<std::string&>(_name) + " you're not channel operator");
|
op->sendCodeInChannel(ERR_CHANOPRIVSNEEDED, *this, "you're not channel operator");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for(client_it it = _clients.begin(); it != _clients.end(); ++it)
|
for(client_it it = _clients.begin(); it != _clients.end(); ++it)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/21 09:31:17 by maldavid #+# #+# */
|
/* Created: 2024/01/21 09:31:17 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/25 21:20:52 by maldavid ### ########.fr */
|
/* Updated: 2024/01/29 22:10:26 by vvaas ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
|||||||
@@ -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 21:16:00 by vvaas ### ########.fr */
|
/* Updated: 2024/01/29 21:32:24 by vvaas ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@@ -52,8 +52,9 @@ namespace irc
|
|||||||
client->printUserHeader();
|
client->printUserHeader();
|
||||||
client->setNewNickName(msg.getTokens()[1]);
|
client->setNewNickName(msg.getTokens()[1]);
|
||||||
client->sendMsg(oldNick, "NICK", msg.getTokens()[1]);
|
client->sendMsg(oldNick, "NICK", msg.getTokens()[1]);
|
||||||
|
std::string welcome_msg = "Welcome to yipirc :), " + client->getNickName();
|
||||||
if (client->isLogged())
|
if (client->isLogged())
|
||||||
client->sendCode(RPL_WELCOME, "Welcome to yipiirc :)\n");
|
client->sendCode(RPL_WELCOME, welcome_msg);
|
||||||
std::cout << "new nickname, " << client->getNickName() << std::endl;
|
std::cout << "new nickname, " << client->getNickName() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,13 +76,14 @@ namespace irc
|
|||||||
|
|
||||||
void Server::handlePass(unstd::SharedPtr<class Client> client, const Message& msg)
|
void Server::handlePass(unstd::SharedPtr<class Client> client, const Message& msg)
|
||||||
{
|
{
|
||||||
|
std::string welcome_msg = "Welcone to yipirc :), " + client->getNickName();
|
||||||
if(client->isLogged())
|
if(client->isLogged())
|
||||||
return;
|
return;
|
||||||
if(msg.getTokens()[1] == _password)
|
if(msg.getTokens()[1] == _password)
|
||||||
{
|
{
|
||||||
client->login();
|
client->login();
|
||||||
if (client->getNickName().size() != 0)
|
if (client->getNickName().size() != 0)
|
||||||
client->sendCode(RPL_WELCOME, "Welcome to yipiirc :)\n");
|
client->sendCode(RPL_WELCOME, welcome_msg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -429,7 +431,10 @@ namespace irc
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
if(!chan->isOp(client))
|
if(!chan->isOp(client))
|
||||||
|
{
|
||||||
client->sendCodeInChannel(ERR_CHANOPRIVSNEEDED, *chan, "You need operator privileges to execute this command");
|
client->sendCodeInChannel(ERR_CHANOPRIVSNEEDED, *chan, "You need operator privileges to execute this command");
|
||||||
|
return ;
|
||||||
|
}
|
||||||
if(msg.getTokens()[2][0] != '-' && msg.getTokens()[2][0] != '+')
|
if(msg.getTokens()[2][0] != '-' && msg.getTokens()[2][0] != '+')
|
||||||
return ;
|
return ;
|
||||||
chan->changeMode(client, msg);
|
chan->changeMode(client, msg);
|
||||||
|
|||||||
Reference in New Issue
Block a user