Files
ft_irc/cmds/join.cpp
2026-05-15 22:07:05 +02:00

40 lines
1.6 KiB
C++

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* join.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/05/15 15:35:16 by aortigos #+# #+# */
/* Updated: 2026/05/15 22:06:36 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "../Server/Server.hpp"
void Server::join_cmd(User &client, std::istringstream &ss)
{
std::string args;
ss >> args;
if (!client.isRegistered()) return (client.send("You are not registered"));
if (args.empty()) return (client.send("No name specified\r\n"));
std::map<std::string, Channel>::iterator it = channels_.find(args);
if (it == channels_.end())
{
// Channel doesnt exists, create and join
channels_[args] = Channel(args);
channels_[args].addMember(client.getFd());
channels_[args].addOperator(client.getFd());
return (client.send("Channel created\r\n"));
}
else
{
if (it->second.hasMember(client.getFd())) return (client.send("You are already in this channel\r\n"));
it->second.addMember(client.getFd());
}
}