IRC SERVER
The goal of this project is to make you write your own IRC server.
Invite.hpp
Go to the documentation of this file.
1 #ifndef INVITE_H
2 #define INVITE_H
3 
4 // Our includes
5 #include "../Command.hpp"
6 
7 class Invite : public Command
8 {
9  public:
11  {
12  _name = "invite";
13  _description = "invita usuario a canal";
14  _usage = "invite";
15  _example[0] = "invite <nick> <canal>";
16  // _is_opec = true;
17  }
18 
19  bool validate(void)
20  {
21  std::map<size_t, std::string> p = _message->getParams();
22 
23  if (p.size() < 2)
24  {
26  _message->getCmd()));
27  return (false);
28  }
29  Client *client = _server->getClient(p[0]);
30  if (client == NULL)
31  {
33  return (false);
34  }
35  Channel *channel = _server->getChannel(p[1]);
36  if (!channel || !channel->joined(_sender))
37  {
39  return (false);
40  }
41  else if (channel->joined(client))
42  {
45  return (false);
46  }
47  else if (!channel->isOpe(_sender) && !channel->hasMode(CHANNEL_MODE_INVITE_ONLY))
48  {
50  return (false);
51  }
52  return (true);
53  }
54 
55  void execute()
56  {
57  std::map<size_t, std::string> p = _message->getParams();
58 
59  Channel *channel = _server->getChannel(p[1]);
60  Client * client = _server->getClient(p[0]);
61 
63  channel->getName(), client->getUsername()));
64  client->message(
65  RPL_CUSTOM_INVITE(_sender->getUserId(), channel->getName(), client->getUsername()));
66  channel->invite(client);
67  }
68 };
69 #endif
Channel
Definition: Channel.hpp:26
Channel::getName
std::string & getName(void)
Definition: Channel.hpp:82
Channel::isOpe
bool isOpe(Client *client)
Definition: Channel.hpp:195
Invite
Definition: Invite.hpp:7
Command::_description
std::string _description
Definition: Command.hpp:12
Client::_username
std::string _username
Definition: Client.hpp:27
Client::getNick
const std::string getNick(void) const
Definition: Client.hpp:142
Command::_name
std::string _name
Definition: Command.hpp:11
RPL_INVITING
#define RPL_INVITING(servername, nick, channel, user)
Definition: Replies.hpp:76
Command
Definition: Command.hpp:7
Message::getCmd
std::string getCmd(void) const
Definition: message.cpp:74
Client::message
void message(char const *message)
Definition: client.cpp:15
Channel::invite
void invite(Client *client)
Definition: Channel.hpp:279
Client::getUsername
const std::string getUsername(void) const
Definition: Client.hpp:147
ERR_NOSUCHNICK
#define ERR_NOSUCHNICK(servername, nick)
Definition: Replies.hpp:104
Command::_message
Message * _message
Definition: Command.hpp:21
ERR_CHANOPRIVSNEEDED
#define ERR_CHANOPRIVSNEEDED(servername, nick, channel)
Definition: Replies.hpp:154
ERR_NEEDMOREPARAMS
#define ERR_NEEDMOREPARAMS(servername, nick, command)
Definition: Replies.hpp:131
Command::_example
std::map< size_t, std::string > _example
Definition: Command.hpp:16
Invite::validate
bool validate(void)
Definition: Invite.hpp:19
ERR_NOTONCHANNEL
#define ERR_NOTONCHANNEL(servername, nick, channel)
Definition: Replies.hpp:126
Invite::Invite
Invite()
Definition: Invite.hpp:10
RPL_CUSTOM_INVITE
#define RPL_CUSTOM_INVITE(user, channel, nick)
Definition: Replies.hpp:192
Server::getClient
Client * getClient(std::string const &name)
Definition: Server.hpp:140
Channel::joined
bool joined(Client *client)
Definition: Channel.hpp:183
Message::getParams
std::map< size_t, std::string > getParams(void) const
Definition: message.cpp:79
Server::getChannel
Channel * getChannel(std::string &name)
Definition: Server.hpp:202
Client
Definition: Client.hpp:22
Command::_usage
std::string _usage
Definition: Command.hpp:13
Channel::hasMode
bool hasMode(ChannelMode mode)
Definition: Channel.hpp:337
Client::getUserId
const std::string getUserId(void) const
Definition: Client.hpp:162
Command::_sender
Client * _sender
Definition: Command.hpp:19
ERR_USERONCHANNEL
#define ERR_USERONCHANNEL(servername, nick, username, channel)
Definition: Replies.hpp:128
Client::_nick
std::string _nick
Definition: Client.hpp:26
CHANNEL_MODE_INVITE_ONLY
@ CHANNEL_MODE_INVITE_ONLY
Definition: Channel.hpp:10
Client::_servername
std::string _servername
Definition: Client.hpp:30
Invite::execute
void execute()
Definition: Invite.hpp:55
Command::_server
Server * _server
Definition: Command.hpp:20