feat(cmd/list): exec finished

This commit is contained in:
Raphael 2025-06-19 14:12:32 +02:00
parent d62ffb35a4
commit f1878de554
2 changed files with 47 additions and 6 deletions

View file

@ -6,7 +6,7 @@
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */ /* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ /* 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"); INFO_MSG("You can only LIST registered users");
return ERR_NOSUCHNICK; return ERR_NOSUCHNICK;
} }
if (this->_args.size() == 2) {
std::string tmp_line = this->_args.back();
this->_args.pop_back();
std::vector<std::string> 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; return _PARSING_OK;
} }
@ -41,13 +50,42 @@ void List::execute() {
ERROR_MSG("Invalid arguments for LIST command (see warning message)"); ERROR_MSG("Invalid arguments for LIST command (see warning message)");
return; return;
} }
std::string msg321 = ":localhost 321 " + _sender->getNickname() + " Channel :Users Name\r\n";
this->_sender->appendToWriteBuffer(msg321);
if (this->_args.size() > 1) { if (this->_args.size() > 1) {
for (size_t i = 1; i < this->_args.size(); i++) { std::vector<std::string> 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 { } else {
std::list<Channel *> &channelList = this->_server->getChannelsList(); for (std::list<Channel *>::iterator it = this->_server->getChannelsList().begin(); it != this->_server->getChannelsList().end(); it++) {
for (std::list<Channel *>::iterator it = channelList.begin(); it != channelList.end(); it++) {
DEBUG_MSG((*it)->getName());
std::ostringstream msg322; msg322 << ":localhost 322 " << _sender->getNickname() std::ostringstream msg322; msg322 << ":localhost 322 " << _sender->getNickname()
<< " " << (*it)->getName() << " " << << " " << (*it)->getName() << " " <<
(*it)->getUsers().size() << (*it)->getUsers().size() <<
@ -55,4 +93,6 @@ void List::execute() {
this->_sender->appendToWriteBuffer(msg322.str()); this->_sender->appendToWriteBuffer(msg322.str());
} }
} }
std::string msg323 = ":localhost 323 " + _sender->getNickname() + " :End of /LIST\r\n";
this->_sender->appendToWriteBuffer(msg323);
} }

View file

@ -6,7 +6,7 @@
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */ /* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ /* 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; return ERR_NOSUCHCHANNEL;
} else } else
this->_args.at(1).erase(0, 1); this->_args.at(1).erase(0, 1);
_cTarget = searchList(_server->getChannelsList(), _args.at(1));
if (this->_cTarget == NULL) { if (this->_cTarget == NULL) {
WARNING_MSG("Channel not found for INVITE command"); WARNING_MSG("Channel not found for INVITE command");
INFO_MSG("You can only invite users to channels you are in"); INFO_MSG("You can only invite users to channels you are in");