mirror of
https://github.com/Ladebeze66/ft_irc.git
synced 2025-12-16 05:58:09 +01:00
fef
This commit is contained in:
parent
0fa9a1b3ea
commit
79a4688520
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/21 18:09:05 by fgras-ca #+# #+# */
|
/* Created: 2024/05/21 18:09:05 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/05/21 19:46:40 by fgras-ca ### ########.fr */
|
/* Updated: 2024/05/28 14:16:57 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -34,15 +34,15 @@ class CommandHandler;
|
|||||||
class AdditionalCommands
|
class AdditionalCommands
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Server *_server;
|
Server *_server;
|
||||||
CommandHandler *_commandhandler;
|
CommandHandler *_commandhandler;
|
||||||
public:
|
public:
|
||||||
AdditionalCommands(Server *server);
|
AdditionalCommands(Server *server);
|
||||||
void processCommand(Client *client, const std::string &command);
|
void processCommand(Client *client, const std::string &command);
|
||||||
void broadcastChannelList(Client *client, Server *server);
|
void broadcastChannelList(Client *client, Server *server);
|
||||||
void handlePartCommand(Server *server, Client *client, const std::string &command);
|
void handlePartCommand(Server *server, Client *client, const std::string &command);
|
||||||
void handleNickCommand(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);
|
void handlePrivmsgCommand(Server *server, Client *client, const std::string &command);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADDITIONALCOMMANDS_HPP
|
#endif // ADDITIONALCOMMANDS_HPP
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/15 12:41:35 by fgras-ca #+# #+# */
|
/* Created: 2024/05/15 12:41:35 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/05/28 11:13:12 by fgras-ca ### ########.fr */
|
/* Updated: 2024/05/28 14:16:55 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -29,42 +29,42 @@ class Client;
|
|||||||
class Channel
|
class Channel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Channel(const std::string &name);
|
Channel(const std::string &name);
|
||||||
~Channel();
|
~Channel();
|
||||||
|
|
||||||
const std::string &getName() const;
|
const std::string &getName() const;
|
||||||
void addClient(Client *client);
|
void addClient(Client *client);
|
||||||
void removeClient(Client *client);
|
void removeClient(Client *client);
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
const std::vector<Client *> &getClients() const;
|
const std::vector<Client *> &getClients() const;
|
||||||
void addOperator(Client *client);
|
void addOperator(Client *client);
|
||||||
bool isOperator(Client *client) const;
|
bool isOperator(Client *client) const;
|
||||||
bool hasClient(Client *client) const;
|
bool hasClient(Client *client) const;
|
||||||
void broadcast(const std::string &message, Client *_client, Server *_server);
|
void broadcast(const std::string &message, Client *_client, Server *_server);
|
||||||
|
|
||||||
// Ajouts
|
// Ajouts
|
||||||
bool isBanned(Client *client) const;
|
bool isBanned(Client *client) const;
|
||||||
bool isFull() const;
|
bool isFull() const;
|
||||||
bool isInviteOnly() const;
|
bool isInviteOnly() const;
|
||||||
bool isInvited(Client *client) const;
|
bool isInvited(Client *client) const;
|
||||||
bool checkKey(const std::string &key) const;
|
bool checkKey(const std::string &key) const;
|
||||||
const std::string &getTopic() const;
|
const std::string &getTopic() const;
|
||||||
const std::string &getTopicSetter() const;
|
const std::string &getTopicSetter() const;
|
||||||
time_t getTopicTime() const;
|
time_t getTopicTime() const;
|
||||||
void setTopic(const std::string &topic, const std::string &setter);
|
void setTopic(const std::string &topic, const std::string &setter);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string _name;
|
std::string _name;
|
||||||
std::vector<Client *> _clients;
|
std::vector<Client *> _clients;
|
||||||
std::vector<Client *> _operators;
|
std::vector<Client *> _operators;
|
||||||
std::set<Client *> _bannedClients;
|
std::set<Client *> _bannedClients;
|
||||||
std::set<Client *> _invitedClients;
|
std::set<Client *> _invitedClients;
|
||||||
std::string _key;
|
std::string _key;
|
||||||
std::string _topic;
|
std::string _topic;
|
||||||
std::string _topicSetter;
|
std::string _topicSetter;
|
||||||
time_t _topicTime;
|
time_t _topicTime;
|
||||||
size_t _clientLimit;
|
size_t _clientLimit;
|
||||||
bool _inviteOnly;
|
bool _inviteOnly;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CHANNEL_HPP
|
#endif // CHANNEL_HPP
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/15 12:15:42 by fgras-ca #+# #+# */
|
/* Created: 2024/05/15 12:15:42 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/05/28 14:09:24 by fgras-ca ### ########.fr */
|
/* Updated: 2024/05/28 14:17:16 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -18,41 +18,41 @@
|
|||||||
class Client
|
class Client
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Client(int fd, const std::string &nickname, const std::string &user, const std::string &host, const std::string &password, const std::string &realname);
|
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;
|
int getFd() const;
|
||||||
const std::string &getNickname() const;
|
const std::string &getNickname() const;
|
||||||
void setNickname(const std::string &nickname);
|
void setNickname(const std::string &nickname);
|
||||||
const std::string &getUser() const;
|
const std::string &getUser() const;
|
||||||
void setUser(const std::string &user);
|
void setUser(const std::string &user);
|
||||||
const std::string &getHost() const;
|
const std::string &getHost() const;
|
||||||
void setHost(const std::string &host);
|
void setHost(const std::string &host);
|
||||||
const std::string &getPassword() const;
|
const std::string &getPassword() const;
|
||||||
void setPassword(const std::string &password);
|
void setPassword(const std::string &password);
|
||||||
const std::string &getRealName() const;
|
const std::string &getRealName() const;
|
||||||
void setRealName(const std::string &realname);
|
void setRealName(const std::string &realname);
|
||||||
bool isAuthenticated() const;
|
bool isAuthenticated() const;
|
||||||
void authenticate();
|
void authenticate();
|
||||||
bool isOperator() const;
|
bool isOperator() const;
|
||||||
void setOperator(bool isOperator);
|
void setOperator(bool isOperator);
|
||||||
|
|
||||||
// Ajout des méthodes pour la gestion du statut "away"
|
// Ajout des méthodes pour la gestion du statut "away"
|
||||||
bool isAway() const;
|
bool isAway() const;
|
||||||
const std::string &getAwayMessage() const;
|
const std::string &getAwayMessage() const;
|
||||||
void setAwayMessage(const std::string &message);
|
void setAwayMessage(const std::string &message);
|
||||||
void setAway(bool away);
|
void setAway(bool away);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _fd;
|
int _fd;
|
||||||
std::string _nickname;
|
std::string _nickname;
|
||||||
std::string _user;
|
std::string _user;
|
||||||
std::string _host;
|
std::string _host;
|
||||||
std::string _password;
|
std::string _password;
|
||||||
std::string _realname;
|
std::string _realname;
|
||||||
bool _authenticated;
|
bool _authenticated;
|
||||||
bool _operator;
|
bool _operator;
|
||||||
bool _away;
|
bool _away;
|
||||||
std::string _awayMessage;
|
std::string _awayMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CLIENT_HPP
|
#endif // CLIENT_HPP
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/15 18:30:07 by fgras-ca #+# #+# */
|
/* Created: 2024/05/15 18:30:07 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/05/21 18:01:47 by fgras-ca ### ########.fr */
|
/* Updated: 2024/05/28 14:17:28 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -40,14 +40,14 @@ class Client;
|
|||||||
class ClientManager
|
class ClientManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ClientManager(Server *server);
|
ClientManager(Server *server);
|
||||||
void acceptClient();
|
void acceptClient();
|
||||||
void handleClient(int client_fd);
|
void handleClient(int client_fd);
|
||||||
void removeClient(int client_fd);
|
void removeClient(int client_fd);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Server *_server;
|
Server *_server;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/15 18:14:12 by fgras-ca #+# #+# */
|
/* Created: 2024/05/15 18:14:12 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/05/21 20:15:58 by fgras-ca ### ########.fr */
|
/* Updated: 2024/05/28 14:17:40 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -36,22 +36,22 @@ class AdditionalCommands;
|
|||||||
class CommandHandler
|
class CommandHandler
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Server *_server;
|
Server *_server;
|
||||||
AdditionalCommands *_additionalCommands;
|
AdditionalCommands *_additionalCommands;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CommandHandler(Server *server);
|
CommandHandler(Server *server);
|
||||||
bool isValidNickname(const std::string& nickname);
|
bool isValidNickname(const std::string& nickname);
|
||||||
bool isNicknameInUse(const std::string& nickname);
|
bool isNicknameInUse(const std::string& nickname);
|
||||||
void handleNick(Client* client, const std::vector<std::string>& tokens);
|
void handleNick(Client* client, const std::vector<std::string>& tokens);
|
||||||
|
|
||||||
void handleUser(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 handlePingCommand(Client* client, const std::vector<std::string>& tokens);
|
||||||
void handleCommand(Client *client, const std::string &command);
|
void handleCommand(Client *client, const std::string &command);
|
||||||
void handleCapCommand(Client* client, const std::vector<std::string>& tokens);
|
void handleCapCommand(Client* client, const std::vector<std::string>& tokens);
|
||||||
void handlePassCommand(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 handleQuitCommand(Client* client, const std::vector<std::string>& tokens);
|
||||||
void handleErrorCommand(Client* client, const std::string &message);
|
void handleErrorCommand(Client* client, const std::string &message);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/21 19:51:08 by fgras-ca #+# #+# */
|
/* Created: 2024/05/21 19:51:08 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/05/28 11:09:22 by fgras-ca ### ########.fr */
|
/* Updated: 2024/05/28 14:17:52 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -22,11 +22,11 @@
|
|||||||
class JoinHandler
|
class JoinHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void handleJoinCommand(Client *client, const std::string &channelName, Server *server);
|
void handleJoinCommand(Client *client, const std::string &channelName, Server *server);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void sendJoinSuccess(Client *client, Channel *channel, Server *server);
|
void sendJoinSuccess(Client *client, Channel *channel, Server *server);
|
||||||
std::string getUsersList(Channel *channel);
|
std::string getUsersList(Channel *channel);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // JOIN_HPP
|
#endif // JOIN_HPP
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/19 15:12:47 by fgras-ca #+# #+# */
|
/* Created: 2024/05/19 15:12:47 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/05/28 13:56:19 by fgras-ca ### ########.fr */
|
/* Updated: 2024/05/28 15:26:33 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -34,78 +34,84 @@
|
|||||||
|
|
||||||
// Fonctions pour générer les réponses RPL
|
// 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;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 001 " << CLIENT_NICK(client)
|
oss << ":" << SERVER_NAME << " 001 " << CLIENT_NICK(client)
|
||||||
<< " :Welcome to the Internet Relay Network " << CLIENT_NICK(client)
|
<< " :Welcome to the Internet Relay Network " << CLIENT_NICK(client)
|
||||||
<< "!" << CLIENT_USER(client) << "@" << CLIENT_HOST(client) << "\r\n";
|
<< "!" << CLIENT_USER(client) << "@" << CLIENT_HOST(client) << "\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string RPL_YOURHOST(Client* client) {
|
inline std::string RPL_YOURHOST(Client* client) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 002 " << CLIENT_FD(client)
|
oss << ":" << SERVER_NAME << " 002 " << CLIENT_FD(client)
|
||||||
<< " :Your host is " << SERVER_NAME << ", running version " << SERVER_VERSION << "\r\n";
|
<< " :Your host is " << SERVER_NAME << ", running version " << SERVER_VERSION << "\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string RPL_CREATED(Client* client) {
|
inline std::string RPL_CREATED(Client* client) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 003 " << CLIENT_FD(client)
|
oss << ":" << SERVER_NAME << " 003 " << CLIENT_FD(client)
|
||||||
<< " :This server was created " << __DATE__ << "\r\n";
|
<< " :This server was created " << __DATE__ << "\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string RPL_MYINFO(Client* client) {
|
inline std::string RPL_MYINFO(Client* client) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 004 " << CLIENT_FD(client) << " "
|
oss << ":" << SERVER_NAME << " 004 " << CLIENT_FD(client) << " "
|
||||||
<< SERVER_NAME << " " << SERVER_VERSION << " "
|
<< SERVER_NAME << " " << SERVER_VERSION << " "
|
||||||
<< USER_MODES << " " << CHANNEL_MODES << " "
|
<< USER_MODES << " " << CHANNEL_MODES << " "
|
||||||
<< CHANNEL_MODES_WITH_PARAMS << "\r\n";
|
<< CHANNEL_MODES_WITH_PARAMS << "\r\n";
|
||||||
return oss.str();
|
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;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 005 " << CLIENT_FD(client)
|
oss << ":" << SERVER_NAME << " 005 " << CLIENT_FD(client)
|
||||||
<< " " << tokens << " :are supported by this server\r\n";
|
<< " " << tokens << " :are supported by this server\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string RPL_UMODEIS(int clientFd, const std::string& modes) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << ":" << SERVER_NAME << " 221 " << clientFd << " :" << 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(int clientFd, const std::string& target, const std::string& message) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 301 " << clientFd << " " << target << " :" << message << "\r\n";
|
oss << ":" << SERVER_NAME << " 301 " << clientFd << " " << target << " :" << message << "\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// WHOIS Command RPLs
|
// WHOIS Command RPLs
|
||||||
inline std::string RPL_WHOISUSER(int clientFd, Client* target)
|
inline std::string RPL_WHOISUSER(int clientFd, Client* target)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 311 " << clientFd << " " << CLIENT_NICK(target) << " "
|
oss << ":" << SERVER_NAME << " 311 " << clientFd << " " << CLIENT_NICK(target) << " "
|
||||||
<< CLIENT_USER(target) << " " << CLIENT_HOST(target) << " * :" << CLIENT_REALNAME(target) << "\r\n";
|
<< CLIENT_USER(target) << " " << CLIENT_HOST(target) << " * :" << CLIENT_REALNAME(target) << "\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string RPL_WHOISSERVER(int clientFd, const std::string& targetNick, const std::string& serverInfo)
|
inline std::string RPL_WHOISSERVER(int clientFd, const std::string& targetNick, const std::string& serverInfo)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 312 " << clientFd << " " << targetNick << " " << SERVER_NAME
|
oss << ":" << SERVER_NAME << " 312 " << clientFd << " " << targetNick << " " << SERVER_NAME
|
||||||
<< " :" << serverInfo << "\r\n";
|
<< " :" << serverInfo << "\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string RPL_ENDOFWHO(int clientFd, const std::string& channel)
|
inline std::string RPL_ENDOFWHO(int clientFd, const std::string& channel)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 315 " << clientFd << " " << channel << " :End of /WHO list.\r\n";
|
oss << ":" << SERVER_NAME << " 315 " << clientFd << " " << channel << " :End of /WHO list.\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string RPL_ENDOFWHOIS(int clientFd, const std::string& targetNick)
|
inline std::string RPL_ENDOFWHOIS(int clientFd, const std::string& targetNick)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 318 " << clientFd << " " << targetNick << " :End of /WHOIS list.\r\n";
|
oss << ":" << SERVER_NAME << " 318 " << clientFd << " " << targetNick << " :End of /WHOIS list.\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// RPL Channel List Messages
|
// RPL Channel List Messages
|
||||||
@ -126,255 +132,338 @@ inline std::string RPL_LISTEND(int clientFd)
|
|||||||
// RPL Mode Messages
|
// RPL Mode Messages
|
||||||
inline std::string RPL_CHANNELMODEIS(int clientFd, 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 " << clientFd << " " << channel << " " << mode << "\r\n";
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string RPL_CREATIONTIME(int clientFd, const std::string& channel, time_t creationTime) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << ":" << SERVER_NAME << " 329 " << clientFd << " " << channel << " " << creationTime << "\r\n";
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string RPL_NOTOPIC(Client* client, const std::string& channel) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 324 " << clientFd << " " << channel << " " << mode << "\r\n";
|
oss << ":" << SERVER_NAME << " 331 " << CLIENT_NICK(client) << " " << channel
|
||||||
|
<< " :No topic is set\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string RPL_TOPIC(Client* client, const std::string& channel, const std::string& topic) {
|
inline std::string RPL_TOPIC(Client* client, const std::string& channel, const std::string& topic) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 332 " << CLIENT_NICK(client) << " " << channel << " :" << topic << "\r\n";
|
oss << ":" << SERVER_NAME << " 332 " << CLIENT_NICK(client) << " " << channel << " :" << topic << "\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string RPL_TOPICWHOTIME(Client* client, const std::string& channel, const std::string& setter, time_t setTime) {
|
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(int clientFd, const std::string& channel, const std::string& inviteMask) {
|
||||||
|
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";
|
||||||
|
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;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 333 " << CLIENT_NICK(client) << " " << channel << " " << setter << " " << setTime << "\r\n";
|
oss << ":" << SERVER_NAME << " 341 " << CLIENT_NICK(client) << " " << nick << " " << channel << "\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::string RPL_EXCEPTLIST(int clientFd, const std::string& channel, const std::string& exceptionMask) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << ":" << SERVER_NAME << " 348 " << clientFd << " " << channel << " " << exceptionMask << "\r\n";
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string RPL_ENDOFEXCEPTLIST(int clientFd, const std::string& channel) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << ":" << SERVER_NAME << " 349 " << clientFd << " " << 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;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 353 " << CLIENT_NICK(client) << " = " << channel << " :" << users << "\r\n";
|
oss << ":" << SERVER_NAME << " 353 " << CLIENT_NICK(client) << " = " << channel << " :" << users << "\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
// WHO Command RPLs
|
// WHO Command RPLs
|
||||||
inline std::string RPL_WHOREPLY(const std::string& channel, Client* target)
|
inline std::string RPL_WHOREPLY(const std::string& channel, Client* target)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 352 " << CLIENT_NICK(target) << " " << channel << " "
|
oss << ":" << SERVER_NAME << " 352 " << CLIENT_NICK(target) << " " << channel << " "
|
||||||
<< CLIENT_USER(target) << " " << CLIENT_HOST(target) << " " << SERVER_NAME << " "
|
<< CLIENT_USER(target) << " " << CLIENT_HOST(target) << " " << SERVER_NAME << " "
|
||||||
<< CLIENT_NICK(target) << " H :0 " << CLIENT_REALNAME(target) << "\r\n";
|
<< CLIENT_NICK(target) << " H :0 " << CLIENT_REALNAME(target) << "\r\n";
|
||||||
return oss.str();
|
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;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 366 " << CLIENT_NICK(client) << " " << channel << " :End of /NAMES list\r\n";
|
oss << ":" << SERVER_NAME << " 366 " << CLIENT_NICK(client) << " " << channel << " :End of /NAMES list\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string RPL_BANLIST(int clientFd, const std::string& channel, const std::string& banMask) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << ":" << SERVER_NAME << " 367 " << clientFd << " " << channel << " " << banMask << "\r\n";
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string RPL_ENDOFBANLIST(int clientFd, const std::string& channel) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << ":" << SERVER_NAME << " 368 " << clientFd << " " << 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;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 372 " << CLIENT_FD(client)
|
oss << ":" << SERVER_NAME << " 372 " << CLIENT_FD(client)
|
||||||
<< " :- " << line << "\r\n";
|
<< " :- " << line << "\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string RPL_MOTDSTART(Client* client) {
|
inline std::string RPL_MOTDSTART(Client* client) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 375 " << CLIENT_FD(client)
|
oss << ":" << SERVER_NAME << " 375 " << CLIENT_FD(client)
|
||||||
<< " :- " << SERVER_NAME << " Message of the day - \r\n";
|
<< " :- " << SERVER_NAME << " Message of the day - \r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string RPL_ENDOFMOTD(Client* client) {
|
inline std::string RPL_ENDOFMOTD(Client* client) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 376 " << CLIENT_FD(client)
|
oss << ":" << SERVER_NAME << " 376 " << CLIENT_FD(client)
|
||||||
<< " :End of /MOTD command.\r\n";
|
<< " :End of /MOTD command.\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string ERR_NOSUCHNICK(int clientFd, const std::string& nick)
|
inline std::string ERR_NOSUCHNICK(int clientFd, const std::string& nick)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 401 " << clientFd << " " << nick << " :No such nick/channel\r\n";
|
oss << ":" << SERVER_NAME << " 401 " << clientFd << " " << nick << " :No such nick/channel\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string ERR_NOSUCHCHANNEL(int clientFd, const std::string& channel)
|
inline std::string ERR_NOSUCHCHANNEL(int clientFd, const std::string& channel)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 403 " << clientFd << " " << channel << " :No such channel\r\n";
|
oss << ":" << SERVER_NAME << " 403 " << clientFd << " " << channel << " :No such channel\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string ERR_CANNOTSENDTOCHAN(int clientFd, const std::string& channel) {
|
inline std::string ERR_CANNOTSENDTOCHAN(int clientFd, const std::string& channel) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 404 " << clientFd << " " << channel << " :Cannot send to channel\r\n";
|
oss << ":" << SERVER_NAME << " 404 " << clientFd << " " << channel << " :Cannot send to channel\r\n";
|
||||||
return oss.str();
|
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;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 405 " << CLIENT_NICK(client) << " " << channel << " :You have joined too many channels\r\n";
|
oss << ":" << SERVER_NAME << " 405 " << CLIENT_NICK(client) << " " << channel << " :You have joined too many channels\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// RPL Error Messages
|
// RPL Error Messages
|
||||||
inline std::string ERR_NOORIGIN(Client* client)
|
inline std::string ERR_NOORIGIN(Client* client)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 409 " << CLIENT_FD(client) << " :No origin specified\r\n";
|
oss << ":" << SERVER_NAME << " 409 " << CLIENT_FD(client) << " :No origin specified\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string ERR_NORECIPIENT(int clientFd, const std::string& command) {
|
inline std::string ERR_NORECIPIENT(int clientFd, const std::string& command) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 411 " << clientFd << " :No recipient given (" << command << ")\r\n";
|
oss << ":" << SERVER_NAME << " 411 " << clientFd << " :No recipient given (" << command << ")\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string ERR_NOTEXTTOSEND(int clientFd) {
|
inline std::string ERR_NOTEXTTOSEND(int clientFd) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 412 " << clientFd << " :No text to send\r\n";
|
oss << ":" << SERVER_NAME << " 412 " << clientFd << " :No text to send\r\n";
|
||||||
return oss.str();
|
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;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 421 " << CLIENT_NICK(client) << " " << command << " :Unknown command\r\n";
|
oss << ":" << SERVER_NAME << " 421 " << CLIENT_NICK(client) << " " << command << " :Unknown command\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string ERR_NOMOTD(Client* client) {
|
inline std::string ERR_NOMOTD(Client* client) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 422 " << CLIENT_FD(client)
|
oss << ":" << SERVER_NAME << " 422 " << CLIENT_FD(client)
|
||||||
<< " :MOTD File is missing\r\n";
|
<< " :MOTD File is missing\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string ERR_NONICKNAMEGIVEN(Client* client)
|
inline std::string ERR_NONICKNAMEGIVEN(Client* client)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 431 " << CLIENT_FD(client) << " :No nickname given\r\n";
|
oss << ":" << SERVER_NAME << " 431 " << CLIENT_FD(client) << " :No nickname given\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string ERR_ERRONEUSNICKNAME(Client* client, const std::string& nickname)
|
inline std::string ERR_ERRONEUSNICKNAME(Client* client, const std::string& nickname)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 432 " << CLIENT_FD(client) << " " << nickname << " :Erroneous nickname\r\n";
|
oss << ":" << SERVER_NAME << " 432 " << CLIENT_FD(client) << " " << nickname << " :Erroneous nickname\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string ERR_NICKNAMEINUSE(Client* client, const std::string& nickname)
|
inline std::string ERR_NICKNAMEINUSE(Client* client, const std::string& nickname)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 433 " << CLIENT_FD(client) << " " << nickname << " :Nickname is already in use\r\n";
|
oss << ":" << SERVER_NAME << " 433 " << CLIENT_FD(client) << " " << nickname << " :Nickname is already in use\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string ERR_USERNOTINCHANNEL(int clientFd, const std::string& nick, const std::string& channel) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << ":" << SERVER_NAME << " 441 " << clientFd << " " << 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(int clientFd, const std::string& channel) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << ":" << SERVER_NAME << " 442 " << clientFd << " " << 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;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 442 " << clientFd << " " << channel << " :You're not on that channel\r\n";
|
oss << ":" << SERVER_NAME << " 443 " << CLIENT_NICK(client) << " " << nick << " " << channel
|
||||||
|
<< " :is already on channel\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string ERR_NOTREGISTERED(Client* client)
|
inline std::string ERR_NOTREGISTERED(Client* client)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 451 " << CLIENT_FD(client) << " :You have not registered\r\n";
|
oss << ":" << SERVER_NAME << " 451 " << CLIENT_FD(client) << " :You have not registered\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
//RPL Password
|
//RPL Password
|
||||||
// RPL Error Messages
|
// RPL Error Messages
|
||||||
inline std::string ERR_NEEDMOREPARAMS(Client* client, const std::string& command)
|
inline std::string ERR_NEEDMOREPARAMS(Client* client, const std::string& command)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 461 " << CLIENT_FD(client) << " " << command << " :Not enough parameters\r\n";
|
oss << ":" << SERVER_NAME << " 461 " << CLIENT_FD(client) << " " << command << " :Not enough parameters\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string ERR_ALREADYREGISTERED(Client* client)
|
inline std::string ERR_ALREADYREGISTERED(Client* client)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 462 " << CLIENT_FD(client) << " :You may not reregister\r\n";
|
oss << ":" << SERVER_NAME << " 462 " << CLIENT_FD(client) << " :You may not reregister\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string ERR_PASSWDMISMATCH(Client* client)
|
inline std::string ERR_PASSWDMISMATCH(Client* client)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 464 " << CLIENT_FD(client) << " :Password incorrect\r\n";
|
oss << ":" << SERVER_NAME << " 464 " << CLIENT_FD(client) << " :Password incorrect\r\n";
|
||||||
return oss.str();
|
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;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 471 " << CLIENT_NICK(client) << " " << channel << " :Cannot join channel (channel is full)\r\n";
|
oss << ":" << SERVER_NAME << " 471 " << CLIENT_NICK(client) << " " << channel << " :Cannot join channel (channel is full)\r\n";
|
||||||
return oss.str();
|
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;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 473 " << CLIENT_NICK(client) << " " << channel << " :Cannot join channel (invite only)\r\n";
|
oss << ":" << SERVER_NAME << " 473 " << CLIENT_NICK(client) << " " << channel << " :Cannot join channel (invite only)\r\n";
|
||||||
return oss.str();
|
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;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 474 " << CLIENT_NICK(client) << " " << channel << " :Cannot join channel (banned)\r\n";
|
oss << ":" << SERVER_NAME << " 474 " << CLIENT_NICK(client) << " " << channel << " :Cannot join channel (banned)\r\n";
|
||||||
return oss.str();
|
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;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 475 " << CLIENT_NICK(client) << " " << channel << " :Cannot join channel (incorrect key)\r\n";
|
oss << ":" << SERVER_NAME << " 475 " << CLIENT_NICK(client) << " " << channel << " :Cannot join channel (incorrect key)\r\n";
|
||||||
return oss.str();
|
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;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 476 " << CLIENT_NICK(client) << " " << channel << " :Bad channel mask\r\n";
|
oss << ":" << SERVER_NAME << " 476 " << CLIENT_NICK(client) << " " << channel << " :Bad channel mask\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string RPL_NOCHANMODES(int clientFd, const std::string& channel)
|
inline std::string RPL_NOCHANMODES(int clientFd, const std::string& channel)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 477 " << clientFd << " " << channel << " :Channel doesn't support modes\r\n";
|
oss << ":" << SERVER_NAME << " 477 " << clientFd << " " << channel << " :Channel doesn't support modes\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string ERR_CHANOPRIVSNEEDED(int clientFd, const std::string& channel)
|
inline std::string ERR_CHANOPRIVSNEEDED(int clientFd, const std::string& channel)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " 482 " << clientFd << " " << channel << " :You're not channel operator\r\n";
|
oss << ":" << SERVER_NAME << " 482 " << clientFd << " " << channel << " :You're not channel operator\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string ERR_UMODEUNKNOWNFLAG(int clientFd) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << ":" << SERVER_NAME << " 501 " << clientFd << " :Unknown MODE flag\r\n";
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string ERR_USERSDONTMATCH(int clientFd) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << ":" << SERVER_NAME << " 502 " << clientFd << " :Cannot change mode for other users\r\n";
|
||||||
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// PONG Reply
|
// PONG Reply
|
||||||
inline std::string RPL_PONG(const std::string& token)
|
inline std::string RPL_PONG(const std::string& token)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " PONG " << SERVER_NAME << " " << token << "\r\n";
|
oss << ":" << SERVER_NAME << " PONG " << SERVER_NAME << " " << token << "\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// CAP Command RPLs
|
// CAP Command RPLs
|
||||||
inline std::string RPL_CAP(int clientFd, const std::string& subcommand, const std::string& capabilities)
|
inline std::string RPL_CAP(int clientFd, const std::string& subcommand, const std::string& capabilities)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " CAP " << clientFd << " " << subcommand << " :" << capabilities << "\r\n";
|
oss << ":" << SERVER_NAME << " CAP " << clientFd << " " << subcommand << " :" << capabilities << "\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string RPL_PASSACCEPTED(Client* client)
|
inline std::string RPL_PASSACCEPTED(Client* client)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " NOTICE " << CLIENT_FD(client)
|
oss << ":" << SERVER_NAME << " NOTICE " << CLIENT_FD(client)
|
||||||
<< " :Password accepted!\r\n";
|
<< " :Password accepted!\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add this function to handle the CAP END response
|
// Add this function to handle the CAP END response
|
||||||
inline std::string RPL_CAPEND(int clientFd)
|
inline std::string RPL_CAPEND(int clientFd)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << ":" << SERVER_NAME << " CAP " << clientFd << " END\r\n";
|
oss << ":" << SERVER_NAME << " CAP " << clientFd << " END\r\n";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // RPL_HPP
|
#endif // RPL_HPP
|
||||||
|
|||||||
BIN
ft_irc3/ircserv
Executable file
BIN
ft_irc3/ircserv
Executable file
Binary file not shown.
0
ft_irc3/logs/irc_server.log
Normal file
0
ft_irc3/logs/irc_server.log
Normal file
BIN
ft_irc3/obj/AdditionalCommands.o
Normal file
BIN
ft_irc3/obj/AdditionalCommands.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/Channel.o
Normal file
BIN
ft_irc3/obj/Channel.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/Client.o
Normal file
BIN
ft_irc3/obj/Client.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/ClientManager.o
Normal file
BIN
ft_irc3/obj/ClientManager.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/CommandHandler.o
Normal file
BIN
ft_irc3/obj/CommandHandler.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/Join.o
Normal file
BIN
ft_irc3/obj/Join.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/Server.o
Normal file
BIN
ft_irc3/obj/Server.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/Utils.o
Normal file
BIN
ft_irc3/obj/Utils.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/Welcome.o
Normal file
BIN
ft_irc3/obj/Welcome.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/Who.o
Normal file
BIN
ft_irc3/obj/Who.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/main.o
Normal file
BIN
ft_irc3/obj/main.o
Normal file
Binary file not shown.
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/15 12:17:42 by fgras-ca #+# #+# */
|
/* Created: 2024/05/15 12:17:42 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/05/28 14:10:21 by fgras-ca ### ########.fr */
|
/* Updated: 2024/05/28 14:32:11 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -15,51 +15,97 @@
|
|||||||
Client::Client(int fd, const std::string &nickname, const std::string &user, const std::string &host, const std::string &password, const std::string &realname)
|
Client::Client(int fd, const std::string &nickname, const std::string &user, const std::string &host, const std::string &password, const std::string &realname)
|
||||||
: _fd(fd), _nickname(nickname), _user(user), _host(host), _password(password), _realname(realname), _authenticated(false), _operator(false), _away(false) {}
|
: _fd(fd), _nickname(nickname), _user(user), _host(host), _password(password), _realname(realname), _authenticated(false), _operator(false), _away(false) {}
|
||||||
|
|
||||||
int Client::getFd() const { return _fd; }
|
|
||||||
const std::string &Client::getNickname() const { return _nickname; }
|
|
||||||
void Client::setNickname(const std::string &nickname) { _nickname = nickname; }
|
|
||||||
const std::string &Client::getUser() const { return _user; }
|
|
||||||
void Client::setUser(const std::string &user) { _user = user; }
|
|
||||||
const std::string &Client::getHost() const { return _host; }
|
|
||||||
void Client::setHost(const std::string &host) { _host = host; }
|
|
||||||
const std::string &Client::getPassword() const { return _password; }
|
|
||||||
void Client::setPassword(const std::string &password) { _password = password; }
|
|
||||||
const std::string &Client::getRealName() const { return _realname; }
|
|
||||||
void Client::setRealName(const std::string &realname) { _realname = realname; }
|
|
||||||
bool Client::isAuthenticated() const { return _authenticated; }
|
|
||||||
void Client::authenticate() { _authenticated = true; }
|
|
||||||
bool Client::isOperator() const { return _operator; }
|
|
||||||
void Client::setOperator(bool isOperator) { _operator = isOperator; }
|
|
||||||
|
|
||||||
bool Client::isAway() const { return _away; }
|
|
||||||
const std::string &Client::getAwayMessage() const { return _awayMessage; }
|
|
||||||
void Client::setAwayMessage(const std::string &message) { _awayMessage = message; }
|
|
||||||
void Client::setAway(bool away) { _away = away; }
|
|
||||||
|
|
||||||
/*Client::Client(int fd)
|
|
||||||
|
|
||||||
Description: Constructeur de la classe Client. Initialise le client avec le descripteur de fichier fourni.
|
|
||||||
Paramètres:
|
|
||||||
int fd: Le descripteur de fichier du client.
|
|
||||||
Client::~Client()
|
|
||||||
|
|
||||||
Description: Destructeur de la classe Client. Gère la destruction de l'objet.
|
|
||||||
int Client::getFd() const
|
int Client::getFd() const
|
||||||
|
{
|
||||||
|
return _fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &Client::getNickname() const
|
||||||
|
{
|
||||||
|
return _nickname;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::setNickname(const std::string &nickname)
|
||||||
|
{
|
||||||
|
_nickname = nickname;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &Client::getUser() const
|
||||||
|
{
|
||||||
|
return _user;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::setUser(const std::string &user)
|
||||||
|
{
|
||||||
|
_user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &Client::getHost() const
|
||||||
|
{
|
||||||
|
return _host;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::setHost(const std::string &host)
|
||||||
|
{
|
||||||
|
_host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &Client::getPassword() const
|
||||||
|
{
|
||||||
|
return _password;
|
||||||
|
}
|
||||||
|
|
||||||
Description: Renvoie le descripteur de fichier du client.
|
|
||||||
Retourne: Le descripteur de fichier du client.
|
|
||||||
void Client::setPassword(const std::string &password)
|
void Client::setPassword(const std::string &password)
|
||||||
|
{
|
||||||
|
_password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &Client::getRealName() const
|
||||||
|
{
|
||||||
|
return _realname;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::setRealName(const std::string &realname)
|
||||||
|
{
|
||||||
|
_realname = realname;
|
||||||
|
}
|
||||||
|
|
||||||
Description: Définit le mot de passe du client et le marque comme authentifié.
|
|
||||||
Paramètres:
|
|
||||||
const std::string &password: Le mot de passe à définir.
|
|
||||||
bool Client::isAuthenticated() const
|
bool Client::isAuthenticated() const
|
||||||
|
{
|
||||||
|
return _authenticated;
|
||||||
|
}
|
||||||
|
|
||||||
Description: Vérifie si le client est authentifié.
|
void Client::authenticate()
|
||||||
Retourne: true si le client est authentifié, false sinon.
|
{
|
||||||
void logMessage(const std::string &message, const std::string &color)
|
_authenticated = true;
|
||||||
|
}
|
||||||
|
|
||||||
Description: Enregistre un message dans les logs et l'affiche avec des couleurs dans la console.
|
bool Client::isOperator() const
|
||||||
Paramètres:
|
{
|
||||||
const std::string &message: Le message à enregistrer.
|
return _operator;
|
||||||
const std::string &color: La couleur du message.*/
|
}
|
||||||
|
|
||||||
|
void Client::setOperator(bool isOperator)
|
||||||
|
{
|
||||||
|
_operator = isOperator;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Client::isAway() const
|
||||||
|
{
|
||||||
|
return _away;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &Client::getAwayMessage() const
|
||||||
|
{
|
||||||
|
return _awayMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::setAwayMessage(const std::string &message)
|
||||||
|
{
|
||||||
|
_awayMessage = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::setAway(bool away)
|
||||||
|
{
|
||||||
|
_away = away;
|
||||||
|
}
|
||||||
|
|||||||
@ -6,126 +6,126 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/15 18:32:23 by fgras-ca #+# #+# */
|
/* Created: 2024/05/15 18:32:23 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/05/21 20:28:41 by fgras-ca ### ########.fr */
|
/* Updated: 2024/05/28 14:32:28 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ClientManager.hpp"
|
#include "ClientManager.hpp"
|
||||||
|
|
||||||
ClientManager::ClientManager(Server *server)
|
ClientManager::ClientManager(Server *server)
|
||||||
: _server(server)
|
: _server(server)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientManager::acceptClient()
|
void ClientManager::acceptClient()
|
||||||
{
|
{
|
||||||
int client_fd = accept(_server->_server_fd, NULL, NULL);
|
int client_fd = accept(_server->_server_fd, NULL, NULL);
|
||||||
if (client_fd < 0)
|
if (client_fd < 0)
|
||||||
{
|
{
|
||||||
_server->log("Failed to accept client.", RED);
|
_server->log("Failed to accept client.", RED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Client *newClient = new Client(client_fd, "", "", "", "", ""); // Fournir six arguments
|
Client *newClient = new Client(client_fd, "", "", "", "", ""); // Fournir six arguments
|
||||||
_server->_clients[client_fd] = newClient;
|
_server->_clients[client_fd] = newClient;
|
||||||
struct pollfd client_pollfd;
|
struct pollfd client_pollfd;
|
||||||
client_pollfd.fd = client_fd;
|
client_pollfd.fd = client_fd;
|
||||||
client_pollfd.events = POLLIN;
|
client_pollfd.events = POLLIN;
|
||||||
_server->_poll_fds.push_back(client_pollfd);
|
_server->_poll_fds.push_back(client_pollfd);
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "Client attempting connection: " << client_fd;
|
ss << "Client attempting connection: " << client_fd;
|
||||||
_server->log(ss.str(), YELLOW);
|
_server->log(ss.str(), YELLOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientManager::handleClient(int client_fd)
|
void ClientManager::handleClient(int client_fd)
|
||||||
{
|
{
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
std::memset(buffer, 0, sizeof(buffer));
|
std::memset(buffer, 0, sizeof(buffer));
|
||||||
int bytes_received = recv(client_fd, buffer, sizeof(buffer), 0);
|
int bytes_received = recv(client_fd, buffer, sizeof(buffer), 0);
|
||||||
|
|
||||||
if (bytes_received <= 0)
|
if (bytes_received <= 0)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "Client disconnected: " << client_fd;
|
oss << "Client disconnected: " << client_fd;
|
||||||
_server->log(oss.str(), RED);
|
_server->log(oss.str(), RED);
|
||||||
removeClient(client_fd);
|
removeClient(client_fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string message(buffer, bytes_received);
|
std::string message(buffer, bytes_received);
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "Received from client " << client_fd << ": " << message;
|
oss << "Received from client " << client_fd << ": " << message;
|
||||||
_server->log(oss.str(), BLUE);
|
_server->log(oss.str(), BLUE);
|
||||||
|
|
||||||
Client* client = _server->getClients()[client_fd];
|
Client* client = _server->getClients()[client_fd];
|
||||||
if (!client)
|
if (!client)
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "Client not found for fd: " << client_fd;
|
oss << "Client not found for fd: " << client_fd;
|
||||||
_server->log(oss.str(), RED);
|
_server->log(oss.str(), RED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::istringstream message_stream(message);
|
std::istringstream message_stream(message);
|
||||||
std::string line;
|
std::string line;
|
||||||
|
|
||||||
while (std::getline(message_stream, line))
|
while (std::getline(message_stream, line))
|
||||||
{
|
{
|
||||||
// Remove trailing '\r' and '\n'
|
// Remove trailing '\r' and '\n'
|
||||||
line.erase(std::remove(line.begin(), line.end(), '\r'), line.end());
|
line.erase(std::remove(line.begin(), line.end(), '\r'), line.end());
|
||||||
line.erase(std::remove(line.begin(), line.end(), '\n'), line.end());
|
line.erase(std::remove(line.begin(), line.end(), '\n'), line.end());
|
||||||
|
|
||||||
if (!line.empty())
|
if (!line.empty())
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "Processing command from client " << client_fd << ": " << line;
|
oss << "Processing command from client " << client_fd << ": " << line;
|
||||||
_server->log(oss.str(), BLUE);
|
_server->log(oss.str(), BLUE);
|
||||||
_server->_commandHandler->handleCommand(client, line);
|
_server->_commandHandler->handleCommand(client, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ClientManager::removeClient(int clientFd)
|
void ClientManager::removeClient(int clientFd)
|
||||||
{
|
{
|
||||||
Client* client = _server->_clients[clientFd];
|
Client* client = _server->_clients[clientFd];
|
||||||
if (client)
|
if (client)
|
||||||
{
|
{
|
||||||
// Log the nickname being freed
|
// Log the nickname being freed
|
||||||
_server->log("Removing client: " + client->getNickname(), YELLOW);
|
_server->log("Removing client: " + client->getNickname(), YELLOW);
|
||||||
|
|
||||||
std::map<std::string, Channel*>::iterator it = _server->_channels.begin();
|
std::map<std::string, Channel*>::iterator it = _server->_channels.begin();
|
||||||
while (it != _server->_channels.end())
|
while (it != _server->_channels.end())
|
||||||
{
|
{
|
||||||
it->second->removeClient(client);
|
it->second->removeClient(client);
|
||||||
if (it->second->isEmpty())
|
if (it->second->isEmpty())
|
||||||
{
|
{
|
||||||
delete it->second;
|
delete it->second;
|
||||||
std::map<std::string, Channel*>::iterator it_to_delete = it++;
|
std::map<std::string, Channel*>::iterator it_to_delete = it++;
|
||||||
_server->_channels.erase(it_to_delete);
|
_server->_channels.erase(it_to_delete);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete client;
|
delete client;
|
||||||
_server->_clients.erase(clientFd);
|
_server->_clients.erase(clientFd);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<struct pollfd>::iterator it_poll = _server->_poll_fds.begin();
|
std::vector<struct pollfd>::iterator it_poll = _server->_poll_fds.begin();
|
||||||
while (it_poll != _server->_poll_fds.end())
|
while (it_poll != _server->_poll_fds.end())
|
||||||
{
|
{
|
||||||
if (it_poll->fd == clientFd)
|
if (it_poll->fd == clientFd)
|
||||||
{
|
{
|
||||||
_server->_poll_fds.erase(it_poll);
|
_server->_poll_fds.erase(it_poll);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++it_poll;
|
++it_poll;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "Client disconnected: " << clientFd;
|
ss << "Client disconnected: " << clientFd;
|
||||||
_server->log(ss.str(), YELLOW);
|
_server->log(ss.str(), YELLOW);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/21 19:51:31 by fgras-ca #+# #+# */
|
/* Created: 2024/05/21 19:51:31 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/05/28 13:07:53 by fgras-ca ### ########.fr */
|
/* Updated: 2024/05/28 14:33:01 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,66 +14,66 @@
|
|||||||
|
|
||||||
void JoinHandler::handleJoinCommand(Client *client, const std::string &channelName, Server *server)
|
void JoinHandler::handleJoinCommand(Client *client, const std::string &channelName, Server *server)
|
||||||
{
|
{
|
||||||
if (channelName.empty()) {
|
if (channelName.empty()) {
|
||||||
server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "JOIN"));
|
server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "JOIN"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, Channel *> &channels = server->getChannels();
|
std::map<std::string, Channel *> &channels = server->getChannels();
|
||||||
Channel *channel;
|
Channel *channel;
|
||||||
|
|
||||||
if (channels.find(channelName) == channels.end()) {
|
if (channels.find(channelName) == channels.end()) {
|
||||||
channel = new Channel(channelName);
|
channel = new Channel(channelName);
|
||||||
channels[channelName] = channel;
|
channels[channelName] = channel;
|
||||||
} else {
|
} else {
|
||||||
channel = channels[channelName];
|
channel = channels[channelName];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel->isBanned(client)) {
|
if (channel->isBanned(client)) {
|
||||||
server->sendToClient(client->getFd(), ERR_BANNEDFROMCHAN(client, channelName));
|
server->sendToClient(client->getFd(), ERR_BANNEDFROMCHAN(client, channelName));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel->isFull()) {
|
if (channel->isFull()) {
|
||||||
server->sendToClient(client->getFd(), ERR_CHANNELISFULL(client, channelName));
|
server->sendToClient(client->getFd(), ERR_CHANNELISFULL(client, channelName));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel->isInviteOnly() && !channel->isInvited(client)) {
|
if (channel->isInviteOnly() && !channel->isInvited(client)) {
|
||||||
server->sendToClient(client->getFd(), ERR_INVITEONLYCHAN(client, channelName));
|
server->sendToClient(client->getFd(), ERR_INVITEONLYCHAN(client, channelName));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
channel->addClient(client);
|
channel->addClient(client);
|
||||||
sendJoinSuccess(client, channel, server);
|
sendJoinSuccess(client, channel, server);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoinHandler::sendJoinSuccess(Client *client, Channel *channel, Server *server)
|
void JoinHandler::sendJoinSuccess(Client *client, Channel *channel, Server *server)
|
||||||
{
|
{
|
||||||
std::string joinMessage = ":" + client->getNickname() + " JOIN " + channel->getName() + "\r\n";
|
std::string joinMessage = ":" + client->getNickname() + " JOIN " + channel->getName() + "\r\n";
|
||||||
server->sendToClient(client->getFd(), joinMessage);
|
server->sendToClient(client->getFd(), joinMessage);
|
||||||
|
|
||||||
if (!channel->getTopic().empty()) {
|
if (!channel->getTopic().empty()) {
|
||||||
server->sendToClient(client->getFd(), RPL_TOPIC(client, channel->getName(), channel->getTopic()));
|
server->sendToClient(client->getFd(), RPL_TOPIC(client, channel->getName(), channel->getTopic()));
|
||||||
server->sendToClient(client->getFd(), RPL_TOPICWHOTIME(client, channel->getName(), channel->getTopicSetter(), channel->getTopicTime()));
|
server->sendToClient(client->getFd(), RPL_TOPICWHOTIME(client, channel->getName(), channel->getTopicSetter(), channel->getTopicTime()));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string usersList = getUsersList(channel);
|
std::string usersList = getUsersList(channel);
|
||||||
server->sendToClient(client->getFd(), usersList);
|
server->sendToClient(client->getFd(), usersList);
|
||||||
|
|
||||||
channel->broadcast(joinMessage, client, server);
|
channel->broadcast(joinMessage, client, server);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string JoinHandler::getUsersList(Channel *channel)
|
std::string JoinHandler::getUsersList(Channel *channel)
|
||||||
{
|
{
|
||||||
std::vector<Client *> clients = channel->getClients();
|
std::vector<Client *> clients = channel->getClients();
|
||||||
std::string users;
|
std::string users;
|
||||||
for (std::vector<Client *>::iterator it = clients.begin(); it != clients.end(); ++it) {
|
for (std::vector<Client *>::iterator it = clients.begin(); it != clients.end(); ++it) {
|
||||||
users += (*it)->getNickname() + " ";
|
users += (*it)->getNickname() + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << RPL_NAMREPLY(clients[0], channel->getName(), users);
|
oss << RPL_NAMREPLY(clients[0], channel->getName(), users);
|
||||||
oss << RPL_ENDOFNAMES(clients[0], channel->getName());
|
oss << RPL_ENDOFNAMES(clients[0], channel->getName());
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,66 +6,66 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/17 16:09:20 by fgras-ca #+# #+# */
|
/* Created: 2024/05/17 16:09:20 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/05/28 13:08:30 by fgras-ca ### ########.fr */
|
/* Updated: 2024/05/28 14:33:29 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "Who.hpp"
|
#include "Who.hpp"
|
||||||
|
|
||||||
WhoHandler::WhoHandler(Server *server)
|
WhoHandler::WhoHandler(Server *server)
|
||||||
: _server(server)
|
: _server(server)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void WhoHandler::handleWhoCommand(Client *client, const std::string &command)
|
void WhoHandler::handleWhoCommand(Client *client, const std::string &command)
|
||||||
{
|
{
|
||||||
std::istringstream iss(command);
|
std::istringstream iss(command);
|
||||||
std::string cmd, mask;
|
std::string cmd, mask;
|
||||||
iss >> cmd >> mask;
|
iss >> cmd >> mask;
|
||||||
|
|
||||||
std::map<std::string, Channel *> &channels = _server->getChannels();
|
std::map<std::string, Channel *> &channels = _server->getChannels();
|
||||||
if (channels.find(mask) != channels.end())
|
if (channels.find(mask) != channels.end())
|
||||||
{
|
{
|
||||||
Channel *channel = channels[mask];
|
Channel *channel = channels[mask];
|
||||||
std::vector<Client *> channelClients = channel->getClients();
|
std::vector<Client *> channelClients = channel->getClients();
|
||||||
|
|
||||||
for (size_t i = 0; i < channelClients.size(); ++i)
|
for (size_t i = 0; i < channelClients.size(); ++i)
|
||||||
{
|
{
|
||||||
_server->sendToClient(client->getFd(), RPL_WHOREPLY(mask, channelClients[i]));
|
_server->sendToClient(client->getFd(), RPL_WHOREPLY(mask, channelClients[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Client *targetClient = _server->getClientByName(mask);
|
Client *targetClient = _server->getClientByName(mask);
|
||||||
if (targetClient)
|
if (targetClient)
|
||||||
{
|
{
|
||||||
_server->sendToClient(client->getFd(), RPL_WHOREPLY("*", targetClient));
|
_server->sendToClient(client->getFd(), RPL_WHOREPLY("*", targetClient));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_server->sendToClient(client->getFd(), RPL_ENDOFWHO(client->getFd(), mask));
|
_server->sendToClient(client->getFd(), RPL_ENDOFWHO(client->getFd(), mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WhoHandler::handleWhoisCommand(Client *client, const std::string &command)
|
void WhoHandler::handleWhoisCommand(Client *client, const std::string &command)
|
||||||
{
|
{
|
||||||
std::istringstream iss(command);
|
std::istringstream iss(command);
|
||||||
std::string cmd, target;
|
std::string cmd, target;
|
||||||
iss >> cmd >> target;
|
iss >> cmd >> target;
|
||||||
|
|
||||||
if (target.empty())
|
if (target.empty())
|
||||||
{
|
{
|
||||||
_server->sendToClient(client->getFd(), ERR_NONICKNAMEGIVEN(client));
|
_server->sendToClient(client->getFd(), ERR_NONICKNAMEGIVEN(client));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Client *targetClient = _server->getClientByName(target);
|
Client *targetClient = _server->getClientByName(target);
|
||||||
if (!targetClient)
|
if (!targetClient)
|
||||||
{
|
{
|
||||||
_server->sendToClient(client->getFd(), ERR_NOSUCHNICK(client->getFd(), target));
|
_server->sendToClient(client->getFd(), ERR_NOSUCHNICK(client->getFd(), target));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_server->sendToClient(client->getFd(), RPL_WHOISUSER(client->getFd(), targetClient));
|
_server->sendToClient(client->getFd(), RPL_WHOISUSER(client->getFd(), targetClient));
|
||||||
_server->sendToClient(client->getFd(), RPL_WHOISSERVER(client->getFd(), target, "IRC server info"));
|
_server->sendToClient(client->getFd(), RPL_WHOISSERVER(client->getFd(), target, "IRC server info"));
|
||||||
_server->sendToClient(client->getFd(), RPL_ENDOFWHOIS(client->getFd(), target));
|
_server->sendToClient(client->getFd(), RPL_ENDOFWHOIS(client->getFd(), target));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user