From 08b94a7d0030b3b218627398ebf90bc8c2197ac7 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 2 Jun 2025 00:31:43 +0200 Subject: [PATCH 1/9] style(user): compaticting the class user --- sources/user/user.cpp | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/sources/user/user.cpp b/sources/user/user.cpp index bb4de98..5287c7d 100644 --- a/sources/user/user.cpp +++ b/sources/user/user.cpp @@ -6,7 +6,7 @@ /* By: omoudni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/21 20:37:12 by omoudni #+# #+# */ -/* Updated: 2025/05/29 12:38:46 by rparodi ### ########.fr */ +/* Updated: 2025/05/29 13:30:51 by rparodi ### ########.fr */ /* */ /******************************************************************************/ @@ -31,34 +31,23 @@ std::string User::getName() const { return this->_nickname; } -void User::setUsername(const std::string &username) -{ +void User::setUsername(const std::string &username) { _username = username; _hasUser = true; checkRegistration(); } // Setter for nickname (with basic checks) -void User::setNickname(const std::string &nickname) -{ - if (nickname.empty()) - { +void User::setNickname(const std::string &nickname) { + if (nickname.empty()) { throw std::invalid_argument("Nickname cannot be empty"); - } - else if (nickname == "anonymous") - { + } else if (nickname == "anonymous") { throw std::invalid_argument("Nickname cannot be 'anonymous'"); - } - else if (nickname.length() > 9) - { + } else if (nickname.length() > 9) { throw std::length_error("Nickname is too long"); - } - else if (nickname == _nickname) - { + } else if (nickname == _nickname) { throw std::invalid_argument("The nickname is the same"); - } - else - { + } else { _nickname = nickname; _hasNick = true; checkRegistration(); From 48821409a1c387190389b6ca13deff8856343983 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 2 Jun 2025 00:36:36 +0200 Subject: [PATCH 2/9] fix(commands/ACommand): add the forgotten constructor --- include/commands/invite.hpp | 3 ++- include/commands/join.hpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/commands/invite.hpp b/include/commands/invite.hpp index 11973ed..be4ece6 100644 --- a/include/commands/invite.hpp +++ b/include/commands/invite.hpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */ -/* Updated: 2025/05/26 16:27:42 by rparodi ### ########.fr */ +/* Updated: 2025/06/02 00:34:16 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,7 @@ class cmd::Invite : public ACommand { public: + Invite(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {} virtual void execute(void); virtual bool checkArgs(); }; diff --git a/include/commands/join.hpp b/include/commands/join.hpp index 135d235..ce8d1f5 100644 --- a/include/commands/join.hpp +++ b/include/commands/join.hpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */ -/* Updated: 2025/05/26 22:43:47 by rparodi ### ########.fr */ +/* Updated: 2025/06/02 00:33:23 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,7 @@ class cmd::Join : public ACommand { public: + Join(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {} virtual void execute(void); virtual bool checkArgs(); }; From 24c854b3f534b9983a923d108dd7a1f8f479cea3 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 2 Jun 2025 00:38:31 +0200 Subject: [PATCH 3/9] build(cmd): adding all command --- Makefile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index b621a04..065f3af 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: omoudni +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/05/02 15:40:00 by rparodi #+# #+# # -# Updated: 2025/05/29 12:31:53 by rparodi ### ########.fr # +# Updated: 2025/06/02 00:38:02 by rparodi ### ########.fr # # # #******************************************************************************# @@ -25,15 +25,16 @@ SESSION = test-irc # Sources SRC = sources/channel/channel.cpp \ + sources/commands/commands.cpp \ + sources/commands/invite.cpp \ + sources/commands/join.cpp \ + sources/commands/pass.cpp \ sources/core/PollManager.cpp \ sources/core/Server.cpp \ sources/core/check.cpp \ sources/core/main.cpp \ sources/core/parser.cpp \ - sources/user/user.cpp \ - sources/commands/commands.cpp \ - sources/commands/pass.cpp \ - sources/commands/invite.cpp + sources/user/user.cpp INC_DIR = include/core \ include/commands \ From 10ee8774518b73d4f4cd73bccbf1ab0f4a54be2b Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 2 Jun 2025 01:01:25 +0200 Subject: [PATCH 4/9] build(nix): adding fd to flakes --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index b27d8ca..ba771de 100644 --- a/flake.nix +++ b/flake.nix @@ -19,6 +19,7 @@ irssi tmux lld + fd ] ++ ( if pkgs.stdenv.isLinux then [ valgrind From ede2219ba4aaa6efc875a9babe2387134b3c1418 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 2 Jun 2025 01:02:25 +0200 Subject: [PATCH 5/9] feat(cmd/nick): adding nick commands --- include/commands/nick.hpp | 22 ++++++++++++++++++ sources/commands/nick.cpp | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 include/commands/nick.hpp create mode 100644 sources/commands/nick.cpp diff --git a/include/commands/nick.hpp b/include/commands/nick.hpp new file mode 100644 index 0000000..fdc88ac --- /dev/null +++ b/include/commands/nick.hpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* nick.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */ +/* Updated: 2025/06/02 00:40:18 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "commands.hpp" + +class cmd::Nick : public ACommand { + public: + Nick(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {} + virtual void execute(void); + virtual bool checkArgs(); +}; diff --git a/sources/commands/nick.cpp b/sources/commands/nick.cpp new file mode 100644 index 0000000..1eec360 --- /dev/null +++ b/sources/commands/nick.cpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* nick.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ +/* Updated: 2025/06/02 00:55:45 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "nick.hpp" +#include "commands.hpp" +#include "logs.hpp" + +using namespace cmd; + +bool Nick::checkArgs() { + if (this->_uTarget->isRegistered() == false) { + WARNING_MSG("User is not registered for Nick command"); + INFO_MSG("You can only Nick registered users"); + return false; + } + if (_args.size() < 2) { + WARNING_MSG("Not enough arguments for Nick command"); + return false; + } + _uTarget = searchList(this->_users, _args.at(1)); + if (this->_uTarget != NULL) { + WARNING_MSG(_uTarget->getName() << " is already taken") + return false; + } + return true; +} + +/** + * @brief Execute the Nick command + * @note To change the nickname of the user + */ +void Nick::execute() { + if (checkArgs() == false) { + ERROR_MSG("Invalid arguments for Nick command (see warning message)"); + return; + } + // check how the com +} From 67dd7f0ae82f6c55ef4d002ae2254bee06317d69 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 2 Jun 2025 01:02:55 +0200 Subject: [PATCH 6/9] feat(cmd/privmsg): adding privmsg commands --- include/commands/privmsg.cpp | 57 ++++++++++++++++++++++++++++++++++++ include/commands/privmsg.hpp | 22 ++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 include/commands/privmsg.cpp create mode 100644 include/commands/privmsg.hpp diff --git a/include/commands/privmsg.cpp b/include/commands/privmsg.cpp new file mode 100644 index 0000000..b2f9fc5 --- /dev/null +++ b/include/commands/privmsg.cpp @@ -0,0 +1,57 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* privmsg.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ +/* Updated: 2025/06/02 01:01:13 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "privmsg.hpp" +#include "commands.hpp" +#include "logs.hpp" + +using namespace cmd; + +bool PrivMsg::checkArgs() { + if (_args.size() < 3) { + WARNING_MSG("Not enough arguments for PrivMsg command"); + return false; + } + if (_args.at(1).at(0) != '#') { + _uTarget = searchList(this->_users, _args.at(1)); + if (this->_uTarget == NULL) { + WARNING_MSG("User not found"); + return false; + } + if (this->_uTarget->isRegistered() == false) { + WARNING_MSG("User is not registered for PrivMsg command"); + INFO_MSG("You can only PrivMsg registered users"); + return false; + } + } else { + _cTarget = searchList(_channels, _args.at(1)); + if (_cTarget == NULL) { + WARNING_MSG("Channel not found for PrivMsg command"); + INFO_MSG("You can only PrivMsg users to channels you are in"); + return false; + } else + _args.at(1).erase(0, 1); + } + return true; +} + +/** + * @brief Execute the PrivMsg command + * @note To send a private message to a user / channel + */ +void PrivMsg::execute() { + if (checkArgs() == false) { + ERROR_MSG("Invalid arguments for PrivMsg command (see warning message)"); + return; + } + // check how the com +} diff --git a/include/commands/privmsg.hpp b/include/commands/privmsg.hpp new file mode 100644 index 0000000..6c012d2 --- /dev/null +++ b/include/commands/privmsg.hpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* privmsg.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */ +/* Updated: 2025/06/02 00:58:18 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "commands.hpp" + +class cmd::PrivMsg : public ACommand { + public: + PrivMsg(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {} + virtual void execute(void); + virtual bool checkArgs(); +}; From 76448d592330f95b388abdbe94f78e177587c86d Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 2 Jun 2025 01:03:13 +0200 Subject: [PATCH 7/9] feat(cmd/part): adding part commands --- include/commands/part.hpp | 22 ++++++++++++++++ sources/commands/part.cpp | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 include/commands/part.hpp create mode 100644 sources/commands/part.cpp diff --git a/include/commands/part.hpp b/include/commands/part.hpp new file mode 100644 index 0000000..4a2bba5 --- /dev/null +++ b/include/commands/part.hpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */ +/* Updated: 2025/06/02 00:51:23 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "commands.hpp" + +class cmd::Part : public ACommand { + public: + Part(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {} + virtual void execute(void); + virtual bool checkArgs(); +}; diff --git a/sources/commands/part.cpp b/sources/commands/part.cpp new file mode 100644 index 0000000..584eb39 --- /dev/null +++ b/sources/commands/part.cpp @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ +/* Updated: 2025/06/02 00:55:56 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "part.hpp" +#include "commands.hpp" +#include "logs.hpp" + +using namespace cmd; + +bool Part::checkArgs() { + if (_args.size() < 2) { + WARNING_MSG("Not enough arguments for PART command"); + return false; + } + if (_args.at(1).at(0) != '#') { + WARNING_MSG("Invalid channel name for PART command"); + INFO_MSG("Channel names must start with a '#' character"); + return false; + } else + _args.at(1).erase(0, 1); + _cTarget = searchList(_channels, _args.at(1)); + if (_cTarget == NULL) { + WARNING_MSG("Channel not found for PART command"); + INFO_MSG("You can only Part users to channels you are in"); + return false; + } else + _args.at(1).erase(0, 1); + if (searchList(this->_cTarget->getUsers(), this->_uTarget->getName())) { + WARNING_MSG("User is not in the channel he wants to leave"); + INFO_MSG("You cannot leave a channel where ur not a member"); + return false; + } + return true; +} + +/** + * @brief Execute the Part command + * @note To leave a channel givent in parameter + */ +void Part::execute() { + if (checkArgs() == false) { + ERROR_MSG("Invalid arguments for Part command (see warning message)"); + return; + } + // check how the com +} From adabe2c2f07727625cdafc3ffdd4c45325ec9eda Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 2 Jun 2025 01:19:19 +0200 Subject: [PATCH 8/9] build(cmd): adding privmsg / notice commands --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 065f3af..8eba51c 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: omoudni +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/05/02 15:40:00 by rparodi #+# #+# # -# Updated: 2025/06/02 00:38:02 by rparodi ### ########.fr # +# Updated: 2025/06/02 01:18:57 by rparodi ### ########.fr # # # #******************************************************************************# @@ -28,7 +28,11 @@ SRC = sources/channel/channel.cpp \ sources/commands/commands.cpp \ sources/commands/invite.cpp \ sources/commands/join.cpp \ + sources/commands/nick.cpp \ + sources/commands/notice.cpp \ + sources/commands/part.cpp \ sources/commands/pass.cpp \ + sources/commands/privmsg.cpp \ sources/core/PollManager.cpp \ sources/core/Server.cpp \ sources/core/check.cpp \ From e9511e9fc3f387a19c5b9ae87d9a008fca776a6e Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 2 Jun 2025 01:19:56 +0200 Subject: [PATCH 9/9] feat(cmd/notice): adding the notice command --- include/commands/notice.hpp | 22 +++++++++ sources/commands/notice.cpp | 57 +++++++++++++++++++++++ {include => sources}/commands/privmsg.cpp | 20 ++++---- 3 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 include/commands/notice.hpp create mode 100644 sources/commands/notice.cpp rename {include => sources}/commands/privmsg.cpp (73%) diff --git a/include/commands/notice.hpp b/include/commands/notice.hpp new file mode 100644 index 0000000..256eb28 --- /dev/null +++ b/include/commands/notice.hpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* notice.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */ +/* Updated: 2025/06/02 01:18:19 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "commands.hpp" + +class cmd::Notice : public ACommand { + public: + Notice(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {} + virtual void execute(void); + virtual bool checkArgs(); +}; diff --git a/sources/commands/notice.cpp b/sources/commands/notice.cpp new file mode 100644 index 0000000..9985b3c --- /dev/null +++ b/sources/commands/notice.cpp @@ -0,0 +1,57 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* notice.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ +/* Updated: 2025/06/02 01:18:05 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "notice.hpp" +#include "commands.hpp" +#include "logs.hpp" + +using namespace cmd; + +bool Notice::checkArgs() { + if (_args.size() < 3) { + WARNING_MSG("Not enough arguments for NOTICE command"); + return false; + } + if (_args.at(1).at(0) != '#') { + _uTarget = searchList(this->_users, _args.at(2)); + if (this->_uTarget == NULL) { + WARNING_MSG("User not found"); + return false; + } + if (this->_uTarget->isRegistered() == false) { + WARNING_MSG("User is not registered for NOTICE command"); + INFO_MSG("You can only NOTICE registered users"); + return false; + } + } else { + _cTarget = searchList(_channels, _args.at(1)); + if (_cTarget == NULL) { + WARNING_MSG("Channel not found for NOTICE command"); + INFO_MSG("You can only NOTICE users to channels you are in"); + return false; + } else + _args.at(1).erase(0, 1); + } + return true; +} + +/** + * @brief Execute the PrivMsg command + * @note To send a private message to a user / a channel + */ +void Notice::execute() { + if (checkArgs() == false) { + ERROR_MSG("Invalid arguments for PRIVMSG command (see warning message)"); + return; + } + // check how the com +} diff --git a/include/commands/privmsg.cpp b/sources/commands/privmsg.cpp similarity index 73% rename from include/commands/privmsg.cpp rename to sources/commands/privmsg.cpp index b2f9fc5..c1c3cd4 100644 --- a/include/commands/privmsg.cpp +++ b/sources/commands/privmsg.cpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ -/* Updated: 2025/06/02 01:01:13 by rparodi ### ########.fr */ +/* Updated: 2025/06/02 01:15:00 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,27 +18,27 @@ using namespace cmd; bool PrivMsg::checkArgs() { if (_args.size() < 3) { - WARNING_MSG("Not enough arguments for PrivMsg command"); + WARNING_MSG("Not enough arguments for PRIVMSG command"); return false; } if (_args.at(1).at(0) != '#') { - _uTarget = searchList(this->_users, _args.at(1)); + _uTarget = searchList(this->_users, _args.at(2)); if (this->_uTarget == NULL) { WARNING_MSG("User not found"); return false; } if (this->_uTarget->isRegistered() == false) { - WARNING_MSG("User is not registered for PrivMsg command"); - INFO_MSG("You can only PrivMsg registered users"); + WARNING_MSG("User is not registered for PRIVMSG command"); + INFO_MSG("You can only privmsg registered users"); return false; } } else { _cTarget = searchList(_channels, _args.at(1)); if (_cTarget == NULL) { - WARNING_MSG("Channel not found for PrivMsg command"); - INFO_MSG("You can only PrivMsg users to channels you are in"); + WARNING_MSG("Channel not found for PRIVMSG command"); + INFO_MSG("You can only privmsg users to channels you are in"); return false; - } else + } else _args.at(1).erase(0, 1); } return true; @@ -46,11 +46,11 @@ bool PrivMsg::checkArgs() { /** * @brief Execute the PrivMsg command - * @note To send a private message to a user / channel + * @note To send a private message to a user / a channel */ void PrivMsg::execute() { if (checkArgs() == false) { - ERROR_MSG("Invalid arguments for PrivMsg command (see warning message)"); + ERROR_MSG("Invalid arguments for PRIVMSG command (see warning message)"); return; } // check how the com