Merge pull request #24 from EniumRaphael/raph
Adding Topic and sending the NEEDMOREPARAMS (461) error message
This commit is contained in:
commit
8096edb63d
17 changed files with 144 additions and 34 deletions
|
|
@ -28,6 +28,8 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
|
git fetch origin
|
||||||
|
git merge origin/master
|
||||||
export CXX=clang++
|
export CXX=clang++
|
||||||
export CXXFLAGS="-std=cpp98 -Wall -Werror -Wextra"
|
export CXXFLAGS="-std=cpp98 -Wall -Werror -Wextra"
|
||||||
printf "\n\033[0;90mCPP env loaded for: \033[38;5;220m${system}\033[0m\n"
|
printf "\n\033[0;90mCPP env loaded for: \033[38;5;220m${system}\033[0m\n"
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
22
include/commands/topic.hpp
Normal file
22
include/commands/topic.hpp
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* topic.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/06/02 22:48:36 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/06/17 22:10:31 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "commands.hpp"
|
||||||
|
|
||||||
|
class cmd::Topic : public ACommand {
|
||||||
|
public:
|
||||||
|
Topic(User *user, Channel *channel, Server *server, std::string &line) : ACommand(user, channel, server, line) {}
|
||||||
|
virtual void execute(void);
|
||||||
|
virtual e_code checkArgs();
|
||||||
|
};
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/06/08 22:10:24 by sben-tay #+# #+# */
|
/* Created: 2025/06/08 22:10:24 by sben-tay #+# #+# */
|
||||||
/* Updated: 2025/06/14 22:26:07 by sben-tay ### ########.fr */
|
/* Updated: 2025/06/18 12:54:41 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,12 +16,12 @@
|
||||||
using namespace cmd;
|
using namespace cmd;
|
||||||
|
|
||||||
e_code Cap::checkArgs() {
|
e_code Cap::checkArgs() {
|
||||||
if (_args.size() < 2){
|
if (_args.size() < 2) {
|
||||||
|
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;
|
||||||
|
|
||||||
_sender->appendToReadBuffer(_command);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
_sender->appendToReadBuffer(_command);
|
||||||
return (_PARSING_OK);
|
return (_PARSING_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/06/12 13:24:05 by sben-tay ### ########.fr */
|
/* Updated: 2025/06/18 12:52:35 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,7 +18,8 @@ using namespace cmd;
|
||||||
|
|
||||||
e_code Invite::checkArgs() {
|
e_code Invite::checkArgs() {
|
||||||
if (_args.size() < 3) {
|
if (_args.size() < 3) {
|
||||||
WARNING_MSG("Not enough arguments for INVITE command");
|
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 (_args.at(1).at(0) != '#') {
|
if (_args.at(1).at(0) != '#') {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/06/18 00:58:16 by sben-tay ### ########.fr */
|
/* Updated: 2025/06/18 12:51:54 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,7 +19,8 @@ using namespace cmd;
|
||||||
|
|
||||||
e_code Join::checkArgs() {
|
e_code Join::checkArgs() {
|
||||||
if (_args.size() < 2 || _args[1].empty()) {
|
if (_args.size() < 2 || _args[1].empty()) {
|
||||||
WARNING_MSG("Not enough arguments for Join command");
|
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 (_args[1][0] != '#') {
|
if (_args[1][0] != '#') {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/06/12 13:24:16 by sben-tay ### ########.fr */
|
/* Updated: 2025/06/18 12:55:06 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,7 +18,8 @@ using namespace cmd;
|
||||||
|
|
||||||
e_code Kick::checkArgs() {
|
e_code Kick::checkArgs() {
|
||||||
if (_args.size() < 3) {
|
if (_args.size() < 3) {
|
||||||
WARNING_MSG("Not enough arguments for KICK command");
|
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 (_args.at(1).at(0) != '#') {
|
if (_args.at(1).at(0) != '#') {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/06/12 13:24:21 by sben-tay ### ########.fr */
|
/* Updated: 2025/06/18 12:52:13 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,7 +18,8 @@ using namespace cmd;
|
||||||
|
|
||||||
e_code List::checkArgs() {
|
e_code List::checkArgs() {
|
||||||
if (_args.size() < 3) {
|
if (_args.size() < 3) {
|
||||||
WARNING_MSG("Not enough arguments for LIST command");
|
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 (this->_sender->isRegistered() == false) {
|
if (this->_sender->isRegistered() == false) {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/06/17 18:00:26 by rparodi ### ########.fr */
|
/* Updated: 2025/06/18 12:53:44 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -74,8 +74,11 @@ void Mode::checkMode() {
|
||||||
* @return return the e_code if there is an error else return _PARSING_OK
|
* @return return the e_code if there is an error else return _PARSING_OK
|
||||||
*/
|
*/
|
||||||
e_code Mode::checkArgs() {
|
e_code Mode::checkArgs() {
|
||||||
if (this->_args.size() < 2)
|
if (this->_args.size() < 2) {
|
||||||
|
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 (this->_args.at(1).at(0) != '#') {
|
if (this->_args.at(1).at(0) != '#') {
|
||||||
WARNING_MSG("Invalid channel name for INVITE command");
|
WARNING_MSG("Invalid channel name for INVITE command");
|
||||||
INFO_MSG("Channel names must start with a '#' character");
|
INFO_MSG("Channel names must start with a '#' character");
|
||||||
|
|
@ -98,9 +101,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 +178,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:
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/06/12 13:24:35 by sben-tay ### ########.fr */
|
/* Updated: 2025/06/18 12:56:37 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,7 +18,8 @@ using namespace cmd;
|
||||||
|
|
||||||
e_code Notice::checkArgs() {
|
e_code Notice::checkArgs() {
|
||||||
if (_args.size() < 3) {
|
if (_args.size() < 3) {
|
||||||
WARNING_MSG("Not enough arguments for NOTICE command");
|
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 (_args.at(1).at(0) != '#') {
|
if (_args.at(1).at(0) != '#') {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/06/12 13:24:39 by sben-tay ### ########.fr */
|
/* Updated: 2025/06/18 12:55:38 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,7 +19,8 @@ using namespace cmd;
|
||||||
|
|
||||||
e_code Part::checkArgs() {
|
e_code Part::checkArgs() {
|
||||||
if (_args.size() < 2) {
|
if (_args.size() < 2) {
|
||||||
WARNING_MSG("Not enough arguments for PART command");
|
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 (_args.at(1).at(0) != '#') {
|
if (_args.at(1).at(0) != '#') {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/06/16 17:33:20 by sben-tay ### ########.fr */
|
/* Updated: 2025/06/18 12:55:50 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,7 +18,8 @@ using namespace cmd;
|
||||||
|
|
||||||
e_code Pass::checkArgs() {
|
e_code Pass::checkArgs() {
|
||||||
if (_args.size() != 2) {
|
if (_args.size() != 2) {
|
||||||
WARNING_MSG("Not correct for Pass command");
|
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;
|
||||||
}
|
}
|
||||||
return _PARSING_OK;
|
return _PARSING_OK;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/06/17 16:58:06 by sben-tay ### ########.fr */
|
/* Updated: 2025/06/18 12:53:01 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,7 +20,8 @@ using namespace cmd;
|
||||||
|
|
||||||
e_code Ping::checkArgs() {
|
e_code Ping::checkArgs() {
|
||||||
if (_args.size() < 2) {
|
if (_args.size() < 2) {
|
||||||
WARNING_MSG("Not enough arguments for PING command");
|
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;
|
||||||
}
|
}
|
||||||
return _PARSING_OK;
|
return _PARSING_OK;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/06/18 00:56:49 by sben-tay ### ########.fr */
|
/* Updated: 2025/06/18 12:51:56 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,7 +21,8 @@ using namespace cmd;
|
||||||
|
|
||||||
e_code PrivMsg::checkArgs() {
|
e_code PrivMsg::checkArgs() {
|
||||||
if (_args.size() < 3) {
|
if (_args.size() < 3) {
|
||||||
WARNING_MSG("Not enough arguments for PRIVMSG command");
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
56
sources/commands/topic.cpp
Normal file
56
sources/commands/topic.cpp
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* topic.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/06/18 12:51:40 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "commands.hpp"
|
||||||
|
#include "core.hpp"
|
||||||
|
#include "logs.hpp"
|
||||||
|
#include "topic.hpp"
|
||||||
|
|
||||||
|
using namespace cmd;
|
||||||
|
|
||||||
|
e_code Topic::checkArgs() {
|
||||||
|
if (_args.size() < 2) {
|
||||||
|
std::string msg461 = ":localhost 461 " + this->_sender->getNickname() + " " + this->_command + " :Not enough parameters\r\n";
|
||||||
|
this->_sender->appendToWriteBuffer(msg461);
|
||||||
|
return ERR_NEEDMOREPARAMS;
|
||||||
|
}
|
||||||
|
this->_cTarget = searchList(this->_channels, this->_args[1]);
|
||||||
|
if (this->_cTarget == NULL)
|
||||||
|
return ERR_NOSUCHCHANNEL;
|
||||||
|
if (this->_cTarget->getProtectTopic()) {
|
||||||
|
if (searchList(this->_cTarget->getOperators(), this->_sender->getName()) == NULL)
|
||||||
|
return ERR_CHANOPRIVSNEEDED;
|
||||||
|
} else {
|
||||||
|
if (searchList(this->_cTarget->getUsers(), this->_sender->getName()) == NULL)
|
||||||
|
return ERR_NOTONCHANNEL;
|
||||||
|
}
|
||||||
|
return _PARSING_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Execute the Topic
|
||||||
|
* @note To change the topic of the channel
|
||||||
|
*/
|
||||||
|
|
||||||
|
void Topic::execute() {
|
||||||
|
if (checkArgs() != _PARSING_OK) {
|
||||||
|
ERROR_MSG("Invalid arguments for TOPIC command (see warning message)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this->_cTarget->getTopic().empty()) {
|
||||||
|
std::string msg331 = ":localhost 331 " + this->_sender->getNickname() + " " + this->_cTarget->getName() + " :No topic is set" + "\r\n";
|
||||||
|
this->_sender->appendToWriteBuffer(msg331);
|
||||||
|
} else {
|
||||||
|
std::string msg332 = ":localhost 332 " + this->_sender->getNickname() + " " + this->_cTarget->getName() + " :" + _cTarget->getTopic() + "\r\n";
|
||||||
|
this->_sender->appendToWriteBuffer(msg332);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/06/08 19:16:10 by sben-tay #+# #+# */
|
/* Created: 2025/06/08 19:16:10 by sben-tay #+# #+# */
|
||||||
/* Updated: 2025/06/17 23:17:54 by sben-tay ### ########.fr */
|
/* Updated: 2025/06/18 12:56:17 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -17,7 +17,8 @@ using namespace cmd;
|
||||||
|
|
||||||
e_code cmd::userCmd::checkArgs() {
|
e_code cmd::userCmd::checkArgs() {
|
||||||
if (_args.size() < 5) {
|
if (_args.size() < 5) {
|
||||||
WARNING_MSG("USER: Not enough parameters");
|
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;
|
||||||
}
|
}
|
||||||
return _PARSING_OK;
|
return _PARSING_OK;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue