feat(cmd/mode): mode exec is seem good (not send message to client yet but debug msg
This commit is contained in:
parent
8d53681c19
commit
46e4f86c16
4 changed files with 133 additions and 8 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/20 22:43:24 by rparodi #+# #+# */
|
||||
/* Updated: 2025/05/26 22:55:45 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/06/17 17:22:09 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -58,6 +58,51 @@ std::list<User *> Channel::getOperators() const {
|
|||
return this->_operators;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the password of the channel
|
||||
*
|
||||
* @return string with the password
|
||||
*/
|
||||
std::string Channel::getPassword() const {
|
||||
return this->_password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the max user allowd to be in the channel
|
||||
*
|
||||
* @return size_t max user
|
||||
*/
|
||||
size_t Channel::getMaxUsers() const {
|
||||
return this->_maxUsers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get if an invitation is needed for this channel
|
||||
*
|
||||
* @return the boolean to check if an invite is needed for the channel
|
||||
*/
|
||||
bool Channel::getNeedInvite() const {
|
||||
return this->_needInvite;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Setter got the NeedInvite channel
|
||||
*
|
||||
* @param toSet The new value for need Invite
|
||||
*/
|
||||
void Channel::setNeedInvite(bool toSet) {
|
||||
this->_needInvite = toSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Setter for the Max User for the channel
|
||||
*
|
||||
* @param arg the new number (integer / long)
|
||||
*/
|
||||
void Channel::setMaxUser(size_t arg) {
|
||||
this->_maxUsers = arg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the list of the Invited in the channel
|
||||
*
|
||||
|
|
@ -106,6 +151,15 @@ void Channel::setTopic(const std::string &topic) {
|
|||
this->_topic = topic;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Setter for the Channel's password
|
||||
*
|
||||
* @param newPass the new password to set
|
||||
*/
|
||||
void Channel::setPassword(const std::string &newPass) {
|
||||
this->_password = newPass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Setter to set a new operator in the channel
|
||||
*
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
||||
/* Updated: 2025/06/17 16:09:26 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/06/17 17:57:02 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,6 +14,8 @@
|
|||
#include "commands.hpp"
|
||||
#include "core.hpp"
|
||||
#include "logs.hpp"
|
||||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
#include <utility>
|
||||
|
||||
using namespace cmd;
|
||||
|
|
@ -96,7 +98,7 @@ e_code Mode::checkArgs() {
|
|||
const e_mode &ret = this->_mode[i].first;
|
||||
if (ret == ERROR_MODE)
|
||||
return ERR_UNKNOWNMODE;
|
||||
if (ret == CHAN_SET_KEY || ret == CHAN_SET_LIMIT || ret == CHAN_SET_OP)
|
||||
if ((ret == CHAN_SET_KEY && this->_mode[i].second.add) || (ret == CHAN_SET_TOPIC && this->_mode[i].second.add) || (ret == CHAN_SET_LIMIT && this->_mode[i].second.add) || ret == CHAN_SET_OP)
|
||||
if (this->_mode[i].second.arguments.empty())
|
||||
return ERR_NEEDMOREPARAMS;
|
||||
if (searchList(this->_cTarget->getOperators(), this->_sender->getName()) != NULL) {
|
||||
|
|
@ -108,12 +110,73 @@ e_code Mode::checkArgs() {
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Execute the invite command
|
||||
* @note To invite a peapol to join a channel (from an operator)
|
||||
* @brief Execute the mode command
|
||||
* @note To manipulate de moderation of a channel
|
||||
*/
|
||||
void Mode::execute() {
|
||||
if (checkArgs() != _PARSING_OK) {
|
||||
ERROR_MSG("Invalid arguments for INVITE command (see warning message)");
|
||||
return;
|
||||
}
|
||||
if (searchList(this->_cTarget->getOperators(), this->_sender->getName()) == NULL) {
|
||||
DEBUG_MSG("send is not an operator for MODE COMMAND");
|
||||
}
|
||||
for (size_t i = 0; i < this->_mode.size(); ++i) {
|
||||
size_t tmp;
|
||||
switch (this->_mode[i].first) {
|
||||
case CHAN_INVITE_ONLY:
|
||||
if (this->_mode[i].second.add) {
|
||||
if (this->_cTarget->getNeedInvite() == true) {
|
||||
DEBUG_MSG("Already as invite only");
|
||||
} this->_cTarget->setNeedInvite(true);
|
||||
} else if (this->_mode[i].second.remove) {
|
||||
if (this->_cTarget->getNeedInvite() == false) {
|
||||
DEBUG_MSG("Already as not invite only");
|
||||
this->_cTarget->setNeedInvite(false);
|
||||
}
|
||||
break;
|
||||
case CHAN_SET_KEY:
|
||||
if (this->_mode[i].second.add)
|
||||
this->_cTarget->setPassword(this->_mode[i].second.arguments);
|
||||
else if (this->_mode[i].second.remove)
|
||||
this->_cTarget->setPassword("");
|
||||
break;
|
||||
case CHAN_SET_LIMIT:
|
||||
if (this->_mode[i].second.add) {
|
||||
errno = 0;
|
||||
tmp = strtol(this->_mode[i].second.arguments.c_str(), NULL, 10);
|
||||
if (tmp <= 0 || (this->_cTarget->getNeedInvite() && tmp >= this->_cTarget->getUsers().size()) || errno != ERANGE) {
|
||||
DEBUG_MSG("Overflow / negative number on mode +l abort");
|
||||
return;
|
||||
}
|
||||
this->_cTarget->setMaxUser(tmp);
|
||||
} else if (this->_mode[i].second.remove) {
|
||||
this->_cTarget->setMaxUser(0);
|
||||
}
|
||||
break;
|
||||
case CHAN_SET_OP:
|
||||
this->_uTarget = searchList(this->_cTarget->getUsers(), this->_mode[i].second.arguments);
|
||||
if (this->_uTarget == NULL)
|
||||
DEBUG_MSG("USER NOT FOUND");
|
||||
if (this->_mode[i].second.add) {
|
||||
this->_cTarget->getOperators().push_back(this->_uTarget);
|
||||
} else if (this->_mode[i].second.add) {
|
||||
if (searchList(this->_cTarget->getOperators(), this->_mode[i].second.arguments) == NULL) {
|
||||
DEBUG_MSG("NOT OPERATOR");
|
||||
} else {
|
||||
this->_cTarget->getOperators().remove(this->_uTarget);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CHAN_SET_TOPIC:
|
||||
if (this->_mode[i].second.add) {
|
||||
this->_cTarget->setTopic(this->_mode[i].second.arguments);
|
||||
} else if (this->_mode[i].second.remove) {
|
||||
this->_cTarget->setTopic("");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue