IRC SERVER
The goal of this project is to make you write your own IRC server.
Help.hpp
Go to the documentation of this file.
1 #ifndef HELP_H
2 #define HELP_H
3 
4 // Our includes
5 #include "../Command.hpp"
6 
7 class Help : public Command
8 {
9  public:
10  Help()
11  {
12  _name = "help";
13  _description = "See a guide about each implemented command";
14  _usage = "help <command?>";
15  _example[0] = "help";
16  _example[1] = "help ping";
17  }
18 
19  void execute()
20  {
21  std::string res = "";
22  bool filtering = false;
23  std::map<std::string, Command *>::iterator it = _server->_commands.begin();
24  std::map<size_t, std::string> params = _message->getParams();
25 
26  res = std::string(C_U) + std::string(C_BOLD) + std::string(C_GREEN) + "Commands usage guide" + std::string(C_X) + "\n";
27 
28  if (params.size() == 1 && _server->_commands.count(params[0]))
29  filtering = true;
30 
31  for (; it != _server->_commands.end(); it++)
32  {
33  if (filtering && it->second->getName() != params[0])
34  continue;
35  res += std::string("Command: " + it->second->getName() +
36  "\n\t Description: " + it->second->getDescription() +
37  "\n\t Usage: " + it->second->getUsage() + "\n\t Example:\n");
38 
39  std::map<size_t, std::string> example(it->second->getExample());
40  std::map<size_t, std::string>::iterator it_ex = example.begin();
41  for (; it_ex != example.end(); it_ex++)
42  res += std::string("\t\t" + it_ex->second + "\n");
43  res += "\n";
44  }
45  _sender->message(res.c_str());
46  }
47 };
48 #endif
C_GREEN
#define C_GREEN
Definition: Color.hpp:7
Server::_commands
std::map< std::string, Command * > _commands
Definition: Server.hpp:51
Command::_description
std::string _description
Definition: Command.hpp:12
Command::_name
std::string _name
Definition: Command.hpp:11
Command
Definition: Command.hpp:7
Client::message
void message(char const *message)
Definition: client.cpp:15
Help::execute
void execute()
Definition: Help.hpp:19
Command::_message
Message * _message
Definition: Command.hpp:21
Command::_example
std::map< size_t, std::string > _example
Definition: Command.hpp:16
Help
Definition: Help.hpp:7
Message::getParams
std::map< size_t, std::string > getParams(void) const
Definition: message.cpp:79
C_U
#define C_U
Definition: Color.hpp:14
Help::Help
Help()
Definition: Help.hpp:10
Command::_usage
std::string _usage
Definition: Command.hpp:13
Command::_sender
Client * _sender
Definition: Command.hpp:19
C_BOLD
#define C_BOLD
Definition: Color.hpp:16
C_X
#define C_X
Definition: Color.hpp:4
Command::_server
Server * _server
Definition: Command.hpp:20