ajoutKick

This commit is contained in:
2024-06-01 19:19:18 +02:00
parent 49537a7282
commit 0c3c24a2f1
26 changed files with 933 additions and 659 deletions

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 18:09:05 by fgras-ca #+# #+# */
/* Updated: 2024/05/30 17:10:18 by fgras-ca ### ########.fr */
/* Updated: 2024/06/01 18:48:32 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,30 +22,27 @@
#include "Who.hpp"
#include "InviteHandler.hpp"
#include "TopicHandler.hpp"
#include "KickHandler.hpp"
#include <sstream>
#include <string>
#include <fstream>
// Forward declarations
class Server;
class Client;
class Channel;
class CommandHandler;
class AdditionalCommands
{
private:
Server *_server;
CommandHandler *_commandhandler;
//InviteHandler *_inviteHandler;
public:
AdditionalCommands(Server *server);
void processCommand(Client *client, const std::string &command);
void broadcastChannelList(Client *client, Server *server);
void handlePartCommand(Server *server, Client *client, const std::string &command);
void handleNickCommand(Server *server, Client *client, const std::string &command);
void handlePrivmsgCommand(Server *server, Client *client, const std::string &command);
private:
Server *_server;
public:
AdditionalCommands(Server *server);
void processCommand(Client *client, const std::string &command);
void broadcastChannelList(Client *client, Server *server);
void handlePartCommand(Server *server, Client *client, const std::string &command);
void handleNickCommand(Server *server, Client *client, const std::string &command);
void handlePrivmsgCommand(Server *server, Client *client, const std::string &command);
};
#endif // ADDITIONALCOMMANDS_HPP
#endif

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 12:41:35 by fgras-ca #+# #+# */
/* Updated: 2024/05/30 18:32:18 by fgras-ca ### ########.fr */
/* Updated: 2024/06/01 18:49:53 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -28,57 +28,53 @@ class Client;
class Channel
{
public:
Channel(const std::string &name);
~Channel();
public:
Channel(const std::string &name);
~Channel();
const std::string &getName() const;
void addClient(Client *client);
void removeClient(Client *client);
bool isEmpty() const;
const std::vector<Client *> &getClients() const;
void addOperator(Client *client);
bool isOperator(Client *client) const;
void removeOperator(Client *client); // Ajouté
bool hasClient(Client *client) const;
void broadcast(const std::string &message, Client *_client, Server *_server);
const std::string &getName() const;
void addClient(Client *client);
void removeClient(Client *client);
bool isEmpty() const;
const std::vector<Client *> &getClients() const;
void addOperator(Client *client);
bool isOperator(Client *client) const;
void removeOperator(Client *client); // Ajouté
bool hasClient(Client *client) const;
void broadcast(const std::string &message, Client *_client, Server *_server);
bool isBanned(Client *client) const;
bool isFull() const;
bool isInviteOnly() const;
bool isInvited(Client *client) const;
bool checkKey(const std::string &key) const;
const std::string &getTopic() const;
const std::string &getTopicSetter() const;
time_t getTopicTime() const;
void setTopic(const std::string &topic, const std::string &setter);
// Ajouts
bool isBanned(Client *client) const;
bool isFull() const;
bool isInviteOnly() const;
bool isInvited(Client *client) const;
bool checkKey(const std::string &key) const;
const std::string &getTopic() const;
const std::string &getTopicSetter() const;
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é
bool getTopicProtection() const;
void addInvitedClient(Client* client);
private:
std::string _name;
std::vector<Client *> _clients;
std::vector<Client *> _operators;
std::set<Client *> _bannedClients;
std::set<Client *> _invitedClients;
std::string _key;
std::string _topic;
std::string _topicSetter;
time_t _topicTime;
size_t _clientLimit;
bool _inviteOnly;
bool _topicProtection; // Ajouté
void setClientLimit(size_t limit);
size_t getClientLimit() const;
void setInviteOnly(bool inviteOnly);
void setKey(const std::string &key);
void setTopicProtection(bool protection);
std::string getModes() const;
bool getTopicProtection() const;
void addInvitedClient(Client* client);
private:
std::string _name;
std::vector<Client *> _clients;
std::vector<Client *> _operators;
std::set<Client *> _bannedClients;
std::set<Client *> _invitedClients;
std::string _key;
std::string _topic;
std::string _topicSetter;
time_t _topicTime;
size_t _clientLimit;
bool _inviteOnly;
bool _topicProtection;
};
#endif // CHANNEL_HPP
#endif

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 12:15:42 by fgras-ca #+# #+# */
/* Updated: 2024/05/31 11:31:54 by fgras-ca ### ########.fr */
/* Updated: 2024/06/01 18:47:36 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -35,13 +35,13 @@ public:
void authenticate();
bool isOperator() const;
void setOperator(bool isOperator);
// Ajout des méthodes pour la gestion du statut "away"
bool isAway() const;
const std::string &getAwayMessage() const;
void setAwayMessage(const std::string &message);
void setAway(bool away);
const std::string &getkey() const;
std::string getKey() const;
void setkey(const std::string &key);
private:
@@ -58,5 +58,4 @@ private:
std::string _key;
};
#endif // CLIENT_HPP
#endif

View File

@@ -6,15 +6,13 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 18:30:07 by fgras-ca #+# #+# */
/* Updated: 2024/05/28 14:17:28 by fgras-ca ### ########.fr */
/* Updated: 2024/06/01 18:50:30 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CLIENTMANAGER_HPP
#define CLIENTMANAGER_HPP
#include <map>
#include <vector>
#include "Client.hpp"
#include "Channel.hpp"
#include "Server.hpp"
@@ -33,21 +31,22 @@
#include <netdb.h>
#include <arpa/inet.h>
#include <fstream>
#include <map>
#include <vector>
class Server;
class Client;
class ClientManager
{
public:
ClientManager(Server *server);
void acceptClient();
void handleClient(int client_fd);
void removeClient(int client_fd);
public:
ClientManager(Server *server);
void acceptClient();
void handleClient(int client_fd);
void removeClient(int client_fd);
private:
Server *_server;
private:
Server *_server;
};
#endif

View File

@@ -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/30 12:42:22 by fgras-ca ### ########.fr */
/* Updated: 2024/06/01 18:47:51 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -59,4 +59,4 @@ public:
};
#endif // COMMANDHANDLER_HPP
#endif

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/30 13:01:50 by fgras-ca #+# #+# */
/* Updated: 2024/05/30 17:48:41 by fgras-ca ### ########.fr */
/* Updated: 2024/06/01 18:51:00 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -27,13 +27,14 @@ class Server;
class Client;
class Channel;
class InviteHandler {
public:
InviteHandler(Server* server);
void handleInviteCommand(Client* client, const std::string& command);
class InviteHandler
{
public:
InviteHandler(Server* server);
void handleInviteCommand(Client* client, const std::string& command);
private:
Server* _server;
private:
Server* _server;
};
#endif // INVITEHANDLER_HPP
#endif

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 19:51:08 by fgras-ca #+# #+# */
/* Updated: 2024/05/30 17:48:55 by fgras-ca ### ########.fr */
/* Updated: 2024/06/01 18:51:10 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,15 +19,22 @@
#include "Channel.hpp"
#include "RPL.hpp"
#include "Utils.hpp"
#include "Server.hpp"
#include "Channel.hpp"
#include "Client.hpp"
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
class JoinHandler
{
public:
void handleJoinCommand(Client *client, const std::string &channelName, Server *server);
public:
void handleJoinCommand(Client *client, const std::string &channelName, Server *server);
void sendJoinSuccess(Client *client, Channel *channel, Server *server);
std::string getUsersList(Channel *channel);
private:
void sendJoinSuccess(Client *client, Channel *channel, Server *server);
std::string getUsersList(Channel *channel);
};
#endif // JOIN_HPP
#endif

View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* KickHandler.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/01 16:59:42 by fgras-ca #+# #+# */
/* Updated: 2024/06/01 18:51:26 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef KICKHANDLER_HPP
#define KICKHANDLER_HPP
#include "Server.hpp"
#include "Client.hpp"
#include "Channel.hpp"
#include "Utils.hpp"
#include <string>
#include <vector>
#include <sstream>
class KickHandler
{
public:
KickHandler(Server* server);
void handleKickCommand(Client* client, const std::string& command);
private:
Server* _server;
};
#endif

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/30 11:12:57 by fgras-ca #+# #+# */
/* Updated: 2024/05/31 11:21:04 by fgras-ca ### ########.fr */
/* Updated: 2024/06/01 18:52:10 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -31,23 +31,22 @@ class Channel;
class ModeHandler
{
public:
ModeHandler(Server* server);
void handleModeCommand(Client* client, const std::string& command);
public:
ModeHandler(Server* server);
void handleModeCommand(Client* client, const std::string& command);
private:
Server* _server;
private:
Server* _server;
void handleUserMode(Client* client, const std::vector<std::string>& tokens);
void handleChannelMode(Client* client, const std::vector<std::string>& tokens);
void handleUserMode(Client* client, const std::vector<std::string>& tokens);
void handleChannelMode(Client* client, const std::vector<std::string>& tokens);
void setChannelMode(Client *client, 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(Client *client, Channel* channel, bool adding, const std::string& argument);
void applyModeT(Channel* channel, bool adding);
void applyModeO(Client *client, Channel* channel, bool adding, const std::string& argument);
void setChannelMode(Client *client, Channel* channel, const std::string& mode, bool adding, const std::string& argument);
void applyModeL(Client *client, Channel* channel, bool adding, const std::string& argument);
void applyModeI(Channel* channel, bool adding);
void applyModeK(Client *client, Channel* channel, bool adding, const std::string& argument);
void applyModeT(Channel* channel, bool adding);
void applyModeO(Client *client, Channel* channel, bool adding, const std::string& argument);
};
#endif // MODEHANDLER_HPP
#endif

View File

@@ -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/31 11:18:49 by fgras-ca ### ########.fr */
/* Updated: 2024/06/01 18:58:37 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,6 +15,7 @@
#include <string>
#include <sstream>
#include "Client.hpp"
#include "Utils.hpp"
@@ -25,16 +26,14 @@
#define CHANNEL_MODES_WITH_PARAMS "l"
// Macros pour accéder aux champs du client
#define CLIENT_FD(client) (client->getFd())
#define CLIENT_NICK(client) ((client)->getNickname())
#define CLIENT_USER(client) ((client)->getUser())
#define CLIENT_HOST(client) ((client)->getHost())
#define CLIENT_REALNAME(client) ((client)->getRealName())
// Fonctions pour générer les réponses RPL
inline std::string RPL_WELCOME(Client* client) {
inline std::string RPL_WELCOME(Client* client)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 001 " << CLIENT_NICK(client)
<< " :Welcome to the Internet Relay Network " << CLIENT_NICK(client)
@@ -42,21 +41,24 @@ inline std::string RPL_WELCOME(Client* client) {
return oss.str();
}
inline std::string RPL_YOURHOST(Client* client) {
inline std::string RPL_YOURHOST(Client* client)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 002 " << CLIENT_NICK(client)
<< " :Your host is " << SERVER_NAME << ", running version " << SERVER_VERSION << "\r\n";
return oss.str();
}
inline std::string RPL_CREATED(Client* client) {
inline std::string RPL_CREATED(Client* client)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 003 " << CLIENT_NICK(client)
<< " :This server was created " << __DATE__ << "\r\n";
return oss.str();
}
inline std::string RPL_MYINFO(Client* client) {
inline std::string RPL_MYINFO(Client* client)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 004 " << CLIENT_NICK(client) << " "
<< SERVER_NAME << " " << SERVER_VERSION << " "
@@ -65,26 +67,28 @@ inline std::string RPL_MYINFO(Client* client) {
return oss.str();
}
inline std::string RPL_ISUPPORT(Client* client, const std::string& tokens) {
inline std::string RPL_ISUPPORT(Client* client, const std::string& tokens)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 005 " << CLIENT_NICK(client)
<< " " << tokens << " :are supported by this server\r\n";
return oss.str();
}
inline std::string RPL_UMODEIS(Client* client, const std::string& modes) {
inline std::string RPL_UMODEIS(Client* client, const std::string& modes)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 221 " << CLIENT_NICK(client) << " :" << modes << "\r\n";
return oss.str();
}
inline std::string RPL_AWAY(Client *client, const std::string& target, const std::string& message) {
inline std::string RPL_AWAY(Client *client, const std::string& target, const std::string& message)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 301 " << CLIENT_NICK(client) << " " << target << " :" << message << "\r\n";
return oss.str();
}
// WHOIS Command RPLs
inline std::string RPL_WHOISUSER(Client *client, Client* target)
{
std::ostringstream oss;
@@ -115,7 +119,6 @@ inline std::string RPL_ENDOFWHOIS(Client *client, const std::string& targetNick)
return oss.str();
}
// RPL Channel List Messages
inline std::string RPL_LIST(Client *client, const std::string& channel, int numVisible, const std::string& topic)
{
std::ostringstream oss;
@@ -130,75 +133,83 @@ inline std::string RPL_LISTEND(Client *client)
return oss.str();
}
// RPL Mode Messages
inline std::string RPL_CHANNELMODEIS(Client *client, const std::string& channel, const std::string& mode)
inline std::string RPL_CHANNELMODEIS(int clientFd, const std::string& channel, const std::string& mode)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 324 " << CLIENT_NICK(client) << " " << channel << " " << mode << "\r\n";
oss << ":" << SERVER_NAME << " 324 " << clientFd << " " << channel << " " << mode << "\r\n";
return oss.str();
}
inline std::string RPL_CREATIONTIME(Client *client, const std::string& channel, time_t creationTime) {
inline std::string RPL_CREATIONTIME(Client *client, const std::string& channel, time_t creationTime)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 329 " << CLIENT_NICK(client) << " " << channel << " " << creationTime << "\r\n";
return oss.str();
}
inline std::string RPL_NOTOPIC(Client* client, const std::string& channel) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 331 " << CLIENT_NICK(client) << " " << channel << " :No topic is set\r\n";
return oss.str();
inline std::string RPL_NOTOPIC(Client* client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 331 " << CLIENT_NICK(client) << " " << channel << " :No topic is set\r\n";
return oss.str();
}
inline std::string RPL_TOPIC(Client* client, const std::string& channel, const std::string& topic) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 332 " << CLIENT_NICK(client) << " " << channel << " :" << topic << "\r\n";
return oss.str();
inline std::string RPL_TOPIC(Client* client, const std::string& channel, const std::string& topic)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 332 " << CLIENT_NICK(client) << " " << channel << " :" << topic << "\r\n";
return oss.str();
}
inline std::string RPL_TOPICWHOTIME(Client* client, const std::string& channel, const std::string& setter, time_t setTime) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 333 " << CLIENT_NICK(client) << " " << channel << " " << setter << " " << setTime << "\r\n";
return oss.str();
inline std::string RPL_TOPICWHOTIME(Client* client, const std::string& channel, const std::string& setter, time_t setTime)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 333 " << CLIENT_NICK(client) << " " << channel << " " << setter << " " << setTime << "\r\n";
return oss.str();
}
inline std::string RPL_INVITELIST(Client *client, const std::string& channel, const std::string& inviteMask) {
inline std::string RPL_INVITELIST(Client *client, const std::string& channel, const std::string& inviteMask)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 336 " << CLIENT_NICK(client) << " " << channel << " " << inviteMask << "\r\n";
return oss.str();
}
inline std::string RPL_ENDOFINVITELIST(Client *client, const std::string& channel) {
inline std::string RPL_ENDOFINVITELIST(Client *client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 337 " << CLIENT_NICK(client) << " " << channel << " :End of channel invite list\r\n";
return oss.str();
}
// Ajoutez cette fonction pour RPL_INVITING
inline std::string RPL_INVITING(Client* client, const std::string& channel, const std::string& nick) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 341 " << CLIENT_NICK(client) << " " << nick << " " << channel << "\r\n";
return oss.str();
inline std::string RPL_INVITING(Client* client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 341 " << CLIENT_NICK(client) << " " << CLIENT_NICK(client) << " " << channel << "\r\n";
return oss.str();
}
inline std::string RPL_EXCEPTLIST(Client *client, const std::string& channel, const std::string& exceptionMask) {
inline std::string RPL_EXCEPTLIST(Client *client, const std::string& channel, const std::string& exceptionMask)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 348 " << CLIENT_NICK(client) << " " << channel << " " << exceptionMask << "\r\n";
return oss.str();
}
inline std::string RPL_ENDOFEXCEPTLIST(Client *client, const std::string& channel) {
inline std::string RPL_ENDOFEXCEPTLIST(Client *client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 349 " << CLIENT_NICK(client) << " " << channel << " :End of channel exception list\r\n";
return oss.str();
}
inline std::string RPL_NAMREPLY(Client* client, const std::string& channel, const std::string& users) {
inline std::string RPL_NAMREPLY(Client* client, const std::string& channel, const std::string& users)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 353 " << CLIENT_NICK(client) << " = " << channel << " :" << users << "\r\n";
return oss.str();
}
// WHO Command RPLs
inline std::string RPL_WHOREPLY(const std::string& channel, Client* target)
{
std::ostringstream oss;
@@ -208,39 +219,45 @@ inline std::string RPL_WHOREPLY(const std::string& channel, Client* target)
return oss.str();
}
inline std::string RPL_ENDOFNAMES(Client* client, const std::string& channel) {
inline std::string RPL_ENDOFNAMES(Client* client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 366 " << CLIENT_NICK(client) << " " << channel << " :End of /NAMES list\r\n";
return oss.str();
}
inline std::string RPL_BANLIST(Client *client, const std::string& channel, const std::string& banMask) {
inline std::string RPL_BANLIST(Client *client, const std::string& channel, const std::string& banMask)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 367 " << CLIENT_NICK(client) << " " << channel << " " << banMask << "\r\n";
return oss.str();
}
inline std::string RPL_ENDOFBANLIST(Client *client, const std::string& channel) {
inline std::string RPL_ENDOFBANLIST(Client *client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 368 " << CLIENT_NICK(client) << " " << channel << " :End of channel ban list\r\n";
return oss.str();
}
inline std::string RPL_MOTD(Client* client, const std::string& line) {
inline std::string RPL_MOTD(Client* client, const std::string& line)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 372 " << CLIENT_NICK(client)
<< " :- " << line << "\r\n";
return oss.str();
}
inline std::string RPL_MOTDSTART(Client* client) {
inline std::string RPL_MOTDSTART(Client* client)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 375 " << CLIENT_NICK(client)
<< " :- " << SERVER_NAME << " Message of the day - \r\n";
return oss.str();
}
inline std::string RPL_ENDOFMOTD(Client* client) {
inline std::string RPL_ENDOFMOTD(Client* client)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 376 " << CLIENT_NICK(client)
<< " :End of /MOTD command.\r\n";
@@ -261,13 +278,15 @@ inline std::string ERR_NOSUCHCHANNEL(Client *client, const std::string& channel)
return oss.str();
}
inline std::string ERR_CANNOTSENDTOCHAN(Client *client, const std::string& channel) {
inline std::string ERR_CANNOTSENDTOCHAN(Client *client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 404 " << CLIENT_NICK(client) << " " << channel << " :Cannot send to channel\r\n";
return oss.str();
}
inline std::string ERR_TOOMANYCHANNELS(Client* client, const std::string& channel) {
inline std::string ERR_TOOMANYCHANNELS(Client* client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 405 " << CLIENT_NICK(client) << " " << channel << " :You have joined too many channels\r\n";
return oss.str();
@@ -281,25 +300,29 @@ inline std::string ERR_NOORIGIN(Client* client)
return oss.str();
}
inline std::string ERR_NORECIPIENT(Client *client, const std::string& command) {
inline std::string ERR_NORECIPIENT(Client *client, const std::string& command)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 411 " << CLIENT_NICK(client) << " :No recipient given (" << command << ")\r\n";
return oss.str();
}
inline std::string ERR_NOTEXTTOSEND(Client *client) {
inline std::string ERR_NOTEXTTOSEND(Client *client)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 412 " << CLIENT_NICK(client) << " :No text to send\r\n";
return oss.str();
}
inline std::string ERR_UNKNOWNCOMMAND(Client* client, const std::string& command) {
inline std::string ERR_UNKNOWNCOMMAND(Client* client, const std::string& command)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 421 " << CLIENT_NICK(client) << " " << command << " :Unknown command\r\n";
return oss.str();
}
inline std::string ERR_NOMOTD(Client* client) {
inline std::string ERR_NOMOTD(Client* client)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 422 " << CLIENT_NICK(client)
<< " :MOTD File is missing\r\n";
@@ -327,25 +350,28 @@ inline std::string ERR_NICKNAMEINUSE(Client* client, const std::string& nickname
return oss.str();
}
inline std::string ERR_USERNOTINCHANNEL(Client *client, const std::string& nick, const std::string& channel) {
inline std::string ERR_USERNOTINCHANNEL(Client *client, const std::string& nick, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 441 " << CLIENT_NICK(client) << " " << nick << " " << channel
<< " :They aren't on that channel\r\n";
return oss.str();
}
inline std::string ERR_NOTONCHANNEL(Client *client, const std::string& channel) {
inline std::string ERR_NOTONCHANNEL(Client *client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 442 " << CLIENT_NICK(client) << " " << channel << " :You're not on that channel\r\n";
return oss.str();
}
// Ajoutez cette fonction pour ERR_USERONCHANNEL
inline std::string ERR_USERONCHANNEL(Client* client, const std::string& nick, const std::string& channel) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 443 " << CLIENT_NICK(client) << " " << nick << " " << channel
<< " :is already on channel\r\n";
return oss.str();
inline std::string ERR_USERONCHANNEL(Client* client, const std::string& nick, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 443 " << CLIENT_NICK(client) << " " << nick << " " << channel
<< " :is already on channel\r\n";
return oss.str();
}
inline std::string ERR_NOTREGISTERED(Client* client)
@@ -378,43 +404,50 @@ inline std::string ERR_PASSWDMISMATCH(Client* client)
return oss.str();
}
inline std::string ERR_INVALIDKEY(Client* client, const std::string& channel) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 467 " << CLIENT_NICK(client) << " " << channel << " :Invalid key\r\n";
return oss.str();
inline std::string ERR_INVALIDKEY(Client* client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 467 " << CLIENT_NICK(client) << " " << channel << " :Invalid key\r\n";
return oss.str();
}
inline std::string ERR_CHANNELISFULL(Client* client, const std::string& channel) {
inline std::string ERR_CHANNELISFULL(Client* client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 471 " << CLIENT_NICK(client) << " " << channel << " :Cannot join channel (channel is full)\r\n";
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_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;
oss << ":" << SERVER_NAME << " 473 " << CLIENT_NICK(client) << " " << channel << " :Cannot join channel (invite only)\r\n";
return oss.str();
}
inline std::string ERR_BANNEDFROMCHAN(Client* client, const std::string& channel) {
inline std::string ERR_BANNEDFROMCHAN(Client* client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 474 " << CLIENT_NICK(client) << " " << channel << " :Cannot join channel (banned)\r\n";
return oss.str();
}
inline std::string ERR_BADCHANNELKEY(Client* client, const std::string& channel) {
inline std::string ERR_BADCHANNELKEY(Client* client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 475 " << CLIENT_NICK(client) << " " << channel << " :Cannot join channel (incorrect key)\r\n";
return oss.str();
}
inline std::string ERR_BADCHANMASK(Client* client, const std::string& channel) {
inline std::string ERR_BADCHANMASK(Client* client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 476 " << CLIENT_NICK(client) << " " << channel << " :Bad channel mask\r\n";
return oss.str();
@@ -434,25 +467,27 @@ inline std::string ERR_CHANOPRIVSNEEDED(Client *client, const std::string& chann
return oss.str();
}
inline std::string ERR_UMODEUNKNOWNFLAG(Client *client) {
inline std::string ERR_UMODEUNKNOWNFLAG(Client *client)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 501 " << CLIENT_NICK(client) << " :Unknown MODE flag\r\n";
return oss.str();
}
inline std::string ERR_USERSDONTMATCH(Client *client) {
inline std::string ERR_USERSDONTMATCH(Client *client)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 502 " << CLIENT_NICK(client) << " :Cannot change mode for other users\r\n";
return oss.str();
}
inline std::string ERR_INVALIDMODEPARAM(Client* client, const std::string& param) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 696 " << CLIENT_NICK(client) << " " << param << " :Invalid mode parameter\r\n";
return oss.str();
inline std::string ERR_INVALIDMODEPARAM(Client* client, const std::string& param)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 696 " << CLIENT_NICK(client) << " " << param << " :Invalid mode parameter\r\n";
return oss.str();
}
// PONG Reply
inline std::string RPL_PONG(const std::string& token)
{
std::ostringstream oss;
@@ -460,7 +495,6 @@ inline std::string RPL_PONG(const std::string& token)
return oss.str();
}
// CAP Command RPLs
inline std::string RPL_CAP(Client *client, const std::string& subcommand, const std::string& capabilities)
{
std::ostringstream oss;
@@ -476,7 +510,6 @@ inline std::string RPL_PASSACCEPTED(Client* client)
return oss.str();
}
// Add this function to handle the CAP END response
inline std::string RPL_CAPEND(Client *client)
{
std::ostringstream oss;
@@ -484,4 +517,4 @@ inline std::string RPL_CAPEND(Client *client)
return oss.str();
}
#endif // RPL_HPP
#endif

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 12:15:13 by fgras-ca #+# #+# */
/* Updated: 2024/05/30 17:13:41 by fgras-ca ### ########.fr */
/* Updated: 2024/06/01 19:01:40 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -46,48 +46,47 @@ class TopicHandler;
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);
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<std::string, Channel *> &getChannels();
std::map<int, Client *> &getClients();
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);
void removePollFd(int clientFd);
std::map<std::string, Channel *> &getChannels();
std::map<int, Client *> &getClients();
const std::string &getPassword() const;
void broadcast(const std::string &message);
Client* getClientByName(const std::string &name);
Channel* getChannelByName(const std::string &name);
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<int, Client *> _clients;
std::map<std::string, Channel *> _channels;
std::vector<struct pollfd> _poll_fds;
ClientManager *_clientManager;
CommandHandler *_commandHandler;
ModeHandler *_modeHandler;
TopicHandler *_topicHandler;
protected:
int _server_fd;
int _port;
std::string _password;
std::map<int, Client *> _clients;
std::map<std::string, Channel *> _channels;
std::vector<struct pollfd> _poll_fds;
ClientManager *_clientManager;
CommandHandler *_commandHandler;
ModeHandler *_modeHandler;
TopicHandler *_topicHandler;
friend class ClientManager;
friend class CommandHandler;
friend class ModeHandler;
friend class TopicHandler;
friend class ClientManager;
friend class CommandHandler;
friend class ModeHandler;
friend class TopicHandler;
private:
void initServer();
void handleServerCommands();
void acceptClient();
void removeClient(int client_fd);
private:
void initServer();
void handleServerCommands();
void acceptClient();
void removeClient(int client_fd);
};
#endif

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/30 17:04:33 by fgras-ca #+# #+# */
/* Updated: 2024/05/30 17:47:56 by fgras-ca ### ########.fr */
/* Updated: 2024/06/01 19:02:10 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -24,15 +24,15 @@
class TopicHandler
{
public:
TopicHandler(Server* server);
void handleTopicCommand(Client* client, const std::string& command);
public:
TopicHandler(Server* server);
void handleTopicCommand(Client* client, const std::string& command);
private:
void viewTopic(Client* client, Channel* channel);
void changeTopic(Client* client, Channel* channel, const std::string& topic);
private:
void viewTopic(Client* client, Channel* channel);
void changeTopic(Client* client, Channel* channel, const std::string& topic);
Server* _server;
Server* _server;
};
#endif

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 12:16:02 by fgras-ca #+# #+# */
/* Updated: 2024/05/16 18:14:58 by fgras-ca ### ########.fr */
/* Updated: 2024/06/01 15:13:40 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,12 +18,12 @@
#include <vector>
#define RESET "\033[0m"
#define RED "\033[31m"
#define GREEN "\033[32m"
#define YELLOW "\033[33m"
#define BLUE "\033[34m"
#define MAGENTA "\033[35m"
#define CYAN "\033[36m"
#define RED "\033[1;31m"
#define GREEN "\033[1;32m"
#define YELLOW "\033[1;33m"
#define BLUE "\033[1;34m"
#define MAGENTA "\033[1;35m"
#define CYAN "\033[1;36m"
std::vector<std::string> split(const std::string &input, const std::string &delimiters);

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 19:53:17 by fgras-ca #+# #+# */
/* Updated: 2024/05/30 17:48:13 by fgras-ca ### ########.fr */
/* Updated: 2024/06/01 19:02:40 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,13 +16,14 @@
#include "Client.hpp"
#include "Server.hpp"
#include "Utils.hpp"
#include <string>
class WelcomeHandler
{
public:
void sendWelcomeMessages(Client *client, Server *server);
void sendMotd(Client *client, Server *server);
public:
void sendWelcomeMessages(Client *client, Server *server);
void sendMotd(Client *client, Server *server);
};
#endif // WELCOME_HPP
#endif

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/17 16:08:48 by fgras-ca #+# #+# */
/* Updated: 2024/05/21 18:04:10 by fgras-ca ### ########.fr */
/* Updated: 2024/06/01 19:03:06 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,16 +23,16 @@
#include <iostream>
class Server;
class WhoHandler
{
public:
WhoHandler(Server *server);
void handleWhoCommand(Client *client, const std::string &command);
void handleWhoisCommand(Client *client, const std::string &command);
public:
WhoHandler(Server *server);
void handleWhoCommand(Client *client, const std::string &command);
void handleWhoisCommand(Client *client, const std::string &command);
private:
Server *_server;
private:
Server *_server;
};
#endif