From 731d40061d5aba284bb12eff8682dd27ca9347c4 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 3 Jun 2025 16:59:58 +0200 Subject: [PATCH] feat(cmd/p*ng): adding ping/pong commands and patch the configuration for irssi issues --- Makefile | 9 ++++----- include/commands/ping.hpp | 22 ++++++++++++++++++++ include/commands/pong.hpp | 21 ++++++++++++++++++++ sources/commands/pass.cpp | 3 +++ sources/commands/ping.cpp | 42 +++++++++++++++++++++++++++++++++++++++ sources/commands/pong.cpp | 26 ++++++++++++++++++++++++ 6 files changed, 118 insertions(+), 5 deletions(-) create mode 100644 include/commands/ping.hpp create mode 100644 include/commands/pong.hpp create mode 100644 sources/commands/ping.cpp create mode 100644 sources/commands/pong.cpp diff --git a/Makefile b/Makefile index daf179f..afc5b7e 100644 --- a/Makefile +++ b/Makefile @@ -114,17 +114,16 @@ test: debug 'bash -lc "nc localhost $(PORT) || exec yes \"netcat exit code: $?\""' @tmux attach -t $(SESSION) - -run: re + # @tmux split-window -h -p 70 -t $(SESSION):0 \ + # 'bash -lc "irssi -c localhost -p $(PORT) -w irc || exec yes \"irssi exit code: $?\""' +run: all @printf '$(GREY) now running with\n\t- Port:\t\t$(GREEN)$(PORT)$(GREY)\n\t- Password:\t$(GREEN)irc$(END)\n' @if tmux has-session -t $(SESSION) 2>/dev/null; then \ tmux kill-session -t $(SESSION); \ fi @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 || exec yes \"irssi exit code: $?\""' - @tmux split-window -v -p 50 -t $(SESSION):0.1 \ + @tmux split-window -v -p 50 -t $(SESSION):0 \ 'bash -lc "nc localhost $(PORT) || exec yes \"netcat exit code: $?\""' @tmux attach -t $(SESSION) diff --git a/include/commands/ping.hpp b/include/commands/ping.hpp new file mode 100644 index 0000000..e5734c9 --- /dev/null +++ b/include/commands/ping.hpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ping.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/06/02 22:48:36 by rparodi #+# #+# */ +/* Updated: 2025/06/02 22:48:48 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "commands.hpp" + +class cmd::Ping : public ACommand { + public: + Ping(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/pong.hpp b/include/commands/pong.hpp new file mode 100644 index 0000000..7a10acd --- /dev/null +++ b/include/commands/pong.hpp @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* pong.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/06/02 22:48:36 by rparodi #+# #+# */ +/* Updated: 2025/06/02 23:01:19 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "commands.hpp" + +class cmd::Pong { + public: + Pong(void){} + clock_t answer(clock_t start); +}; diff --git a/sources/commands/pass.cpp b/sources/commands/pass.cpp index 479d377..a79a686 100644 --- a/sources/commands/pass.cpp +++ b/sources/commands/pass.cpp @@ -21,6 +21,7 @@ bool Pass::checkArgs() { WARNING_MSG("Not correct for Pass command"); return false; } + DEBUG_MSG("coucou"); if (_sender->isRegistered()) { WARNING_MSG(_sender->getName() << " is already is already log in the server !"); return false; @@ -35,8 +36,10 @@ bool Pass::checkArgs() { void Pass::execute() { if (checkArgs() == false) { ERROR_MSG("Invalid arguments for Pass command (see warning message)"); + DEBUG_MSG("skill issues"); return; } + DEBUG_MSG("mais pas trop skill issues"); if (_args.at(1) != _server->getPassword()) { ERROR_MSG("The password is incorrect"); return; diff --git a/sources/commands/ping.cpp b/sources/commands/ping.cpp new file mode 100644 index 0000000..488e262 --- /dev/null +++ b/sources/commands/ping.cpp @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ping.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ +/* Updated: 2025/06/03 14:49:27 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ping.hpp" +#include "commands.hpp" +#include "logs.hpp" +#include "pong.hpp" +#include + +using namespace cmd; + +bool Ping::checkArgs() { + if (_args.size() < 3) { + WARNING_MSG("Not enough arguments for PING command"); + return false; + } + return true; +} + +/** + * @brief Execute the Ping + * @note To send a private message to a user / a channel + */ +void Ping::execute() { + clock_t start = clock() / CLOCKS_PER_SEC; + if (checkArgs() == false) { + ERROR_MSG("Invalid arguments for PRIVMSG command (see warning message)"); + return; + } + clock_t diff = Pong().answer(start); + INFO_MSG(diff); + // check how the com +} diff --git a/sources/commands/pong.cpp b/sources/commands/pong.cpp new file mode 100644 index 0000000..861b451 --- /dev/null +++ b/sources/commands/pong.cpp @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* pong.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */ +/* Updated: 2025/06/02 23:04:53 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "commands.hpp" +#include "logs.hpp" +#include "pong.hpp" +#include + +using namespace cmd; + +/** + * @brief Execute the Pong + * @note answer to PING command (managed by the server) + */ +clock_t Pong::answer(clock_t start) { + return (start - (clock() / CLOCKS_PER_SEC)); +}