The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

ctables.h

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013  
00014 #ifndef __CTABLES_H__
00015 #define __CTABLES_H__
00016 
00019 enum CmdResult
00020 {
00021         CMD_FAILURE = 0,        /* Command exists, but failed */
00022         CMD_SUCCESS = 1,        /* Command exists, and succeeded */
00023         CMD_INVALID = 2         /* Command doesnt exist at all! */
00024 };
00025 
00026 enum TranslateType
00027 {
00028         TR_END,                 /* End of known parameters, everything after this is TR_TEXT */
00029         TR_TEXT,                /* Raw text, leave as-is */
00030         TR_NICK,                /* Nickname, translate to UUID for server->server */
00031         TR_NICKLIST,            /* Comma seperated nickname list, translate to UUIDs */
00032         TR_SPACENICKLIST,       /* Space seperated nickname list, translate to UUIDs */
00033         TR_CUSTOM               /* Custom translation handled by EncodeParameter/DecodeParameter */
00034 };
00035 
00042 #define CMD_LOCALONLY CMD_FAILURE
00043 
00044 
00048 class CoreExport Command : public Extensible
00049 {
00050  protected:
00053         InspIRCd* ServerInstance;
00054  public:
00057          std::string command;
00060         char flags_needed;
00063         unsigned int min_params;
00066         long double use_count;
00069         long double total_bytes;
00072         std::string source;
00075         bool disabled;
00078         bool works_before_reg;
00082         std::string syntax;
00083 
00084         std::vector<TranslateType> translation;
00085 
00088         const int Penalty;
00089 
00100         Command(InspIRCd* Instance, const std::string &cmd, const char *flags, int minpara, int before_reg = false, int penalty = 1) :  ServerInstance(Instance), command(cmd), flags_needed(flags ? *flags : 0), min_params(minpara), disabled(false), works_before_reg(before_reg),   Penalty(penalty)
00101         {
00102                 use_count = 0;
00103                 total_bytes = 0;
00104                 source = "<core>";
00105                 syntax = "";
00106                 translation.clear();
00107         }
00108 
00116         virtual CmdResult Handle(const std::vector<std::string>& parameters, User* user) = 0;
00117 
00125         virtual CmdResult HandleInternal(const unsigned int /* id */, const std::deque<classbase*>& /* params */)
00126         {
00127                 return CMD_INVALID;
00128         }
00129 
00138         virtual CmdResult HandleServer(const std::vector<std::string>& /* parameters */, const std::string& /* servername */)
00139         {
00140                 return CMD_INVALID;
00141         }
00142 
00148         virtual void EncodeParameter(std::string& parameter, int index)
00149         {
00150         }
00151 
00158         virtual void DecodeParameter(std::string& parameter, int index)
00159         {
00160         }
00161 
00165         void Disable(bool setting)
00166         {
00167                 disabled = setting;
00168         }
00169 
00174         bool IsDisabled()
00175         {
00176                 return disabled;
00177         }
00178 
00181         bool WorksBeforeReg()
00182         {
00183                 return works_before_reg;
00184         }
00185 
00188         virtual ~Command()
00189         {
00190                 syntax.clear();
00191         }
00192 };
00193 
00196 typedef nspace::hash_map<std::string,Command*> Commandtable;
00197 
00198 #define TRANSLATE1(x1)  translation.push_back(x1);
00199 #define TRANSLATE2(x1,x2)  translation.push_back(x1);translation.push_back(x2);
00200 #define TRANSLATE3(x1,x2,x3)  translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);
00201 #define TRANSLATE4(x1,x2,x3,x4)  translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);
00202 #define TRANSLATE5(x1,x2,x3,x4,x5)  translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
00203         translation.push_back(x5);
00204 #define TRANSLATE6(x1,x2,x3,x4,x5,x6)  translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
00205         translation.push_back(x5);translation.push_back(x6);
00206 #define TRANSLATE7(x1,x2,x3,x4,x5,x6,x7)  translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
00207         translation.push_back(x5);translation.push_back(x6);translation.push_back(x7);
00208 #define TRANSLATE8(x1,x2,x3,x4,x5,x6,x7,x8)  translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
00209         translation.push_back(x5);translation.push_back(x6);translation.push_back(x7);translation.push_back(x8);
00210 
00211 #endif
00212