diff --git a/Makefile b/Makefile index 8eba51c..daf179f 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: omoudni +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/05/02 15:40:00 by rparodi #+# #+# # -# Updated: 2025/06/02 01:18:57 by rparodi ### ########.fr # +# Updated: 2025/06/03 16:50:01 by rparodi ### ########.fr # # # #******************************************************************************# @@ -32,6 +32,8 @@ SRC = sources/channel/channel.cpp \ sources/commands/notice.cpp \ sources/commands/part.cpp \ sources/commands/pass.cpp \ + sources/commands/ping.cpp \ + sources/commands/pong.cpp \ sources/commands/privmsg.cpp \ sources/core/PollManager.cpp \ sources/core/Server.cpp \ @@ -80,7 +82,7 @@ re: header fclean all $(NAME): $(OBJ) @mkdir -p $(OBJDIRNAME) @printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n' - @$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(NAME) $(OBJ) -fuse-ld=lld + @$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(NAME) $(OBJ) #-fuse-ld=lld # Creating the objects $(OBJDIRNAME)/%.o: %.cpp diff --git a/sources/commands/commands.cpp b/sources/commands/commands.cpp index b6afc79..9c1ce9a 100644 --- a/sources/commands/commands.cpp +++ b/sources/commands/commands.cpp @@ -6,13 +6,14 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 16:11:56 by rparodi #+# #+# */ -/* Updated: 2025/05/29 12:48:13 by rparodi ### ########.fr */ +/* Updated: 2025/06/03 16:46:58 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "commands.hpp" #include "logs.hpp" #include "pass.hpp" +#include "ping.hpp" /** * @brief To send the line where a command is invoqued to execute @@ -24,6 +25,8 @@ std::vector cmd::split(const std::string &line) { std::vector args; std::string arg; + if (line.empty()) + return args; size_t pos = line.find(' '); while (pos != std::string::npos) { arg = line.substr(0, pos); @@ -47,7 +50,13 @@ std::vector cmd::split(const std::string &line) { * @param line input line from the user */ void cmd::dispatch(::User *user, Channel *channel, Server *server, const std::string &line) { - std::string command_name = cmd::split(line).at(0); + DEBUG_MSG("in dispatch"); + std::vector args = cmd::split(line); + if (args.empty()) { + ERROR_MSG("Empty line"); + return; + } + std::string command_name = args[0]; if (command_name.empty()) { WARNING_MSG("No command found in line: " << line); return; @@ -95,6 +104,9 @@ void cmd::dispatch(::User *user, Channel *channel, Server *server, const std::st if (command_name == "pass") { Pass(user, channel, server, line).execute(); } + if (command_name == "ping") { + Ping(user, channel, server, line).execute(); + } // if (command_name == "part") { // Part(user, channel, server, line).execute(); // } diff --git a/sources/commands/pass.cpp b/sources/commands/pass.cpp index 3991e90..479d377 100644 --- a/sources/commands/pass.cpp +++ b/sources/commands/pass.cpp @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ -/* Updated: 2025/06/02 22:41:12 by rparodi ### ########.fr */ +/* Updated: 2025/06/03 15:04:10 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/sources/core/Server.cpp b/sources/core/Server.cpp index ed2a121..4c707ad 100644 --- a/sources/core/Server.cpp +++ b/sources/core/Server.cpp @@ -6,12 +6,13 @@ /* By: omoudni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/13 11:11:07 by rparodi #+# #+# */ -/* Updated: 2025/05/29 12:17:15 by rparodi ### ########.fr */ +/* Updated: 2025/06/03 14:56:06 by rparodi ### ########.fr */ /* */ /******************************************************************************/ #include "color.hpp" #include "server.hpp" +#include "commands.hpp" #include "core.hpp" #include "PollManager.hpp" #include "logs.hpp" @@ -107,6 +108,7 @@ void Server::start() { // This prints every command/message received from any client std::cout << "Client " << fd << " says: " << cmd << std::endl; + cmd::dispatch(_users[fd], NULL, this, cmd); } } }