Doing join command

This commit is contained in:
aortigos
2026-05-15 22:07:05 +02:00
parent f3400b6151
commit b7487c193d
6 changed files with 34 additions and 16 deletions

View File

@@ -6,7 +6,7 @@
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/05/15 15:35:16 by aortigos #+# #+# */
/* Updated: 2026/05/15 15:35:44 by aortigos ### ########.fr */
/* Updated: 2026/05/15 22:06:36 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,5 +15,25 @@
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());
}
}