diff --git a/srcs/channel.cpp b/srcs/channel.cpp index 6fc86d1..44023f1 100644 --- a/srcs/channel.cpp +++ b/srcs/channel.cpp @@ -6,7 +6,7 @@ /* By: vvaas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 client, const std::string &clientname, bool mode) { 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&>(*it)->getNickName() == clientname) + for (it = _clients.begin(); it != _clients.end(); ++it) { - if (mode) + if (const_cast&>(*it)->getNickName() == clientname) + { _operators.insert(const_cast&>(*it)); - else - _operators.erase(const_cast&>(*it)); - break ; + 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&>(*it)->getNickName().c_str(), clientname.c_str()); + if (const_cast&>(*it)->getNickName() == clientname) + { + logs::report(log_message, "found %s to erase", const_cast&>(*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) @@ -151,7 +167,7 @@ namespace irc } break; case 'o': - if (isOp(client) && modevalue) + if (isOp(client)) ModOperator(client, msg.getTokens()[3], modevalue); else if (!isOp(client)) client->sendCode(ERR_CHANOPRIVSNEEDED, "You need to be operator to execute this command"); @@ -232,12 +248,12 @@ namespace irc } if(!hasClient(target)) { - op->sendCode(ERR_USERNOTINCHANNEL, const_cast(target->getNickName()) + ' ' + _name + " they aren't on that channel"); + op->sendCodeInChannel(ERR_USERNOTINCHANNEL, *this, "they aren't on that channel"); return false; } if(!isOp(op)) { - op->sendCode(ERR_CHANOPRIVSNEEDED, const_cast(_name) + " you're not channel operator"); + op->sendCodeInChannel(ERR_CHANOPRIVSNEEDED, *this, "you're not channel operator"); return false; } for(client_it it = _clients.begin(); it != _clients.end(); ++it) diff --git a/srcs/server.cpp b/srcs/server.cpp index 29eca2c..5418493 100644 --- a/srcs/server.cpp +++ b/srcs/server.cpp @@ -6,7 +6,7 @@ /* By: vvaas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /******************************************************************************/ diff --git a/srcs/server_functions.cpp b/srcs/server_functions.cpp index d0d9bbd..2352a9b 100644 --- a/srcs/server_functions.cpp +++ b/srcs/server_functions.cpp @@ -6,7 +6,7 @@ /* By: vvaas +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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->setNewNickName(msg.getTokens()[1]); client->sendMsg(oldNick, "NICK", msg.getTokens()[1]); + std::string welcome_msg = "Welcome to yipirc :), " + client->getNickName(); 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; } @@ -75,13 +76,14 @@ namespace irc void Server::handlePass(unstd::SharedPtr client, const Message& msg) { + std::string welcome_msg = "Welcone to yipirc :), " + client->getNickName(); if(client->isLogged()) return; if(msg.getTokens()[1] == _password) { client->login(); if (client->getNickName().size() != 0) - client->sendCode(RPL_WELCOME, "Welcome to yipiirc :)\n"); + client->sendCode(RPL_WELCOME, welcome_msg); } else { @@ -429,7 +431,10 @@ namespace irc return ; } if(!chan->isOp(client)) + { client->sendCodeInChannel(ERR_CHANOPRIVSNEEDED, *chan, "You need operator privileges to execute this command"); + return ; + } if(msg.getTokens()[2][0] != '-' && msg.getTokens()[2][0] != '+') return ; chan->changeMode(client, msg);