diff --git a/sources/commands/list.cpp b/sources/commands/list.cpp index 4607172..104cf2b 100644 --- a/sources/commands/list.cpp +++ b/sources/commands/list.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ -/* Updated: 2025/06/19 11:42:56 by sben-tay ### ########.fr */ +/* Updated: 2025/06/19 13:50:09 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,6 +29,15 @@ e_code List::checkArgs() { INFO_MSG("You can only LIST registered users"); return ERR_NOSUCHNICK; } + if (this->_args.size() == 2) { + std::string tmp_line = this->_args.back(); + this->_args.pop_back(); + std::vector tmp = split(tmp_line, ','); + for (size_t i = 0; i < tmp.size(); i++) { + this->_args.push_back(tmp.back()); + tmp.pop_back(); + } + } return _PARSING_OK; } @@ -41,13 +50,42 @@ void List::execute() { ERROR_MSG("Invalid arguments for LIST command (see warning message)"); return; } + std::string msg321 = ":localhost 321 " + _sender->getNickname() + " Channel :Users Name\r\n"; + this->_sender->appendToWriteBuffer(msg321); if (this->_args.size() > 1) { - for (size_t i = 1; i < this->_args.size(); i++) { + std::vector vec_tmp; + bool to_print = true; + for (size_t i = 1; i < this->_args.size(); ++i) { + DEBUG_MSG("[" << i << "] " << this->_args[i]); + if (this->_args[i][0] == '#') + this->_args[i].erase(0, 1); + else { + WARNING_MSG("Thanks to check if all the Channel have an '#' at the start of the name !"); + to_print = false; + break; + } + this->_cTarget = searchList(this->_server->getChannelsList(), this->_args[i]); + if (this->_cTarget == NULL) { + WARNING_MSG("Channel not found, aborting the command !"); + to_print = false; + break; + } else { + std::ostringstream tmp; + tmp << ":localhost 322 " << _sender->getNickname() + << " " << this->_cTarget->getName() << " " << + this->_cTarget->getUsers().size() << + " :" << this->_cTarget->getTopic() << "\r\n"; + vec_tmp.push_back(tmp.str()); + } + } + if (to_print) { + for (size_t j = 0; j < vec_tmp.size(); j++) { + DEBUG_MSG(vec_tmp[j]); + this->_sender->appendToWriteBuffer(vec_tmp[j]); + } } } else { - std::list &channelList = this->_server->getChannelsList(); - for (std::list::iterator it = channelList.begin(); it != channelList.end(); it++) { - DEBUG_MSG((*it)->getName()); + for (std::list::iterator it = this->_server->getChannelsList().begin(); it != this->_server->getChannelsList().end(); it++) { std::ostringstream msg322; msg322 << ":localhost 322 " << _sender->getNickname() << " " << (*it)->getName() << " " << (*it)->getUsers().size() << @@ -55,4 +93,6 @@ void List::execute() { this->_sender->appendToWriteBuffer(msg322.str()); } } + std::string msg323 = ":localhost 323 " + _sender->getNickname() + " :End of /LIST\r\n"; + this->_sender->appendToWriteBuffer(msg323); } diff --git a/sources/commands/modes.cpp b/sources/commands/modes.cpp index c9be75a..d5175e5 100644 --- a/sources/commands/modes.cpp +++ b/sources/commands/modes.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ -/* Updated: 2025/06/18 12:53:44 by rparodi ### ########.fr */ +/* Updated: 2025/06/19 14:02:08 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -85,6 +85,7 @@ e_code Mode::checkArgs() { return ERR_NOSUCHCHANNEL; } else this->_args.at(1).erase(0, 1); + _cTarget = searchList(_server->getChannelsList(), _args.at(1)); if (this->_cTarget == NULL) { WARNING_MSG("Channel not found for INVITE command"); INFO_MSG("You can only invite users to channels you are in");