Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #ifndef COMMANDS_H
  2. #define COMMANDS_H
  3.  
  4. namespace Irc
  5. {
  6.     class Commands;
  7.     class User;
  8.     class Channel;
  9.     enum CommandType_t
  10.     {
  11.         CMD_JOIN, //normal users
  12.         CMD_PART, //normal ///
  13.         CMD_QUIT, //normal
  14.         CMD_NICK, //normal
  15.         CMD_KILL, //oper
  16.         CMD_KLINE, //oper
  17.         CMD_GLINE, //oper
  18.         CMD_AWAY, //normal
  19.         CMD_WHOIS, //normal
  20.         CMD_PRIVMSG, //normal
  21.         CMD_TOPIC, //normal
  22.         CMD_USER, //normal
  23.         CMD_CMDLIST, //normal
  24.         CMD_OPER, //oper
  25.         CMD_KICK, //normal
  26.         CMD_MODE, //normal
  27.         CMD_CHAN_MODE
  28.     };
  29. } //namespace Irc
  30.  
  31. #include <string>
  32.  
  33. #ifndef cmdInstance
  34.     #define cmdInstance &Commands::instance()
  35. #endif
  36. #ifndef CMD_NOTIFY
  37.     #define CMD_NOTIFY(x) cmdInstance->registerCommand(x)
  38. #endif
  39.  
  40. #include <map>
  41.  
  42. class Irc::Commands
  43. {
  44.     public:
  45.         Commands();
  46.         ~Commands();
  47.  
  48.         static Commands instance()
  49.         {
  50.             static Commands i;
  51.             return i;
  52.         }
  53.  
  54.         void registerCommand(const char *cmd);
  55.         bool isRegistered();
  56.  
  57.         void executeCommand(const char *cmd, bool check = true);
  58.  
  59.         //channel commands
  60.         void join(User* user, Channel* chan, const char *msg);
  61.         void part(User* user, Channel* chan, const char *msg);
  62.         void topic(User* user, Channel* chan, const char *msg);
  63.         void kick(User* user, Channel* chan, const char *msg);
  64.         void chanMode(User* user, Channel* chan, const char* mode);
  65.  
  66.         ////odd commands
  67.         void quit(User* user);
  68.         void nick(User* user, const char *__nick);
  69.         void away(User* user, const char *__msg);
  70.         void whois(User* dest, User* from);
  71.         void privmsg(User* from, const char *__channel, const char *__msg);
  72.         void user(User* user, ...);
  73.         void cmdList(User* user);
  74.         void oper(User* user, const char *acc, const char *pass);
  75.         void mode(User* user, const char mode);
  76.  
  77.         //oper commands
  78.         void kill(User* dest, User* from);
  79.         void kline(User* dest, User* from);
  80.         void gline(User* dest, User* from);
  81.  
  82.     protected:
  83.         typedef void(*chan_t)(User* user, Channel* chan, const char *msg);
  84.         typedef std::map<const char*, chan_t> ChannelCommandsMap;
  85.         typedef void(*normal_t)(User* dest, User* from);
  86.         typedef std::map<const char*, normal_t> NormalCommandsMap;
  87.         typedef void(*opercmd_t)(User* dest, User* oper);
  88.         typedef std::map<const char*, opercmd_t> OperCommandsMap;
  89.         ChannelCommandsMap m_channelCommands;
  90.         NormalCommandsMap m_normalCommands;
  91.         OperCommandsMap m_operCommands;
  92. };
  93. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement