Merge pull request #11 from EniumRaphael/raph

fix(core/error_code): now commands use the correct error code
This commit is contained in:
Raphaël 2025-06-05 22:57:27 +02:00 committed by GitHub
commit 8a77409158
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 81 additions and 77 deletions

View file

@ -6,7 +6,7 @@
# By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ # # By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2025/05/02 15:40:00 by rparodi #+# #+# # # Created: 2025/05/02 15:40:00 by rparodi #+# #+# #
# Updated: 2025/06/03 16:50:01 by rparodi ### ########.fr # # Updated: 2025/06/05 22:54:26 by rparodi ### ########.fr #
# # # #
#******************************************************************************# #******************************************************************************#

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/20 23:31:58 by rparodi #+# #+# */ /* Created: 2025/05/20 23:31:58 by rparodi #+# #+# */
/* Updated: 2025/05/29 12:47:57 by rparodi ### ########.fr */ /* Updated: 2025/06/05 22:55:54 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,6 +17,7 @@
#include "user.hpp" #include "user.hpp"
#include "channel.hpp" #include "channel.hpp"
#include "server.hpp" #include "server.hpp"
#include "core.hpp"
#include "logs.hpp" #include "logs.hpp"
namespace cmd namespace cmd
@ -39,7 +40,7 @@ namespace cmd
std::vector<std::string> _args; std::vector<std::string> _args;
public: public:
virtual void execute() = 0; virtual void execute() = 0;
virtual bool checkArgs() = 0; virtual e_code checkArgs() = 0;
~ACommand(); ~ACommand();
ACommand(User *user, Channel *channel, Server *server, const std::string &line); ACommand(User *user, Channel *channel, Server *server, const std::string &line);
}; };

View file

@ -18,5 +18,5 @@ class cmd::Invite : public ACommand {
public: public:
Invite(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {} Invite(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
virtual void execute(void); virtual void execute(void);
virtual bool checkArgs(); virtual e_code checkArgs();
}; };

View file

@ -18,5 +18,5 @@ class cmd::Join : public ACommand {
public: public:
Join(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {} Join(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
virtual void execute(void); virtual void execute(void);
virtual bool checkArgs(); virtual e_code checkArgs();
}; };

View file

@ -18,5 +18,5 @@ class cmd::Nick : public ACommand {
public: public:
Nick(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {} Nick(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
virtual void execute(void); virtual void execute(void);
virtual bool checkArgs(); virtual e_code checkArgs();
}; };

View file

@ -18,5 +18,5 @@ class cmd::Notice : public ACommand {
public: public:
Notice(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {} Notice(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
virtual void execute(void); virtual void execute(void);
virtual bool checkArgs(); virtual e_code checkArgs();
}; };

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */ /* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */
/* Updated: 2025/06/02 00:51:23 by rparodi ### ########.fr */ /* Updated: 2025/06/04 23:49:09 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,5 +18,5 @@ class cmd::Part : public ACommand {
public: public:
Part(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {} Part(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
virtual void execute(void); virtual void execute(void);
virtual bool checkArgs(); virtual e_code checkArgs();
}; };

View file

@ -19,6 +19,6 @@ namespace cmd {
public: public:
Pass(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {} Pass(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
virtual void execute(void); virtual void execute(void);
virtual bool checkArgs(); virtual e_code checkArgs();
}; };
} }

View file

@ -18,5 +18,5 @@ class cmd::Ping : public ACommand {
public: public:
Ping(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {} Ping(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
virtual void execute(void); virtual void execute(void);
virtual bool checkArgs(); virtual e_code checkArgs();
}; };

View file

@ -18,5 +18,5 @@ class cmd::PrivMsg : public ACommand {
public: public:
PrivMsg(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {} PrivMsg(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
virtual void execute(void); virtual void execute(void);
virtual bool checkArgs(); virtual e_code checkArgs();
}; };

View file

@ -6,7 +6,7 @@
/* By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ */ /* By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/12 14:16:03 by rparodi #+# #+# */ /* Created: 2025/05/12 14:16:03 by rparodi #+# #+# */
/* Updated: 2025/06/04 23:45:35 by rparodi ### ########.fr */ /* Updated: 2025/06/05 11:10:45 by rparodi ### ########.fr */
/* */ /* */
/******************************************************************************/ /******************************************************************************/
@ -17,6 +17,8 @@
#endif #endif
enum e_code { enum e_code {
//command for parsing
_PARSING_OK = 000,
// Reply codes (RPL_*) // Reply codes (RPL_*)
RPL_WELCOME = 001, // “<nick> :Welcome to the Internet Relay Network <nick>!<user>@<host>” RPL_WELCOME = 001, // “<nick> :Welcome to the Internet Relay Network <nick>!<user>@<host>”
RPL_YOURHOST = 002, // “<nick> :Your host is <servername>, running version <ver>” RPL_YOURHOST = 002, // “<nick> :Your host is <servername>, running version <ver>”
@ -153,7 +155,7 @@ enum e_code {
ERR_TOOMANYTARGETS = 407, // “<target> :Duplicate recipients. No message delivered” ERR_TOOMANYTARGETS = 407, // “<target> :Duplicate recipients. No message delivered”
ERR_NOSUCHSERVICE = 408, // “<service name> :No such service ” ERR_NOSUCHSERVICE = 408, // “<service name> :No such service ”
ERR_NOORIGIN = 409, // “:No origin specified” ERR_NOORIGIN = 409, // “:No origin specified”
ERR_NORECIPIENT = 411, // “:No recipient given (<command>)” ERR_NOREC = 411, // “:No recipient given (<command>)”
ERR_NOTEXTTOSEND = 412, // “:No text to send” ERR_NOTEXTTOSEND = 412, // “:No text to send”
ERR_NOTOPLEVEL = 413, // “<mask> :No toplevel domain specified” ERR_NOTOPLEVEL = 413, // “<mask> :No toplevel domain specified”
ERR_WILDTOPLEVEL = 414, // “<mask> :Wildcard in toplevel domain” ERR_WILDTOPLEVEL = 414, // “<mask> :Wildcard in toplevel domain”
@ -173,7 +175,7 @@ enum e_code {
ERR_NOLOGIN = 444, // “<user> :User not logged in” ERR_NOLOGIN = 444, // “<user> :User not logged in”
ERR_SUMMONDISABLED = 445, // “:SUMMON has been disabled” ERR_SUMMONDISABLED = 445, // “:SUMMON has been disabled”
ERR_USERSDISABLED = 446, // “:USERS has been disabled” ERR_USERSDISABLED = 446, // “:USERS has been disabled”
ERR_NOTREGISTERED = 451, // “:You have not registered” ERR_NOTTERED = 451, // “:You have not registered”
ERR_NEEDMOREPARAMS = 461, // “<command> :Not enough parameters” ERR_NEEDMOREPARAMS = 461, // “<command> :Not enough parameters”
ERR_ALREADYREGISTERED = 462, // “:You may not reregister” ERR_ALREADYREGISTERED = 462, // “:You may not reregister”
ERR_NOPERMFORHOST = 463, // “:Your host isn't among the privileged” ERR_NOPERMFORHOST = 463, // “:Your host isn't among the privileged”

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
/* Updated: 2025/05/29 12:10:25 by rparodi ### ########.fr */ /* Updated: 2025/06/05 11:10:36 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,44 +16,44 @@
using namespace cmd; using namespace cmd;
bool Invite::checkArgs() { e_code Invite::checkArgs() {
if (_args.size() < 3) { if (_args.size() < 3) {
WARNING_MSG("Not enough arguments for INVITE command"); WARNING_MSG("Not enough arguments for INVITE command");
return false; return ERR_NEEDMOREPARAMS;
} }
if (_args.at(1).at(0) != '#') { if (_args.at(1).at(0) != '#') {
WARNING_MSG("Invalid channel name for INVITE command"); WARNING_MSG("Invalid channel name for INVITE command");
INFO_MSG("Channel names must start with a '#' character"); INFO_MSG("Channel names must start with a '#' character");
return false; return ERR_NOSUCHCHANNEL;
} else } else
_args.at(1).erase(0, 1); _args.at(1).erase(0, 1);
_cTarget = searchList(_channels, _args.at(1)); _cTarget = searchList(_channels, _args.at(1));
if (_cTarget == NULL) { if (_cTarget == NULL) {
WARNING_MSG("Channel not found for INVITE command"); WARNING_MSG("Channel not found for INVITE command");
INFO_MSG("You can only invite users to channels you are in"); INFO_MSG("You can only invite users to channels you are in");
return false; return ERR_NOSUCHCHANNEL;
} else } else
_args.at(1).erase(0, 1); _args.at(1).erase(0, 1);
if (searchList(_cTarget->getOperators(), _sender->getName()) != NULL) { if (searchList(_cTarget->getOperators(), _sender->getName()) != NULL) {
WARNING_MSG("You are not an operator in the channel for INVITE command"); WARNING_MSG("You are not an operator in the channel for INVITE command");
return false; return ERR_NOPRIVILEGES;
} }
_uTarget = searchList(this->_users, _args.at(2)); _uTarget = searchList(this->_users, _args.at(2));
if (this->_uTarget == NULL) { if (this->_uTarget == NULL) {
WARNING_MSG("User not found"); WARNING_MSG("User not found");
return false; return ERR_NOSUCHNICK;
} }
if (this->_uTarget->isRegistered() == false) { if (this->_uTarget->isRegistered() == false) {
WARNING_MSG("User is not registered for INVITE command"); WARNING_MSG("User is not registered for INVITE command");
INFO_MSG("You can only invite registered users"); INFO_MSG("You can only invite registered users");
return false; return ERR_NOSUCHNICK;
} }
if (searchList(this->_cTarget->getUsers(), this->_uTarget->getName())) { if (searchList(this->_cTarget->getUsers(), this->_uTarget->getName())) {
WARNING_MSG("User is already in the channel for INVITE command"); WARNING_MSG("User is already in the channel for INVITE command");
INFO_MSG("You cannot invite a user who is already in the channel"); INFO_MSG("You cannot invite a user who is already in the channel");
return false; return ERR_USERONCHANNEL;
} }
return true; return _PARSING_OK;
} }
/** /**
@ -61,7 +61,7 @@ bool Invite::checkArgs() {
* @note To invite a peapol to join a channel (from an operator) * @note To invite a peapol to join a channel (from an operator)
*/ */
void Invite::execute() { void Invite::execute() {
if (checkArgs() == false) { if (checkArgs() == _PARSING_OK) {
ERROR_MSG("Invalid arguments for INVITE command (see warning message)"); ERROR_MSG("Invalid arguments for INVITE command (see warning message)");
return; return;
} }

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
/* Updated: 2025/06/02 22:42:17 by rparodi ### ########.fr */ /* Updated: 2025/06/05 22:34:07 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,32 +16,32 @@
using namespace cmd; using namespace cmd;
bool Join::checkArgs() { e_code Join::checkArgs() {
if (_args.size() < 2) { if (_args.size() < 2) {
WARNING_MSG("Not enough arguments for Join command"); WARNING_MSG("Not enough arguments for Join command");
return false; return ERR_NEEDMOREPARAMS;
} }
if (_args.at(1).at(0) != '#') { if (_args.at(1).at(0) != '#') {
WARNING_MSG("Invalid channel name for Join command"); WARNING_MSG("Invalid channel name for Join command");
INFO_MSG("Channel names must start with a '#' character"); INFO_MSG("Channel names must start with a '#' character");
return false; return ERR_NOSUCHCHANNEL;
} else } else
_args.at(1).erase(0, 1); _args.at(1).erase(0, 1);
_cTarget = searchList(_channels, _args.at(1)); _cTarget = searchList(_channels, _args.at(1));
if (_cTarget == NULL) { if (_cTarget == NULL) {
WARNING_MSG("Channel not found for Join command"); WARNING_MSG("Channel not found for Join command");
INFO_MSG("You can only Join users to channels you are in"); INFO_MSG("You can only Join users to channels you are in");
return false; return ERR_NOSUCHCHANNEL;
} }
if (searchList(_cTarget->getOperators(), _sender->getName()) != NULL) { if (searchList(_cTarget->getOperators(), _sender->getName()) != NULL) {
WARNING_MSG("You are not an operator in the channel for Join command"); WARNING_MSG("You are not an operator in the channel for Join command");
return false; return ERR_NOPRIVILEGES;
} }
if (searchList(_cTarget->getInvited(), _sender->getName()) != NULL) { if (searchList(_cTarget->getInvited(), _sender->getName()) != NULL) {
WARNING_MSG("This channel is private and ur not invited"); WARNING_MSG("This channel is private and ur not invited");
return false; return ERR_INVITEONLYCHAN;
} }
return true; return _PARSING_OK;
} }
/** /**
@ -49,7 +49,7 @@ bool Join::checkArgs() {
* @note To join a new channel * @note To join a new channel
*/ */
void Join::execute() { void Join::execute() {
if (checkArgs() == false) { if (checkArgs() == _PARSING_OK) {
ERROR_MSG("Invalid arguments for Join command (see warning message)"); ERROR_MSG("Invalid arguments for Join command (see warning message)");
return; return;
} }

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
/* Updated: 2025/06/02 00:55:45 by rparodi ### ########.fr */ /* Updated: 2025/06/05 22:48:17 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,22 +16,22 @@
using namespace cmd; using namespace cmd;
bool Nick::checkArgs() { e_code Nick::checkArgs() {
if (this->_uTarget->isRegistered() == false) { if (this->_uTarget->isRegistered() == false) {
WARNING_MSG("User is not registered for Nick command"); WARNING_MSG("User is not registered for Nick command");
INFO_MSG("You can only Nick registered users"); INFO_MSG("You can only Nick registered users");
return false; return ERR_NOSUCHNICK;
} }
if (_args.size() < 2) { if (_args.size() < 2) {
WARNING_MSG("Not enough arguments for Nick command"); WARNING_MSG("Not enough arguments for Nick command");
return false; return ERR_NEEDMOREPARAMS;
} }
_uTarget = searchList(this->_users, _args.at(1)); _uTarget = searchList(this->_users, _args.at(1));
if (this->_uTarget != NULL) { if (this->_uTarget != NULL) {
WARNING_MSG(_uTarget->getName() << " is already taken") WARNING_MSG(_uTarget->getName() << " is already taken")
return false; return ERR_NICKNAMEINUSE;
} }
return true; return _PARSING_OK;
} }
/** /**
@ -39,7 +39,7 @@ bool Nick::checkArgs() {
* @note To change the nickname of the user * @note To change the nickname of the user
*/ */
void Nick::execute() { void Nick::execute() {
if (checkArgs() == false) { if (checkArgs() == _PARSING_OK) {
ERROR_MSG("Invalid arguments for Nick command (see warning message)"); ERROR_MSG("Invalid arguments for Nick command (see warning message)");
return; return;
} }

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
/* Updated: 2025/06/02 22:44:49 by rparodi ### ########.fr */ /* Updated: 2025/06/05 22:49:09 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,32 +16,32 @@
using namespace cmd; using namespace cmd;
bool Notice::checkArgs() { e_code Notice::checkArgs() {
if (_args.size() < 3) { if (_args.size() < 3) {
WARNING_MSG("Not enough arguments for NOTICE command"); WARNING_MSG("Not enough arguments for NOTICE command");
return false; return ERR_NEEDMOREPARAMS;
} }
if (_args.at(1).at(0) != '#') { if (_args.at(1).at(0) != '#') {
_uTarget = searchList(this->_users, _args.at(2)); _uTarget = searchList(this->_users, _args.at(2));
if (this->_uTarget == NULL) { if (this->_uTarget == NULL) {
WARNING_MSG("User not found"); WARNING_MSG("User not found");
return false; return ERR_NOSUCHNICK;
} }
if (this->_uTarget->isRegistered() == false) { if (this->_uTarget->isRegistered() == false) {
WARNING_MSG("User is not registered for NOTICE command"); WARNING_MSG("User is not registered for NOTICE command");
INFO_MSG("You can only NOTICE registered users"); INFO_MSG("You can only NOTICE registered users");
return false; return ERR_NOSUCHNICK;
} }
} else { } else {
_cTarget = searchList(_channels, _args.at(1)); _cTarget = searchList(_channels, _args.at(1));
if (_cTarget == NULL) { if (_cTarget == NULL) {
WARNING_MSG("Channel not found for NOTICE command"); WARNING_MSG("Channel not found for NOTICE command");
INFO_MSG("You can only NOTICE users to channels you are in"); INFO_MSG("You can only NOTICE users to channels you are in");
return false; return ERR_NOSUCHCHANNEL;
} else } else
_args.at(1).erase(0, 1); _args.at(1).erase(0, 1);
} }
return true; return _PARSING_OK;
} }
/** /**
@ -49,7 +49,7 @@ bool Notice::checkArgs() {
* @note To send a private message to a user / a channel (like privmsg but without error) * @note To send a private message to a user / a channel (like privmsg but without error)
*/ */
void Notice::execute() { void Notice::execute() {
if (checkArgs() == false) { if (checkArgs() == _PARSING_OK) {
ERROR_MSG("Invalid arguments for NOTICE command (see warning message)"); ERROR_MSG("Invalid arguments for NOTICE command (see warning message)");
return; return;
} }

View file

@ -6,40 +6,41 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
/* Updated: 2025/06/02 00:55:56 by rparodi ### ########.fr */ /* Updated: 2025/06/05 22:50:21 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "part.hpp" #include "part.hpp"
#include "commands.hpp" #include "commands.hpp"
#include "core.hpp"
#include "logs.hpp" #include "logs.hpp"
using namespace cmd; using namespace cmd;
bool Part::checkArgs() { e_code Part::checkArgs() {
if (_args.size() < 2) { if (_args.size() < 2) {
WARNING_MSG("Not enough arguments for PART command"); WARNING_MSG("Not enough arguments for PART command");
return false; return ERR_NEEDMOREPARAMS;
} }
if (_args.at(1).at(0) != '#') { if (_args.at(1).at(0) != '#') {
WARNING_MSG("Invalid channel name for PART command"); WARNING_MSG("Invalid channel name for PART command");
INFO_MSG("Channel names must start with a '#' character"); INFO_MSG("Channel names must start with a '#' character");
return false; return ERR_NOSUCHCHANNEL;
} else } else
_args.at(1).erase(0, 1); _args.at(1).erase(0, 1);
_cTarget = searchList(_channels, _args.at(1)); _cTarget = searchList(_channels, _args.at(1));
if (_cTarget == NULL) { if (_cTarget == NULL) {
WARNING_MSG("Channel not found for PART command"); WARNING_MSG("Channel not found for PART command");
INFO_MSG("You can only Part users to channels you are in"); INFO_MSG("You can only Part users to channels you are in");
return false; return ERR_NOSUCHCHANNEL;
} else } else
_args.at(1).erase(0, 1); _args.at(1).erase(0, 1);
if (searchList(this->_cTarget->getUsers(), this->_uTarget->getName())) { if (searchList(this->_cTarget->getUsers(), this->_uTarget->getName())) {
WARNING_MSG("User is not in the channel he wants to leave"); WARNING_MSG("User is not in the channel he wants to leave");
INFO_MSG("You cannot leave a channel where ur not a member"); INFO_MSG("You cannot leave a channel where ur not a member");
return false; return ERR_USERNOTINCHANNEL;
} }
return true; return _PARSING_OK;
} }
/** /**
@ -47,7 +48,7 @@ bool Part::checkArgs() {
* @note To leave a channel givent in parameter * @note To leave a channel givent in parameter
*/ */
void Part::execute() { void Part::execute() {
if (checkArgs() == false) { if (checkArgs() == _PARSING_OK) {
ERROR_MSG("Invalid arguments for Part command (see warning message)"); ERROR_MSG("Invalid arguments for Part command (see warning message)");
return; return;
} }

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
/* Updated: 2025/06/03 15:04:10 by rparodi ### ########.fr */ /* Updated: 2025/06/04 23:59:57 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,17 +16,17 @@
using namespace cmd; using namespace cmd;
bool Pass::checkArgs() { e_code Pass::checkArgs() {
if (_args.size() != 2) { if (_args.size() != 2) {
WARNING_MSG("Not correct for Pass command"); WARNING_MSG("Not correct for Pass command");
return false; return ERR_NEEDMOREPARAMS;
} }
DEBUG_MSG("coucou"); DEBUG_MSG("coucou");
if (_sender->isRegistered()) { if (_sender->isRegistered()) {
WARNING_MSG(_sender->getName() << " is already is already log in the server !"); WARNING_MSG(_sender->getName() << " is already is already log in the server !");
return false; return ERR_ALREADYREGISTERED;
} }
return true; return _PARSING_OK;
} }
/** /**
@ -34,7 +34,7 @@ bool Pass::checkArgs() {
* @note To connect a user with the password * @note To connect a user with the password
*/ */
void Pass::execute() { void Pass::execute() {
if (checkArgs() == false) { if (checkArgs() == _PARSING_OK) {
ERROR_MSG("Invalid arguments for Pass command (see warning message)"); ERROR_MSG("Invalid arguments for Pass command (see warning message)");
DEBUG_MSG("skill issues"); DEBUG_MSG("skill issues");
return; return;

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
/* Updated: 2025/06/03 14:49:27 by rparodi ### ########.fr */ /* Updated: 2025/06/04 23:54:56 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,12 +18,12 @@
using namespace cmd; using namespace cmd;
bool Ping::checkArgs() { e_code Ping::checkArgs() {
if (_args.size() < 3) { if (_args.size() < 3) {
WARNING_MSG("Not enough arguments for PING command"); WARNING_MSG("Not enough arguments for PING command");
return false; return ERR_NEEDMOREPARAMS;
} }
return true; return _PARSING_OK;
} }
/** /**
@ -32,7 +32,7 @@ bool Ping::checkArgs() {
*/ */
void Ping::execute() { void Ping::execute() {
clock_t start = clock() / CLOCKS_PER_SEC; clock_t start = clock() / CLOCKS_PER_SEC;
if (checkArgs() == false) { if (checkArgs() == _PARSING_OK) {
ERROR_MSG("Invalid arguments for PRIVMSG command (see warning message)"); ERROR_MSG("Invalid arguments for PRIVMSG command (see warning message)");
return; return;
} }

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
/* Updated: 2025/06/02 01:15:00 by rparodi ### ########.fr */ /* Updated: 2025/06/05 22:46:54 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,32 +16,32 @@
using namespace cmd; using namespace cmd;
bool PrivMsg::checkArgs() { e_code PrivMsg::checkArgs() {
if (_args.size() < 3) { if (_args.size() < 3) {
WARNING_MSG("Not enough arguments for PRIVMSG command"); WARNING_MSG("Not enough arguments for PRIVMSG command");
return false; return ERR_NEEDMOREPARAMS;
} }
if (_args.at(1).at(0) != '#') { if (_args.at(1).at(0) != '#') {
_uTarget = searchList(this->_users, _args.at(2)); _uTarget = searchList(this->_users, _args.at(2));
if (this->_uTarget == NULL) { if (this->_uTarget == NULL) {
WARNING_MSG("User not found"); WARNING_MSG("User not found");
return false; return ERR_NOSUCHNICK;
} }
if (this->_uTarget->isRegistered() == false) { if (this->_uTarget->isRegistered() == false) {
WARNING_MSG("User is not registered for PRIVMSG command"); WARNING_MSG("User is not registered for PRIVMSG command");
INFO_MSG("You can only privmsg registered users"); INFO_MSG("You can only privmsg registered users");
return false; return ERR_NOSUCHNICK;
} }
} else { } else {
_cTarget = searchList(_channels, _args.at(1)); _cTarget = searchList(_channels, _args.at(1));
if (_cTarget == NULL) { if (_cTarget == NULL) {
WARNING_MSG("Channel not found for PRIVMSG command"); WARNING_MSG("Channel not found for PRIVMSG command");
INFO_MSG("You can only privmsg users to channels you are in"); INFO_MSG("You can only privmsg users to channels you are in");
return false; return ERR_NOSUCHCHANNEL;
} else } else
_args.at(1).erase(0, 1); _args.at(1).erase(0, 1);
} }
return true; return _PARSING_OK;
} }
/** /**
@ -49,7 +49,7 @@ bool PrivMsg::checkArgs() {
* @note To send a private message to a user / a channel * @note To send a private message to a user / a channel
*/ */
void PrivMsg::execute() { void PrivMsg::execute() {
if (checkArgs() == false) { if (checkArgs() == _PARSING_OK) {
ERROR_MSG("Invalid arguments for PRIVMSG command (see warning message)"); ERROR_MSG("Invalid arguments for PRIVMSG command (see warning message)");
return; return;
} }