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 */
36 /** For commands which should not be replicated to other
37 * servers, we usually return CMD_FAILURE. this isnt readable,
38 * so we define this alias for CMD_FAILURE called
39 * CMD_LOCALONLY, which of course does the same thing but is
42 #define CMD_LOCALONLY CMD_FAILURE
45 /** A structure that defines a command. Every command available
46 * in InspIRCd must be defined as derived from command_t.
48 class CoreExport command_t : public Extensible
51 /** Owner/Creator object
53 InspIRCd* ServerInstance;
58 /** User flags needed to execute the command or 0
61 /** Minimum number of parameters command takes
70 /** used for resource tracking between modules
73 /** True if the command is disabled to non-opers
76 /** True if the command can be issued before registering
78 bool works_before_reg;
79 /** Syntax string for the command, displayed if non-empty string.
80 * This takes place of the text in the 'not enough parameters' numeric.
84 /** Create a new command.
85 * @param Instance Pointer to creator class
86 * @param cmd Command name. This must be UPPER CASE.
87 * @param flags User modes required to execute the command.
88 * For oper only commands, set this to 'o', otherwise use 0.
89 * @param minpara Minimum parameters required for the command.
90 * @param before_reg If this is set to true, the command will
91 * be allowed before the user is 'registered' (has sent USER,
92 * NICK, optionally PASS, and been resolved).
94 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)
102 /** Handle the command from a user.
103 * @param parameters The parameters for the command.
104 * @param pcnt The number of parameters available in 'parameters'
105 * @param user The user who issued the command.
106 * @return Return CMD_SUCCESS on success, or CMD_FAILURE on failure.
107 * If the command succeeds but should remain local to this server,
108 * return CMD_LOCALONLY.
110 virtual CmdResult Handle(const char** parameters, int pcnt, userrec* user) = 0;
112 /** Handle an internal request from another command, the core, or a module
114 * @param Zero or more parameters, whos form is specified by the command ID.
115 * @return Return CMD_SUCCESS on success, or CMD_FAILURE on failure.
116 * If the command succeeds but should remain local to this server,
117 * return CMD_LOCALONLY.
119 virtual CmdResult HandleInternal(const unsigned int id, const std::deque<classbase*> ¶ms)
124 /** Handle the command from a server.
125 * Not currently used in this version of InspIRCd.
126 * @param parameters The parameters given
127 * @param pcnt The number of parameters available
128 * @param servername The server name which issued the command
129 * @return Return CMD_SUCCESS on success, or CMD_FAILURE on failure.
130 * If the command succeeds but should remain local to this server,
131 * return CMD_LOCALONLY.
133 virtual CmdResult HandleServer(const char** parameters, int pcnt, const std::string &servername)
138 /** Disable or enable this command.
139 * @param setting True to disable the command.
141 void Disable(bool setting)
146 /** Obtain this command's disable state.
147 * @return true if the command is currently disabled
148 * (disabled commands can be used only by operators)
155 /** @return true if the command works before registration.
157 bool WorksBeforeReg()
159 return works_before_reg;
162 /** Standard constructor gubbins
164 virtual ~command_t() {}
167 /** A hash of commands used by the core
169 typedef nspace::hash_map<std::string,command_t*> command_table;