From 7f718779819bad397a9b4fb1584b5b78de6c15a1 Mon Sep 17 00:00:00 2001 From: Ladebeze66 Date: Thu, 30 May 2024 13:55:15 +0200 Subject: [PATCH] modif3005 --- ft_irc3/includes/AdditionalCommands.hpp | 4 +- ft_irc3/includes/Channel.hpp | 11 +- ft_irc3/includes/CommandHandler.hpp | 6 +- ft_irc3/includes/InviteHandler.hpp | 38 ++++++ ft_irc3/includes/ModeHandler.hpp | 52 ++++++++ ft_irc3/includes/RPL.hpp | 14 ++- ft_irc3/includes/Server.hpp | 7 +- ft_irc3/src/AdditionalCommands.cpp | 7 +- ft_irc3/src/Channel.cpp | 33 ++++- ft_irc3/src/CommandHandler.cpp | 8 +- ft_irc3/src/InviteHandler.cpp | 60 +++++++++ ft_irc3/src/ModeHandler.cpp | 154 ++++++++++++++++++++++++ ft_irc3/src/Server.cpp | 12 +- 13 files changed, 392 insertions(+), 14 deletions(-) create mode 100644 ft_irc3/includes/InviteHandler.hpp create mode 100644 ft_irc3/includes/ModeHandler.hpp create mode 100644 ft_irc3/src/InviteHandler.cpp create mode 100644 ft_irc3/src/ModeHandler.cpp diff --git a/ft_irc3/includes/AdditionalCommands.hpp b/ft_irc3/includes/AdditionalCommands.hpp index 182ebdf..a442f2a 100644 --- a/ft_irc3/includes/AdditionalCommands.hpp +++ b/ft_irc3/includes/AdditionalCommands.hpp @@ -6,7 +6,7 @@ /* 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 "RPL.hpp" #include "Who.hpp" +#include "InviteHandler.hpp" #include #include @@ -36,6 +37,7 @@ class AdditionalCommands private: Server *_server; CommandHandler *_commandhandler; + //InviteHandler *_inviteHandler; public: AdditionalCommands(Server *server); void processCommand(Client *client, const std::string &command); diff --git a/ft_irc3/includes/Channel.hpp b/ft_irc3/includes/Channel.hpp index 538a2ef..275c8f3 100644 --- a/ft_irc3/includes/Channel.hpp +++ b/ft_irc3/includes/Channel.hpp @@ -6,7 +6,7 @@ /* 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; 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: std::string _name; std::vector _clients; @@ -65,6 +73,7 @@ private: time_t _topicTime; size_t _clientLimit; bool _inviteOnly; + bool _topicProtection; // Ajouté }; #endif // CHANNEL_HPP diff --git a/ft_irc3/includes/CommandHandler.hpp b/ft_irc3/includes/CommandHandler.hpp index d1197c0..d646203 100644 --- a/ft_irc3/includes/CommandHandler.hpp +++ b/ft_irc3/includes/CommandHandler.hpp @@ -6,7 +6,7 @@ /* 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 "Join.hpp" #include "Welcome.hpp" +#include "ModeHandler.hpp" #include #include @@ -32,12 +33,15 @@ class Client; class Channel; class WhoHandler; class AdditionalCommands; +class ModeHandler; class CommandHandler { private: Server *_server; AdditionalCommands *_additionalCommands; + ModeHandler *_modeHandler; + public: CommandHandler(Server *server); diff --git a/ft_irc3/includes/InviteHandler.hpp b/ft_irc3/includes/InviteHandler.hpp new file mode 100644 index 0000000..3d97043 --- /dev/null +++ b/ft_irc3/includes/InviteHandler.hpp @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* InviteHanndler.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fgras-ca +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#include +#include + +#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 diff --git a/ft_irc3/includes/ModeHandler.hpp b/ft_irc3/includes/ModeHandler.hpp new file mode 100644 index 0000000..9d4e5f5 --- /dev/null +++ b/ft_irc3/includes/ModeHandler.hpp @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ModeHandler.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fgras-ca +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 +#include +#include +#include +#include + +#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& tokens); + void handleChannelMode(Client* client, const std::vector& 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 diff --git a/ft_irc3/includes/RPL.hpp b/ft_irc3/includes/RPL.hpp index c644187..186f608 100644 --- a/ft_irc3/includes/RPL.hpp +++ b/ft_irc3/includes/RPL.hpp @@ -6,7 +6,7 @@ /* 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_VERSION "1.0" -#define USER_MODES "" -#define CHANNEL_MODES "" -#define CHANNEL_MODES_WITH_PARAMS "" +#define USER_MODES "+o" +#define CHANNEL_MODES "i/t/k/o/l" +#define CHANNEL_MODES_WITH_PARAMS "None" @@ -384,6 +384,12 @@ inline std::string ERR_CHANNELISFULL(Client* client, const std::string& channel) 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) { std::ostringstream oss; oss << ":" << SERVER_NAME << " 473 " << CLIENT_NICK(client) << " " << channel << " :Cannot join channel (invite only)\r\n"; diff --git a/ft_irc3/includes/Server.hpp b/ft_irc3/includes/Server.hpp index 4074a42..52981a8 100644 --- a/ft_irc3/includes/Server.hpp +++ b/ft_irc3/includes/Server.hpp @@ -6,7 +6,7 @@ /* 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 "AdditionalCommands.hpp" #include "RPL.hpp" +#include "ModeHandler.hpp" #include #include @@ -39,6 +40,7 @@ class Channel; class ClientManager; class CommandHandler; class AdditionalCommands; +class ModeHandler; class Server { @@ -55,6 +57,7 @@ public: const std::string &getPassword() const; void broadcast(const std::string &message); 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 disconnectClient(int clientFd); bool MatchFd(const pollfd& pfd, int clientFd); @@ -70,9 +73,11 @@ protected: std::vector _poll_fds; ClientManager *_clientManager; CommandHandler *_commandHandler; + ModeHandler *_modeHandler; friend class ClientManager; friend class CommandHandler; + friend class ModeHandler; private: void initServer(); diff --git a/ft_irc3/src/AdditionalCommands.cpp b/ft_irc3/src/AdditionalCommands.cpp index ffc2cf9..2a2ccd5 100644 --- a/ft_irc3/src/AdditionalCommands.cpp +++ b/ft_irc3/src/AdditionalCommands.cpp @@ -6,7 +6,7 @@ /* 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.handleWhoisCommand(client, command); } + else if (command.find("INVITE") == 0) + { + InviteHandler inviteHandler(_server); + inviteHandler.handleInviteCommand(client, command); + } else if (command.find("LIST") == 0) { broadcastChannelList(client, _server); diff --git a/ft_irc3/src/Channel.cpp b/ft_irc3/src/Channel.cpp index 86d739e..6f0ef02 100644 --- a/ft_irc3/src/Channel.cpp +++ b/ft_irc3/src/Channel.cpp @@ -6,7 +6,7 @@ /* 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); } +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; +} diff --git a/ft_irc3/src/CommandHandler.cpp b/ft_irc3/src/CommandHandler.cpp index 5eba6b3..b196e8c 100644 --- a/ft_irc3/src/CommandHandler.cpp +++ b/ft_irc3/src/CommandHandler.cpp @@ -6,14 +6,14 @@ /* 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" 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 if (!_server) @@ -51,6 +51,10 @@ void CommandHandler::handleCommand(Client* client, const std::string& command) handleErrorCommand(client, tokens[1]); } } + else if (commandType == "MODE") + { + _modeHandler->handleModeCommand(client, command); + } else if (commandType == "JOIN") { JoinHandler joinHandler; joinHandler.handleJoinCommand(client, tokens[1], _server); diff --git a/ft_irc3/src/InviteHandler.cpp b/ft_irc3/src/InviteHandler.cpp new file mode 100644 index 0000000..d2339bf --- /dev/null +++ b/ft_irc3/src/InviteHandler.cpp @@ -0,0 +1,60 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* InviteHandler.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fgras-ca +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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()); +} diff --git a/ft_irc3/src/ModeHandler.cpp b/ft_irc3/src/ModeHandler.cpp new file mode 100644 index 0000000..85ce87e --- /dev/null +++ b/ft_irc3/src/ModeHandler.cpp @@ -0,0 +1,154 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ModeHandler.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fgras-ca +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 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& 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& 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); +} + diff --git a/ft_irc3/src/Server.cpp b/ft_irc3/src/Server.cpp index e69acc4..31e4cce 100644 --- a/ft_irc3/src/Server.cpp +++ b/ft_irc3/src/Server.cpp @@ -6,14 +6,14 @@ /* 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" 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(); } @@ -208,6 +208,14 @@ Client* Server::getClientByName(const std::string &name) return NULL; // Remplacez nullptr par NULL } +Channel* Server::getChannelByName(const std::string &name) { + std::map::iterator it = _channels.find(name); + if (it != _channels.end()) { + return it->second; + } + return NULL; +} + void Server::sendChannelListToClient(Client *client) { std::map &channels = getChannels();