From a97800dd6e61ee2e89770038ec58b2d3e9cbc067 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 18 Jun 2025 12:12:07 +0200 Subject: [PATCH 1/4] feat(nix/git): auto fetch / merge on oy own branch --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index 6584ead..9af1162 100644 --- a/flake.nix +++ b/flake.nix @@ -28,6 +28,8 @@ ); shellHook = '' + git fetch origin + git merge origin/master export CXX=clang++ export CXXFLAGS="-std=cpp98 -Wall -Werror -Wextra" printf "\n\033[0;90mCPP env loaded for: \033[38;5;220m${system}\033[0m\n" From f84492e17587f1c1ca392106a160e2801f4c3341 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 18 Jun 2025 12:57:32 +0200 Subject: [PATCH 2/4] fix(cmd/mode): now topic mode is for protect not edit --- include/channel.hpp | 5 ++++- sources/channel/channel.cpp | 11 +++++++++-- sources/commands/modes.cpp | 15 +++++++++++---- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/include/channel.hpp b/include/channel.hpp index edbbd29..c8dcd67 100644 --- a/include/channel.hpp +++ b/include/channel.hpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 isUserInChannel(User *user) const; bool getNeedInvite() const; + bool getProtectTopic() const; // setters + void setProtectTopic(bool toSet); void setMaxUser(size_t args); void setNeedInvite(bool toSet); void setTopic(const std::string &topic); @@ -53,6 +55,7 @@ class Channel { std::string _password; size_t _maxUsers; bool _needInvite; + bool _protectTopic; std::string _topic; std::list _operators; std::list _users; diff --git a/sources/channel/channel.cpp b/sources/channel/channel.cpp index c9acd75..c746077 100644 --- a/sources/channel/channel.cpp +++ b/sources/channel/channel.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; } +bool Channel::getProtectTopic() const { + return this->_protectTopic; +} + +void Channel::setProtectTopic(bool toSet) { + this->_protectTopic = toSet; +} /** * @brief Setter for the topic of the channel * @@ -226,4 +233,4 @@ void Channel::sendAllClientInAChannel(const std::string toSend, User *sender) { } (*it)->appendToWriteBuffer(toSend); } -} \ No newline at end of file +} diff --git a/sources/commands/modes.cpp b/sources/commands/modes.cpp index eae6a72..5239739 100644 --- a/sources/commands/modes.cpp +++ b/sources/commands/modes.cpp @@ -98,9 +98,12 @@ e_code Mode::checkArgs() { const e_mode &ret = this->_mode[i].first; if (ret == ERROR_MODE) 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 (this->_mode[i].second.arguments.empty()) + 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()) { + std::string msg461 = ":localhost 461 " + this->_sender->getNickname() + " " + this->_command + " :Not enough parameters\r\n"; + this->_sender->appendToWriteBuffer(msg461); return ERR_NEEDMOREPARAMS; + } if (searchList(this->_cTarget->getOperators(), this->_sender->getName()) != NULL) { WARNING_MSG("You are not an operator in the channel for INVITE command"); return ERR_CHANOPRIVSNEEDED; @@ -172,9 +175,13 @@ void Mode::execute() { break; case CHAN_SET_TOPIC: 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) { - this->_cTarget->setTopic(""); + if (!this->_cTarget->getProtectTopic()) + DEBUG_MSG("Topic is already non-protected"); + this->_cTarget->setProtectTopic(false); } break; default: From 1c0e771dd57f3fc4133921714f9f32f649354229 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 18 Jun 2025 12:58:04 +0200 Subject: [PATCH 3/4] fix(cmds): sending the message ERR_NEEDMOREPARAMS (461) --- sources/commands/cap.cpp | 10 +++++----- sources/commands/invite.cpp | 5 +++-- sources/commands/join.cpp | 5 +++-- sources/commands/kick.cpp | 5 +++-- sources/commands/list.cpp | 5 +++-- sources/commands/modes.cpp | 7 +++++-- sources/commands/notice.cpp | 5 +++-- sources/commands/part.cpp | 5 +++-- sources/commands/pass.cpp | 5 +++-- sources/commands/ping.cpp | 5 +++-- sources/commands/privmsg.cpp | 5 +++-- sources/commands/userCmd.cpp | 5 +++-- 12 files changed, 40 insertions(+), 27 deletions(-) diff --git a/sources/commands/cap.cpp b/sources/commands/cap.cpp index 7a0418c..3b1510d 100644 --- a/sources/commands/cap.cpp +++ b/sources/commands/cap.cpp @@ -6,7 +6,7 @@ /* 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; 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; - - _sender->appendToReadBuffer(_command); - } + _sender->appendToReadBuffer(_command); return (_PARSING_OK); } diff --git a/sources/commands/invite.cpp b/sources/commands/invite.cpp index e1996d8..a4a3545 100644 --- a/sources/commands/invite.cpp +++ b/sources/commands/invite.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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() { 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; } if (_args.at(1).at(0) != '#') { diff --git a/sources/commands/join.cpp b/sources/commands/join.cpp index 2bfe86d..ebc4667 100644 --- a/sources/commands/join.cpp +++ b/sources/commands/join.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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() { 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; } if (_args[1][0] != '#') { diff --git a/sources/commands/kick.cpp b/sources/commands/kick.cpp index 2bce2e9..2dc0820 100644 --- a/sources/commands/kick.cpp +++ b/sources/commands/kick.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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() { 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; } if (_args.at(1).at(0) != '#') { diff --git a/sources/commands/list.cpp b/sources/commands/list.cpp index 132e025..026df47 100644 --- a/sources/commands/list.cpp +++ b/sources/commands/list.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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() { 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; } if (this->_sender->isRegistered() == false) { diff --git a/sources/commands/modes.cpp b/sources/commands/modes.cpp index 5239739..c9be75a 100644 --- a/sources/commands/modes.cpp +++ b/sources/commands/modes.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ 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; + } if (this->_args.at(1).at(0) != '#') { WARNING_MSG("Invalid channel name for INVITE command"); INFO_MSG("Channel names must start with a '#' character"); diff --git a/sources/commands/notice.cpp b/sources/commands/notice.cpp index b9d42ee..7f81a09 100644 --- a/sources/commands/notice.cpp +++ b/sources/commands/notice.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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() { 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; } if (_args.at(1).at(0) != '#') { diff --git a/sources/commands/part.cpp b/sources/commands/part.cpp index 6532dbd..d8fde2c 100644 --- a/sources/commands/part.cpp +++ b/sources/commands/part.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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() { 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; } if (_args.at(1).at(0) != '#') { diff --git a/sources/commands/pass.cpp b/sources/commands/pass.cpp index f16983d..0b917fc 100644 --- a/sources/commands/pass.cpp +++ b/sources/commands/pass.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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() { 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 _PARSING_OK; diff --git a/sources/commands/ping.cpp b/sources/commands/ping.cpp index 5bc63c2..989d657 100644 --- a/sources/commands/ping.cpp +++ b/sources/commands/ping.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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() { 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 _PARSING_OK; diff --git a/sources/commands/privmsg.cpp b/sources/commands/privmsg.cpp index a1df043..16d9dbb 100644 --- a/sources/commands/privmsg.cpp +++ b/sources/commands/privmsg.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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() { 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; } diff --git a/sources/commands/userCmd.cpp b/sources/commands/userCmd.cpp index 3ec72a5..9d44325 100644 --- a/sources/commands/userCmd.cpp +++ b/sources/commands/userCmd.cpp @@ -6,7 +6,7 @@ /* 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() { 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 _PARSING_OK; From 49a9f4b40a14d7ff8ae0565ff32c87f3e1c6654f Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 18 Jun 2025 12:59:15 +0200 Subject: [PATCH 4/4] feat(cmd/topic): topic command is now working --- include/commands/topic.hpp | 22 +++++++++++++++ sources/commands/topic.cpp | 56 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 include/commands/topic.hpp create mode 100644 sources/commands/topic.cpp diff --git a/include/commands/topic.hpp b/include/commands/topic.hpp new file mode 100644 index 0000000..7656a84 --- /dev/null +++ b/include/commands/topic.hpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* topic.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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(); +}; diff --git a/sources/commands/topic.cpp b/sources/commands/topic.cpp new file mode 100644 index 0000000..c9379c9 --- /dev/null +++ b/sources/commands/topic.cpp @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* topic.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: sben-tay +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); + } +}