Files
irc/commands/join.cpp
aortigos 94028a5215 part cmd
2026-04-19 01:47:20 +02:00

42 lines
1.5 KiB
C++

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* join.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/04/17 16:26:18 by aortigos #+# #+# */
/* Updated: 2026/04/19 01:37:10 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "../Server/Server.hpp"
void Server::cmd_join(int fd, std::istringstream &ss)
{
std::string args;
ss >> args;
if (!clients[fd].isRegistered())
{
std::string msg = "You are not registered\r\n";
send(fd, msg.c_str(), msg.size(), 0);
return ;
}
if (channels.find(args) == channels.end())
{
channels.insert(std::make_pair(args, Channel(args)));
channels[args].addMember(fd);
std::string msg = "Channel created\r\n";
send(fd, msg.c_str(), msg.size(), 0);
} else {
channels[args].addMember(fd);
std::string msg = "Channel already exists\r\n";
send(fd, msg.c_str(), msg.size(), 0);
}
}