From 29a3bb114b57c0812f6f86c6f4caf3aeae918599 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 26 May 2025 17:55:31 +0200 Subject: [PATCH] fix(commands/cmd): now using NULL instead nullptr --- Makefile | 11 +++++--- include/commands.hpp | 4 +-- include/commands/commands.tpp | 6 ++--- include/commands/invite.hpp | 4 +-- include/user.hpp | 48 +++++++++++++++++------------------ sources/commands/commands.cpp | 4 +-- sources/commands/invite.cpp | 31 +++++++++++++++++++--- 7 files changed, 67 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index adde70c..ab85ad6 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: omoudni +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/05/02 15:40:00 by rparodi #+# #+# # -# Updated: 2025/05/24 16:48:43 by rparodi ### ########.fr # +# Updated: 2025/05/26 16:18:54 by rparodi ### ########.fr # # # #******************************************************************************# @@ -31,10 +31,13 @@ SRC = sources/core/logs.cpp \ sources/core/main.cpp \ sources/core/Server.cpp \ sources/user/user.cpp \ - sources/channel/channel.cpp + sources/channel/channel.cpp \ + sources/commands/commands.cpp \ + sources/commands/invite.cpp -INC_DIR = include/core \ - include +INC_DIR = include/core \ + include/commands \ + include CPPFLAGS = $(addprefix -I, $(INC_DIR)) -MMD -MP diff --git a/include/commands.hpp b/include/commands.hpp index 6514903..96e62c6 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/24 18:21:55 by rparodi ### ########.fr */ +/* Updated: 2025/05/26 16:28:58 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,7 +60,7 @@ namespace cmd class Quit; class Topic; class Unknown; - class User; + class cmdUser; }; #include "./commands/commands.tpp" diff --git a/include/commands/commands.tpp b/include/commands/commands.tpp index 28e3e0d..5707b2a 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/24 18:23:26 by rparodi ### ########.fr */ +/* Updated: 2025/05/26 16:14:24 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ * @tparam T Type of the list have to be search (have to get an getName() method) * @param list list to search in * @param name name of the element to search - * @return pointer to the element found or nullptr if not found + * @return pointer to the element found or NULL if not found */ template T cmd::searchList(const std::list &list, const std::string &name) { @@ -26,5 +26,5 @@ T cmd::searchList(const std::list &list, const std::string &name) { if ((*it)->getName() == name) return *it; } - return nullptr; + return NULL; } diff --git a/include/commands/invite.hpp b/include/commands/invite.hpp index e2eb1ed..11973ed 100644 --- a/include/commands/invite.hpp +++ b/include/commands/invite.hpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */ -/* Updated: 2025/05/24 17:32:43 by rparodi ### ########.fr */ +/* Updated: 2025/05/26 16:27:42 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,6 @@ class cmd::Invite : public ACommand { public: - virtual void execute(Server &server, User &client, const std::vector &args); + virtual void execute(void); virtual bool checkArgs(); }; diff --git a/include/user.hpp b/include/user.hpp index 866ca37..edded4a 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/21 21:16:56 by omoudni ### ########.fr */ +/* Updated: 2025/05/26 16:16:01 by rparodi ### ########.fr */ /* */ /******************************************************************************/ @@ -16,27 +16,27 @@ class User { -private: - short unsigned int _fd; - bool _registered; - std::string _nickname; - std::string _hostname; - std::string _read_buffer; - std::string _write_buffer; - std::string _username; - bool _hasNick; - bool _hasUser; - -public: - User(short unsigned fd); - short unsigned int getFd() const; - bool isReadyToSend() const; - bool isRegistered() const; - std::string getName() const; - std::string extractFullCommand(); - void appendToReadBuffer(const std::string &data); - void appendToWriteBuffer(const std::string &data); - void setNickname(const std::string &nickname); - void setUsername(const std::string &username); - void checkRegistration(); + private: + short unsigned int _fd; + bool _registered; + std::string _nickname; + std::string _hostname; + std::string _read_buffer; + std::string _write_buffer; + std::string _username; + bool _hasNick; + bool _hasUser; + + public: + User(short unsigned fd); + short unsigned int getFd() const; + bool isReadyToSend() const; + bool isRegistered() const; + std::string getName() const; + std::string extractFullCommand(); + void appendToReadBuffer(const std::string &data); + void appendToWriteBuffer(const std::string &data); + void setNickname(const std::string &nickname); + void setUsername(const std::string &username); + void checkRegistration(); }; diff --git a/sources/commands/commands.cpp b/sources/commands/commands.cpp index 280c4b3..43cb9f5 100644 --- a/sources/commands/commands.cpp +++ b/sources/commands/commands.cpp @@ -112,8 +112,8 @@ ACommand::ACommand(::User *user, ::Channel *channel, ::Server *server, const std _command = _args.at(0); _channels = server->getChannelsList(); _users = server->getUsersList(); - _uTarget = nullptr; - _cTarget = nullptr; + _uTarget = NULL; + _cTarget = NULL; } ACommand::~ACommand() { diff --git a/sources/commands/invite.cpp b/sources/commands/invite.cpp index cdfacd2..ae2b55a 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/24 17:58:36 by rparodi ### ########.fr */ +/* Updated: 2025/05/26 16:43:01 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,14 +27,37 @@ bool Invite::checkArgs() { return false; } _cTarget = searchList(_channels, _args.at(1)); - if (_cTarget == nullptr) { + if (_cTarget == NULL) { WARNING_MSG("Channel not found for INVITE command"); INFO_MSG("You can only invite users to channels you are in"); return false; } - if (searchList(_cTarget->getOperators(), _sender->getName()) != nullptr) { + if (searchList(_cTarget->getOperators(), _sender->getName()) != NULL) { WARNING_MSG("You are not an operator in the channel for INVITE command"); return false; } - return (true); + uTarget = searchList(this->_users, _args.at(2)); + if (this->_uTarget == NULL) { + WARNING_MSG("User not found"); + return false; + } + if (this->_uTarget->isRegistered() == false) { + WARNING_MSG("User is not registered for INVITE command"); + INFO_MSG("You can only invite registered users"); + return false; + } + if (searchList(this->_cTarget->getUsers(), this->_uTarget->getName())) { + WARNING_MSG("User is already in the channel for INVITE command"); + INFO_MSG("You cannot invite a user who is already in the channel"); + return false; + } + return true; +} + +void Invite::execute() { + if (checkArgs() == false) { + ERROR_MSG("Invalid arguments for INVITE command (see warning message)"); + return; + } + // check how the com }