diff --git a/include/commands/list.hpp b/include/commands/list.hpp new file mode 100644 index 0000000..490f77f --- /dev/null +++ b/include/commands/list.hpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* list.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */ +/* Updated: 2025/06/09 14:35:44 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "commands.hpp" + +class cmd::List : public ACommand { + public: + List(User *user, Channel *channel, Server *server, std::string &line) : ACommand(user, channel, server, line) {} + virtual void execute(void); + virtual e_code checkArgs(); +}; diff --git a/sources/commands/list.cpp b/sources/commands/list.cpp new file mode 100644 index 0000000..314615f --- /dev/null +++ b/sources/commands/list.cpp @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* list.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ +/* Updated: 2025/06/09 15:33:52 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "list.hpp" +#include "commands.hpp" +#include "logs.hpp" + +using namespace cmd; + +e_code List::checkArgs() { + if (_args.size() < 3) { + WARNING_MSG("Not enough arguments for LIST command"); + return ERR_NEEDMOREPARAMS; + } + if (this->_sender->isRegistered() == false) { + WARNING_MSG("User is not registered for LIST command"); + INFO_MSG("You can only LIST registered users"); + return ERR_NOSUCHNICK; + } + if (_args.at(1).at(0) != '#') { + WARNING_MSG("Invalid channel name for LIST command"); + INFO_MSG("Channel names must start with a '#' character"); + return ERR_NOSUCHCHANNEL; + } else + _args.at(1).erase(0, 1); + _cTarget = searchList(_channels, _args.at(1)); + if (_cTarget == NULL) { + WARNING_MSG("Channel not found for LIST command"); + INFO_MSG("You can only LIST users to channels you are in"); + return ERR_NOSUCHCHANNEL; + } else + _args.at(1).erase(0, 1); + return _PARSING_OK; +} + +/** + * @brief Execute the list command + * @note To list the channel + */ +void List::execute() { + if (checkArgs() == _PARSING_OK) { + ERROR_MSG("Invalid arguments for LIST command (see warning message)"); + return; + } + // check how the com +}