commit
6750109953
11 changed files with 111 additions and 16 deletions
3
Makefile
3
Makefile
|
|
@ -6,7 +6,7 @@
|
|||
# By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2025/05/02 15:40:00 by rparodi #+# #+# #
|
||||
# Updated: 2025/05/26 18:22:38 by rparodi ### ########.fr #
|
||||
# Updated: 2025/05/29 12:31:53 by rparodi ### ########.fr #
|
||||
# #
|
||||
#******************************************************************************#
|
||||
|
||||
|
|
@ -32,6 +32,7 @@ SRC = sources/channel/channel.cpp \
|
|||
sources/core/parser.cpp \
|
||||
sources/user/user.cpp \
|
||||
sources/commands/commands.cpp \
|
||||
sources/commands/pass.cpp \
|
||||
sources/commands/invite.cpp
|
||||
|
||||
INC_DIR = include/core \
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/20 23:31:58 by rparodi #+# #+# */
|
||||
/* Updated: 2025/05/26 18:25:49 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/05/29 12:47:57 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -53,7 +53,6 @@ namespace cmd
|
|||
class Nick;
|
||||
class Notice;
|
||||
class Part;
|
||||
class Pass;
|
||||
class Ping;
|
||||
class Pong;
|
||||
class PrivMsg;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/24 17:34:30 by rparodi #+# #+# */
|
||||
/* Updated: 2025/05/26 18:20:34 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/05/27 14:34:56 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
24
include/commands/pass.hpp
Normal file
24
include/commands/pass.hpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* pass.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/24 17:17:31 by rparodi #+# #+# */
|
||||
/* Updated: 2025/05/29 12:52:25 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "commands.hpp"
|
||||
|
||||
namespace cmd {
|
||||
class Pass : public ACommand {
|
||||
public:
|
||||
Pass(User *user, Channel *channel, Server *server, const std::string &line) : ACommand(user, channel, server, line) {}
|
||||
virtual void execute(void);
|
||||
virtual bool checkArgs();
|
||||
};
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/20 21:50:32 by rparodi #+# #+# */
|
||||
/* Updated: 2025/05/26 22:26:04 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/05/29 12:17:55 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
|
|
@ -37,6 +37,7 @@ public:
|
|||
unsigned short int getPort() const;
|
||||
std::list<User *> getUsersList() const;
|
||||
std::list<Channel *> getChannelsList() const;
|
||||
std::string getPassword() const;
|
||||
void showInfo() const;
|
||||
void printUsers() const;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/20 21:57:49 by rparodi #+# #+# */
|
||||
/* Updated: 2025/05/26 18:10:24 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/05/29 12:37:11 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
|
|
@ -34,6 +34,7 @@ class User
|
|||
bool isRegistered() const;
|
||||
std::string getName() const;
|
||||
std::string extractFullCommand();
|
||||
void setRegistered();
|
||||
void appendToReadBuffer(const std::string &data);
|
||||
void appendToWriteBuffer(const std::string &data);
|
||||
void setNickname(const std::string &nickname);
|
||||
|
|
|
|||
|
|
@ -6,12 +6,13 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/24 16:11:56 by rparodi #+# #+# */
|
||||
/* Updated: 2025/05/26 18:25:18 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/05/29 12:48:13 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "commands.hpp"
|
||||
#include "logs.hpp"
|
||||
#include "pass.hpp"
|
||||
|
||||
/**
|
||||
* @brief To send the line where a command is invoqued to execute
|
||||
|
|
@ -91,6 +92,9 @@ void cmd::dispatch(::User *user, Channel *channel, Server *server, const std::st
|
|||
// }
|
||||
break;
|
||||
case 'p':
|
||||
if (command_name == "pass") {
|
||||
Pass(user, channel, server, line).execute();
|
||||
}
|
||||
// if (command_name == "part") {
|
||||
// Part(user, channel, server, line).execute();
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
||||
/* Updated: 2025/05/26 22:50:04 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/05/29 12:10:25 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -25,7 +25,8 @@ bool Invite::checkArgs() {
|
|||
WARNING_MSG("Invalid channel name for INVITE command");
|
||||
INFO_MSG("Channel names must start with a '#' character");
|
||||
return false;
|
||||
}
|
||||
} else
|
||||
_args.at(1).erase(0, 1);
|
||||
_cTarget = searchList(_channels, _args.at(1));
|
||||
if (_cTarget == NULL) {
|
||||
WARNING_MSG("Channel not found for INVITE command");
|
||||
|
|
@ -55,6 +56,10 @@ bool Invite::checkArgs() {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Execute the invite command
|
||||
* @note To invite a peapol to join a channel (from an operator)
|
||||
*/
|
||||
void Invite::execute() {
|
||||
if (checkArgs() == false) {
|
||||
ERROR_MSG("Invalid arguments for INVITE command (see warning message)");
|
||||
|
|
|
|||
45
sources/commands/pass.cpp
Normal file
45
sources/commands/pass.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* pass.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/24 17:29:48 by rparodi #+# #+# */
|
||||
/* Updated: 2025/05/29 12:41:39 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "pass.hpp"
|
||||
#include "commands.hpp"
|
||||
#include "logs.hpp"
|
||||
|
||||
using namespace cmd;
|
||||
|
||||
bool Pass::checkArgs() {
|
||||
if (_args.size() != 2) {
|
||||
WARNING_MSG("Not correct for Pass command");
|
||||
return false;
|
||||
}
|
||||
if (_sender->isRegistered()) {
|
||||
WARNING_MSG(_sender->getName() << " is already is already log in the server !");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Execute the Pass command
|
||||
* @note To Pass a users to join a channel (from an operator)
|
||||
*/
|
||||
void Pass::execute() {
|
||||
if (checkArgs() == false) {
|
||||
ERROR_MSG("Invalid arguments for Pass command (see warning message)");
|
||||
return;
|
||||
}
|
||||
if (_args.at(1) != _server->getPassword()) {
|
||||
ERROR_MSG("The password is incorrect");
|
||||
return;
|
||||
}
|
||||
_sender->setRegistered();
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/13 11:11:07 by rparodi #+# #+# */
|
||||
/* Updated: 2025/05/26 22:30:07 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/05/29 12:17:15 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
|
|
@ -148,6 +148,13 @@ void Server::printUsers() const
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The getter for the password
|
||||
*
|
||||
* @return the password of the server
|
||||
*/
|
||||
std::string Server::getPassword() const { return this->_password; }
|
||||
|
||||
std::list<User *> Server::getUsersList() const {
|
||||
// to_delete when done
|
||||
WARNING_MSG("TO DO FILL")
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/21 20:37:12 by omoudni #+# #+# */
|
||||
/* Updated: 2025/05/22 17:13:35 by omoudni ### ########.fr */
|
||||
/* Updated: 2025/05/29 12:38:46 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/******************************************************************************/
|
||||
|
||||
|
|
@ -15,11 +15,12 @@
|
|||
// Constructor
|
||||
User::User(short unsigned int fd) : _fd(fd), _registered(false), _hasNick(false), _hasUser(false) {}
|
||||
|
||||
// Getter for fd
|
||||
short unsigned int User::getFd() const
|
||||
{
|
||||
return _fd;
|
||||
}
|
||||
/**
|
||||
* @brief Getter for the fd
|
||||
*
|
||||
* @return the fd of the user
|
||||
*/
|
||||
short unsigned int User::getFd() const { return this->_fd; }
|
||||
|
||||
/**
|
||||
* @brief Getter for the nickname of the user
|
||||
|
|
@ -64,6 +65,13 @@ void User::setNickname(const std::string &nickname)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Setter to register a user
|
||||
*/
|
||||
void User::setRegistered() {
|
||||
this->_registered = true;
|
||||
}
|
||||
|
||||
// Registration state
|
||||
bool User::isRegistered() const
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue