diff --git a/Makefile b/Makefile index ab85ad6..7c8ef78 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: omoudni +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/05/02 15:40:00 by rparodi #+# #+# # -# Updated: 2025/05/26 16:18:54 by rparodi ### ########.fr # +# Updated: 2025/05/26 18:22:38 by rparodi ### ########.fr # # # #******************************************************************************# @@ -24,14 +24,13 @@ CXXFLAGS = -Werror -Wextra -Wall -std=c++98 SESSION = test-irc # Sources -SRC = sources/core/logs.cpp \ - sources/core/check.cpp \ +SRC = sources/channel/channel.cpp \ sources/core/PollManager.cpp \ - sources/core/parser.cpp \ - sources/core/main.cpp \ sources/core/Server.cpp \ + sources/core/check.cpp \ + sources/core/main.cpp \ + sources/core/parser.cpp \ sources/user/user.cpp \ - sources/channel/channel.cpp \ sources/commands/commands.cpp \ sources/commands/invite.cpp @@ -75,7 +74,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 diff --git a/include/commands.hpp b/include/commands.hpp index 96e62c6..a5c8965 100644 --- a/include/commands.hpp +++ b/include/commands.hpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/20 23:31:58 by rparodi #+# #+# */ -/* Updated: 2025/05/26 16:28:58 by rparodi ### ########.fr */ +/* Updated: 2025/05/26 18:25:49 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ namespace cmd { - void dispatch(User *user, Channel *channel, const std::string &line); + void dispatch(User *user, Channel *channel, Server *server, const std::string &line); std::vector split(const std::string &line); template T searchList(const std::list &list, const std::string &name); diff --git a/include/commands/commands.tpp b/include/commands/commands.tpp index 5707b2a..94dc22e 100644 --- a/include/commands/commands.tpp +++ b/include/commands/commands.tpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 17:34:30 by rparodi #+# #+# */ -/* Updated: 2025/05/26 16:14:24 by rparodi ### ########.fr */ +/* Updated: 2025/05/26 18:20:34 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ */ template T cmd::searchList(const std::list &list, const std::string &name) { - for (typename std::list::iterator it = list.begin(); it != list.end(); ++it) { + for (typename std::list::const_iterator it = list.begin(); it != list.end(); ++it) { if ((*it)->getName() == name) return *it; } diff --git a/include/core/logs.hpp b/include/core/logs.hpp index d7efc90..ed02e7d 100644 --- a/include/core/logs.hpp +++ b/include/core/logs.hpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/15 12:25:58 by rparodi #+# #+# */ -/* Updated: 2025/05/15 12:38:10 by rparodi ### ########.fr */ +/* Updated: 2025/05/26 18:08:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,20 +15,14 @@ #include #include "color.hpp" -#define DEBUG_MSG(str) "print_debug(str, __FILE__, __LINE__)" -#define ERROR_MSG(str) "print_error(str, __FILE__, __LINE__)" -#define WARNING_MSG(str) "print_warning(str, __FILE__, __LINE__)" -#define INFO_MSG(str) "print_info(str, __FILE__, __LINE__)" -#define SUCCESS_MSG(str) "print_success(str, __FILE__, __LINE__)" +#define DEBUG_MSG(str) std::cerr << CLR_CYAN << "\tDebug: " << str << "(" << __FILE__ << ":" << __LINE__ << ")" << CLR_RESET << std::endl; +#define ERROR_MSG(str) std::cerr << CLR_RED << "\tError: " << str << "(" << __FILE__ << ":" << __LINE__ << ")" << CLR_RESET << std::endl; +#define WARNING_MSG(str) std::cerr << CLR_YELLOW << "\tWarning: " << str << "(" << __FILE__ << ":" << __LINE__ << ")" << CLR_RESET << std::endl; +#define INFO_MSG(str) std::cerr << CLR_GREY << "\tInfo: " << str << "(" << __FILE__ << ":" << __LINE__ << ")" << CLR_RESET << std::endl; +#define SUCCESS_MSG(str) std::cerr << CLR_GREEN << "\tSuccess: " << str << "(" << __FILE__ << ":" << __LINE__ << ")" << CLR_RESET << std::endl; #ifndef DEBUG #define DEBUG 0 #define LOG "" #endif - -void print_debug(const char *str, const char *file, int line); -void print_error(const char *str, const char *file, int line); -void print_warning(const char *str, const char *file, int line); -void print_info(const char *str, const char *file, int line); -void print_success(const char *str, const char *file, int line); diff --git a/include/user.hpp b/include/user.hpp index edded4a..a1188ce 100644 --- a/include/user.hpp +++ b/include/user.hpp @@ -6,13 +6,13 @@ /* By: omoudni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/20 21:57:49 by rparodi #+# #+# */ -/* Updated: 2025/05/26 16:16:01 by rparodi ### ########.fr */ +/* Updated: 2025/05/26 18:10:24 by rparodi ### ########.fr */ /* */ /******************************************************************************/ #pragma once -#include "core.hpp" +#include class User { diff --git a/sources/channel/channel.cpp b/sources/channel/channel.cpp index da8d51c..c95ef88 100644 --- a/sources/channel/channel.cpp +++ b/sources/channel/channel.cpp @@ -6,11 +6,12 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/20 22:43:24 by rparodi #+# #+# */ -/* Updated: 2025/05/20 22:55:20 by rparodi ### ########.fr */ +/* Updated: 2025/05/26 18:10:43 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "channel.hpp" +#include /** * @brief Get the name of the channel diff --git a/sources/commands/commands.cpp b/sources/commands/commands.cpp index 43cb9f5..0798e62 100644 --- a/sources/commands/commands.cpp +++ b/sources/commands/commands.cpp @@ -6,15 +6,13 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 16:11:56 by rparodi #+# #+# */ -/* Updated: 2025/05/24 18:21:36 by rparodi ### ########.fr */ +/* Updated: 2025/05/26 18:25:18 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "commands.hpp" #include "logs.hpp" -using namespace cmd; - /** * @brief To send the line where a command is invoqued to execute * @@ -22,7 +20,7 @@ using namespace cmd; * @param channel channel where the command is sent * @param line line send by the user */ -std::vector split(const std::string &line) { +std::vector cmd::split(const std::string &line) { std::vector args; std::string arg; size_t pos = line.find(' '); @@ -47,7 +45,7 @@ std::vector split(const std::string &line) { * @param server Server where the command is sent * @param line input line from the user */ -void dispatch(::User *user, Channel *channel, Server *server, const std::string &line) { +void cmd::dispatch(::User *user, Channel *channel, Server *server, const std::string &line) { std::string command_name = cmd::split(line).at(0); if (command_name.empty()) { WARNING_MSG("No command found in line: " << line); @@ -106,7 +104,7 @@ void dispatch(::User *user, Channel *channel, Server *server, const std::string (void)line; } -ACommand::ACommand(::User *user, ::Channel *channel, ::Server *server, const std::string &line) : _sender(user), _channel(channel), _server(server) { +cmd::ACommand::ACommand(::User *user, ::Channel *channel, ::Server *server, const std::string &line) : _sender(user), _channel(channel), _server(server) { DEBUG_MSG("ACommand constructor called"); _args = split(line); _command = _args.at(0); @@ -116,6 +114,6 @@ ACommand::ACommand(::User *user, ::Channel *channel, ::Server *server, const std _cTarget = NULL; } -ACommand::~ACommand() { +cmd::ACommand::~ACommand() { DEBUG_MSG("ACommand destructor called"); } diff --git a/sources/commands/invite.cpp b/sources/commands/invite.cpp index ae2b55a..fb2de57 100644 --- a/sources/commands/invite.cpp +++ b/sources/commands/invite.cpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ -/* Updated: 2025/05/26 16:43:01 by rparodi ### ########.fr */ +/* Updated: 2025/05/26 18:17:15 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,7 +36,7 @@ bool Invite::checkArgs() { WARNING_MSG("You are not an operator in the channel for INVITE command"); return false; } - uTarget = searchList(this->_users, _args.at(2)); + _uTarget = searchList(this->_users, _args.at(2)); if (this->_uTarget == NULL) { WARNING_MSG("User not found"); return false; diff --git a/sources/core/logs.cpp b/sources/core/logs.cpp deleted file mode 100644 index 8b75ec8..0000000 --- a/sources/core/logs.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* logs.cpp :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rparodi +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/05/15 12:29:56 by rparodi #+# #+# */ -/* Updated: 2025/05/15 12:38:56 by rparodi ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "logs.hpp" - -void print_debug(const char *str, const char *file, int line) -{ - if (DEBUG) - std::cout << CLR_CYAN << "\tDebug: " << str << "(" << file << ":" << line << ")" << CLR_RESET << std::endl; -} - -void print_error(const char *str, const char *file, int line) -{ - std::cerr << CLR_RED << "\tError: " << str << "(" << file << ":" << line << ")" << CLR_RESET << std::endl; -} - -void print_warning(const char *str, const char *file, int line) -{ - std::cerr << CLR_YELLOW << "\tWarning: " << str << "(" << file << ":" << line << ")" << CLR_RESET << std::endl; -} - -void print_info(const char *str, const char *file, int line) -{ - std::cout << CLR_GREY << "\tInfo: " << str << "(" << file << ":" << line << ")" << CLR_RESET << std::endl; -} - -void print_success(const char *str, const char *file, int line) -{ - std::cout << CLR_GREEN << "\tSuccess: " << str << "(" << file << ":" << line << ")" << CLR_RESET << std::endl; -}