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> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <sstream>
#include <string>
@@ -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);

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/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<Client *> _clients;
@@ -65,6 +73,7 @@ private:
time_t _topicTime;
size_t _clientLimit;
bool _inviteOnly;
bool _topicProtection; // Ajouté
};
#endif // CHANNEL_HPP

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/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 <string>
#include <sstream>
@@ -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);

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> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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";

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/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 <sys/socket.h>
#include <netinet/in.h>
@@ -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<struct pollfd> _poll_fds;
ClientManager *_clientManager;
CommandHandler *_commandHandler;
ModeHandler *_modeHandler;
friend class ClientManager;
friend class CommandHandler;
friend class ModeHandler;
private:
void initServer();