Improving commands and added quit
This commit is contained in:
42
cmds/quit.cpp
Normal file
42
cmds/quit.cpp
Normal 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());
|
||||
}
|
||||
Reference in New Issue
Block a user