Added MODE and invite only functionality
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* join.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* By: iherman- <iherman-@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/05/15 15:35:16 by aortigos #+# #+# */
|
||||
/* Updated: 2026/05/16 17:04:29 by aortigos ### ########.fr */
|
||||
/* Updated: 2026/05/23 18:32:37 by iherman- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -23,6 +23,7 @@ void Server::join_cmd(User &client, std::istringstream &ss)
|
||||
|
||||
std::map<std::string, Channel>::iterator it = channels_.find(args);
|
||||
|
||||
// creates channel
|
||||
if (it == channels_.end())
|
||||
{
|
||||
channels_[args] = Channel(args);
|
||||
@@ -51,29 +52,37 @@ void Server::join_cmd(User &client, std::istringstream &ss)
|
||||
else
|
||||
{
|
||||
if (it->second.hasMember(client.getFd()))
|
||||
client.send(":" SERVER_NAME " 443 " + client.getNick() + " " + args + " :is already on channel\r\n");
|
||||
else
|
||||
{
|
||||
client.joinChannel(it->first);
|
||||
it->second.addMember(client.getFd());
|
||||
std::string joinMsg = ":" + client.getNick() + "!" + client.getUsername() + "@localhost JOIN " + args + "\r\n";
|
||||
channels_[args].broadcast(joinMsg, clients_, -1);
|
||||
|
||||
|
||||
std::string namesList = ":" SERVER_NAME " 353 " + client.getNick() + " = " + args + " :";
|
||||
const std::set<int> &members = channels_[args].getMembers();
|
||||
for (std::set<int>::const_iterator m = members.begin(); m != members.end(); m++)
|
||||
{
|
||||
std::map<int, User>::iterator u = clients_.find(*m);
|
||||
if (u != clients_.end())
|
||||
{
|
||||
if (channels_[args].hasOperator(*m))
|
||||
namesList += "@";
|
||||
namesList += u->second.getNick() + " ";
|
||||
}
|
||||
}
|
||||
client.send(namesList + "\r\n");
|
||||
client.send(":" SERVER_NAME " 366 " + client.getNick() + " " + args + " :End of /NAMES list\r\n");
|
||||
client.send(":" SERVER_NAME " 443 " + client.getNick() + " " + args + " :is already on channel\r\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
if (it->second.isInviteOnly() && !it->second.isInvited(client.getFd()))
|
||||
{
|
||||
client.send(":" SERVER_NAME " 473 " + client.getNick() + " " + args + " :Cannot join channel (+i)\r\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
it->second.addMember(client.getFd());
|
||||
|
||||
client.joinChannel(it->first);
|
||||
|
||||
std::string joinMsg = ":" + client.getNick() + "!" + client.getUsername() + "@localhost JOIN " + args + "\r\n";
|
||||
channels_[args].broadcast(joinMsg, clients_, -1);
|
||||
|
||||
std::string namesList = ":" SERVER_NAME " 353 " + client.getNick() + " = " + args + " :";
|
||||
const std::set<int> &members = channels_[args].getMembers();
|
||||
for (std::set<int>::const_iterator m = members.begin(); m != members.end(); m++)
|
||||
{
|
||||
std::map<int, User>::iterator u = clients_.find(*m);
|
||||
if (u != clients_.end())
|
||||
{
|
||||
if (channels_[args].hasOperator(*m))
|
||||
namesList += "@";
|
||||
namesList += u->second.getNick() + " ";
|
||||
}
|
||||
}
|
||||
client.send(namesList + "\r\n");
|
||||
client.send(":" SERVER_NAME " 366 " + client.getNick() + " " + args + " :End of /NAMES list\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user