Improving commands and added quit

This commit is contained in:
aortigos
2026-05-16 11:47:45 +02:00
parent 3de8940560
commit 66bd57bfde
9 changed files with 108 additions and 11 deletions

42
cmds/quit.cpp Normal file
View File

@@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* quit.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/05/15 15:35:16 by aortigos #+# #+# */
/* Updated: 2026/05/16 11:46:45 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "../Server/Server.hpp"
void Server::quit_cmd(User &client, std::istringstream &ss)
{
std::string reason;
std::getline(ss, reason);
if (!reason.empty() && reason[0] == ' ')
reason = reason.substr(1);
if (!reason.empty() && reason[0] == ':')
reason = reason.substr(1);
if (reason.empty())
reason = "Leaving";
std::string msg = ":" + client.getNick() + "!" + client.getUsername() + "@localhost QUIT :" + reason + "\r\n";
const std::set<std::string> channels = client.getChannels();
for (std::set<std::string>::const_iterator it = channels.begin(); it != channels.end(); it++)
{
std::map<std::string, Channel>::iterator ch = channels_.find(*it);
if (ch != channels_.end())
{
ch->second.broadcast(msg, clients_, client.getFd());
ch->second.removeMember(client.getFd());
}
}
close(client.getFd());
}