/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* Server.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/15 12:15:13 by fgras-ca #+# #+# */ /* Updated: 2024/05/21 19:44:24 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef SERVER_HPP #define SERVER_HPP #include "Utils.hpp" #include "Client.hpp" #include "Channel.hpp" #include "ClientManager.hpp" #include "CommandHandler.hpp" #include "AdditionalCommands.hpp" #include "RPL.hpp" #include #include #include #include #include #include #include #include #include #include #include #include class Client; class Channel; class ClientManager; class CommandHandler; class AdditionalCommands; class Server { public: Server(int port, const std::string &password); ~Server(); void run(); void log(const std::string &message, const std::string &color = "\033[0m"); void sendToClient(int client_fd, const std::string &message); // Méthodes d'accès pour les canaux et les clients std::map &getChannels(); std::map &getClients(); const std::string &getPassword() const; void broadcast(const std::string &message); Client* getClientByName(const std::string &name); // Ajoutez cette méthode void sendChannelListToClient(Client *client); void disconnectClient(int clientFd); bool MatchFd(const pollfd& pfd, int clientFd); void removePollFd(int clientFd); protected: int _server_fd; int _port; std::string _password; std::map _clients; std::map _channels; std::vector _poll_fds; ClientManager *_clientManager; CommandHandler *_commandHandler; friend class ClientManager; friend class CommandHandler; private: void initServer(); void handleServerCommands(); void acceptClient(); void removeClient(int client_fd); }; #endif