fix(core/error_code): now commands use the correct error code

This commit is contained in:
Raphael 2025-06-05 22:56:28 +02:00
parent 8ea4da3b82
commit bc8410a21d
19 changed files with 81 additions and 77 deletions

View file

@ -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;
}