fix(commands/cmd): now using NULL instead nullptr
This commit is contained in:
parent
bcfa001d5e
commit
29a3bb114b
7 changed files with 67 additions and 41 deletions
11
Makefile
11
Makefile
|
|
@ -6,7 +6,7 @@
|
|||
# By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <typename T>
|
||||
T cmd::searchList(const std::list<T> &list, const std::string &name) {
|
||||
|
|
@ -26,5 +26,5 @@ T cmd::searchList(const std::list<T> &list, const std::string &name) {
|
|||
if ((*it)->getName() == name)
|
||||
return *it;
|
||||
}
|
||||
return nullptr;
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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<std::string> &args);
|
||||
virtual void execute(void);
|
||||
virtual bool checkArgs();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
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();
|
||||
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();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue