1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
18 #include "inspircd_config.h"
22 /* Forward declarations - required */
26 /** Used to indicate command success codes
30 CMD_FAILURE = 0, /* Command exists, but failed */
31 CMD_SUCCESS = 1, /* Command exists, and succeeded */
32 CMD_INVALID = 2, /* Command doesnt exist at all! */
33 CMD_USER_DELETED = 3 /* User was deleted - DEPRECIATED */
38 TR_END, /* End of known parameters, everything after this is TR_TEXT */
39 TR_TEXT, /* Raw text, leave as-is */
40 TR_NICK, /* Nickname, translate to UUID for server->server */
41 TR_NICKLIST, /* Comma seperated nickname list, translate to UUIDs */
42 TR_SPACENICKLIST /* Space seperated nickname list, translate to UUIDs */
45 /** For commands which should not be replicated to other
46 * servers, we usually return CMD_FAILURE. this isnt readable,
47 * so we define this alias for CMD_FAILURE called
48 * CMD_LOCALONLY, which of course does the same thing but is
51 #define CMD_LOCALONLY CMD_FAILURE
54 /** A structure that defines a command. Every command available
55 * in InspIRCd must be defined as derived from command_t.
57 class CoreExport command_t : public Extensible
60 /** Owner/Creator object
62 InspIRCd* ServerInstance;
67 /** User flags needed to execute the command or 0
70 /** Minimum number of parameters command takes
79 /** used for resource tracking between modules
82 /** True if the command is disabled to non-opers
85 /** True if the command can be issued before registering
87 bool works_before_reg;
88 /** Syntax string for the command, displayed if non-empty string.
89 * This takes place of the text in the 'not enough parameters' numeric.
93 std::vector<TranslateType> translation;
95 /** Create a new command.
96 * @param Instance Pointer to creator class
97 * @param cmd Command name. This must be UPPER CASE.
98 * @param flags User modes required to execute the command.
99 * For oper only commands, set this to 'o', otherwise use 0.
100 * @param minpara Minimum parameters required for the command.
101 * @param before_reg If this is set to true, the command will
102 * be allowed before the user is 'registered' (has sent USER,
103 * NICK, optionally PASS, and been resolved).
105 command_t(InspIRCd* Instance, const std::string &cmd, char flags, int minpara, int before_reg = false) : ServerInstance(Instance), command(cmd), flags_needed(flags), min_params(minpara), disabled(false), works_before_reg(before_reg)
114 /** Handle the command from a user.
115 * @param parameters The parameters for the command.
116 * @param pcnt The number of parameters available in 'parameters'
117 * @param user The user who issued the command.
118 * @return Return CMD_SUCCESS on success, or CMD_FAILURE on failure.
119 * If the command succeeds but should remain local to this server,
120 * return CMD_LOCALONLY.
122 virtual CmdResult Handle(const char** parameters, int pcnt, userrec* user) = 0;
124 /** Handle an internal request from another command, the core, or a module
126 * @param Zero or more parameters, whos form is specified by the command ID.
127 * @return Return CMD_SUCCESS on success, or CMD_FAILURE on failure.
128 * If the command succeeds but should remain local to this server,
129 * return CMD_LOCALONLY.
131 virtual CmdResult HandleInternal(const unsigned int id, const std::deque<classbase*> ¶ms)
136 /** Handle the command from a server.
137 * Not currently used in this version of InspIRCd.
138 * @param parameters The parameters given
139 * @param pcnt The number of parameters available
140 * @param servername The server name which issued the command
141 * @return Return CMD_SUCCESS on success, or CMD_FAILURE on failure.
142 * If the command succeeds but should remain local to this server,
143 * return CMD_LOCALONLY.
145 virtual CmdResult HandleServer(const char** parameters, int pcnt, const std::string &servername)
150 /** Disable or enable this command.
151 * @param setting True to disable the command.
153 void Disable(bool setting)
158 /** Obtain this command's disable state.
159 * @return true if the command is currently disabled
160 * (disabled commands can be used only by operators)
167 /** @return true if the command works before registration.
169 bool WorksBeforeReg()
171 return works_before_reg;
174 /** Standard constructor gubbins
176 virtual ~command_t() {}
179 /** A hash of commands used by the core
181 typedef nspace::hash_map<std::string,command_t*> command_table;
183 #define TRANSLATE1(x1) translation.push_back(x1);
184 #define TRANSLATE2(x1,x2) translation.push_back(x1);translation.push_back(x2);
185 #define TRANSLATE3(x1,x2,x3) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);
186 #define TRANSLATE4(x1,x2,x3,x4) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);
187 #define TRANSLATE5(x1,x2,x3,x4,x5) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
188 translation.push_back(x5);
189 #define TRANSLATE6(x1,x2,x3,x4,x5,x6) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
190 translation.push_back(x5);translation.push_back(x6);
191 #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);\
192 translation.push_back(x5);translation.push_back(x6);translation.push_back(x7);
193 #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);\
194 translation.push_back(x5);translation.push_back(x6);translation.push_back(x7);translation.push_back(x8);