45 lines
1.6 KiB
C++
45 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/16 11:22:00 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\r\n"));
|
|
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())
|
|
{
|
|
channels_[args] = Channel(args);
|
|
channels_[args].addMember(client.getFd());
|
|
channels_[args].addOperator(client.getFd());
|
|
client.joinChannel(args);
|
|
return (client.send("Channel created\r\n"));
|
|
}
|
|
else
|
|
{
|
|
if (it->second.hasMember(client.getFd()))
|
|
client.send("You are already in this channel\r\n");
|
|
else
|
|
{
|
|
client.joinChannel(it->first);
|
|
it->second.addMember(client.getFd());
|
|
}
|
|
}
|
|
}
|