IRC SERVER
The goal of this project is to make you write your own IRC server.
Command.hpp
Go to the documentation of this file.
1 #ifndef COMMAND_H
2 #define COMMAND_H
3 
4 // Our includes
5 #include "./Server.hpp"
6 
7 class Command
8 {
9  // We make it protected in order to be able to implemet it
10  protected:
11  std::string _name;
12  std::string _description;
13  std::string _usage;
14  bool _is_ope;
16  std::map<size_t, std::string> _example;
17 
18  // Command non related vars
22  size_t _sender_index;
23 
24  public:
25  std::string getName() const
26  {
27  return _name;
28  };
29  std::string getDescription() const
30  {
31  return _description;
32  };
33  std::string getUsage() const
34  {
35  return _usage;
36  };
37  std::map<size_t, std::string> getExample() const
38  {
39  return _example;
40  };
41  Client *getSender() const
42  {
43  return _sender;
44  };
45  void setSender(Client *sender)
46  {
47  _sender = sender;
48  };
49  void setServer(Server *server)
50  {
51  _server = server;
52  };
53  void setMessage(Message *message)
54  {
55  _message = message;
56  };
57  bool hasOpe(void)
58  {
59  return (_is_ope);
60  };
61  bool needsAuth(void)
62  {
63  return (_needs_auth);
64  };
65 
66  public:
67  virtual void execute() = 0;
68 
69  virtual bool validate(void)
70  {
71  return (true);
72  }
73 
74  virtual std::vector<Message> parser(Message *message)
75  {
76  std::vector<Message> messages;
77  messages.push_back(Message(message->_buffer));
78  return (messages);
79  }
81  : _is_ope(false), _needs_auth(true), _sender(NULL), _server(NULL), _message(NULL){};
82  void missingOpe(void)
83  {
85  std::string("You need operator role in order to exec " + _name + "\n")
86  .c_str());
87  };
88  virtual ~Command()
89  {
90  std::cout << "Command " << _name << " destructor called" << std::endl;
91  };
92 };
93 
94 #endif
Command::getDescription
std::string getDescription() const
Definition: Command.hpp:29
Command::getUsage
std::string getUsage() const
Definition: Command.hpp:33
Command::getSender
Client * getSender() const
Definition: Command.hpp:41
Command::execute
virtual void execute()=0
Command::_description
std::string _description
Definition: Command.hpp:12
Message::_buffer
std::string _buffer
Definition: Message.hpp:15
Command::_name
std::string _name
Definition: Command.hpp:11
Command
Definition: Command.hpp:7
Server.hpp
Client::message
void message(char const *message)
Definition: client.cpp:15
Command::_sender_index
size_t _sender_index
Definition: Command.hpp:22
Command::setSender
void setSender(Client *sender)
Definition: Command.hpp:45
Command::missingOpe
void missingOpe(void)
Definition: Command.hpp:82
Command::hasOpe
bool hasOpe(void)
Definition: Command.hpp:57
Command::_needs_auth
bool _needs_auth
Definition: Command.hpp:15
Command::getExample
std::map< size_t, std::string > getExample() const
Definition: Command.hpp:37
Command::_message
Message * _message
Definition: Command.hpp:21
Command::_is_ope
bool _is_ope
Definition: Command.hpp:14
Command::_example
std::map< size_t, std::string > _example
Definition: Command.hpp:16
Command::setServer
void setServer(Server *server)
Definition: Command.hpp:49
Command::getName
std::string getName() const
Definition: Command.hpp:25
Command::parser
virtual std::vector< Message > parser(Message *message)
Definition: Command.hpp:74
Command::needsAuth
bool needsAuth(void)
Definition: Command.hpp:61
Command::setMessage
void setMessage(Message *message)
Definition: Command.hpp:53
Command::Command
Command()
Definition: Command.hpp:80
Message
Definition: Message.hpp:12
Command::validate
virtual bool validate(void)
Definition: Command.hpp:69
Client
Definition: Client.hpp:22
Command::_usage
std::string _usage
Definition: Command.hpp:13
Command::_sender
Client * _sender
Definition: Command.hpp:19
Server
Definition: Server.hpp:32
Command::_server
Server * _server
Definition: Command.hpp:20
Command::~Command
virtual ~Command()
Definition: Command.hpp:88