fix(cmd/mode): now topic mode is for protect not edit

This commit is contained in:
Raphael 2025-06-18 12:57:32 +02:00
parent a97800dd6e
commit f84492e175
3 changed files with 24 additions and 7 deletions

View file

@ -6,7 +6,7 @@
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */ /* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/20 22:18:17 by rparodi #+# #+# */ /* Created: 2025/05/20 22:18:17 by rparodi #+# #+# */
/* Updated: 2025/06/18 01:18:05 by sben-tay ### ########.fr */ /* Updated: 2025/06/18 12:24:15 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -33,8 +33,10 @@ class Channel {
bool isOperator(User *user) const; bool isOperator(User *user) const;
bool isUserInChannel(User *user) const; bool isUserInChannel(User *user) const;
bool getNeedInvite() const; bool getNeedInvite() const;
bool getProtectTopic() const;
// setters // setters
void setProtectTopic(bool toSet);
void setMaxUser(size_t args); void setMaxUser(size_t args);
void setNeedInvite(bool toSet); void setNeedInvite(bool toSet);
void setTopic(const std::string &topic); void setTopic(const std::string &topic);
@ -53,6 +55,7 @@ class Channel {
std::string _password; std::string _password;
size_t _maxUsers; size_t _maxUsers;
bool _needInvite; bool _needInvite;
bool _protectTopic;
std::string _topic; std::string _topic;
std::list<User *> _operators; std::list<User *> _operators;
std::list<User *> _users; std::list<User *> _users;

View file

@ -6,7 +6,7 @@
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */ /* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/20 22:43:24 by rparodi #+# #+# */ /* Created: 2025/05/20 22:43:24 by rparodi #+# #+# */
/* Updated: 2025/06/18 01:17:37 by sben-tay ### ########.fr */ /* Updated: 2025/06/18 12:20:01 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -145,6 +145,13 @@ bool Channel::isUserInChannel(User *user) const {
return false; return false;
} }
bool Channel::getProtectTopic() const {
return this->_protectTopic;
}
void Channel::setProtectTopic(bool toSet) {
this->_protectTopic = toSet;
}
/** /**
* @brief Setter for the topic of the channel * @brief Setter for the topic of the channel
* *
@ -226,4 +233,4 @@ void Channel::sendAllClientInAChannel(const std::string toSend, User *sender) {
} }
(*it)->appendToWriteBuffer(toSend); (*it)->appendToWriteBuffer(toSend);
} }
} }

View file

@ -98,9 +98,12 @@ e_code Mode::checkArgs() {
const e_mode &ret = this->_mode[i].first; const e_mode &ret = this->_mode[i].first;
if (ret == ERROR_MODE) if (ret == ERROR_MODE)
return ERR_UNKNOWNMODE; return ERR_UNKNOWNMODE;
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 ((ret == CHAN_SET_KEY && 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()) if (this->_mode[i].second.arguments.empty()) {
std::string msg461 = ":localhost 461 " + this->_sender->getNickname() + " " + this->_command + " :Not enough parameters\r\n";
this->_sender->appendToWriteBuffer(msg461);
return ERR_NEEDMOREPARAMS; return ERR_NEEDMOREPARAMS;
}
if (searchList(this->_cTarget->getOperators(), this->_sender->getName()) != NULL) { if (searchList(this->_cTarget->getOperators(), this->_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 ERR_CHANOPRIVSNEEDED; return ERR_CHANOPRIVSNEEDED;
@ -172,9 +175,13 @@ void Mode::execute() {
break; break;
case CHAN_SET_TOPIC: case CHAN_SET_TOPIC:
if (this->_mode[i].second.add) { if (this->_mode[i].second.add) {
this->_cTarget->setTopic(this->_mode[i].second.arguments); if (this->_cTarget->getProtectTopic())
DEBUG_MSG("Topic is already protected");
this->_cTarget->setProtectTopic(true);
} else if (this->_mode[i].second.remove) { } else if (this->_mode[i].second.remove) {
this->_cTarget->setTopic(""); if (!this->_cTarget->getProtectTopic())
DEBUG_MSG("Topic is already non-protected");
this->_cTarget->setProtectTopic(false);
} }
break; break;
default: default: