fix(core/error_code): now commands use the correct error code
This commit is contained in:
parent
8ea4da3b82
commit
bc8410a21d
19 changed files with 81 additions and 77 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
||||
bool Invite::checkArgs() {
|
||||
e_code Invite::checkArgs() {
|
||||
if (_args.size() < 3) {
|
||||
WARNING_MSG("Not enough arguments for INVITE command");
|
||||
return false;
|
||||
return ERR_NEEDMOREPARAMS;
|
||||
}
|
||||
if (_args.at(1).at(0) != '#') {
|
||||
WARNING_MSG("Invalid channel name for INVITE command");
|
||||
INFO_MSG("Channel names must start with a '#' character");
|
||||
return false;
|
||||
return ERR_NOSUCHCHANNEL;
|
||||
} else
|
||||
_args.at(1).erase(0, 1);
|
||||
_cTarget = searchList(_channels, _args.at(1));
|
||||
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;
|
||||
return ERR_NOSUCHCHANNEL;
|
||||
} else
|
||||
_args.at(1).erase(0, 1);
|
||||
if (searchList(_cTarget->getOperators(), _sender->getName()) != NULL) {
|
||||
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));
|
||||
if (this->_uTarget == NULL) {
|
||||
WARNING_MSG("User not found");
|
||||
return false;
|
||||
return ERR_NOSUCHNICK;
|
||||
}
|
||||
if (this->_uTarget->isRegistered() == false) {
|
||||
WARNING_MSG("User is not registered for INVITE command");
|
||||
INFO_MSG("You can only invite registered users");
|
||||
return false;
|
||||
return ERR_NOSUCHNICK;
|
||||
}
|
||||
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 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)
|
||||
*/
|
||||
void Invite::execute() {
|
||||
if (checkArgs() == false) {
|
||||
if (checkArgs() == _PARSING_OK) {
|
||||
ERROR_MSG("Invalid arguments for INVITE command (see warning message)");
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
||||
bool Join::checkArgs() {
|
||||
e_code Join::checkArgs() {
|
||||
if (_args.size() < 2) {
|
||||
WARNING_MSG("Not enough arguments for Join command");
|
||||
return false;
|
||||
return ERR_NEEDMOREPARAMS;
|
||||
}
|
||||
if (_args.at(1).at(0) != '#') {
|
||||
WARNING_MSG("Invalid channel name for Join command");
|
||||
INFO_MSG("Channel names must start with a '#' character");
|
||||
return false;
|
||||
return ERR_NOSUCHCHANNEL;
|
||||
} else
|
||||
_args.at(1).erase(0, 1);
|
||||
_cTarget = searchList(_channels, _args.at(1));
|
||||
if (_cTarget == NULL) {
|
||||
WARNING_MSG("Channel not found for Join command");
|
||||
INFO_MSG("You can only Join users to channels you are in");
|
||||
return false;
|
||||
return ERR_NOSUCHCHANNEL;
|
||||
}
|
||||
if (searchList(_cTarget->getOperators(), _sender->getName()) != NULL) {
|
||||
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) {
|
||||
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
|
||||
*/
|
||||
void Join::execute() {
|
||||
if (checkArgs() == false) {
|
||||
if (checkArgs() == _PARSING_OK) {
|
||||
ERROR_MSG("Invalid arguments for Join command (see warning message)");
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
||||
bool Nick::checkArgs() {
|
||||
e_code Nick::checkArgs() {
|
||||
if (this->_uTarget->isRegistered() == false) {
|
||||
WARNING_MSG("User is not registered for Nick command");
|
||||
INFO_MSG("You can only Nick registered users");
|
||||
return false;
|
||||
return ERR_NOSUCHNICK;
|
||||
}
|
||||
if (_args.size() < 2) {
|
||||
WARNING_MSG("Not enough arguments for Nick command");
|
||||
return false;
|
||||
return ERR_NEEDMOREPARAMS;
|
||||
}
|
||||
_uTarget = searchList(this->_users, _args.at(1));
|
||||
if (this->_uTarget != NULL) {
|
||||
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
|
||||
*/
|
||||
void Nick::execute() {
|
||||
if (checkArgs() == false) {
|
||||
if (checkArgs() == _PARSING_OK) {
|
||||
ERROR_MSG("Invalid arguments for Nick command (see warning message)");
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
||||
bool Notice::checkArgs() {
|
||||
e_code Notice::checkArgs() {
|
||||
if (_args.size() < 3) {
|
||||
WARNING_MSG("Not enough arguments for NOTICE command");
|
||||
return false;
|
||||
return ERR_NEEDMOREPARAMS;
|
||||
}
|
||||
if (_args.at(1).at(0) != '#') {
|
||||
_uTarget = searchList(this->_users, _args.at(2));
|
||||
if (this->_uTarget == NULL) {
|
||||
WARNING_MSG("User not found");
|
||||
return false;
|
||||
return ERR_NOSUCHNICK;
|
||||
}
|
||||
if (this->_uTarget->isRegistered() == false) {
|
||||
WARNING_MSG("User is not registered for NOTICE command");
|
||||
INFO_MSG("You can only NOTICE registered users");
|
||||
return false;
|
||||
return ERR_NOSUCHNICK;
|
||||
}
|
||||
} else {
|
||||
_cTarget = searchList(_channels, _args.at(1));
|
||||
if (_cTarget == NULL) {
|
||||
WARNING_MSG("Channel not found for NOTICE command");
|
||||
INFO_MSG("You can only NOTICE users to channels you are in");
|
||||
return false;
|
||||
return ERR_NOSUCHCHANNEL;
|
||||
} else
|
||||
_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)
|
||||
*/
|
||||
void Notice::execute() {
|
||||
if (checkArgs() == false) {
|
||||
if (checkArgs() == _PARSING_OK) {
|
||||
ERROR_MSG("Invalid arguments for NOTICE command (see warning message)");
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,40 +6,41 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 "commands.hpp"
|
||||
#include "core.hpp"
|
||||
#include "logs.hpp"
|
||||
|
||||
using namespace cmd;
|
||||
|
||||
bool Part::checkArgs() {
|
||||
e_code Part::checkArgs() {
|
||||
if (_args.size() < 2) {
|
||||
WARNING_MSG("Not enough arguments for PART command");
|
||||
return false;
|
||||
return ERR_NEEDMOREPARAMS;
|
||||
}
|
||||
if (_args.at(1).at(0) != '#') {
|
||||
WARNING_MSG("Invalid channel name for PART command");
|
||||
INFO_MSG("Channel names must start with a '#' character");
|
||||
return false;
|
||||
return ERR_NOSUCHCHANNEL;
|
||||
} else
|
||||
_args.at(1).erase(0, 1);
|
||||
_cTarget = searchList(_channels, _args.at(1));
|
||||
if (_cTarget == NULL) {
|
||||
WARNING_MSG("Channel not found for PART command");
|
||||
INFO_MSG("You can only Part users to channels you are in");
|
||||
return false;
|
||||
return ERR_NOSUCHCHANNEL;
|
||||
} else
|
||||
_args.at(1).erase(0, 1);
|
||||
if (searchList(this->_cTarget->getUsers(), this->_uTarget->getName())) {
|
||||
WARNING_MSG("User is not in the channel he wants to leave");
|
||||
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
|
||||
*/
|
||||
void Part::execute() {
|
||||
if (checkArgs() == false) {
|
||||
if (checkArgs() == _PARSING_OK) {
|
||||
ERROR_MSG("Invalid arguments for Part command (see warning message)");
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
||||
bool Pass::checkArgs() {
|
||||
e_code Pass::checkArgs() {
|
||||
if (_args.size() != 2) {
|
||||
WARNING_MSG("Not correct for Pass command");
|
||||
return false;
|
||||
return ERR_NEEDMOREPARAMS;
|
||||
}
|
||||
DEBUG_MSG("coucou");
|
||||
if (_sender->isRegistered()) {
|
||||
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
|
||||
*/
|
||||
void Pass::execute() {
|
||||
if (checkArgs() == false) {
|
||||
if (checkArgs() == _PARSING_OK) {
|
||||
ERROR_MSG("Invalid arguments for Pass command (see warning message)");
|
||||
DEBUG_MSG("skill issues");
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
||||
bool Ping::checkArgs() {
|
||||
e_code Ping::checkArgs() {
|
||||
if (_args.size() < 3) {
|
||||
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() {
|
||||
clock_t start = clock() / CLOCKS_PER_SEC;
|
||||
if (checkArgs() == false) {
|
||||
if (checkArgs() == _PARSING_OK) {
|
||||
ERROR_MSG("Invalid arguments for PRIVMSG command (see warning message)");
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
||||
bool PrivMsg::checkArgs() {
|
||||
e_code PrivMsg::checkArgs() {
|
||||
if (_args.size() < 3) {
|
||||
WARNING_MSG("Not enough arguments for PRIVMSG command");
|
||||
return false;
|
||||
return ERR_NEEDMOREPARAMS;
|
||||
}
|
||||
if (_args.at(1).at(0) != '#') {
|
||||
_uTarget = searchList(this->_users, _args.at(2));
|
||||
if (this->_uTarget == NULL) {
|
||||
WARNING_MSG("User not found");
|
||||
return false;
|
||||
return ERR_NOSUCHNICK;
|
||||
}
|
||||
if (this->_uTarget->isRegistered() == false) {
|
||||
WARNING_MSG("User is not registered for PRIVMSG command");
|
||||
INFO_MSG("You can only privmsg registered users");
|
||||
return false;
|
||||
return ERR_NOSUCHNICK;
|
||||
}
|
||||
} else {
|
||||
_cTarget = searchList(_channels, _args.at(1));
|
||||
if (_cTarget == NULL) {
|
||||
WARNING_MSG("Channel not found for PRIVMSG command");
|
||||
INFO_MSG("You can only privmsg users to channels you are in");
|
||||
return false;
|
||||
return ERR_NOSUCHCHANNEL;
|
||||
} else
|
||||
_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
|
||||
*/
|
||||
void PrivMsg::execute() {
|
||||
if (checkArgs() == false) {
|
||||
if (checkArgs() == _PARSING_OK) {
|
||||
ERROR_MSG("Invalid arguments for PRIVMSG command (see warning message)");
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue