feat(cmd/p*ng): adding ping/pong commands and patch the configuration for irssi issues

This commit is contained in:
Raphael 2025-06-03 16:59:58 +02:00
parent 97103ac852
commit 731d40061d
6 changed files with 118 additions and 5 deletions

View file

@ -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;

42
sources/commands/ping.cpp Normal file
View file

@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ping.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <ctime>
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
}

26
sources/commands/pong.cpp Normal file
View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pong.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <ctime>
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));
}