diff --git a/Makefile b/Makefile index 7c8ef78..b621a04 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: omoudni +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/05/02 15:40:00 by rparodi #+# #+# # -# Updated: 2025/05/26 18:22:38 by rparodi ### ########.fr # +# Updated: 2025/05/29 12:31:53 by rparodi ### ########.fr # # # #******************************************************************************# @@ -32,6 +32,7 @@ SRC = sources/channel/channel.cpp \ sources/core/parser.cpp \ sources/user/user.cpp \ sources/commands/commands.cpp \ + sources/commands/pass.cpp \ sources/commands/invite.cpp INC_DIR = include/core \ diff --git a/include/commands.hpp b/include/commands.hpp index a5c8965..47bc160 100644 --- a/include/commands.hpp +++ b/include/commands.hpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/20 23:31:58 by rparodi #+# #+# */ -/* Updated: 2025/05/26 18:25:49 by rparodi ### ########.fr */ +/* Updated: 2025/05/29 12:47:57 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -53,7 +53,6 @@ namespace cmd class Nick; class Notice; class Part; - class Pass; class Ping; class Pong; class PrivMsg; diff --git a/include/commands/commands.tpp b/include/commands/commands.tpp index 94dc22e..7683e95 100644 --- a/include/commands/commands.tpp +++ b/include/commands/commands.tpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 17:34:30 by rparodi #+# #+# */ -/* Updated: 2025/05/26 18:20:34 by rparodi ### ########.fr */ +/* Updated: 2025/05/27 14:34:56 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ 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/include/server.hpp b/include/server.hpp index 9424bcb..fea3efc 100644 --- a/include/server.hpp +++ b/include/server.hpp @@ -6,7 +6,7 @@ /* By: omoudni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/20 21:50:32 by rparodi #+# #+# */ -/* Updated: 2025/05/26 22:26:04 by rparodi ### ########.fr */ +/* Updated: 2025/05/29 12:17:55 by rparodi ### ########.fr */ /* */ /******************************************************************************/ @@ -37,6 +37,7 @@ public: unsigned short int getPort() const; std::list getUsersList() const; std::list getChannelsList() const; + std::string getPassword() const; void showInfo() const; void printUsers() const; }; diff --git a/include/user.hpp b/include/user.hpp index a1188ce..a002556 100644 --- a/include/user.hpp +++ b/include/user.hpp @@ -6,7 +6,7 @@ /* By: omoudni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/20 21:57:49 by rparodi #+# #+# */ -/* Updated: 2025/05/26 18:10:24 by rparodi ### ########.fr */ +/* Updated: 2025/05/29 12:37:11 by rparodi ### ########.fr */ /* */ /******************************************************************************/ @@ -34,6 +34,7 @@ class User bool isRegistered() const; std::string getName() const; std::string extractFullCommand(); + void setRegistered(); void appendToReadBuffer(const std::string &data); void appendToWriteBuffer(const std::string &data); void setNickname(const std::string &nickname); diff --git a/sources/commands/commands.cpp b/sources/commands/commands.cpp index 0798e62..b6afc79 100644 --- a/sources/commands/commands.cpp +++ b/sources/commands/commands.cpp @@ -6,12 +6,13 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 16:11:56 by rparodi #+# #+# */ -/* Updated: 2025/05/26 18:25:18 by rparodi ### ########.fr */ +/* Updated: 2025/05/29 12:48:13 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "commands.hpp" #include "logs.hpp" +#include "pass.hpp" /** * @brief To send the line where a command is invoqued to execute @@ -91,6 +92,9 @@ void cmd::dispatch(::User *user, Channel *channel, Server *server, const std::st // } break; case 'p': + if (command_name == "pass") { + Pass(user, channel, server, line).execute(); + } // if (command_name == "part") { // Part(user, channel, server, line).execute(); // } diff --git a/sources/commands/invite.cpp b/sources/commands/invite.cpp index b2e4612..ebfa953 100644 --- a/sources/commands/invite.cpp +++ b/sources/commands/invite.cpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ -/* Updated: 2025/05/26 22:50:04 by rparodi ### ########.fr */ +/* Updated: 2025/05/29 12:10:25 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,8 @@ bool Invite::checkArgs() { WARNING_MSG("Invalid channel name for INVITE command"); INFO_MSG("Channel names must start with a '#' character"); return false; - } + } else + _args.at(1).erase(0, 1); _cTarget = searchList(_channels, _args.at(1)); if (_cTarget == NULL) { WARNING_MSG("Channel not found for INVITE command"); @@ -55,6 +56,10 @@ bool Invite::checkArgs() { return true; } +/** + * @brief Execute the invite command + * @note To invite a peapol to join a channel (from an operator) + */ void Invite::execute() { if (checkArgs() == false) { ERROR_MSG("Invalid arguments for INVITE command (see warning message)"); 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(); +} diff --git a/sources/core/Server.cpp b/sources/core/Server.cpp index 0bd410a..ed2a121 100644 --- a/sources/core/Server.cpp +++ b/sources/core/Server.cpp @@ -6,7 +6,7 @@ /* By: omoudni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/13 11:11:07 by rparodi #+# #+# */ -/* Updated: 2025/05/26 22:30:07 by rparodi ### ########.fr */ +/* Updated: 2025/05/29 12:17:15 by rparodi ### ########.fr */ /* */ /******************************************************************************/ @@ -148,6 +148,13 @@ void Server::printUsers() const } } +/** + * @brief The getter for the password + * + * @return the password of the server + */ +std::string Server::getPassword() const { return this->_password; } + std::list Server::getUsersList() const { // to_delete when done WARNING_MSG("TO DO FILL") diff --git a/sources/user/user.cpp b/sources/user/user.cpp index a47b20f..bb4de98 100644 --- a/sources/user/user.cpp +++ b/sources/user/user.cpp @@ -6,7 +6,7 @@ /* By: omoudni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/21 20:37:12 by omoudni #+# #+# */ -/* Updated: 2025/05/22 17:13:35 by omoudni ### ########.fr */ +/* Updated: 2025/05/29 12:38:46 by rparodi ### ########.fr */ /* */ /******************************************************************************/ @@ -15,11 +15,12 @@ // Constructor User::User(short unsigned int fd) : _fd(fd), _registered(false), _hasNick(false), _hasUser(false) {} -// Getter for fd -short unsigned int User::getFd() const -{ - return _fd; -} +/** + * @brief Getter for the fd + * + * @return the fd of the user + */ +short unsigned int User::getFd() const { return this->_fd; } /** * @brief Getter for the nickname of the user @@ -64,6 +65,13 @@ void User::setNickname(const std::string &nickname) } } +/** + * @brief Setter to register a user + */ +void User::setRegistered() { + this->_registered = true; +} + // Registration state bool User::isRegistered() const {