diff --git a/sources/commands/kick.cpp b/sources/commands/kick.cpp index a6c23c8..0598ffa 100644 --- a/sources/commands/kick.cpp +++ b/sources/commands/kick.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ -/* Updated: 2025/06/21 19:19:30 by sben-tay ### ########.fr */ +/* Updated: 2025/06/22 19:38:09 by sben-tay ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,6 @@ #include "logs.hpp" #include "bonus.hpp" - using namespace cmd; e_code Kick::checkArgs() { @@ -28,68 +27,68 @@ e_code Kick::checkArgs() { WARNING_MSG("Invalid channel name for KICK command"); INFO_MSG("Channel names must start with a '#' character"); return ERR_NOSUCHCHANNEL; - } else - _args.at(1).erase(0, 1); + } + _args.at(1).erase(0, 1); // On enlève le '#' pour chercher le nom réel _cTarget = searchList(this->_server->getChannelsList(), _args.at(1)); if (_cTarget == NULL) { WARNING_MSG("Channel not found for KICK command"); - INFO_MSG("You can only KICK users to channels you are in"); return ERR_NOSUCHCHANNEL; - } else - _args.at(1).erase(0, 1); + } if (searchList(_cTarget->getOperators(), _sender->getName()) == NULL) { WARNING_MSG("You are not an operator in the channel for KICK command"); return ERR_CHANOPRIVSNEEDED; } - _uTarget = searchList(this->_users, _args.at(2)); - if (BONUS && _args.at(2) == "bot" && _cTarget->getBotChannel() == true) { + if (BONUS && _args.at(2) == "bot" && _cTarget->getBotChannel()) { return _PARSING_OK; } - else if (this->_uTarget == NULL) { - WARNING_MSG("User not found"); + + _uTarget = searchList(this->_users, _args.at(2)); + if (_uTarget == NULL || !_uTarget->isRegistered()) { + WARNING_MSG("User not found or not registered"); return ERR_NOSUCHNICK; } - if (this->_uTarget->isRegistered() == false) { - WARNING_MSG("User is not registered for KICK command"); - INFO_MSG("You can only KICK registered users"); - return ERR_NOSUCHNICK; - } - if (searchList(this->_cTarget->getUsers(), this->_uTarget->getName()) == NULL) { - WARNING_MSG("User is already in the channel for KICK command"); - INFO_MSG("You cannot KICK a user who is already in the channel"); - return ERR_USERONCHANNEL; + if (searchList(this->_cTarget->getUsers(), _uTarget->getName()) == NULL) { + WARNING_MSG("User is not in the channel for KICK command"); + return ERR_USERNOTINCHANNEL; } return _PARSING_OK; } /** - * @brief Execute the kick command - * @note To kick a user from a channel + * @brief Execute the KICK command + * @note Operator removes a user from a channel */ void Kick::execute() { if (checkArgs() != _PARSING_OK) { - ERROR_MSG("Invalid arguments for INVITE command (see warning message)"); + ERROR_MSG("Invalid arguments for KICK command (see warning message)"); return; } - std::cout << "MODE BONUS ?" << BONUS << std::endl; + if (BONUS && _args.at(2) == "bot") { - if (_cTarget->getBotChannel() == true) { - std::cout << "Bot is already in the channel, kicking it" << std::endl; - std::string msgKickBot = ":bot!ircbot@localhost KICK #" + _cTarget->getName() + " bot :Bot kicked from channel\r\n"; - this->_sender->appendToWriteBuffer(msgKickBot); + if (_cTarget->getBotChannel()) { + std::string msgKickBot = ":bot!ircbot@localhost KICK #" + _cTarget->getName() + " " + "bot"; + if (_args.size() > 4) + msgKickBot += " :" + _args.at(3); + msgKickBot += "\r\n"; + std::cout << " msgKickBot: " << msgKickBot << std::endl; + _cTarget->sendAllClientInAChannel(msgKickBot); _cTarget->setBotChannel(false); } - std::cout << "peace" << std::endl; return; } + + std::string msgPart = ":" + this->_uTarget->getPrefix() + " PART #" + _cTarget->getName() + "\r\n"; - std::string msgKick = ":" + this->_uTarget->getPrefix() + " KICK #" + this->_cTarget->getName() + " " + this->_uTarget->getName() + " :kicked from channel\r\n"; + std::string msgKick = ":" + this->_uTarget->getPrefix() + " KICK #" + this->_cTarget->getName(); if (_args.size() > 4) msgKick += " :" + _args.at(4); msgKick += "\r\n"; - this->_uTarget->appendToWriteBuffer(msgKick + msgPart); + std::cout << " msgKick: " << msgKick << "msgPart: " << msgPart << std::endl; + _cTarget->sendAllClientInAChannel(msgKick); + _uTarget->appendToWriteBuffer(msgPart); + _cTarget->removeUser(this->_uTarget); _cTarget->removeOperator(this->_uTarget); diff --git a/sources/commands/privmsg.cpp b/sources/commands/privmsg.cpp index 782ab66..fa36e38 100644 --- a/sources/commands/privmsg.cpp +++ b/sources/commands/privmsg.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ -/* Updated: 2025/06/21 18:52:06 by sben-tay ### ########.fr */ +/* Updated: 2025/06/22 01:53:33 by sben-tay ### ########.fr */ /* */ /* ************************************************************************** */ @@ -81,7 +81,7 @@ void PrivMsg::execute() { if (_cTarget) _cTarget->sendAllClientInAChannel(msg, _sender); - if (BONUS) { + if (BONUS && _cTarget->getBotChannel()) { if (_args.at(2) == "!help") { std::cout << "BONUS: PING command received, sending PONG" << std::endl; _cTarget->sendAllClientInAChannel(msgBot);