mirror of
https://github.com/Ladebeze66/ft_irc.git
synced 2025-12-17 06:28:03 +01:00
final
This commit is contained in:
parent
a604e93070
commit
826de5d786
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/21 18:09:05 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/06 18:41:04 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/06/10 13:28:55 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/06 11:44:44 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/06 18:50:12 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/06/10 14:46:42 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -35,6 +35,7 @@ public:
|
||||
void loadBadWords(const std::string& fileName);
|
||||
bool checkMessage(Client* client, Channel* channel, const std::string& message);
|
||||
void warnClient(Client* client, Channel* channel);
|
||||
void warnClientDirect(Client* client);
|
||||
void kickClient(Client* client, Channel* channel);
|
||||
|
||||
private:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/30 11:12:57 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/07 12:24:49 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/06/08 18:53:15 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -45,7 +45,7 @@ class ModeHandler
|
||||
void applyModeL(Client *client, Channel* channel, bool adding, const std::string& argument);
|
||||
void applyModeI(Client *client, Channel* channel, bool adding);
|
||||
void applyModeK(Client *client, Channel* channel, bool adding, const std::string& argument);
|
||||
void applyModeT(Channel* channel, bool adding);
|
||||
void applyModeT(Client *client, Channel* channel, bool adding);
|
||||
void applyModeO(Client *client, Channel* channel, bool adding, const std::string& argument);
|
||||
bool needsArgument(char mode);
|
||||
};
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/19 15:12:47 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/07 14:00:45 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/06/08 20:20:39 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -391,10 +391,10 @@ inline std::string ERR_NOTREGISTERED(Client* client)
|
||||
|
||||
//RPL Password
|
||||
// RPL Error Messages
|
||||
inline std::string ERR_NEEDMOREPARAMS(Client* client, const std::string& command)
|
||||
inline std::string ERR_NEEDMOREPARAMS(Client* client, std::string channel, const std::string& command)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << SERVER_NAME << " 461 " << CLIENT_NICK(client) << " " << command << " :Not enough parameters\r\n";
|
||||
oss << ":" << SERVER_NAME << " 461 " << CLIENT_NICK(client) << " " << channel << command << " :Not enough parameters\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@ -541,10 +541,10 @@ inline std::string RPL_CAPEND(Client *client)
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string MODEACCEPTMESSAGE(Client *client, std::string channel, const std::string& mode)
|
||||
inline std::string MODEACCEPTMESSAGE(Client *client, std::string channel, const std::string& mode, const std::string& argument)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ":" << client->getNickname() << " MODE " << channel << " " << mode << " :" << "\r\n";
|
||||
oss << ":" << client->getNickname() << " MODE " << channel << " " << mode << argument << "\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@ -555,10 +555,10 @@ inline std::string BOTMESSAGE(Client *client, const std::string &channel, const
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
inline std::string MODELCHANGE(Client *client, std::string channel, const std::string& mode)
|
||||
inline std::string MODELNEEDPARAM(const std::string& mode)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << SERVER_NAME <<":" << client->getNickname() << " MODE " << channel << " " << mode << " :" << "\r\n";
|
||||
oss << mode << ":NOT enought parameters" << "\r\n";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/16 15:27:29 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/07 11:34:13 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/06/10 15:17:13 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,49 +14,74 @@
|
||||
|
||||
AdditionalCommands::AdditionalCommands(Server *server) : _server(server) {}
|
||||
|
||||
std::string toUpperCase(const std::string &str)
|
||||
{
|
||||
std::string upperStr = str;
|
||||
std::transform(upperStr.begin(), upperStr.end(), upperStr.begin(), ::toupper);
|
||||
return upperStr;
|
||||
}
|
||||
|
||||
void AdditionalCommands::processCommand(Client *client, const std::string &command)
|
||||
{
|
||||
if (command.find("PART") == 0)
|
||||
std::istringstream iss(command);
|
||||
std::string cmd;
|
||||
iss >> cmd;
|
||||
std::string upperCommand = toUpperCase(cmd) + command.substr(cmd.length());
|
||||
|
||||
// Log the received command
|
||||
_server->log("Received command: " + command, BLUE);
|
||||
_server->log("Converted command to uppercase: " + upperCommand, BLUE);
|
||||
|
||||
if (upperCommand.find("PART") == 0)
|
||||
{
|
||||
_server->log("Handling PART command", GREEN);
|
||||
handlePartCommand(_server, client, command);
|
||||
}
|
||||
else if (command.find("PRIVMSG") == 0)
|
||||
else if (upperCommand.find("PRIVMSG") == 0)
|
||||
{
|
||||
_server->log("Handling PRIVMSG command", GREEN);
|
||||
handlePrivmsgCommand(_server, client, command);
|
||||
}
|
||||
else if (command.find("WHO") == 0)
|
||||
else if (upperCommand.find("WHO") == 0)
|
||||
{
|
||||
_server->log("Handling WHO command", GREEN);
|
||||
WhoHandler whoHandler(_server);
|
||||
whoHandler.handleWhoCommand(client, command);
|
||||
}
|
||||
else if (command.find("WHOIS") == 0)
|
||||
else if (upperCommand.find("WHOIS") == 0)
|
||||
{
|
||||
_server->log("Handling WHOIS command", GREEN);
|
||||
WhoHandler whoHandler(_server);
|
||||
whoHandler.handleWhoisCommand(client, command);
|
||||
}
|
||||
else if (command.find("INVITE") == 0)
|
||||
else if (upperCommand.find("INVITE") == 0)
|
||||
{
|
||||
_server->log("Handling INVITE command", GREEN);
|
||||
InviteHandler inviteHandler(_server);
|
||||
inviteHandler.handleInviteCommand(client, command);
|
||||
}
|
||||
else if (command.find("TOPIC") == 0)
|
||||
else if (upperCommand.find("TOPIC") == 0)
|
||||
{
|
||||
_server->log("Handling TOPIC command", GREEN);
|
||||
TopicHandler topichandler(_server);
|
||||
topichandler.handleTopicCommand(client, command);
|
||||
}
|
||||
else if (command.find("LIST") == 0)
|
||||
else if (upperCommand.find("LIST") == 0)
|
||||
{
|
||||
_server->log("Handling LIST command", GREEN);
|
||||
broadcastChannelList(client, _server);
|
||||
}
|
||||
else if (command.find("KICK") == 0)
|
||||
else if (upperCommand.find("KICK") == 0)
|
||||
{
|
||||
_server->log("Handling KICK command", GREEN);
|
||||
KickHandler kickHandler(_server);
|
||||
kickHandler.handleKickCommand(client, command);
|
||||
}
|
||||
else
|
||||
{
|
||||
_server->log("Unknown command received: " + command, RED);
|
||||
_server->sendToClient(client->getFd(), ERR_UNKNOWNCOMMAND(client, command));
|
||||
_server->log("Message from client " + client->getNickname() + ": " + command, MAGENTA);
|
||||
_server->log("Sent unknown command error to client: " + client->getNickname(), MAGENTA);
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,7 +95,6 @@ void AdditionalCommands::broadcastChannelList(Client *client, Server *server)
|
||||
server->sendToClient(client->getFd(), RPL_LISTEND(client));
|
||||
}
|
||||
|
||||
// Fonction pour gérer la commande PART
|
||||
void AdditionalCommands::handlePartCommand(Server *server, Client *client, const std::string &command)
|
||||
{
|
||||
std::istringstream iss(command);
|
||||
@ -79,7 +103,7 @@ void AdditionalCommands::handlePartCommand(Server *server, Client *client, const
|
||||
|
||||
if (channelNames.empty())
|
||||
{
|
||||
server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "PART"));
|
||||
server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, NULL, "PART"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -104,7 +128,7 @@ void AdditionalCommands::handlePartCommand(Server *server, Client *client, const
|
||||
channel->removeClient(client);
|
||||
|
||||
std::ostringstream partMsg;
|
||||
partMsg << ":" << client->getNickname() << " PART " << channelName << "\r\n";
|
||||
partMsg << ":" << client->getNickname() << " PART " << channelName << " Leaving" << "\r\n";
|
||||
server->sendToClient(client->getFd(), partMsg.str());
|
||||
|
||||
channel->broadcast(partMsg.str(), client, server);
|
||||
@ -126,31 +150,42 @@ void AdditionalCommands::handlePrivmsgCommand(Server *server, Client *client, co
|
||||
iss >> cmd >> target;
|
||||
getline(iss, message);
|
||||
|
||||
// Remove the initial ':' in the message if present
|
||||
_server->log("Handling PRIVMSG command from: " + client->getNickname(), GREEN);
|
||||
|
||||
// Enlever le ':' initial dans le message si présent
|
||||
if (!message.empty() && message[0] == ':')
|
||||
message = message.substr(1);
|
||||
|
||||
_server->log("Target: " + target + ", Message: " + message, GREEN);
|
||||
|
||||
if (target.empty())
|
||||
{
|
||||
_server->log("No recipient specified for PRIVMSG", RED);
|
||||
server->sendToClient(client->getFd(), ERR_NORECIPIENT(client, "PRIVMSG"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.empty())
|
||||
{
|
||||
_server->log("No text to send for PRIVMSG", RED);
|
||||
server->sendToClient(client->getFd(), ERR_NOTEXTTOSEND(client));
|
||||
return;
|
||||
}
|
||||
|
||||
// Récupérer les canaux du serveur
|
||||
std::map<std::string, Channel *> &channels = server->getChannels();
|
||||
|
||||
// Check if the target is a channel
|
||||
// Si la cible est un canal
|
||||
if (channels.find(target) != channels.end())
|
||||
{
|
||||
Channel *channel = channels[target];
|
||||
|
||||
_server->log("Target is a channel: " + target, GREEN);
|
||||
|
||||
// Vérifier les conditions spéciales du canal (ex: ban, modération)
|
||||
if (channel->isBanned(client))
|
||||
{
|
||||
_server->log("Client is banned from channel: " + target, RED);
|
||||
server->sendToClient(client->getFd(), ERR_CANNOTSENDTOCHAN(client, target));
|
||||
return;
|
||||
}
|
||||
@ -158,6 +193,7 @@ void AdditionalCommands::handlePrivmsgCommand(Server *server, Client *client, co
|
||||
// Check the message with the bot filter before sending it
|
||||
if (!server->getBotFilter()->checkMessage(client, channel, message))
|
||||
{
|
||||
_server->log("Message contains inappropriate content and was filtered", RED);
|
||||
// If the message is inappropriate, the bot filter will handle warnings or kicks
|
||||
return;
|
||||
}
|
||||
@ -166,23 +202,28 @@ void AdditionalCommands::handlePrivmsgCommand(Server *server, Client *client, co
|
||||
|
||||
for (size_t i = 0; i < channelClients.size(); ++i)
|
||||
{
|
||||
// Envoyer le message à tous les clients du canal sauf l'émetteur
|
||||
if (channelClients[i] != client)
|
||||
{
|
||||
std::stringstream privMsg;
|
||||
privMsg << ":" << client->getNickname() << " PRIVMSG " << target << " :" << message << "\r\n";
|
||||
server->sendToClient(channelClients[i]->getFd(), privMsg.str());
|
||||
_server->log("Sent PRIVMSG to " + channelClients[i]->getNickname(), GREEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Si la cible est un utilisateur
|
||||
else
|
||||
{
|
||||
Client *targetClient = server->getClientByName(target);
|
||||
_server->log("Target is a user: " + target, GREEN);
|
||||
|
||||
Client *targetClient = server->getClientByName(target); // Utiliser getClientByName pour trouver le client par nom
|
||||
|
||||
if (targetClient)
|
||||
{
|
||||
// Check the message with the bot filter before sending it
|
||||
if (!server->getBotFilter()->checkMessage(client, NULL, message))
|
||||
{
|
||||
_server->log("Message contains inappropriate content and was filtered", RED);
|
||||
// If the message is inappropriate, the bot filter will handle warnings or kicks
|
||||
return;
|
||||
}
|
||||
@ -190,15 +231,19 @@ void AdditionalCommands::handlePrivmsgCommand(Server *server, Client *client, co
|
||||
std::stringstream privMsg;
|
||||
privMsg << ":" << client->getNickname() << " PRIVMSG " << target << " :" << message << "\r\n";
|
||||
server->sendToClient(targetClient->getFd(), privMsg.str());
|
||||
_server->log("Sent PRIVMSG to " + targetClient->getNickname(), GREEN);
|
||||
|
||||
// Check the message with the bot filter before sending it
|
||||
if (targetClient->isAway())
|
||||
{
|
||||
server->sendToClient(client->getFd(), RPL_AWAY(client, targetClient->getNickname(), targetClient->getAwayMessage()));
|
||||
_server->log(targetClient->getNickname() + " is away, sent AWAY reply", GREEN);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the target is neither a channel nor an existing user, send an error message
|
||||
_server->log("No such nick/channel: " + target, RED);
|
||||
// Si la cible n'est ni un canal ni un utilisateur existant, envoyer un message d'erreur
|
||||
server->sendToClient(client->getFd(), ERR_NOSUCHNICK(client, target));
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/06 11:45:43 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/06 21:08:25 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/06/10 14:56:40 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -24,16 +24,22 @@ void BotFilter::loadBadWords(const std::string &fileName)
|
||||
}
|
||||
}
|
||||
|
||||
bool BotFilter::checkMessage(Client *client, Channel *channel, const std::string &message)
|
||||
bool BotFilter::checkMessage(Client* client, Channel* channel, const std::string& message)
|
||||
{
|
||||
if (containsBadWords(message))
|
||||
{
|
||||
warnClient(client, channel);
|
||||
return false; // Message is not allowed
|
||||
if (channel != NULL)
|
||||
{
|
||||
warnClient(client, channel);
|
||||
}
|
||||
else
|
||||
{
|
||||
warnClientDirect(client);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true; // Message is allowed
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotFilter::containsBadWords(const std::string &message)
|
||||
{
|
||||
for (std::vector<std::string>::iterator it = _badWords.begin(); it != _badWords.end(); ++it)
|
||||
@ -68,3 +74,20 @@ void BotFilter::kickClient(Client *client, Channel *channel)
|
||||
_server->sendToClient(client->getFd(), BOTMESSAGE(client, channel->getName(), "You have been kicked for inappropriate language.\r\n"));
|
||||
_server->disconnectClient(client->getFd());
|
||||
}
|
||||
|
||||
void BotFilter::warnClientDirect(Client* client)
|
||||
{
|
||||
int fd = client->getFd();
|
||||
_warnings[fd] += 1;
|
||||
if (_warnings[fd] >= 3)
|
||||
{
|
||||
_server->sendToClient(fd, BOTMESSAGE(client, "", "You have been kicked from the server for inappropriate language.\r\n"));
|
||||
_server->disconnectClient(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Warning: Inappropriate language detected. You have " << (3 - _warnings[fd]) << " warnings left before you are kicked.\r\n";
|
||||
_server->sendToClient(fd, BOTMESSAGE(client, "", oss.str()));
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/15 18:26:34 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/07 11:32:32 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/06/08 19:14:48 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -92,7 +92,7 @@ void CommandHandler::handleCapCommand(Client* client, const std::vector<std::str
|
||||
{
|
||||
if (tokens.size() < 2)
|
||||
{
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "CAP"));
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, NULL, "CAP"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ void CommandHandler::handleCapCommand(Client* client, const std::vector<std::str
|
||||
{
|
||||
if (tokens.size() < 3)
|
||||
{
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "CAP"));
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, NULL, "CAP"));
|
||||
return;
|
||||
}
|
||||
std::string requestedCapabilities = tokens[2];
|
||||
@ -131,7 +131,7 @@ void CommandHandler::handlePassCommand(Client* client, const std::vector<std::st
|
||||
{
|
||||
if (tokens.size() < 2)
|
||||
{
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "PASS"));
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, NULL, "PASS"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -215,7 +215,7 @@ void CommandHandler::handleUser(Client* client, const std::vector<std::string>&
|
||||
{
|
||||
if (tokens.size() < 5)
|
||||
{
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "USER"));
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, NULL, "USER"));
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << "Client " << client->getFd() << ": USER command failed - not enough parameters.";
|
||||
@ -264,7 +264,7 @@ void CommandHandler::handlePingCommand(Client* client, const std::vector<std::st
|
||||
{
|
||||
if (tokens.size() < 2)
|
||||
{
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "PING"));
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, NULL, "PING"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/30 13:02:09 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/07 11:44:34 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/06/08 19:15:29 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -22,7 +22,7 @@ void InviteHandler::handleInviteCommand(Client* client, const std::string& comma
|
||||
|
||||
if (nickname.empty() || channelName.empty())
|
||||
{
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "INVITE"));
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, NULL, "INVITE"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ void JoinHandler::handleJoinCommand(Client* client, const std::string& params, S
|
||||
std::vector<std::string> parts = split(params, " ");
|
||||
if (parts.empty())
|
||||
{
|
||||
server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "JOIN"));
|
||||
server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, NULL, "JOIN"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ void JoinHandler::handleJoinCommand(Client* client, const std::string& params, S
|
||||
|
||||
if (channelName.empty())
|
||||
{
|
||||
server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "JOIN"));
|
||||
server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, NULL, "JOIN"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -139,6 +139,7 @@ void JoinHandler::sendJoinSuccess(Client* client, Channel* channel, Server* serv
|
||||
server->sendToClient(client->getFd(), usersList);
|
||||
}
|
||||
|
||||
|
||||
std::string JoinHandler::getUsersList(Channel* channel)
|
||||
{
|
||||
std::vector<Client*> clients = channel->getClients();
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/01 17:00:31 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/01 19:12:13 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/06/08 19:16:10 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -21,7 +21,7 @@ void KickHandler::handleKickCommand(Client* client, const std::string& command)
|
||||
std::vector<std::string> tokens = split(command, " ");
|
||||
if (tokens.size() < 3)
|
||||
{
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "KICK"));
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, NULL, "KICK"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/30 11:13:08 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/07 14:10:23 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/06/08 22:12:20 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -21,7 +21,7 @@ void ModeHandler::handleModeCommand(Client* client, const std::string& command)
|
||||
|
||||
if (tokens.size() < 2)
|
||||
{
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "MODE"));
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, NULL, "MODE"));
|
||||
_server->log("MODE command error: Need more parameters", RED);
|
||||
return;
|
||||
}
|
||||
@ -139,7 +139,7 @@ void ModeHandler::setChannelMode(Client *client, Channel* channel, const std::st
|
||||
}
|
||||
else if (mode == "t")
|
||||
{
|
||||
applyModeT(channel, adding);
|
||||
applyModeT(client, channel, adding);
|
||||
}
|
||||
else if (mode == "o")
|
||||
applyModeO(client, channel, adding, argument);
|
||||
@ -152,18 +152,19 @@ void ModeHandler::applyModeL(Client *client, Channel* channel, bool adding, cons
|
||||
int limit = std::atoi(argument.c_str());
|
||||
if (limit <= 0)
|
||||
{
|
||||
_server->sendToClient(client->getFd(), ERR_INVALIDMODEPARAM(client, argument));
|
||||
_server->sendToClient(client->getFd(), MODELNEEDPARAM("MODE +l"));
|
||||
_server->log("Invalid limit for mode +l: " + argument, RED);
|
||||
return;
|
||||
}
|
||||
std::ostringstream oss;
|
||||
oss << limit;
|
||||
_server->sendToClient(client->getFd(), MODELCHANGE(client, channel->getName(), argument));
|
||||
_server->sendToClient(client->getFd(), MODEACCEPTMESSAGE(client, channel->getName(), "+l", " " + argument));
|
||||
_server->log("Applying mode L: Setting limit to " + oss.str(), GREEN);
|
||||
channel->setClientLimit(limit);
|
||||
}
|
||||
else
|
||||
{
|
||||
_server->sendToClient(client->getFd(), MODEACCEPTMESSAGE(client, channel->getName(), "-l", " " + argument));
|
||||
_server->log("Applying mode L: Removing limit", RED);
|
||||
channel->setClientLimit(0);
|
||||
}
|
||||
@ -178,7 +179,7 @@ void ModeHandler::applyModeI(Client *client, Channel *channel, bool adding)
|
||||
isAlreadySet = channel->isInviteOnly() == adding;
|
||||
if (!isAlreadySet)
|
||||
{
|
||||
_server->sendToClient(client->getFd(), MODEACCEPTMESSAGE(client, channel->getName(), modeChange));
|
||||
_server->sendToClient(client->getFd(), MODEACCEPTMESSAGE(client, channel->getName(), modeChange, ""));
|
||||
_server->log("Applying mode I: " + std::string(adding ? "Setting invite-only" : "Removing invite-only"), GREEN);
|
||||
channel->setInviteOnly(adding);
|
||||
}
|
||||
@ -199,7 +200,7 @@ void ModeHandler::applyModeK(Client *client, Channel *channel, bool adding, cons
|
||||
}
|
||||
if (argument.empty())
|
||||
{
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "MODE +k"));
|
||||
_server->sendToClient(client->getFd(), MODELNEEDPARAM("MODE +k"));
|
||||
_server->log("Mode +k error: No key provided", RED);
|
||||
return;
|
||||
}
|
||||
@ -209,7 +210,7 @@ void ModeHandler::applyModeK(Client *client, Channel *channel, bool adding, cons
|
||||
_server->log("Invalid key for mode +k: contains spaces", RED);
|
||||
return;
|
||||
}
|
||||
_server->sendToClient(client->getFd(), MODEACCEPTMESSAGE(client, channel->getName(), "+k " + argument));
|
||||
_server->sendToClient(client->getFd(), MODEACCEPTMESSAGE(client, channel->getName(), "+k ", argument));
|
||||
_server->log("Applying mode K: Setting key to " + argument, GREEN);
|
||||
channel->setKey(argument);
|
||||
}
|
||||
@ -221,13 +222,13 @@ void ModeHandler::applyModeK(Client *client, Channel *channel, bool adding, cons
|
||||
_server->log("Mode -k error: No key to remove", RED);
|
||||
return;
|
||||
}
|
||||
_server->sendToClient(client->getFd(), MODEACCEPTMESSAGE(client, channel->getName(), "-k"));
|
||||
_server->sendToClient(client->getFd(), MODELNEEDPARAM("MODE +k "));
|
||||
_server->log("Applying mode K: Removing key", RED);
|
||||
channel->setKey("");
|
||||
}
|
||||
}
|
||||
|
||||
void ModeHandler::applyModeT(Channel* channel, bool adding)
|
||||
void ModeHandler::applyModeT(Client *client, Channel* channel, bool adding)
|
||||
{
|
||||
std::string modeChange;
|
||||
bool isAlreadySet;
|
||||
@ -239,7 +240,7 @@ void ModeHandler::applyModeT(Channel* channel, bool adding)
|
||||
_server->log("Applying mode T: " + std::string(adding ? "Setting topic protection" : "Removing topic protection"), GREEN);
|
||||
channel->setTopicProtection(adding);
|
||||
// Inform the client and channel about the mode change
|
||||
channel->broadcast(MODEACCEPTMESSAGE(NULL, channel->getName(), modeChange), NULL, _server);
|
||||
channel->broadcast(MODEACCEPTMESSAGE(client, channel->getName(), modeChange, ""), NULL, _server);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/30 17:04:58 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/06/01 19:17:25 by fgras-ca ### ########.fr */
|
||||
/* Updated: 2024/06/08 19:17:37 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -21,7 +21,7 @@ void TopicHandler::handleTopicCommand(Client* client, const std::string& command
|
||||
|
||||
if (tokens.size() < 2)
|
||||
{
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, "TOPIC"));
|
||||
_server->sendToClient(client->getFd(), ERR_NEEDMOREPARAMS(client, NULL, "TOPIC"));
|
||||
_server->log("TOPIC command error: Need more parameters", RED);
|
||||
return;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user