IRC SERVER
The goal of this project is to make you write your own IRC server.
List.hpp
Go to the documentation of this file.
1 #ifndef LIST_H
2 #define LIST_H
3 
4 // Our includes
5 #include "../Command.hpp"
6 
7 class List : public Command
8 {
9  public:
10  List()
11  {
12  _name = "list";
13  _description = "listar informacion del canal";
14  _usage = "list [<canales>]";
15  _example[0] = "list";
16  _example[1] = "list #hola";
17  _example[2] = "list #hola,#chau";
18  }
19 
20  void execute()
21  {
22  std::map<size_t, std::string> p = _message->getParams();
24  if (p.size() == 1)
25  {
26  std::vector<std::string> _ch_params = split(p[0], ",");
27 
28  for (size_t i = 0; i < _ch_params.size(); i++)
29  {
30  Channel *channel = _server->getChannel(_ch_params[i]);
31  if (channel)
32  {
34  _sender->_servername, _sender->getNick(), channel->getName(),
35  itoa(channel->getClients().size()), channel->getTopic()));
36  }
37  }
38  }
39  else
40  {
41  std::vector<Channel *> channels = _server->getChannels();
42  for (size_t i = 0; i < channels.size(); i++)
43  {
44  if (!channels[i]->hasMode(CHANNEL_MODE_SECRET) || channels[i]->joined(_sender))
45  {
47  _sender->_servername, _sender->getNick(), channels[i]->getName(),
48  itoa(channels[i]->getClients().size()), channels[i]->getTopic()));
49  }
50  }
51  }
53  }
54 };
55 #endif
List::execute
void execute()
Definition: List.hpp:20
Channel
Definition: Channel.hpp:26
Channel::getName
std::string & getName(void)
Definition: Channel.hpp:82
RPL_LISTEND
#define RPL_LISTEND(servername, nick)
Definition: Replies.hpp:63
Command::_description
std::string _description
Definition: Command.hpp:12
Channel::getTopic
std::string & getTopic(void)
Definition: Channel.hpp:87
Client::getNick
const std::string getNick(void) const
Definition: Client.hpp:142
Command::_name
std::string _name
Definition: Command.hpp:11
Command
Definition: Command.hpp:7
CHANNEL_MODE_SECRET
@ CHANNEL_MODE_SECRET
Definition: Channel.hpp:9
Client::message
void message(char const *message)
Definition: client.cpp:15
Server::getChannels
std::vector< Channel * > getChannels(void)
Definition: Server.hpp:212
Command::_message
Message * _message
Definition: Command.hpp:21
List::List
List()
Definition: List.hpp:10
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
RPL_LISTSTART
#define RPL_LISTSTART(servername, nick)
Definition: Replies.hpp:59
Channel::getClients
std::vector< Client * > getClients(void) const
Definition: Channel.hpp:172
itoa
std::string itoa(int a)
Definition: functions.cpp:15
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
List
Definition: List.hpp:7
Command::_usage
std::string _usage
Definition: Command.hpp:13
RPL_LIST
#define RPL_LIST(servername, nick, channel, users, topic)
Definition: Replies.hpp:61
Command::_sender
Client * _sender
Definition: Command.hpp:19
Client::_servername
std::string _servername
Definition: Client.hpp:30
Command::_server
Server * _server
Definition: Command.hpp:20