mirror of
https://github.com/Ladebeze66/ft_irc.git
synced 2026-11-09 13:17:13 +01:00
Initial commit
This commit is contained in:
48
ft_irc3/includes/AdditionalCommands.hpp
Normal file
48
ft_irc3/includes/AdditionalCommands.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* AdditionalCommands.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/21 18:09:05 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/01 18:48:32 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ADDITIONALCOMMANDS_HPP
|
||||
#define ADDITIONALCOMMANDS_HPP
|
||||
|
||||
#include "Client.hpp"
|
||||
#include "Server.hpp"
|
||||
#include "Channel.hpp"
|
||||
#include "CommandHandler.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "RPL.hpp"
|
||||
#include "Who.hpp"
|
||||
#include "InviteHandler.hpp"
|
||||
#include "TopicHandler.hpp"
|
||||
#include "KickHandler.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
class Server;
|
||||
class Client;
|
||||
class Channel;
|
||||
class AdditionalCommands
|
||||
{
|
||||
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
|
||||
45
ft_irc3/includes/BotFilter.hpp
Normal file
45
ft_irc3/includes/BotFilter.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* BotFilter.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/06 11:44:44 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/06 13:41:41 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BOTFILTER_HPP
|
||||
#define BOTFILTER_HPP
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
|
||||
#include "Server.hpp"
|
||||
#include "Client.hpp"
|
||||
#include "Channel.hpp"
|
||||
|
||||
class BotFilter
|
||||
{
|
||||
public:
|
||||
BotFilter(Server *server);
|
||||
void loadBadWords(const std::string &fileName);
|
||||
bool checkMessage(Client *client, Channel *channel, const std::string &message);
|
||||
|
||||
private:
|
||||
Server *_server;
|
||||
std::vector<std::string> _badWords;
|
||||
std::map<int, int> _warnings;
|
||||
|
||||
bool containsBadWords(const std::string &message);
|
||||
void warnClient(Client *client, Channel *channel);
|
||||
void kickClient(Client *client, Channel *channel);
|
||||
};
|
||||
|
||||
#endif
|
||||
81
ft_irc3/includes/Channel.hpp
Normal file
81
ft_irc3/includes/Channel.hpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Channel.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/15 12:41:35 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/04 16:12:23 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CHANNEL_HPP
|
||||
#define CHANNEL_HPP
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <ctime>
|
||||
|
||||
#include "RPL.hpp"
|
||||
#include "Client.hpp"
|
||||
#include "Server.hpp"
|
||||
|
||||
class Server;
|
||||
class Client;
|
||||
|
||||
class 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);
|
||||
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);
|
||||
std::string getKey();
|
||||
|
||||
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
|
||||
68
ft_irc3/includes/Client.hpp
Normal file
68
ft_irc3/includes/Client.hpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Client.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/15 12:15:42 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/06 13:23:23 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CLIENT_HPP
|
||||
#define CLIENT_HPP
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
|
||||
class Client
|
||||
{
|
||||
public:
|
||||
Client(int fd, const std::string &nickname, const std::string &user, const std::string &host, const std::string &password, const std::string &realname);
|
||||
|
||||
int getFd() const;
|
||||
const std::string &getNickname() const;
|
||||
void setNickname(const std::string &nickname);
|
||||
const std::string &getUser() const;
|
||||
void setUser(const std::string &user);
|
||||
const std::string &getHost() const;
|
||||
void setHost(const std::string &host);
|
||||
const std::string &getPassword() const;
|
||||
void setPassword(const std::string &password);
|
||||
const std::string &getRealName() const;
|
||||
void setRealName(const std::string &realname);
|
||||
bool isAuthenticated() const;
|
||||
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);
|
||||
std::string getKey() const;
|
||||
void setkey(const std::string &key);
|
||||
char buffer[1024];
|
||||
char buffer2[1024];
|
||||
void joinChannel(const std::string &channel);
|
||||
void leaveChannel(const std::string &channel);
|
||||
const std::set<std::string> &getChannels() const;
|
||||
|
||||
private:
|
||||
int _fd;
|
||||
std::string _nickname;
|
||||
std::string _user;
|
||||
std::string _host;
|
||||
std::string _password;
|
||||
std::string _realname;
|
||||
bool _authenticated;
|
||||
bool _operator;
|
||||
bool _away;
|
||||
std::string _awayMessage;
|
||||
std::string _key;
|
||||
std::set<std::string> _channels;
|
||||
};
|
||||
|
||||
#endif
|
||||
56
ft_irc3/includes/ClientManager.hpp
Normal file
56
ft_irc3/includes/ClientManager.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ClientManager.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/15 18:30:07 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/06 13:01:05 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CLIENTMANAGER_HPP
|
||||
#define CLIENTMANAGER_HPP
|
||||
|
||||
#include "Client.hpp"
|
||||
#include "Channel.hpp"
|
||||
#include "Server.hpp"
|
||||
#include "CommandHandler.hpp"
|
||||
#include "RPL.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "BotFilter.hpp"
|
||||
|
||||
#include <poll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <fcntl.h>
|
||||
#include <iostream>
|
||||
#include <netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class Server;
|
||||
class Client;
|
||||
class BotFilter;
|
||||
|
||||
class ClientManager
|
||||
{
|
||||
public:
|
||||
ClientManager(Server *server);
|
||||
void acceptClient();
|
||||
void handleClientNext(int client_fd, char * buffer, int bytes_received);
|
||||
void handleClient(int client_fd);
|
||||
void removeClient(int client_fd);
|
||||
|
||||
private:
|
||||
Server *_server;
|
||||
BotFilter *_botFilter;
|
||||
};
|
||||
|
||||
#endif
|
||||
62
ft_irc3/includes/CommandHandler.hpp
Normal file
62
ft_irc3/includes/CommandHandler.hpp
Normal file
@@ -0,0 +1,62 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* CommandHandler.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/15 18:14:12 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/01 18:47:51 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef COMMANDHANDLER_HPP
|
||||
#define COMMANDHANDLER_HPP
|
||||
|
||||
#include "Utils.hpp"
|
||||
#include "Server.hpp"
|
||||
#include "Client.hpp"
|
||||
#include "Channel.hpp"
|
||||
#include "Who.hpp"
|
||||
#include "AdditionalCommands.hpp"
|
||||
#include "RPL.hpp"
|
||||
#include "Join.hpp"
|
||||
#include "Welcome.hpp"
|
||||
#include "ModeHandler.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
class Server;
|
||||
class Client;
|
||||
class Channel;
|
||||
class WhoHandler;
|
||||
class AdditionalCommands;
|
||||
class ModeHandler;
|
||||
|
||||
class CommandHandler
|
||||
{
|
||||
private:
|
||||
Server *_server;
|
||||
AdditionalCommands *_additionalCommands;
|
||||
ModeHandler *_modeHandler;
|
||||
|
||||
|
||||
public:
|
||||
CommandHandler(Server *server);
|
||||
bool isValidNickname(const std::string& nickname);
|
||||
bool isNicknameInUse(const std::string& nickname);
|
||||
void handleNick(Client* client, const std::vector<std::string>& tokens);
|
||||
|
||||
void handleUser(Client* client, const std::vector<std::string>& tokens);
|
||||
void handlePingCommand(Client* client, const std::vector<std::string>& tokens);
|
||||
void handleCommand(Client *client, const std::string &command);
|
||||
void handleCapCommand(Client* client, const std::vector<std::string>& tokens);
|
||||
void handlePassCommand(Client* client, const std::vector<std::string>& tokens);
|
||||
void handleQuitCommand(Client* client, const std::vector<std::string>& tokens);
|
||||
void handleErrorCommand(Client* client, const std::string &message);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
40
ft_irc3/includes/InviteHandler.hpp
Normal file
40
ft_irc3/includes/InviteHandler.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* InviteHandler.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/30 13:01:50 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/01 18:51:00 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"
|
||||
#include "Utils.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
|
||||
40
ft_irc3/includes/Join.hpp
Normal file
40
ft_irc3/includes/Join.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Join.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/21 19:51:08 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/01 18:51:10 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef JOIN_HPP
|
||||
#define JOIN_HPP
|
||||
|
||||
#include <string>
|
||||
#include "Client.hpp"
|
||||
#include "Server.hpp"
|
||||
#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);
|
||||
void sendJoinSuccess(Client *client, Channel *channel, Server *server);
|
||||
std::string getUsersList(Channel *channel);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
35
ft_irc3/includes/KickHandler.hpp
Normal file
35
ft_irc3/includes/KickHandler.hpp
Normal 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
|
||||
52
ft_irc3/includes/ModeHandler.hpp
Normal file
52
ft_irc3/includes/ModeHandler.hpp
Normal 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/06/04 14:00:47 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(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(Client *client, 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
|
||||
552
ft_irc3/includes/RPL.hpp
Normal file
552
ft_irc3/includes/RPL.hpp
Normal file
@@ -0,0 +1,552 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* RPL.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 15:12:47 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/06 12:28:50 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef RPL_HPP
|
||||
#define RPL_HPP
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include "Client.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "Channel.hpp"
|
||||
|
||||
#define SERVER_NAME "IRC_Server"
|
||||
#define SERVER_VERSION "1.0"
|
||||
#define USER_MODES "None"
|
||||
#define CHANNEL_MODES "l"
|
||||
#define CHANNEL_MODES_WITH_PARAMS "l"
|
||||
|
||||
|
||||
#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())
|
||||
|
||||
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)
|
||||
<< "!" << CLIENT_USER(client) << "@" << CLIENT_HOST(client) << "\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 004 " << CLIENT_NICK(client) << " "
|
||||
<< SERVER_NAME << " " << SERVER_VERSION << " "
|
||||
<< USER_MODES << " " << CHANNEL_MODES << " "
|
||||
<< CHANNEL_MODES_WITH_PARAMS << "\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 301 " << CLIENT_NICK(client) << " " << target << " :" << message << "\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string RPL_WHOISUSER(Client *client, Client* target)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 311 " << CLIENT_NICK(client) << " " << CLIENT_NICK(target) << " "
|
||||
<< CLIENT_USER(target) << " " << CLIENT_HOST(target) << " * :" << CLIENT_REALNAME(target) << "\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string RPL_WHOISSERVER(Client *client, const std::string& targetNick, const std::string& serverInfo)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 312 " << CLIENT_NICK(client) << " " << targetNick << " " << SERVER_NAME
|
||||
<< " :" << serverInfo << "\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string RPL_ENDOFWHO(Client *client, const std::string& channel)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 315 " << CLIENT_NICK(client) << " " << channel << " :End of /WHO list.\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string RPL_ENDOFWHOIS(Client *client, const std::string& targetNick)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 318 " << CLIENT_NICK(client) << " " << targetNick << " :End of /WHOIS list.\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string RPL_LIST(Client *client, const std::string& channel, int numVisible, const std::string& topic)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 322 " << CLIENT_NICK(client) << " " << channel << " " << numVisible << " :" << topic << "\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string RPL_LISTEND(Client *client)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 323 " << CLIENT_NICK(client) << " :End of /LIST\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string RPL_CHANNELMODEIS(int clientFd, const std::string& channel, const std::string& mode)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
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)
|
||||
{
|
||||
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_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_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)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 337 " << CLIENT_NICK(client) << " " << channel << " :End of channel invite list\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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 353 " << CLIENT_NICK(client) << " = " << channel << " :" << users << "\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string RPL_WHOREPLY(const std::string& channel, Client* target)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 352 " << CLIENT_NICK(target) << " " << channel << " "
|
||||
<< CLIENT_USER(target) << " " << CLIENT_HOST(target) << " " << SERVER_NAME << " "
|
||||
<< CLIENT_NICK(target) << " H :0 " << CLIENT_REALNAME(target) << "\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 372 " << CLIENT_NICK(client)
|
||||
<< " :- " << line << "\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 376 " << CLIENT_NICK(client)
|
||||
<< " :End of /MOTD command.\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string ERR_NOSUCHNICK(Client *client, const std::string& nick)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 401 " << CLIENT_NICK(client) << " " << nick << " :No such nick/channel\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string ERR_NOSUCHCHANNEL(Client *client, const std::string& channel)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 403 " << CLIENT_NICK(client) << " " << channel << " :No such channel\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 405 " << CLIENT_NICK(client) << " " << channel << " :You have joined too many channels\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
// RPL Error Messages
|
||||
inline std::string ERR_NOORIGIN(Client* client)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 409 " << CLIENT_NICK(client) << " :No origin specified\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 422 " << CLIENT_NICK(client)
|
||||
<< " :MOTD File is missing\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string ERR_NONICKNAMEGIVEN(Client* client)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 431 " << CLIENT_NICK(client) << " :No nickname given\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string ERR_ERRONEUSNICKNAME(Client* client, const std::string& nickname)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 432 " << CLIENT_NICK(client) << " " << nickname << " :Erroneous nickname\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string ERR_NICKNAMEINUSE(Client* client, const std::string& nickname)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 433 " << CLIENT_NICK(client) << " " << nickname << " :Nickname is already in use\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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_NOTREGISTERED(Client* client)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 451 " << CLIENT_NICK(client) << " :You have not registered\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
//RPL Password
|
||||
// RPL Error Messages
|
||||
inline std::string ERR_NEEDMOREPARAMS(Client* client, const std::string& command)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 461 " << CLIENT_NICK(client) << " " << command << " :Not enough parameters\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string ERR_ALREADYREGISTERED(Client* client)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 462 " << CLIENT_NICK(client) << " :You may not reregister\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string ERR_PASSWDMISMATCH(Client* client)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 464 " << CLIENT_NICK(client) << " :Password incorrect\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_KEYSET(Client* client, const std::string& channel)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 467 " << CLIENT_NICK(client) << " " << channel
|
||||
<< " :Channel key already set\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string ERR_LINKSET(Client* client, const std::string& channel)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 469 " << CLIENT_NICK(client) << " " << channel
|
||||
<< " :No key set\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
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_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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 476 " << CLIENT_NICK(client) << " " << channel << " :Bad channel mask\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string RPL_NOCHANMODES(Client *client, const std::string& channel)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 477 " << CLIENT_NICK(client) << " " << channel << " :Channel doesn't support modes\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string ERR_CHANOPRIVSNEEDED(Client *client, const std::string& channel)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 482 " << CLIENT_NICK(client) << " " << channel << " :You're not channel operator\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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 RPL_PONG(const std::string& token)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " PONG " << SERVER_NAME << " " << token << "\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string RPL_CAP(Client *client, const std::string& subcommand, const std::string& capabilities)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " CAP " << CLIENT_NICK(client) << " " << subcommand << " :" << capabilities << "\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string RPL_PASSACCEPTED(Client* client)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " NOTICE " << CLIENT_NICK(client)
|
||||
<< " :Password accepted!\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string RPL_CAPEND(Client *client)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " CAP " << CLIENT_NICK(client) << " END\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string MODEACCEPTMESSAGE(Client *client, std::string channel, const std::string& mode)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << client->getNickname() << " MODE " << channel << " " << mode << " :" << "\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
inline std::string BOTMESSAGE(Client *client, std::string channel, const std::string& message)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << client->getNickname() << " WARNING " << channel << " " << message << " :" << "\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
#endif
|
||||
91
ft_irc3/includes/Server.hpp
Normal file
91
ft_irc3/includes/Server.hpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Server.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/15 12:15:13 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/06 12:04:58 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 "ModeHandler.hpp"
|
||||
#include "TopicHandler.hpp"
|
||||
#include "BotFilter.hpp"
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <poll.h>
|
||||
|
||||
class Client;
|
||||
class Channel;
|
||||
class ClientManager;
|
||||
class CommandHandler;
|
||||
class AdditionalCommands;
|
||||
class ModeHandler;
|
||||
class TopicHandler;
|
||||
class BotFilter;
|
||||
|
||||
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);
|
||||
|
||||
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 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;
|
||||
BotFilter *_botFilter;
|
||||
|
||||
friend class ClientManager;
|
||||
friend class CommandHandler;
|
||||
friend class ModeHandler;
|
||||
friend class TopicHandler;
|
||||
|
||||
private:
|
||||
void initServer();
|
||||
void handleServerCommands();
|
||||
};
|
||||
|
||||
#endif
|
||||
38
ft_irc3/includes/TopicHandler.hpp
Normal file
38
ft_irc3/includes/TopicHandler.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* TopicHandler.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/30 17:04:33 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/01 19:02:10 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef TOPIC_HANDLER_HPP
|
||||
#define TOPIC_HANDLER_HPP
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include "Server.hpp"
|
||||
#include "Client.hpp"
|
||||
#include "Channel.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
|
||||
class TopicHandler
|
||||
{
|
||||
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);
|
||||
|
||||
Server* _server;
|
||||
};
|
||||
|
||||
#endif
|
||||
30
ft_irc3/includes/Utils.hpp
Normal file
30
ft_irc3/includes/Utils.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Utils.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/15 12:16:02 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/01 15:13:40 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef UTILS_HPP
|
||||
#define UTILS_HPP
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#define RESET "\033[0m"
|
||||
#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);
|
||||
|
||||
#endif
|
||||
29
ft_irc3/includes/Welcome.hpp
Normal file
29
ft_irc3/includes/Welcome.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Welcome.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/21 19:53:17 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/01 19:02:40 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef WELCOME_HPP
|
||||
#define WELCOME_HPP
|
||||
|
||||
#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);
|
||||
};
|
||||
|
||||
#endif
|
||||
38
ft_irc3/includes/Who.hpp
Normal file
38
ft_irc3/includes/Who.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Who.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/17 16:08:48 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/01 19:03:06 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef WHO_HPP
|
||||
#define WHO_HPP
|
||||
|
||||
#include "Server.hpp"
|
||||
#include "Client.hpp"
|
||||
#include "Channel.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "RPL.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#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);
|
||||
|
||||
private:
|
||||
Server *_server;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user