Added working INVITE command
This commit is contained in:
71
cmds/invite.cpp
Normal file
71
cmds/invite.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* invclient_ite.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: iherman- <iherman-@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/05/23 20:22:46 by iherman- #+# #+# */
|
||||
/* Updated: 2026/05/23 21:14:14 by iherman- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../Server/Server.hpp"
|
||||
|
||||
void Server::invite_cmd(User &client, std::istringstream &ss)
|
||||
{
|
||||
std::string target;
|
||||
std::string channel;
|
||||
|
||||
ss >> target >> channel;
|
||||
|
||||
if (!client.isRegistered()) return (client.send(":" SERVER_NAME " 451 * :You have not registered\r\n"));
|
||||
|
||||
if (target.empty() || channel.empty())
|
||||
{
|
||||
return client.send(":" SERVER_NAME " 461 * INVITE :Not enough parameters\r\n");
|
||||
}
|
||||
|
||||
// verify target exists
|
||||
std::map<int, User>::iterator client_it = clients_.begin();
|
||||
for (; client_it != clients_.end(); ++client_it)
|
||||
{
|
||||
if (client_it->second.getNick() == target)
|
||||
break;
|
||||
}
|
||||
if (client_it == clients_.end())
|
||||
{
|
||||
client.send(":" SERVER_NAME " 401 " + target + " :No such nick\r\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
// verify channel exist & user is on channel
|
||||
std::map<std::string, Channel>::iterator channel_it = channels_.find(channel);
|
||||
if (channel_it == channels_.end())
|
||||
{
|
||||
client.send(":" SERVER_NAME " 401 " + target + " :No such channel\r\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
if (!channel_it->second.hasMember(client.getFd()))
|
||||
{
|
||||
client.send(":" SERVER_NAME " 442 " + channel + " :You are not on that channel\r\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
if (channel_it->second.hasMember(client_it->second.getFd()))
|
||||
{
|
||||
client.send(":" SERVER_NAME " 443 " + channel + " :is already on channel\r\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
if (channel_it->second.isInviteOnly() && !channel_it->second.hasOperator(client.getFd()))
|
||||
{
|
||||
client.send(":" SERVER_NAME " 482 " + channel + ":You're not channel operator\r\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
client_it->second.send("YOUVE BEEN INVITED YAAAAAAAYYYYY!!!!!!");
|
||||
channel_it->second.inviteMember(client_it->second);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user