diff --git a/include/commands/pass.hpp b/include/commands/pass.hpp new file mode 100644 index 0000000..bb289fe --- /dev/null +++ b/include/commands/pass.hpp @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* pass.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */ +/* Updated: 2025/05/29 12:52:25 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "commands.hpp" + +namespace cmd { + class Pass : public ACommand { + public: + Pass(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {} + virtual void execute(void); + virtual bool checkArgs(); + }; +} diff --git a/sources/commands/pass.cpp b/sources/commands/pass.cpp new file mode 100644 index 0000000..ef799b2 --- /dev/null +++ b/sources/commands/pass.cpp @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* pass.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ +/* Updated: 2025/05/29 12:41:39 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "pass.hpp" +#include "commands.hpp" +#include "logs.hpp" + +using namespace cmd; + +bool Pass::checkArgs() { + if (_args.size() != 2) { + WARNING_MSG("Not correct for Pass command"); + return false; + } + if (_sender->isRegistered()) { + WARNING_MSG(_sender->getName() << " is already is already log in the server !"); + return false; + } + return true; +} + +/** + * @brief Execute the Pass command + * @note To Pass a users to join a channel (from an operator) + */ +void Pass::execute() { + if (checkArgs() == false) { + ERROR_MSG("Invalid arguments for Pass command (see warning message)"); + return; + } + if (_args.at(1) != _server->getPassword()) { + ERROR_MSG("The password is incorrect"); + return; + } + _sender->setRegistered(); +}