modif3005soir

This commit is contained in:
2024-05-30 18:50:56 +02:00
parent 7f71877981
commit 4f8d1f3d1f
19 changed files with 436 additions and 244 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 13:10:51 by fgras-ca ### ########.fr */
/* Updated: 2024/05/30 17:10:18 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,6 +21,7 @@
#include "RPL.hpp"
#include "Who.hpp"
#include "InviteHandler.hpp"
#include "TopicHandler.hpp"
#include <sstream>
#include <string>

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 13:09:11 by fgras-ca ### ########.fr */
/* Updated: 2024/05/30 18:32:18 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -39,6 +39,7 @@ public:
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);
@@ -59,8 +60,10 @@ public:
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;
@@ -74,7 +77,8 @@ private:
size_t _clientLimit;
bool _inviteOnly;
bool _topicProtection; // Ajouté
};
#endif // CHANNEL_HPP

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* InviteHanndler.hpp :+: :+: :+: */
/* InviteHandler.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 */
/* Updated: 2024/05/30 17:48:41 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,6 +21,7 @@
#include "Client.hpp"
#include "Channel.hpp"
#include "RPL.hpp"
#include "Utils.hpp"
class Server;
class Client;

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/28 14:17:52 by fgras-ca ### ########.fr */
/* Updated: 2024/05/30 17:48:55 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,6 +18,7 @@
#include "Server.hpp"
#include "Channel.hpp"
#include "RPL.hpp"
#include "Utils.hpp"
class JoinHandler
{

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/30 12:50:39 by fgras-ca ### ########.fr */
/* Updated: 2024/05/30 18:40:48 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -41,12 +41,13 @@ private:
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 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(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

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/30 13:27:52 by fgras-ca ### ########.fr */
/* Updated: 2024/05/30 17:49:15 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,11 +16,12 @@
#include <string>
#include <sstream>
#include "Client.hpp"
#include "Utils.hpp"
#define SERVER_NAME "IRC_Server"
#define SERVER_VERSION "1.0"
#define USER_MODES "+o"
#define CHANNEL_MODES "i/t/k/o/l"
#define USER_MODES "+o/-o"
#define CHANNEL_MODES "none"
#define CHANNEL_MODES_WITH_PARAMS "None"
@@ -43,21 +44,21 @@ inline std::string RPL_WELCOME(Client* client) {
inline std::string RPL_YOURHOST(Client* client) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 002 " << CLIENT_FD(client)
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_FD(client)
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_FD(client) << " "
oss << ":" << SERVER_NAME << " 004 " << CLIENT_NICK(client) << " "
<< SERVER_NAME << " " << SERVER_VERSION << " "
<< USER_MODES << " " << CHANNEL_MODES << " "
<< CHANNEL_MODES_WITH_PARAMS << "\r\n";
@@ -66,111 +67,110 @@ inline std::string RPL_MYINFO(Client* client) {
inline std::string RPL_ISUPPORT(Client* client, const std::string& tokens) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 005 " << CLIENT_FD(client)
oss << ":" << SERVER_NAME << " 005 " << CLIENT_NICK(client)
<< " " << tokens << " :are supported by this server\r\n";
return oss.str();
}
inline std::string RPL_UMODEIS(int clientFd, const std::string& modes) {
inline std::string RPL_UMODEIS(Client* client, const std::string& modes) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 221 " << clientFd << " :" << modes << "\r\n";
oss << ":" << SERVER_NAME << " 221 " << CLIENT_NICK(client) << " :" << modes << "\r\n";
return oss.str();
}
inline std::string RPL_AWAY(int clientFd, 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 " << clientFd << " " << target << " :" << message << "\r\n";
oss << ":" << SERVER_NAME << " 301 " << CLIENT_NICK(client) << " " << target << " :" << message << "\r\n";
return oss.str();
}
// WHOIS Command RPLs
inline std::string RPL_WHOISUSER(int clientFd, Client* target)
inline std::string RPL_WHOISUSER(Client *client, Client* target)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 311 " << clientFd << " " << CLIENT_NICK(target) << " "
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(int clientFd, const std::string& targetNick, const std::string& serverInfo)
inline std::string RPL_WHOISSERVER(Client *client, const std::string& targetNick, const std::string& serverInfo)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 312 " << clientFd << " " << targetNick << " " << SERVER_NAME
oss << ":" << SERVER_NAME << " 312 " << CLIENT_NICK(client) << " " << targetNick << " " << SERVER_NAME
<< " :" << serverInfo << "\r\n";
return oss.str();
}
inline std::string RPL_ENDOFWHO(int clientFd, const std::string& channel)
inline std::string RPL_ENDOFWHO(Client *client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 315 " << clientFd << " " << channel << " :End of /WHO list.\r\n";
oss << ":" << SERVER_NAME << " 315 " << CLIENT_NICK(client) << " " << channel << " :End of /WHO list.\r\n";
return oss.str();
}
inline std::string RPL_ENDOFWHOIS(int clientFd, const std::string& targetNick)
inline std::string RPL_ENDOFWHOIS(Client *client, const std::string& targetNick)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 318 " << clientFd << " " << targetNick << " :End of /WHOIS list.\r\n";
oss << ":" << SERVER_NAME << " 318 " << CLIENT_NICK(client) << " " << targetNick << " :End of /WHOIS list.\r\n";
return oss.str();
}
// RPL Channel List Messages
inline std::string RPL_LIST(int clientFd, const std::string& channel, int numVisible, const std::string& topic)
inline std::string RPL_LIST(Client *client, const std::string& channel, int numVisible, const std::string& topic)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 322 " << clientFd << " " << channel << " " << numVisible << " :" << topic << "\r\n";
oss << ":" << SERVER_NAME << " 322 " << CLIENT_NICK(client) << " " << channel << " " << numVisible << " :" << topic << "\r\n";
return oss.str();
}
inline std::string RPL_LISTEND(int clientFd)
inline std::string RPL_LISTEND(Client *client)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 323 " << clientFd << " :End of /LIST\r\n";
oss << ":" << SERVER_NAME << " 323 " << CLIENT_NICK(client) << " :End of /LIST\r\n";
return oss.str();
}
// RPL Mode Messages
inline std::string RPL_CHANNELMODEIS(int clientFd, const std::string& channel, const std::string& mode)
inline std::string RPL_CHANNELMODEIS(Client *client, const std::string& channel, const std::string& mode)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 324 " << clientFd << " " << channel << " " << mode << "\r\n";
oss << ":" << SERVER_NAME << " 324 " << CLIENT_NICK(client) << " " << channel << " " << mode << "\r\n";
return oss.str();
}
inline std::string RPL_CREATIONTIME(int clientFd, 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 " << clientFd << " " << channel << " " << creationTime << "\r\n";
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";
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();
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 << " 333 " << CLIENT_NICK(client) << " " << channel << " " << setter << " " << setTime << "\r\n";
oss << ":" << SERVER_NAME << " 336 " << CLIENT_NICK(client) << " " << channel << " " << inviteMask << "\r\n";
return oss.str();
}
inline std::string RPL_INVITELIST(int clientFd, const std::string& channel, const std::string& inviteMask) {
inline std::string RPL_ENDOFINVITELIST(Client *client, const std::string& channel) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 336 " << clientFd << " " << channel << " " << inviteMask << "\r\n";
return oss.str();
}
inline std::string RPL_ENDOFINVITELIST(int clientFd, const std::string& channel) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 337 " << clientFd << " " << channel << " :End of channel invite list\r\n";
oss << ":" << SERVER_NAME << " 337 " << CLIENT_NICK(client) << " " << channel << " :End of channel invite list\r\n";
return oss.str();
}
@@ -181,15 +181,15 @@ inline std::string RPL_INVITING(Client* client, const std::string& channel, cons
return oss.str();
}
inline std::string RPL_EXCEPTLIST(int clientFd, 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 " << clientFd << " " << channel << " " << exceptionMask << "\r\n";
oss << ":" << SERVER_NAME << " 348 " << CLIENT_NICK(client) << " " << channel << " " << exceptionMask << "\r\n";
return oss.str();
}
inline std::string RPL_ENDOFEXCEPTLIST(int clientFd, const std::string& channel) {
inline std::string RPL_ENDOFEXCEPTLIST(Client *client, const std::string& channel) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 349 " << clientFd << " " << channel << " :End of channel exception list\r\n";
oss << ":" << SERVER_NAME << " 349 " << CLIENT_NICK(client) << " " << channel << " :End of channel exception list\r\n";
return oss.str();
}
@@ -214,56 +214,56 @@ inline std::string RPL_ENDOFNAMES(Client* client, const std::string& channel) {
return oss.str();
}
inline std::string RPL_BANLIST(int clientFd, 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 " << clientFd << " " << channel << " " << banMask << "\r\n";
oss << ":" << SERVER_NAME << " 367 " << CLIENT_NICK(client) << " " << channel << " " << banMask << "\r\n";
return oss.str();
}
inline std::string RPL_ENDOFBANLIST(int clientFd, const std::string& channel) {
inline std::string RPL_ENDOFBANLIST(Client *client, const std::string& channel) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 368 " << clientFd << " " << channel << " :End of channel ban list\r\n";
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_FD(client)
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_FD(client)
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_FD(client)
oss << ":" << SERVER_NAME << " 376 " << CLIENT_NICK(client)
<< " :End of /MOTD command.\r\n";
return oss.str();
}
inline std::string ERR_NOSUCHNICK(int clientFd, const std::string& nick)
inline std::string ERR_NOSUCHNICK(Client *client, const std::string& nick)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 401 " << clientFd << " " << nick << " :No such nick/channel\r\n";
oss << ":" << SERVER_NAME << " 401 " << CLIENT_NICK(client) << " " << nick << " :No such nick/channel\r\n";
return oss.str();
}
inline std::string ERR_NOSUCHCHANNEL(int clientFd, const std::string& channel)
inline std::string ERR_NOSUCHCHANNEL(Client *client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 403 " << clientFd << " " << channel << " :No such channel\r\n";
oss << ":" << SERVER_NAME << " 403 " << CLIENT_NICK(client) << " " << channel << " :No such channel\r\n";
return oss.str();
}
inline std::string ERR_CANNOTSENDTOCHAN(int clientFd, const std::string& channel) {
inline std::string ERR_CANNOTSENDTOCHAN(Client *client, const std::string& channel) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 404 " << clientFd << " " << channel << " :Cannot send to channel\r\n";
oss << ":" << SERVER_NAME << " 404 " << CLIENT_NICK(client) << " " << channel << " :Cannot send to channel\r\n";
return oss.str();
}
@@ -277,19 +277,19 @@ inline std::string ERR_TOOMANYCHANNELS(Client* client, const std::string& channe
inline std::string ERR_NOORIGIN(Client* client)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 409 " << CLIENT_FD(client) << " :No origin specified\r\n";
oss << ":" << SERVER_NAME << " 409 " << CLIENT_NICK(client) << " :No origin specified\r\n";
return oss.str();
}
inline std::string ERR_NORECIPIENT(int clientFd, const std::string& command) {
inline std::string ERR_NORECIPIENT(Client *client, const std::string& command) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 411 " << clientFd << " :No recipient given (" << command << ")\r\n";
oss << ":" << SERVER_NAME << " 411 " << CLIENT_NICK(client) << " :No recipient given (" << command << ")\r\n";
return oss.str();
}
inline std::string ERR_NOTEXTTOSEND(int clientFd) {
inline std::string ERR_NOTEXTTOSEND(Client *client) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 412 " << clientFd << " :No text to send\r\n";
oss << ":" << SERVER_NAME << " 412 " << CLIENT_NICK(client) << " :No text to send\r\n";
return oss.str();
}
@@ -301,7 +301,7 @@ inline std::string ERR_UNKNOWNCOMMAND(Client* client, const std::string& command
inline std::string ERR_NOMOTD(Client* client) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 422 " << CLIENT_FD(client)
oss << ":" << SERVER_NAME << " 422 " << CLIENT_NICK(client)
<< " :MOTD File is missing\r\n";
return oss.str();
}
@@ -309,34 +309,34 @@ inline std::string ERR_NOMOTD(Client* client) {
inline std::string ERR_NONICKNAMEGIVEN(Client* client)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 431 " << CLIENT_FD(client) << " :No nickname given\r\n";
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_FD(client) << " " << nickname << " :Erroneous nickname\r\n";
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_FD(client) << " " << nickname << " :Nickname is already in use\r\n";
oss << ":" << SERVER_NAME << " 433 " << CLIENT_NICK(client) << " " << nickname << " :Nickname is already in use\r\n";
return oss.str();
}
inline std::string ERR_USERNOTINCHANNEL(int clientFd, 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 " << clientFd << " " << nick << " " << channel
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(int clientFd, const std::string& channel) {
inline std::string ERR_NOTONCHANNEL(Client *client, const std::string& channel) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 442 " << clientFd << " " << channel << " :You're not on that channel\r\n";
oss << ":" << SERVER_NAME << " 442 " << CLIENT_NICK(client) << " " << channel << " :You're not on that channel\r\n";
return oss.str();
}
@@ -351,7 +351,7 @@ inline std::string ERR_USERONCHANNEL(Client* client, const std::string& nick, co
inline std::string ERR_NOTREGISTERED(Client* client)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 451 " << CLIENT_FD(client) << " :You have not registered\r\n";
oss << ":" << SERVER_NAME << " 451 " << CLIENT_NICK(client) << " :You have not registered\r\n";
return oss.str();
}
@@ -360,21 +360,21 @@ inline std::string ERR_NOTREGISTERED(Client* client)
inline std::string ERR_NEEDMOREPARAMS(Client* client, const std::string& command)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 461 " << CLIENT_FD(client) << " " << command << " :Not enough parameters\r\n";
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_FD(client) << " :You may not reregister\r\n";
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_FD(client) << " :Password incorrect\r\n";
oss << ":" << SERVER_NAME << " 464 " << CLIENT_NICK(client) << " :Password incorrect\r\n";
return oss.str();
}
@@ -414,29 +414,29 @@ inline std::string ERR_BADCHANMASK(Client* client, const std::string& channel) {
return oss.str();
}
inline std::string RPL_NOCHANMODES(int clientFd, const std::string& channel)
inline std::string RPL_NOCHANMODES(Client *client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 477 " << clientFd << " " << channel << " :Channel doesn't support modes\r\n";
oss << ":" << SERVER_NAME << " 477 " << CLIENT_NICK(client) << " " << channel << " :Channel doesn't support modes\r\n";
return oss.str();
}
inline std::string ERR_CHANOPRIVSNEEDED(int clientFd, const std::string& channel)
inline std::string ERR_CHANOPRIVSNEEDED(Client *client, const std::string& channel)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 482 " << clientFd << " " << channel << " :You're not channel operator\r\n";
oss << ":" << SERVER_NAME << " 482 " << CLIENT_NICK(client) << " " << channel << " :You're not channel operator\r\n";
return oss.str();
}
inline std::string ERR_UMODEUNKNOWNFLAG(int clientFd) {
inline std::string ERR_UMODEUNKNOWNFLAG(Client *client) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 501 " << clientFd << " :Unknown MODE flag\r\n";
oss << ":" << SERVER_NAME << " 501 " << CLIENT_NICK(client) << " :Unknown MODE flag\r\n";
return oss.str();
}
inline std::string ERR_USERSDONTMATCH(int clientFd) {
inline std::string ERR_USERSDONTMATCH(Client *client) {
std::ostringstream oss;
oss << ":" << SERVER_NAME << " 502 " << clientFd << " :Cannot change mode for other users\r\n";
oss << ":" << SERVER_NAME << " 502 " << CLIENT_NICK(client) << " :Cannot change mode for other users\r\n";
return oss.str();
}
@@ -449,26 +449,26 @@ inline std::string RPL_PONG(const std::string& token)
}
// CAP Command RPLs
inline std::string RPL_CAP(int clientFd, const std::string& subcommand, const std::string& capabilities)
inline std::string RPL_CAP(Client *client, const std::string& subcommand, const std::string& capabilities)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " CAP " << clientFd << " " << subcommand << " :" << capabilities << "\r\n";
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_FD(client)
oss << ":" << SERVER_NAME << " NOTICE " << CLIENT_NICK(client)
<< " :Password accepted!\r\n";
return oss.str();
}
// Add this function to handle the CAP END response
inline std::string RPL_CAPEND(int clientFd)
inline std::string RPL_CAPEND(Client *client)
{
std::ostringstream oss;
oss << ":" << SERVER_NAME << " CAP " << clientFd << " END\r\n";
oss << ":" << SERVER_NAME << " CAP " << CLIENT_NICK(client) << " END\r\n";
return oss.str();
}

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 12:20:53 by fgras-ca ### ########.fr */
/* Updated: 2024/05/30 17:13:41 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,6 +21,7 @@
#include "AdditionalCommands.hpp"
#include "RPL.hpp"
#include "ModeHandler.hpp"
#include "TopicHandler.hpp"
#include <sys/socket.h>
#include <netinet/in.h>
@@ -41,6 +42,7 @@ class ClientManager;
class CommandHandler;
class AdditionalCommands;
class ModeHandler;
class TopicHandler;
class Server
{
@@ -74,10 +76,12 @@ protected:
ClientManager *_clientManager;
CommandHandler *_commandHandler;
ModeHandler *_modeHandler;
TopicHandler *_topicHandler;
friend class ClientManager;
friend class CommandHandler;
friend class ModeHandler;
friend class TopicHandler;
private:
void initServer();

View 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/05/30 17:47:56 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

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/21 19:53:24 by fgras-ca ### ########.fr */
/* Updated: 2024/05/30 17:48:13 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,6 +15,7 @@
#include "Client.hpp"
#include "Server.hpp"
#include "Utils.hpp"
#include <string>
class WelcomeHandler