Merge pull request #14 from EniumRaphael/raph

Finishing all the parsing of all the commands except mode
This commit is contained in:
Raphaël 2025-06-09 15:45:49 +02:00 committed by GitHub
commit a8571c5b09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 168 additions and 0 deletions

22
include/commands/kick.hpp Normal file
View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* kick.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */
/* Updated: 2025/06/09 14:18:03 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include "commands.hpp"
class cmd::Kick : public ACommand {
public:
Kick(User *user, Channel *channel, Server *server, std::string &line) : ACommand(user, channel, server, line) {}
virtual void execute(void);
virtual e_code checkArgs();
};

22
include/commands/list.hpp Normal file
View file

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */
/* Updated: 2025/06/09 14:35:44 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include "commands.hpp"
class cmd::List : public ACommand {
public:
List(User *user, Channel *channel, Server *server, std::string &line) : ACommand(user, channel, server, line) {}
virtual void execute(void);
virtual e_code checkArgs();
};

69
sources/commands/kick.cpp Normal file
View file

@ -0,0 +1,69 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* kick.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
/* Updated: 2025/06/09 14:37:11 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "kick.hpp"
#include "commands.hpp"
#include "logs.hpp"
using namespace cmd;
e_code Kick::checkArgs() {
if (_args.size() < 3) {
WARNING_MSG("Not enough arguments for KICK command");
return ERR_NEEDMOREPARAMS;
}
if (_args.at(1).at(0) != '#') {
WARNING_MSG("Invalid channel name for KICK command");
INFO_MSG("Channel names must start with a '#' character");
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 KICK command");
INFO_MSG("You can only KICK users to channels you are in");
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 KICK command");
return ERR_CHANOPRIVSNEEDED;
}
_uTarget = searchList(this->_users, _args.at(2));
if (this->_uTarget == NULL) {
WARNING_MSG("User not found");
return ERR_NOSUCHNICK;
}
if (this->_uTarget->isRegistered() == false) {
WARNING_MSG("User is not registered for KICK command");
INFO_MSG("You can only KICK registered users");
return ERR_NOSUCHNICK;
}
if (searchList(this->_cTarget->getUsers(), this->_uTarget->getName())) {
WARNING_MSG("User is already in the channel for KICK command");
INFO_MSG("You cannot KICK a user who is already in the channel");
return ERR_USERONCHANNEL;
}
return _PARSING_OK;
}
/**
* @brief Execute the kick command
* @note To kick a user from a channel
*/
void Kick::execute() {
if (checkArgs() == _PARSING_OK) {
ERROR_MSG("Invalid arguments for INVITE command (see warning message)");
return;
}
// check how the com
}

55
sources/commands/list.cpp Normal file
View file

@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
/* Updated: 2025/06/09 15:33:52 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "list.hpp"
#include "commands.hpp"
#include "logs.hpp"
using namespace cmd;
e_code List::checkArgs() {
if (_args.size() < 3) {
WARNING_MSG("Not enough arguments for LIST command");
return ERR_NEEDMOREPARAMS;
}
if (this->_sender->isRegistered() == false) {
WARNING_MSG("User is not registered for LIST command");
INFO_MSG("You can only LIST registered users");
return ERR_NOSUCHNICK;
}
if (_args.at(1).at(0) != '#') {
WARNING_MSG("Invalid channel name for LIST command");
INFO_MSG("Channel names must start with a '#' character");
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 LIST command");
INFO_MSG("You can only LIST users to channels you are in");
return ERR_NOSUCHCHANNEL;
} else
_args.at(1).erase(0, 1);
return _PARSING_OK;
}
/**
* @brief Execute the list command
* @note To list the channel
*/
void List::execute() {
if (checkArgs() == _PARSING_OK) {
ERROR_MSG("Invalid arguments for LIST command (see warning message)");
return;
}
// check how the com
}