IRC SERVER
The goal of this project is to make you write your own IRC server.
Whois.hpp
Go to the documentation of this file.
1 #ifndef WHOIS_H
2 #define WHOIS_H
3 
4 // Our includes
5 #include "../Command.hpp"
6 
7 class Whois : public Command
8 {
9  public:
11  {
12  _name = "whois";
13  _description = "info sobre el usuario usando la mascara";
14  _usage = "whois";
15  _example[0] = "whois <máscara de nick>[,<máscara de nick>[,...]]";
16  _example[1] = "whois guest500";
17 
18  // ERR_NOSUCHSERVER FALTA!!!!
19  /*
20  "<server name> :No such server"
21 
22  - Used to indicate the server name given currently
23  doesn't exist.
24  */
25  // ERR_NONICKNAMEGIVEN
26  // ERR_NOSUCHNICK
27 
28  // RPL_ENDOFWHOIS
29  // RPL_WHOISUSER
30  // RPL_WHOISCHANNELS
31  // RPL_WHOISIDLE
32  // RPL_WHOISOPERATOR
33  // RPL_WHOISSERVER
34  // RPL_AWAY
35  // RPL_WHOISCHANNELS
36  }
37 
38  bool validate(void)
39  {
40  std::map<size_t, std::string> p = _message->getParams();
41  std::vector<std::string> _cl_params = split(p[0], ",");
42 
43  if (_cl_params.size() < 1)
44  {
46  return (false);
47  }
48  for (size_t i = 0; i < _cl_params.size(); i++)
49  {
50  if (_server->getClient(_cl_params[i]) == NULL)
51  {
53  return (false);
54  }
55  }
56  return (true);
57  }
58 
59  void execute()
60  {
61  std::map<size_t, std::string> p = _message->getParams();
62  std::vector<std::string> _cl_params = split(p[0], ",");
63 
64  for (size_t i = 0; i < _cl_params.size(); i++)
65  {
66  Client *client = _server->getClient(_cl_params[i]);
67  client->message(RPL_WHOISUSER(_sender->_servername, client->_nick,
68  client->_username, client->_host,
69  client->_realname));
70  std::map<std::string, Channel *> related_channels = _server->getRelatedChannels(client);
71  std::map<std::string, Channel *>::iterator it = related_channels.begin();
72  std::cout << "servername" << _sender->_servername << std::endl;
73  for (; it != related_channels.end(); it++)
74  {
76  it->second->getClientRoleString(client), it->first));
77  }
78  }
79  }
80 };
81 #endif
Whois::Whois
Whois()
Definition: Whois.hpp:10
Command::_description
std::string _description
Definition: Command.hpp:12
Client::_username
std::string _username
Definition: Client.hpp:27
Command::_name
std::string _name
Definition: Command.hpp:11
Whois
Definition: Whois.hpp:7
RPL_WHOISUSER
#define RPL_WHOISUSER(servername, nick, user, host, realname)
Definition: Replies.hpp:49
Command
Definition: Command.hpp:7
Client::message
void message(char const *message)
Definition: client.cpp:15
Client::_host
std::string _host
Definition: Client.hpp:29
Whois::validate
bool validate(void)
Definition: Whois.hpp:38
ERR_NONICKNAMEGIVEN
#define ERR_NONICKNAMEGIVEN(servername)
Definition: Replies.hpp:118
ERR_NOSUCHNICK
#define ERR_NOSUCHNICK(servername, nick)
Definition: Replies.hpp:104
Command::_message
Message * _message
Definition: Command.hpp:21
split
std::vector< std::string > split(const std::string &str, const std::string &delimiters)
Definition: functions.cpp:37
Command::_example
std::map< size_t, std::string > _example
Definition: Command.hpp:16
Client::_realname
std::string _realname
Definition: Client.hpp:28
Server::getClient
Client * getClient(std::string const &name)
Definition: Server.hpp:140
Message::getParams
std::map< size_t, std::string > getParams(void) const
Definition: message.cpp:79
Client
Definition: Client.hpp:22
Command::_usage
std::string _usage
Definition: Command.hpp:13
Server::getRelatedChannels
std::map< std::string, Channel * > getRelatedChannels(Client *client)
Definition: Server.hpp:114
Command::_sender
Client * _sender
Definition: Command.hpp:19
Client::_nick
std::string _nick
Definition: Client.hpp:26
RPL_WHOISCHANNELS
#define RPL_WHOISCHANNELS(servername, nick, mode, channel)
Definition: Replies.hpp:56
Client::_servername
std::string _servername
Definition: Client.hpp:30
Command::_server
Server * _server
Definition: Command.hpp:20
Whois::execute
void execute()
Definition: Whois.hpp:59