diff --git a/Makefile b/Makefile index cbde13f..7962ace 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: sben-tay +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/05/02 15:40:00 by rparodi #+# #+# # -# Updated: 2025/09/01 16:22:45 by rparodi ### ########.fr # +# Updated: 2025/06/23 14:15:57 by rparodi ### ########.fr # # # # **************************************************************************** # @@ -93,7 +93,7 @@ re: header fclean all $(NAME): $(OBJ) @mkdir -p $(OBJDIRNAME) @printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n' - @$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(NAME) $(OBJ) + @$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(NAME) $(OBJ) #-fuse-ld=lld # Creating the objects $(OBJDIRNAME)/%.o: %.cpp @@ -116,9 +116,13 @@ test: debug @tmux new-session -d -s $(SESSION) \ 'bash -lc "./$(NAME) $(PORT) irc; exec bash"' @tmux split-window -h -p 70 -t $(SESSION):0 \ - 'bash -lc "irssi -c localhost -p $(PORT) -w irc -n test_haut || exec yes \"irssi exit code: $?\""' + 'bash -lc "irssi -c localhost -p $(PORT) -w irc || exec yes \"irssi exit code: $?\""' @tmux split-window -v -p 50 -t $(SESSION):0.1 \ - 'bash -lc "irssi -c localhost -p $(PORT) -w irc -n test_bas || exec yes \"irssi exit code: $?\""' + 'bash -lc "nc localhost $(PORT) || exec yes \"netcat exit code: $?\""' + @tmux split-window -v -p 50 -t $(SESSION):0.2 \ + 'bash -lc "nc localhost $(PORT) || exec yes \"netcat exit code: $?\""' + @tmux split-window -v -p 50 -t $(SESSION):0.3 \ + 'bash -lc "nc localhost $(PORT) || exec yes \"netcat exit code: $?\""' @tmux attach -t $(SESSION) run: all @@ -129,9 +133,9 @@ run: all @tmux new-session -d -s $(SESSION) \ 'bash -lc "./$(NAME) $(PORT) irc; exec bash"' @tmux split-window -h -p 70 -t $(SESSION):0 \ - 'bash -lc "irssi -c localhost -p $(PORT) -w irc -n test_haut || exec yes \"irssi exit code: $?\""' + 'bash -lc "irssi -c localhost -p $(PORT) -w irc || exec yes \"irssi exit code: $?\""' @tmux split-window -v -p 50 -t $(SESSION):0.1 \ - 'bash -lc "irssi -c localhost -p $(PORT) -w irc -n test_bas || exec yes \"irssi exit code: $?\""' + 'bash -lc "nc localhost $(PORT) || exec yes \"netcat exit code: $?\""' @tmux attach -t $(SESSION) 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" diff --git a/include/PollManager.hpp b/include/PollManager.hpp index ddd4088..bf5238c 100644 --- a/include/PollManager.hpp +++ b/include/PollManager.hpp @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* PollManager.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: rparodi +#+ +:+ +#+ */ +/* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/06/24 12:33:07 by rparodi #+# #+# */ -/* Updated: 2025/06/24 12:33:09 by rparodi ### ########.fr */ +/* Created: 2025/05/19 19:15:13 by omoudni #+# #+# */ +/* Updated: 2025/06/18 01:26:38 by sben-tay ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/include/core/core.hpp b/include/core/core.hpp index 076ea22..1f53655 100644 --- a/include/core/core.hpp +++ b/include/core/core.hpp @@ -1,14 +1,14 @@ -/* ************************************************************************** */ +/******************************************************************************/ /* */ /* ::: :::::::: */ /* core.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: rparodi +#+ +:+ +#+ */ +/* By: omoudni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/06/24 12:33:56 by rparodi #+# #+# */ -/* Updated: 2025/06/24 12:33:58 by rparodi ### ########.fr */ +/* Created: 2025/05/12 14:16:03 by rparodi #+# #+# */ +/* Updated: 2025/06/21 11:59:02 by rparodi ### ########.fr */ /* */ -/* ************************************************************************** */ +/******************************************************************************/ #pragma once diff --git a/include/core/parser.hpp b/include/core/parser.hpp index 9fdeaf7..3becac5 100644 --- a/include/core/parser.hpp +++ b/include/core/parser.hpp @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* parser.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: rparodi +#+ +:+ +#+ */ +/* By: omoudni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/06/24 12:34:11 by rparodi #+# #+# */ -/* Updated: 2025/06/24 12:34:12 by rparodi ### ########.fr */ +/* Created: 2025/05/19 14:47:46 by omoudni #+# #+# */ +/* Updated: 2025/05/19 15:14:31 by omoudni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,4 +27,4 @@ public: unsigned short int getPort() const; const std::string& getPassword() const; const std::string& getErrorMsg() const; -}; +}; \ No newline at end of file diff --git a/sources/commands/kick.cpp b/sources/commands/kick.cpp index 7ff898c..47c8e6a 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/24 14:40:17 by sben-tay ### ########.fr */ +/* Updated: 2025/06/23 15:27:38 by sben-tay ### ########.fr */ /* */ /* ************************************************************************** */ @@ -78,10 +78,9 @@ void Kick::execute() { return; } - // std::string msgPart = ":" + _sender->getPrefix() + " PART #" + _cTarget->getName(); std::string msgPart = ":" + this->_uTarget->getPrefix() + " PART #" + _cTarget->getName() + "\r\n"; - std::string msgKick = ":" + _sender->getPrefix() + " KICK #" + this->_cTarget->getName() + " " + _uTarget->getName(); + std::string msgKick = ":" + this->_uTarget->getPrefix() + " KICK #" + this->_cTarget->getName() + " " + _uTarget->getName(); if (_args.size() > 3) { DEBUG_MSG("Je rajoute le message de kick avec un motif"); @@ -89,8 +88,9 @@ void Kick::execute() { } msgKick += "\r\n"; - _uTarget->appendToWriteBuffer(msgPart); + std::cout << " msgKick: " << msgKick << "msgPart: " << msgPart << std::endl; _cTarget->sendAllClientInAChannel(msgKick); + _uTarget->appendToWriteBuffer(msgPart); _cTarget->removeUser(this->_uTarget); _cTarget->removeOperator(this->_uTarget); diff --git a/sources/commands/part.cpp b/sources/commands/part.cpp index 9a2f66d..6c4014d 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/24 14:31:15 by sben-tay ### ########.fr */ +/* Updated: 2025/06/19 01:13:28 by sben-tay ### ########.fr */ /* */ /* ************************************************************************** */ @@ -69,6 +69,7 @@ void Part::execute() { _cTarget->sendAllClientInAChannel(msgPart); _cTarget->removeUser(_sender); _cTarget->removeOperator(_sender); + // remove invited list if (_cTarget->getUsers().empty()) { std::list& allChannels = _server->getChannelsList(); diff --git a/sources/commands/privmsg.cpp b/sources/commands/privmsg.cpp index 0ddba52..fa36e38 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/24 14:40:03 by sben-tay ### ########.fr */ +/* Updated: 2025/06/22 01:53:33 by sben-tay ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,6 @@ #include "commands.hpp" #include "logs.hpp" #include "bonus.hpp" -#include using namespace cmd; @@ -65,50 +64,34 @@ void PrivMsg::execute() { //bonus msgBot std::string msgBot = ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿ“œ Liste des commandes disponibles :\r\n"; - msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- JOIN #channel โ†’ Rejoindre un canal\r\n"; - msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- PART #channel โ†’ Quitter un canal\r\n"; - msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- PRIVMSG msg โ†’ Envoyer un message\r\n"; - msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- TOPIC #channel :txt โ†’ Voir / modifier le topic\r\n"; + msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- JOIN #channel โ†’ Rejoindre un canal\r\n"; + msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- PART #channel โ†’ Quitter un canal\r\n"; + msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- PRIVMSG msg โ†’ Envoyer un message\r\n"; + msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- TOPIC #channel :txt โ†’ Voir / modifier le topic\r\n"; msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- MODE #channel +o nick โ†’ Ajouter un opรฉrateur\r\n"; msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- INVITE nick #channel โ†’ Inviter un utilisateur\r\n"; msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- KICK #channel nick โ†’ ร‰jecter un utilisateur\r\n"; msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- WHO / WHOIS โ†’ Infos sur les utilisateurs\r\n"; - msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- DCC SEND nick /PATH โ†’ Transferer des fichiers ร  l'utilisateur\r\n"; - msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- DCC GET /PATH โ†’ Accepter le transfert des fichiers reรงu\r\n"; - msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- !emote โ†’ Affiche la liste d'emoji\r\n"; msgBot += ":bot!ircbot@localhost PRIVMSG " + target + " :- !help โ†’ Affiche cette aide\r\n"; - std::string msgEmote = ":bot!ircbot@localhost PRIVMSG " + target + " : ๐Ÿ“œ Emote list :\r\n"; - msgEmote += ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿ˜€๐Ÿ˜๐Ÿ˜‚๐Ÿ˜ƒ๐Ÿ˜„๐Ÿ˜…๐Ÿ˜†๐Ÿ˜‡๐Ÿ˜ˆ๐Ÿ˜‰๐Ÿ˜Š๐Ÿ˜‹๐Ÿ˜Œ๐Ÿ˜๐Ÿ˜Ž๐Ÿ˜\r\n"; - msgEmote += ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿ˜๐Ÿ˜‘๐Ÿ˜’๐Ÿ˜“๐Ÿ˜”๐Ÿ˜•๐Ÿ˜–๐Ÿ˜—๐Ÿ˜˜๐Ÿ˜™๐Ÿ˜š๐Ÿ˜›๐Ÿ˜œ๐Ÿ˜๐Ÿ˜ž๐Ÿ˜Ÿ\r\n"; - msgEmote += ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿ˜ ๐Ÿ˜ก๐Ÿ˜ข๐Ÿ˜ฃ๐Ÿ˜ค๐Ÿ˜ฅ๐Ÿ˜ฆ๐Ÿ˜ง๐Ÿ˜จ๐Ÿ˜ฉ๐Ÿ˜ช๐Ÿ˜ซ๐Ÿ˜ฌ๐Ÿ˜ญ๐Ÿ˜ฎ๐Ÿ˜ฏ\r\n"; - msgEmote += ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿ˜ฐ๐Ÿ˜ฑ๐Ÿ˜ฒ๐Ÿ˜ณ๐Ÿ˜ด๐Ÿ˜ต๐Ÿ˜ถ๐Ÿ˜ท๐Ÿ˜ธ๐Ÿ˜น๐Ÿ˜บ๐Ÿ˜ป๐Ÿ˜ผ๐Ÿ˜ฝ๐Ÿ˜พ๐Ÿ˜ฟ\r\n"; - msgEmote += ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿ™€๐Ÿ™๐Ÿ™‚๐Ÿ™ƒ๐Ÿ™„๐Ÿ™…๐Ÿ™†๐Ÿ™‡๐Ÿ™ˆ๐Ÿ™‰๐Ÿ™Š๐Ÿ™‹๐Ÿ™Œ๐Ÿ™๐Ÿ™Ž๐Ÿ™\r\n"; - msgEmote += ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿค๐Ÿค‘๐Ÿค’๐Ÿค“๐Ÿคค๐Ÿค”๐Ÿค•๐Ÿค–๐Ÿค—๐Ÿค˜๐Ÿค™๐Ÿคš๐Ÿค›๐Ÿคœ๐Ÿค๐ŸคŸ\r\n"; - msgEmote += ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿ’๐Ÿ’‘๐Ÿ’’๐Ÿ’“๐Ÿ’”๐Ÿ’•๐Ÿ’–๐Ÿ’—๐Ÿ’˜๐Ÿ’™๐Ÿ’š๐Ÿ’›๐Ÿ’œ๐Ÿ’๐Ÿ’ž๐Ÿ’Ÿ\r\n"; - msgEmote += ":bot!ircbot@localhost PRIVMSG " + target + " :๐Ÿ’ ๐Ÿ’ก๐Ÿ’ข๐Ÿ’ฃ๐Ÿ’ค๐Ÿ’ฅ๐Ÿ’ฆ๐Ÿ’ง๐Ÿ’จ๐Ÿ’ฉ๐Ÿ’ช๐Ÿ’ซ๐Ÿ’ฌ๐Ÿ’ญ๐Ÿ’ฏ๐Ÿคจ\r\n"; // Envoi vers un channel if (target[0] == '#') { target.erase(0, 1); - - if (_cTarget) { - if (BONUS && _cTarget->getBotChannel() && _args.at(2) == "!help") - _sender->appendToWriteBuffer(msgBot); - else if (BONUS && _cTarget->getBotChannel() && _args.at(2) == "!emote") - _sender->appendToWriteBuffer(msgEmote); - else - _cTarget->sendAllClientInAChannel(msg, _sender); + if (_cTarget) + _cTarget->sendAllClientInAChannel(msg, _sender); + + if (BONUS && _cTarget->getBotChannel()) { + if (_args.at(2) == "!help") { + std::cout << "BONUS: PING command received, sending PONG" << std::endl; + _cTarget->sendAllClientInAChannel(msgBot); + } } } // Envoi vers un user - const std::list& users = _server->getUsersList(); - - for (std::list::const_iterator it = users.begin(); it != users.end(); ++it) { - if ((*it)->getName() == target) { - (*it)->appendToWriteBuffer(msg); - break; - } + else { + if (_uTarget) + _uTarget->appendToWriteBuffer(msg); } } diff --git a/sources/core/Server.cpp b/sources/core/Server.cpp index 75d2475..48ccbe7 100644 --- a/sources/core/Server.cpp +++ b/sources/core/Server.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/13 11:11:07 by rparodi #+# #+# */ -/* Updated: 2025/06/24 14:51:44 by sben-tay ### ########.fr */ +/* Updated: 2025/06/23 14:46:53 by sben-tay ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,7 +43,7 @@ void handle_sigint(int sig) { */ Server::Server(int port, const std::string &password) : _port(port), _password(password) { - INFO_MSG("Info: Server constructor called"); + std::cout << CLR_GREY << "Info: Server constructor called" << CLR_RESET << std::endl; } /** @@ -51,7 +51,7 @@ Server::Server(int port, const std::string &password) : _port(port), _password(p */ Server::~Server() { - INFO_MSG("Info: Server destructor called"); + std::cout << CLR_GREY << "Info: Server destructor called" << CLR_RESET << std::endl; if (_serverFd != -1) { close(_serverFd); } @@ -67,7 +67,6 @@ std::vector splitLines(const std::string& input); void Server::start() { - signal(SIGQUIT, SIG_IGN); signal(SIGINT, handle_sigint); _serverFd = socket(AF_INET, SOCK_STREAM, 0); if (_serverFd == -1) { @@ -153,6 +152,7 @@ void Server::start() std::cout << "Poll loop finished" << std::endl; } std::cout << "[INFO] CTRL+C dรฉtectรฉ. Fermeture du serveur..." << std::endl; + close(_serverFd); } /** diff --git a/sources/core/main.cpp b/sources/core/main.cpp index be0642f..8fd050b 100644 --- a/sources/core/main.cpp +++ b/sources/core/main.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/13 11:03:13 by rparodi #+# #+# */ -/* Updated: 2025/06/24 00:47:18 by sben-tay ### ########.fr */ +/* Updated: 2025/06/23 14:38:53 by sben-tay ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,4 +28,3 @@ int main(int argc, char *argv[]) { server.start(); return 0; } - diff --git a/sources/core/parser.cpp b/sources/core/parser.cpp index f3d0023..362fb97 100644 --- a/sources/core/parser.cpp +++ b/sources/core/parser.cpp @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* parser.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: rparodi +#+ +:+ +#+ */ +/* By: omoudni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/06/24 12:34:29 by rparodi #+# #+# */ -/* Updated: 2025/06/24 12:34:30 by rparodi ### ########.fr */ +/* Created: 2025/05/19 14:48:52 by omoudni #+# #+# */ +/* Updated: 2025/05/19 15:08:18 by omoudni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,4 +40,4 @@ Parser::Parser(int argc, char* argv[]) : _port(0), _valid(false) { bool Parser::isValid() const { return _valid; } unsigned short int Parser::getPort() const { return _port; } const std::string& Parser::getPassword() const { return _password; } -const std::string& Parser::getErrorMsg() const { return _errorMsg; } +const std::string& Parser::getErrorMsg() const { return _errorMsg; } \ No newline at end of file diff --git a/sources/user/user.cpp b/sources/user/user.cpp index b862ced..c320d59 100644 --- a/sources/user/user.cpp +++ b/sources/user/user.cpp @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/05/21 20:37:12 by sben-tay #+# #+# */ -/* Updated: 2025/06/24 12:33:39 by rparodi ### ########.fr */ +/* Created: 2025/05/21 20:37:12 by omoudni #+# #+# */ +/* Updated: 2025/06/21 14:38:31 by sben-tay ### ########.fr */ /* */ /* ************************************************************************** */ @@ -202,4 +202,4 @@ void User::consumeWriteBuffer(size_t len) { _write_buffer.clear(); else _write_buffer.erase(0, len); -} +} \ No newline at end of file