modif3005

This commit is contained in:
Ladebeze66 2024-05-30 13:55:15 +02:00
parent 8d7b06ec25
commit 7f71877981
13 changed files with 392 additions and 14 deletions

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */ /* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 18:09:05 by fgras-ca #+# #+# */ /* Created: 2024/05/21 18:09:05 by fgras-ca #+# #+# */
/* Updated: 2024/05/28 14:16:57 by fgras-ca ### ########.fr */ /* Updated: 2024/05/30 13:10:51 by fgras-ca ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,6 +20,7 @@
#include "Utils.hpp" #include "Utils.hpp"
#include "RPL.hpp" #include "RPL.hpp"
#include "Who.hpp" #include "Who.hpp"
#include "InviteHandler.hpp"
#include <sstream> #include <sstream>
#include <string> #include <string>
@ -36,6 +37,7 @@ class AdditionalCommands
private: private:
Server *_server; Server *_server;
CommandHandler *_commandhandler; CommandHandler *_commandhandler;
//InviteHandler *_inviteHandler;
public: public:
AdditionalCommands(Server *server); AdditionalCommands(Server *server);
void processCommand(Client *client, const std::string &command); void processCommand(Client *client, const std::string &command);

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */ /* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 12:41:35 by fgras-ca #+# #+# */ /* Created: 2024/05/15 12:41:35 by fgras-ca #+# #+# */
/* Updated: 2024/05/28 14:16:55 by fgras-ca ### ########.fr */ /* Updated: 2024/05/30 13:09:11 by fgras-ca ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -53,6 +53,14 @@ public:
time_t getTopicTime() const; time_t getTopicTime() const;
void setTopic(const std::string &topic, const std::string &setter); void setTopic(const std::string &topic, const std::string &setter);
void setClientLimit(size_t limit); // Ajouté
size_t getClientLimit() const; // Ajouté
void setInviteOnly(bool inviteOnly); // Ajouté
void setKey(const std::string &key); // Ajouté
void setTopicProtection(bool protection); // Ajouté
std::string getModes() const; // Ajouté
void addInvitedClient(Client* client);
private: private:
std::string _name; std::string _name;
std::vector<Client *> _clients; std::vector<Client *> _clients;
@ -65,6 +73,7 @@ private:
time_t _topicTime; time_t _topicTime;
size_t _clientLimit; size_t _clientLimit;
bool _inviteOnly; bool _inviteOnly;
bool _topicProtection; // Ajouté
}; };
#endif // CHANNEL_HPP #endif // CHANNEL_HPP

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */ /* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 18:14:12 by fgras-ca #+# #+# */ /* Created: 2024/05/15 18:14:12 by fgras-ca #+# #+# */
/* Updated: 2024/05/28 14:17:40 by fgras-ca ### ########.fr */ /* Updated: 2024/05/30 12:42:22 by fgras-ca ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,6 +22,7 @@
#include "RPL.hpp" #include "RPL.hpp"
#include "Join.hpp" #include "Join.hpp"
#include "Welcome.hpp" #include "Welcome.hpp"
#include "ModeHandler.hpp"
#include <string> #include <string>
#include <sstream> #include <sstream>
@ -32,12 +33,15 @@ class Client;
class Channel; class Channel;
class WhoHandler; class WhoHandler;
class AdditionalCommands; class AdditionalCommands;
class ModeHandler;
class CommandHandler class CommandHandler
{ {
private: private:
Server *_server; Server *_server;
AdditionalCommands *_additionalCommands; AdditionalCommands *_additionalCommands;
ModeHandler *_modeHandler;
public: public:
CommandHandler(Server *server); CommandHandler(Server *server);

View File

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* InviteHanndler.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/30 13:01:50 by fgras-ca #+# #+# */
/* Updated: 2024/05/30 13:03:04 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef INVITEHANDLER_HPP
#define INVITEHANDLER_HPP
#include <string>
#include <vector>
#include <sstream>
#include "Server.hpp"
#include "Client.hpp"
#include "Channel.hpp"
#include "RPL.hpp"
class Server;
class Client;
class Channel;
class InviteHandler {
public:
InviteHandler(Server* server);
void handleInviteCommand(Client* client, const std::string& command);
private:
Server* _server;
};
#endif // INVITEHANDLER_HPP

View File

@ -0,0 +1,52 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ModeHandler.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/30 11:12:57 by fgras-ca #+# #+# */
/* Updated: 2024/05/30 12:50:39 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MODEHANDLER_HPP
#define MODEHANDLER_HPP
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <algorithm>
#include "Client.hpp"
#include "Channel.hpp"
#include "Server.hpp"
#include "RPL.hpp"
#include "Utils.hpp"
class Server;
class Client;
class Channel;
class ModeHandler
{
public:
ModeHandler(Server* server);
void handleModeCommand(Client* client, const std::string& command);
private:
Server* _server;
void handleUserMode(Client* client, const std::vector<std::string>& tokens);
void handleChannelMode(Client* client, const std::vector<std::string>& tokens);
void setChannelMode(Channel* channel, const std::string& mode, bool adding, const std::string& argument);
//void applyModeB(Channel* channel, bool adding, const std::string& argument);
void applyModeL(Channel* channel, bool adding, const std::string& argument);
void applyModeI(Channel* channel, bool adding);
void applyModeK(Channel* channel, bool adding, const std::string& argument);
void applyModeT(Channel* channel, bool adding);
};
#endif // MODEHANDLER_HPP

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */ /* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/19 15:12:47 by fgras-ca #+# #+# */ /* Created: 2024/05/19 15:12:47 by fgras-ca #+# #+# */
/* Updated: 2024/05/28 15:26:33 by fgras-ca ### ########.fr */ /* Updated: 2024/05/30 13:27:52 by fgras-ca ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,9 +19,9 @@
#define SERVER_NAME "IRC_Server" #define SERVER_NAME "IRC_Server"
#define SERVER_VERSION "1.0" #define SERVER_VERSION "1.0"
#define USER_MODES "" #define USER_MODES "+o"
#define CHANNEL_MODES "" #define CHANNEL_MODES "i/t/k/o/l"
#define CHANNEL_MODES_WITH_PARAMS "" #define CHANNEL_MODES_WITH_PARAMS "None"
@ -384,6 +384,12 @@ inline std::string ERR_CHANNELISFULL(Client* client, const std::string& channel)
return oss.str(); return oss.str();
} }
inline std::string ERR_UNKNOWNMODE(Client* client, char mode, const std::string& channelName) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 472 " << CLIENT_NICK(client) << " " << mode << " :is unknown mode char to me for " << channelName << "\r\n";
return oss.str();
}
inline std::string ERR_INVITEONLYCHAN(Client* client, const std::string& channel) { inline std::string ERR_INVITEONLYCHAN(Client* client, const std::string& channel) {
std::ostringstream oss; std::ostringstream oss;
oss << ":" << SERVER_NAME << " 473 " << CLIENT_NICK(client) << " " << channel << " :Cannot join channel (invite only)\r\n"; oss << ":" << SERVER_NAME << " 473 " << CLIENT_NICK(client) << " " << channel << " :Cannot join channel (invite only)\r\n";

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */ /* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 12:15:13 by fgras-ca #+# #+# */ /* Created: 2024/05/15 12:15:13 by fgras-ca #+# #+# */
/* Updated: 2024/05/21 19:44:24 by fgras-ca ### ########.fr */ /* Updated: 2024/05/30 12:20:53 by fgras-ca ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,6 +20,7 @@
#include "CommandHandler.hpp" #include "CommandHandler.hpp"
#include "AdditionalCommands.hpp" #include "AdditionalCommands.hpp"
#include "RPL.hpp" #include "RPL.hpp"
#include "ModeHandler.hpp"
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
@ -39,6 +40,7 @@ class Channel;
class ClientManager; class ClientManager;
class CommandHandler; class CommandHandler;
class AdditionalCommands; class AdditionalCommands;
class ModeHandler;
class Server class Server
{ {
@ -55,6 +57,7 @@ public:
const std::string &getPassword() const; const std::string &getPassword() const;
void broadcast(const std::string &message); void broadcast(const std::string &message);
Client* getClientByName(const std::string &name); // Ajoutez cette méthode Client* getClientByName(const std::string &name); // Ajoutez cette méthode
Channel* getChannelByName(const std::string &name); // Ajoutez cette méthode
void sendChannelListToClient(Client *client); void sendChannelListToClient(Client *client);
void disconnectClient(int clientFd); void disconnectClient(int clientFd);
bool MatchFd(const pollfd& pfd, int clientFd); bool MatchFd(const pollfd& pfd, int clientFd);
@ -70,9 +73,11 @@ protected:
std::vector<struct pollfd> _poll_fds; std::vector<struct pollfd> _poll_fds;
ClientManager *_clientManager; ClientManager *_clientManager;
CommandHandler *_commandHandler; CommandHandler *_commandHandler;
ModeHandler *_modeHandler;
friend class ClientManager; friend class ClientManager;
friend class CommandHandler; friend class CommandHandler;
friend class ModeHandler;
private: private:
void initServer(); void initServer();

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */ /* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/16 15:27:29 by fgras-ca #+# #+# */ /* Created: 2024/05/16 15:27:29 by fgras-ca #+# #+# */
/* Updated: 2024/05/29 13:41:49 by fgras-ca ### ########.fr */ /* Updated: 2024/05/30 13:07:33 by fgras-ca ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -35,6 +35,11 @@ void AdditionalCommands::processCommand(Client *client, const std::string &comma
WhoHandler whoHandler(_server); WhoHandler whoHandler(_server);
whoHandler.handleWhoisCommand(client, command); whoHandler.handleWhoisCommand(client, command);
} }
else if (command.find("INVITE") == 0)
{
InviteHandler inviteHandler(_server);
inviteHandler.handleInviteCommand(client, command);
}
else if (command.find("LIST") == 0) else if (command.find("LIST") == 0)
{ {
broadcastChannelList(client, _server); broadcastChannelList(client, _server);

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */ /* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 12:42:57 by fgras-ca #+# #+# */ /* Created: 2024/05/15 12:42:57 by fgras-ca #+# #+# */
/* Updated: 2024/05/28 13:06:02 by fgras-ca ### ########.fr */ /* Updated: 2024/05/30 13:09:45 by fgras-ca ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -116,4 +116,35 @@ void Channel::setTopic(const std::string &topic, const std::string &setter)
_topicTime = std::time(NULL); _topicTime = std::time(NULL);
} }
void Channel::setClientLimit(size_t limit) {
_clientLimit = limit;
}
size_t Channel::getClientLimit() const {
return _clientLimit;
}
void Channel::setInviteOnly(bool inviteOnly) {
_inviteOnly = inviteOnly;
}
void Channel::setKey(const std::string &key) {
_key = key;
}
void Channel::setTopicProtection(bool protection) {
_topicProtection = protection;
}
void Channel::addInvitedClient(Client* client) {
_invitedClients.insert(client);
}
std::string Channel::getModes() const {
std::string modes;
if (_inviteOnly) modes += 'i';
if (!_key.empty()) modes += 'k';
if (_clientLimit > 0) modes += 'l';
if (_topicProtection) modes += 't';
return modes;
}

View File

@ -6,14 +6,14 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */ /* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 18:26:34 by fgras-ca #+# #+# */ /* Created: 2024/05/15 18:26:34 by fgras-ca #+# #+# */
/* Updated: 2024/05/29 13:41:25 by fgras-ca ### ########.fr */ /* Updated: 2024/05/30 12:39:58 by fgras-ca ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "CommandHandler.hpp" #include "CommandHandler.hpp"
CommandHandler::CommandHandler(Server *server) CommandHandler::CommandHandler(Server *server)
: _server(server), _additionalCommands(new AdditionalCommands(server)) : _server(server), _additionalCommands(new AdditionalCommands(server)), _modeHandler(new ModeHandler(server))
{ {
// Ensure that _server is not null // Ensure that _server is not null
if (!_server) if (!_server)
@ -51,6 +51,10 @@ void CommandHandler::handleCommand(Client* client, const std::string& command)
handleErrorCommand(client, tokens[1]); handleErrorCommand(client, tokens[1]);
} }
} }
else if (commandType == "MODE")
{
_modeHandler->handleModeCommand(client, command);
}
else if (commandType == "JOIN") { else if (commandType == "JOIN") {
JoinHandler joinHandler; JoinHandler joinHandler;
joinHandler.handleJoinCommand(client, tokens[1], _server); joinHandler.handleJoinCommand(client, tokens[1], _server);

View File

@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* InviteHandler.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/30 13:02:09 by fgras-ca #+# #+# */
/* Updated: 2024/05/30 13:08:33 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "InviteHandler.hpp"
InviteHandler::InviteHandler(Server* server) : _server(server) {}
void InviteHandler::handleInviteCommand(Client* client, const std::string& command) {
std::istringstream iss(command);
std::string cmd, nickname, channelName;
iss >> cmd >> nickname >> channelName;
if (nickname.empty() || channelName.empty()) {
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "INVITE"));
return;
}
Channel* channel = _server->getChannelByName(channelName);
if (!channel) {
_server->sendToClient(client->getFd(), ERR_NOSUCHCHANNEL(client->getFd(), channelName));
return;
}
if (!channel->hasClient(client)) {
_server->sendToClient(client->getFd(), ERR_NOTONCHANNEL(client->getFd(), channelName));
return;
}
if (!channel->isOperator(client) && channel->isInviteOnly()) {
_server->sendToClient(client->getFd(), ERR_CHANOPRIVSNEEDED(client->getFd(), channelName));
return;
}
Client* targetClient = _server->getClientByName(nickname);
if (!targetClient) {
_server->sendToClient(client->getFd(), ERR_NOSUCHNICK(client->getFd(), nickname));
return;
}
if (channel->hasClient(targetClient)) {
_server->sendToClient(client->getFd(), ERR_USERONCHANNEL(client, nickname, channelName));
return;
}
channel->addInvitedClient(targetClient);
_server->sendToClient(client->getFd(), RPL_INVITING(client, nickname, channelName));
std::ostringstream inviteMsg;
inviteMsg << ":" << client->getNickname() << " INVITE " << nickname << " " << channelName << "\r\n";
_server->sendToClient(targetClient->getFd(), inviteMsg.str());
}

154
ft_irc3/src/ModeHandler.cpp Normal file
View File

@ -0,0 +1,154 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ModeHandler.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/30 11:13:08 by fgras-ca #+# #+# */
/* Updated: 2024/05/30 13:33:36 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "ModeHandler.hpp"
ModeHandler::ModeHandler(Server* server) : _server(server) {}
void ModeHandler::handleModeCommand(Client* client, const std::string& command) {
_server->log("Received MODE command: " + command, "\033[1;34m");
std::vector<std::string> tokens = split(command, " \n\r\t");
if (tokens.size() < 2) {
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "MODE"));
_server->log("MODE command error: Need more parameters", "\033[1;31m");
return;
}
std::string target = tokens[1];
if (target[0] == '#' || target[0] == '&') {
_server->log("Handling channel mode for target: " + target, "\033[1;34m");
handleChannelMode(client, tokens);
} else {
_server->log("Handling user mode for target: " + target, "\033[1;34m");
handleUserMode(client, tokens);
}
}
void ModeHandler::handleUserMode(Client* client, const std::vector<std::string>& tokens) {
std::string target = tokens[1];
if (target != client->getNickname()) {
_server->sendToClient(client->getFd(), ERR_USERSDONTMATCH(client->getFd()));
_server->log("User mode error: Users don't match", "\033[1;31m");
return;
}
if (tokens.size() == 2) {
_server->sendToClient(client->getFd(), RPL_UMODEIS(client->getFd(), "")); // Ajout de la chaîne vide pour les modes utilisateur
_server->log("Sent user modes to client", "\033[1;32m");
} else {
std::string modeString = tokens[2];
// Gestion des modes utilisateur (ajout ou suppression)
// Par exemple, vous pouvez gérer l'ajout ou la suppression du mode invisible ici
_server->log("Updating user modes: " + modeString, "\033[1;34m");
}
}
void ModeHandler::handleChannelMode(Client* client, const std::vector<std::string>& tokens) {
std::string channelName = tokens[1];
Channel* channel = _server->getChannelByName(channelName);
if (!channel) {
_server->sendToClient(client->getFd(), ERR_NOSUCHCHANNEL(client->getFd(), channelName));
_server->log("Channel mode error: No such channel " + channelName, "\033[1;31m");
return;
}
if (tokens.size() == 2) {
// Retourner les modes actuels du canal
std::ostringstream oss;
oss << RPL_CHANNELMODEIS(client->getFd(), channel->getName(), channel->getModes());
oss << RPL_CREATIONTIME(client->getFd(), channel->getName(), channel->getTopicTime());
_server->sendToClient(client->getFd(), oss.str());
_server->log("Sent channel modes to client", "\033[1;32m");
return;
}
if (!channel->isOperator(client)) {
_server->sendToClient(client->getFd(), ERR_CHANOPRIVSNEEDED(client->getFd(), channelName));
_server->log("Channel mode error: Channel operator privileges needed for " + channelName, "\033[1;31m");
return;
}
std::string modeString = tokens[2];
bool adding = true;
size_t argIndex = 3;
for (size_t i = 0; i < modeString.length(); ++i) {
char mode = modeString[i];
if (mode == '+') {
adding = true;
} else if (mode == '-') {
adding = false;
} else if (mode == 'b' || mode == 'l' || mode == 'i' || mode == 'k' || mode == 't') {
std::string argument;
if (argIndex < tokens.size()) {
argument = tokens[argIndex++];
}
setChannelMode(channel, std::string(1, mode), adding, argument);
} else {
_server->sendToClient(client->getFd(), ERR_UNKNOWNMODE(client, mode, channelName));
}
}
}
void ModeHandler::setChannelMode(Channel* channel, const std::string& mode, bool adding, const std::string& argument) {
/*if (mode == "b") {
applyModeB(channel, adding, argument);
}*/
if (mode == "l") {
applyModeL(channel, adding, argument);
} else if (mode == "i") {
applyModeI(channel, adding);
} else if (mode == "k") {
applyModeK(channel, adding, argument);
} else if (mode == "t") {
applyModeT(channel, adding);
}
}
/*void ModeHandler::applyModeB(Channel* channel, bool adding, const std::string& argument) {
// Implémentation de l'ajout ou de la suppression de bannissements
// Note : Vous pouvez ajouter des méthodes à la classe Channel pour gérer la liste des bannissements
if (adding) {
// Ajouter le masque à la liste des bannissements
// channel->banClient(argument);
} else {
// Supprimer le masque de la liste des bannissements
// channel->unbanClient(argument);
}
}*/
void ModeHandler::applyModeL(Channel* channel, bool adding, const std::string& argument) {
if (adding) {
int limit = std::atoi(argument.c_str());
channel->setClientLimit(limit);
} else {
channel->setClientLimit(0); // Retirer la limite
}
}
void ModeHandler::applyModeI(Channel* channel, bool adding) {
channel->setInviteOnly(adding);
}
void ModeHandler::applyModeK(Channel* channel, bool adding, const std::string& argument) {
if (adding) {
channel->setKey(argument);
} else {
channel->setKey("");
}
}
void ModeHandler::applyModeT(Channel* channel, bool adding) {
channel->setTopicProtection(adding);
}

View File

@ -6,14 +6,14 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */ /* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 12:17:12 by fgras-ca #+# #+# */ /* Created: 2024/05/15 12:17:12 by fgras-ca #+# #+# */
/* Updated: 2024/05/21 20:31:51 by fgras-ca ### ########.fr */ /* Updated: 2024/05/30 12:18:40 by fgras-ca ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "Server.hpp" #include "Server.hpp"
Server::Server(int port, const std::string &password) Server::Server(int port, const std::string &password)
: _port(port), _password(password), _clientManager(new ClientManager(this)), _commandHandler(new CommandHandler(this)) : _port(port), _password(password), _clientManager(new ClientManager(this)), _commandHandler(new CommandHandler(this)), _modeHandler(new ModeHandler(this))
{ {
initServer(); initServer();
} }
@ -208,6 +208,14 @@ Client* Server::getClientByName(const std::string &name)
return NULL; // Remplacez nullptr par NULL return NULL; // Remplacez nullptr par NULL
} }
Channel* Server::getChannelByName(const std::string &name) {
std::map<std::string, Channel *>::iterator it = _channels.find(name);
if (it != _channels.end()) {
return it->second;
}
return NULL;
}
void Server::sendChannelListToClient(Client *client) void Server::sendChannelListToClient(Client *client)
{ {
std::map<std::string, Channel *> &channels = getChannels(); std::map<std::string, Channel *> &channels = getChannels();