mirror of
https://github.com/Ladebeze66/ft_irc.git
synced 2025-12-16 05:58:09 +01:00
de
This commit is contained in:
parent
4c13e1b349
commit
0dc9f5c940
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/15 18:14:12 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/05/19 19:13:53 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/05/21 13:47:12 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
#include "Client.hpp"
|
||||
#include "Channel.hpp"
|
||||
#include "AdditionalCommands.hpp"
|
||||
#include "ModeWhoHandler.hpp"
|
||||
#include "Who.hpp"
|
||||
#include "CommandHandler.hpp"
|
||||
#include "RPL.hpp"
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 15:12:47 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/05/19 22:27:05 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/05/21 12:41:51 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -19,9 +19,9 @@
|
||||
|
||||
#define SERVER_NAME "IRC_Server"
|
||||
#define SERVER_VERSION "1.0"
|
||||
#define USER_MODES "iw"
|
||||
#define CHANNEL_MODES "nt"
|
||||
#define CHANNEL_MODES_WITH_PARAMS "kl"
|
||||
#define USER_MODES ""
|
||||
#define CHANNEL_MODES ""
|
||||
#define CHANNEL_MODES_WITH_PARAMS ""
|
||||
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
// Fonctions pour générer les réponses RPL
|
||||
inline std::string RPL_WELCOME(Client* client) {
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 001 " << CLIENT_FD(client)
|
||||
oss << ":" << SERVER_NAME << " 001 " << CLIENT_NICK(client)
|
||||
<< " :Welcome to the Internet Relay Network " << CLIENT_NICK(client)
|
||||
<< "!" << CLIENT_USER(client) << "@" << CLIENT_HOST(client) << "\r\n";
|
||||
return oss.str();
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ModeWhoHandler.hpp :+: :+: :+: */
|
||||
/* Who.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/17 16:08:48 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/05/19 20:36:23 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/05/21 13:47:28 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MODEWHOHANDLER_HPP
|
||||
#define MODEWHOHANDLER_HPP
|
||||
#ifndef WHO_HPP
|
||||
#define WHO_HPP
|
||||
|
||||
#include "Server.hpp"
|
||||
#include "Client.hpp"
|
||||
@ -24,11 +24,10 @@
|
||||
|
||||
class Server;
|
||||
|
||||
class ModeWhoHandler
|
||||
class WhoHandler
|
||||
{
|
||||
public:
|
||||
ModeWhoHandler(Server *server);
|
||||
void handleModeCommand(Client *client, const std::string &command);
|
||||
WhoHandler(Server *server);
|
||||
void handleWhoCommand(Client *client, const std::string &command);
|
||||
void handleWhoisCommand(Client *client, const std::string &command);
|
||||
|
||||
BIN
ft_irc3/ircserv
BIN
ft_irc3/ircserv
Binary file not shown.
9
ft_irc3/motd
Normal file
9
ft_irc3/motd
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
░▒▓████████▓▒░▒▓████████▓▒░▒▓█▓▒░▒▓███████▓▒░ ░▒▓██████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓███████▓▒░
|
||||
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
|
||||
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
|
||||
░▒▓██████▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░▒▓███████▓▒░░▒▓█▓▒░ ░▒▓████████▓▒░░▒▓██████▓▒░
|
||||
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░
|
||||
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░
|
||||
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░ ░▒▓█▓▒░▒▓████████▓▒░
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -6,13 +6,14 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/16 15:27:29 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/05/19 19:22:28 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/05/21 13:52:54 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "AdditionalCommands.hpp"
|
||||
|
||||
void sendWelcomeMessages(Client *client, Server *server) {
|
||||
void sendWelcomeMessages(Client *client, Server *server)
|
||||
{
|
||||
server->sendToClient(client->getFd(), RPL_WELCOME(client));
|
||||
server->sendToClient(client->getFd(), RPL_YOURHOST(client));
|
||||
server->sendToClient(client->getFd(), RPL_CREATED(client));
|
||||
@ -22,17 +23,22 @@ void sendWelcomeMessages(Client *client, Server *server) {
|
||||
sendMotd(client, server);
|
||||
}
|
||||
|
||||
void sendMotd(Client *client, Server *server) {
|
||||
void sendMotd(Client *client, Server *server)
|
||||
{
|
||||
std::ifstream motdFile("motd.txt");
|
||||
if (motdFile.is_open()) {
|
||||
if (motdFile.is_open())
|
||||
{
|
||||
std::string line;
|
||||
server->sendToClient(client->getFd(), RPL_MOTDSTART(client));
|
||||
while (std::getline(motdFile, line)) {
|
||||
while (std::getline(motdFile, line))
|
||||
{
|
||||
server->sendToClient(client->getFd(), RPL_MOTD(client, line));
|
||||
}
|
||||
server->sendToClient(client->getFd(), RPL_ENDOFMOTD(client));
|
||||
motdFile.close();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
server->sendToClient(client->getFd(), ERR_NOMOTD(client));
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/15 18:32:23 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/05/19 22:09:39 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/05/21 14:09:07 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -67,19 +67,22 @@ void ClientManager::handleClient(int client_fd)
|
||||
}
|
||||
}
|
||||
|
||||
void ClientManager::removeClient(int client_fd)
|
||||
void ClientManager::removeClient(int clientFd)
|
||||
{
|
||||
Client *client = _server->_clients[client_fd];
|
||||
Client* client = _server->_clients[clientFd];
|
||||
if (client)
|
||||
{
|
||||
std::map<std::string, Channel *>::iterator it = _server->_channels.begin();
|
||||
// Log the nickname being freed
|
||||
_server->log("Removing client: " + client->getNickname(), YELLOW);
|
||||
|
||||
std::map<std::string, Channel*>::iterator it = _server->_channels.begin();
|
||||
while (it != _server->_channels.end())
|
||||
{
|
||||
it->second->removeClient(client);
|
||||
if (it->second->isEmpty())
|
||||
{
|
||||
delete it->second;
|
||||
std::map<std::string, Channel *>::iterator it_to_delete = it++;
|
||||
std::map<std::string, Channel*>::iterator it_to_delete = it++;
|
||||
_server->_channels.erase(it_to_delete);
|
||||
}
|
||||
else
|
||||
@ -88,13 +91,13 @@ void ClientManager::removeClient(int client_fd)
|
||||
}
|
||||
}
|
||||
delete client;
|
||||
_server->_clients.erase(client_fd);
|
||||
_server->_clients.erase(clientFd);
|
||||
}
|
||||
|
||||
std::vector<struct pollfd>::iterator it_poll = _server->_poll_fds.begin();
|
||||
while (it_poll != _server->_poll_fds.end())
|
||||
{
|
||||
if (it_poll->fd == client_fd)
|
||||
if (it_poll->fd == clientFd)
|
||||
{
|
||||
_server->_poll_fds.erase(it_poll);
|
||||
break;
|
||||
@ -103,6 +106,7 @@ void ClientManager::removeClient(int client_fd)
|
||||
}
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "Client disconnected: " << client_fd;
|
||||
ss << "Client disconnected: " << clientFd;
|
||||
_server->log(ss.str(), YELLOW);
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/15 18:26:34 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/05/19 23:47:26 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/05/21 14:19:19 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -145,10 +145,14 @@ void CommandHandler::handleNick(Client* client, const std::vector<std::string>&
|
||||
_server->sendToClient(client->getFd(), ERR_NICKNAMEINUSE(client, newNick));
|
||||
return;
|
||||
}
|
||||
|
||||
client->setNickname(newNick);
|
||||
|
||||
_server->sendToClient(client->getFd(), ":" + newNick + " NICK " + newNick + "\r\n");
|
||||
_server->log("Client NickName is " + newNick, GREEN);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << "Client " << client->getFd() << " changed nickname to " << newNick;
|
||||
_server->log(oss.str(), GREEN);
|
||||
}
|
||||
|
||||
void CommandHandler::handleUser(Client* client, const std::vector<std::string>& tokens)
|
||||
@ -156,7 +160,8 @@ void CommandHandler::handleUser(Client* client, const std::vector<std::string>&
|
||||
// Set the user and realname fields
|
||||
client->setUser(tokens[1]);
|
||||
std::string realname = tokens[4];
|
||||
if (realname[0] == ':') {
|
||||
if (realname[0] == ':')
|
||||
{
|
||||
realname = realname.substr(1); // Remove leading ':'
|
||||
}
|
||||
client->setRealName(realname);
|
||||
@ -167,11 +172,14 @@ void CommandHandler::handleUser(Client* client, const std::vector<std::string>&
|
||||
_server->log(logMsg.str(), BLUE);
|
||||
|
||||
// Authenticate if password and nickname are already set
|
||||
if (client->getPassword() == _server->_password && !client->getNickname().empty()) {
|
||||
if (client->getPassword() == _server->_password && !client->getNickname().empty())
|
||||
{
|
||||
client->authenticate();
|
||||
sendWelcomeMessages(client, _server);
|
||||
_server->log("Client " + client->getNickname() + " authenticated successfully.", GREEN);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ostringstream authFailMsg;
|
||||
authFailMsg << "Client " << client->getFd() << ": USER command failed - authentication conditions not met.";
|
||||
_server->log(authFailMsg.str(), RED);
|
||||
@ -191,27 +199,22 @@ void CommandHandler::processCommand(Client *client, const std::string &command)
|
||||
{
|
||||
handlePartCommand(_server, client, command);
|
||||
}
|
||||
else if (command.find("NICK") == 0)
|
||||
/*else if (command.find("NICK") == 0)
|
||||
{
|
||||
handleNickCommand(_server, client, command);
|
||||
}
|
||||
}*/
|
||||
else if (command.find("PRIVMSG") == 0)
|
||||
{
|
||||
handlePrivmsgCommand(_server, client, command);
|
||||
}
|
||||
else if (command.find("MODE") == 0)
|
||||
{
|
||||
ModeWhoHandler modeHandler(_server);
|
||||
modeHandler.handleModeCommand(client, command);
|
||||
}
|
||||
else if (command.find("WHO") == 0)
|
||||
{
|
||||
ModeWhoHandler whoHandler(_server);
|
||||
WhoHandler whoHandler(_server);
|
||||
whoHandler.handleWhoCommand(client, command);
|
||||
}
|
||||
else if (command.find("WHOIS") == 0)
|
||||
{
|
||||
ModeWhoHandler whoHandler(_server);
|
||||
WhoHandler whoHandler(_server);
|
||||
whoHandler.handleWhoisCommand(client, command);
|
||||
}
|
||||
else if (command.find("PING") == 0)
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/15 12:17:12 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/05/19 22:16:03 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/05/21 14:18:03 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -216,111 +216,24 @@ void Server::sendChannelListToClient(Client *client)
|
||||
|
||||
void Server::disconnectClient(int clientFd)
|
||||
{
|
||||
close(clientFd);
|
||||
Client* client = _clients[clientFd];
|
||||
if (client)
|
||||
{
|
||||
log("Disconnecting client: " + client->getNickname(), YELLOW);
|
||||
_clients.erase(clientFd);
|
||||
delete client;
|
||||
}
|
||||
|
||||
for (std::vector<struct pollfd>::iterator it = _poll_fds.begin(); it != _poll_fds.end(); ++it)
|
||||
struct MatchFd
|
||||
{
|
||||
if (it->fd == clientFd)
|
||||
{
|
||||
_poll_fds.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
int fd;
|
||||
MatchFd(int fd) : fd(fd) {}
|
||||
bool operator()(const pollfd& pfd) const { return pfd.fd == fd; }
|
||||
};
|
||||
|
||||
_poll_fds.erase(std::remove_if(_poll_fds.begin(), _poll_fds.end(), MatchFd(clientFd)), _poll_fds.end());
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << "Client disconnected: " << clientFd;
|
||||
log(oss.str(), YELLOW);
|
||||
}
|
||||
|
||||
|
||||
/* Explications des Fonctions
|
||||
Server::Server(int port, const std::string &password)
|
||||
|
||||
Description: Constructeur de la classe Server. Initialise le serveur avec le port et le mot de passe fournis.
|
||||
Paramètres:
|
||||
int port: Le port sur lequel le serveur écoute.
|
||||
const std::string &password: Le mot de passe requis pour se connecter au serveur.
|
||||
Détails: Appelle initServer() pour initialiser les paramètres du socket et commencer l'écoute des connexions.
|
||||
Server::~Server()
|
||||
|
||||
Description: Destructeur de la classe Server. Ferme le socket du serveur et libère la mémoire des clients.
|
||||
Détails: Parcourt la map _clients et delete chaque objet Client.
|
||||
void Server::initServer()
|
||||
|
||||
Description: Initialise le socket du serveur et configure le binding et l'écoute.
|
||||
Détails: Crée un socket avec socket(), lie le socket à une adresse avec bind(), et met le socket en mode écoute avec listen().
|
||||
void Server::run()
|
||||
|
||||
Description: Boucle principale du serveur qui gère les connexions entrantes et les communications avec les clients.
|
||||
Détails: Utilise poll() pour surveiller les événements sur les sockets. Accepte les nouvelles connexions avec acceptClient() et gère les communications avec handleClient().
|
||||
void Server::acceptClient()
|
||||
|
||||
Description: Accepte une nouvelle connexion client et l'ajoute à la liste des clients.
|
||||
Détails: Crée un nouvel objet Client et l'ajoute à la map _clients. Ajoute le descripteur de fichier du client à _poll_fds.
|
||||
void Server::handleClient(int client_fd)
|
||||
|
||||
Description: Gère les messages entrants des clients.
|
||||
Paramètres:
|
||||
int client_fd: Le descripteur de fichier du client.
|
||||
Détails: Reçoit les messages du client et vérifie l'authentification. Si le client n'est pas authentifié, vérifie le mot de passe. Si le client est authentifié, répond au message.
|
||||
void Server::removeClient(int client_fd)
|
||||
|
||||
Description: Supprime un client de la liste et ferme la connexion.
|
||||
Paramètres:
|
||||
int client_fd: Le descripteur de fichier du client.
|
||||
Détails: Ferme le socket du client et le supprime de la map _clients et du vecteur _poll_fds.
|
||||
void Server::log(const std::string &message, const std::string &color)
|
||||
|
||||
Description: Enregistre un message dans les logs et l'affiche avec des couleurs dans la console.
|
||||
Paramètres:
|
||||
const std::string &message: Le message à enregistrer.
|
||||
const std::string &color: La couleur du message.
|
||||
Détails: Utilise logMessage() pour enregistrer et afficher le message.
|
||||
void Server::sendToClient(int client_fd, const std::string &message)
|
||||
|
||||
Description: Envoie un message à un client.
|
||||
Paramètres:
|
||||
int client_fd: Le descripteur de fichier du client.
|
||||
const std::string &message: Le message à envoyer.
|
||||
Détails: Utilise send() pour envoyer le message au client.
|
||||
|
||||
Lecture Ligne par Ligne : Utilisez std::istringstream pour lire le message ligne par ligne et traiter chaque commande séparément.
|
||||
Suppression des Caractères de Fin de Ligne : Utilisez erase et std::remove pour supprimer les caractères \r et \n de chaque ligne avant de traiter la commande.
|
||||
Vérification du Mot de Passe : Si le client n'est pas authentifié, vérifiez s'il envoie la commande PASS et validez le mot de passe. Sinon, répondez avec un message demandant le mot de passe.
|
||||
Explications des Modifications
|
||||
Notification de Jonction : Lorsque le client rejoint un canal, le serveur envoie une notification de jonction avec la commande JOIN.
|
||||
|
||||
|
||||
std::stringstream joinMsg;
|
||||
joinMsg << ":" << client->getFd() << " JOIN " << channelName << "\r\n";
|
||||
sendToClient(client->getFd(), joinMsg.str());
|
||||
Liste des Utilisateurs : Le serveur envoie la liste des utilisateurs dans le canal en utilisant le code de réponse 353.
|
||||
|
||||
|
||||
std::string usersList = getUsersList(channel);
|
||||
sendToClient(client->getFd(), usersList);
|
||||
Fin de la Liste des Utilisateurs : Le serveur envoie un message de fin de liste des utilisateurs avec le code de réponse 366.
|
||||
|
||||
std::stringstream endOfNamesMsg;
|
||||
endOfNamesMsg << ":server 366 " << client->getFd() << " " << channelName << " :End of /NAMES list.\r\n";
|
||||
sendToClient(client->getFd(), endOfNamesMsg.str());
|
||||
Fonction getUsersList : Cette fonction génère la liste des utilisateurs dans le canal en utilisant le format correct.
|
||||
|
||||
std::string Server::getUsersList(Channel *channel)
|
||||
{
|
||||
std::vector<Client *> clients = channel->getClients();
|
||||
std::stringstream ss;
|
||||
ss << ":server 353 " << clients[0]->getFd() << " = " << channel->getName() << " :";
|
||||
for (size_t i = 0; i < clients.size(); ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
ss << " ";
|
||||
ss << clients[i]->getFd();
|
||||
}
|
||||
ss << "\r\n";
|
||||
return ss.str();
|
||||
}
|
||||
Avec ces modifications, votre serveur IRC devrait maintenant informer correctement le client HexChat des utilisateurs présents dans un canal, ce qui devrait faire apparaître les canaux et leurs utilisateurs correctement dans l'interface du client.
|
||||
|
||||
*/
|
||||
@ -1,63 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ModeWhoHandler.cpp :+: :+: :+: */
|
||||
/* Who.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/17 16:09:20 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/05/19 20:52:30 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/05/21 13:48:51 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ModeWhoHandler.hpp"
|
||||
#include "Who.hpp"
|
||||
#include "Channel.hpp"
|
||||
#include "RPL.hpp"
|
||||
#include <sstream>
|
||||
|
||||
ModeWhoHandler::ModeWhoHandler(Server *server)
|
||||
WhoHandler::WhoHandler(Server *server)
|
||||
: _server(server)
|
||||
{
|
||||
}
|
||||
|
||||
void ModeWhoHandler::handleModeCommand(Client *client, const std::string &command)
|
||||
{
|
||||
std::istringstream iss(command);
|
||||
std::string cmd, channelName, mode, user;
|
||||
iss >> cmd >> channelName >> mode >> user;
|
||||
|
||||
std::map<std::string, Channel *> &channels = _server->getChannels();
|
||||
if (channels.find(channelName) == channels.end())
|
||||
{
|
||||
_server->sendToClient(client->getFd(), ERR_NOSUCHCHANNEL(client->getFd(), channelName));
|
||||
return;
|
||||
}
|
||||
|
||||
Channel *channel = channels[channelName];
|
||||
if (mode == "+o")
|
||||
{
|
||||
if (client->isOperator())
|
||||
{
|
||||
Client *targetClient = _server->getClientByName(user);
|
||||
if (targetClient)
|
||||
{
|
||||
channel->addOperator(targetClient);
|
||||
_server->sendToClient(client->getFd(), RPL_CHANNELMODEIS(client->getFd(), channelName, "+o"));
|
||||
_server->log("Client " + user + " is now an operator in channel " + channelName, GREEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
_server->sendToClient(client->getFd(), ERR_NOSUCHNICK(client->getFd(), user));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_server->sendToClient(client->getFd(), ERR_CHANOPRIVSNEEDED(client->getFd(), channelName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ModeWhoHandler::handleWhoCommand(Client *client, const std::string &command)
|
||||
void WhoHandler::handleWhoCommand(Client *client, const std::string &command)
|
||||
{
|
||||
std::istringstream iss(command);
|
||||
std::string cmd, mask;
|
||||
@ -86,7 +49,7 @@ void ModeWhoHandler::handleWhoCommand(Client *client, const std::string &command
|
||||
_server->sendToClient(client->getFd(), RPL_ENDOFWHO(client->getFd(), mask));
|
||||
}
|
||||
|
||||
void ModeWhoHandler::handleWhoisCommand(Client *client, const std::string &command)
|
||||
void WhoHandler::handleWhoisCommand(Client *client, const std::string &command)
|
||||
{
|
||||
std::istringstream iss(command);
|
||||
std::string cmd, target;
|
||||
Loading…
x
Reference in New Issue
Block a user