2007-07-16 17:30:04 +00:00
|
|
|
/* +------------------------------------+
|
|
|
|
* | Inspire Internet Relay Chat Daemon |
|
|
|
|
* +------------------------------------+
|
|
|
|
*
|
2009-01-02 18:16:05 +00:00
|
|
|
* InspIRCd: (C) 2002-2009 InspIRCd Development Team
|
2009-03-15 12:42:35 +00:00
|
|
|
* See: http://wiki.inspircd.org/Credits
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
|
|
|
* This program is free but copyrighted software; see
|
|
|
|
* the file COPYING for details.
|
|
|
|
*
|
|
|
|
* ---------------------------------------------------
|
|
|
|
*/
|
2009-02-14 21:14:36 +00:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
#ifndef __CTABLES_H__
|
|
|
|
#define __CTABLES_H__
|
|
|
|
|
|
|
|
/** Used to indicate command success codes
|
|
|
|
*/
|
|
|
|
enum CmdResult
|
|
|
|
{
|
|
|
|
CMD_FAILURE = 0, /* Command exists, but failed */
|
|
|
|
CMD_SUCCESS = 1, /* Command exists, and succeeded */
|
2008-02-03 21:23:06 +00:00
|
|
|
CMD_INVALID = 2 /* Command doesnt exist at all! */
|
2007-07-16 17:30:04 +00:00
|
|
|
};
|
|
|
|
|
2008-09-20 21:14:25 +00:00
|
|
|
/** Translation types for translation of parameters to UIDs.
|
|
|
|
* This allows the core commands to not have to be aware of how UIDs
|
|
|
|
* work (making it still possible to write other linking modules which
|
|
|
|
* do not use UID (but why would you want to?)
|
|
|
|
*/
|
2007-08-27 15:01:14 +00:00
|
|
|
enum TranslateType
|
|
|
|
{
|
|
|
|
TR_END, /* End of known parameters, everything after this is TR_TEXT */
|
|
|
|
TR_TEXT, /* Raw text, leave as-is */
|
|
|
|
TR_NICK, /* Nickname, translate to UUID for server->server */
|
2008-08-09 18:50:12 +00:00
|
|
|
TR_CUSTOM /* Custom translation handled by EncodeParameter/DecodeParameter */
|
2007-08-27 15:01:14 +00:00
|
|
|
};
|
|
|
|
|
2009-09-02 01:06:02 +00:00
|
|
|
/** Routing types for a command. Any command which is created defaults
|
|
|
|
* to having its command broadcasted on success. This behaviour may be
|
|
|
|
* overridden to one of the route types shown below (see the #defines
|
|
|
|
* below for more information on each one's behaviour)
|
|
|
|
*/
|
2009-09-02 00:44:50 +00:00
|
|
|
enum RouteType
|
|
|
|
{
|
|
|
|
ROUTE_TYPE_LOCALONLY,
|
|
|
|
ROUTE_TYPE_BROADCAST,
|
2009-09-02 00:44:59 +00:00
|
|
|
ROUTE_TYPE_UNICAST,
|
2009-10-01 21:41:52 +00:00
|
|
|
ROUTE_TYPE_MESSAGE,
|
2009-09-02 00:44:59 +00:00
|
|
|
ROUTE_TYPE_OPT_BCAST,
|
|
|
|
ROUTE_TYPE_OPT_UCAST
|
2009-09-02 00:44:50 +00:00
|
|
|
};
|
|
|
|
|
2009-09-02 01:06:02 +00:00
|
|
|
/** Defines routing information for a command, containing a destination
|
|
|
|
* server id (if applicable) and a routing type from the enum above.
|
|
|
|
*/
|
2009-09-02 00:44:50 +00:00
|
|
|
struct RouteDescriptor
|
|
|
|
{
|
2009-09-02 01:06:02 +00:00
|
|
|
/** Routing type from the enum above
|
|
|
|
*/
|
2009-10-02 06:13:57 +00:00
|
|
|
RouteType type;
|
2009-09-02 00:44:50 +00:00
|
|
|
/** For unicast, the destination server's name
|
|
|
|
*/
|
2009-10-02 06:13:57 +00:00
|
|
|
std::string serverdest;
|
2009-09-02 01:06:02 +00:00
|
|
|
|
|
|
|
/** Create a RouteDescriptor
|
|
|
|
*/
|
|
|
|
RouteDescriptor(RouteType t, const std::string &d)
|
2009-09-02 00:44:50 +00:00
|
|
|
: type(t), serverdest(d) { }
|
|
|
|
};
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2009-09-02 00:44:59 +00:00
|
|
|
/** Do not route this command */
|
2009-09-02 00:44:50 +00:00
|
|
|
#define ROUTE_LOCALONLY (RouteDescriptor(ROUTE_TYPE_LOCALONLY, ""))
|
2009-09-02 00:44:59 +00:00
|
|
|
/** Route this command to all servers, fail if not understood */
|
2009-09-02 00:44:50 +00:00
|
|
|
#define ROUTE_BROADCAST (RouteDescriptor(ROUTE_TYPE_BROADCAST, ""))
|
2009-09-02 00:44:59 +00:00
|
|
|
/** Route this command to a single server (do nothing if own server name specified) */
|
2009-09-02 00:44:50 +00:00
|
|
|
#define ROUTE_UNICAST(x) (RouteDescriptor(ROUTE_TYPE_UNICAST, x))
|
2009-10-01 21:41:52 +00:00
|
|
|
/** Route this command as a message with the given target (any of user, #channel, @#channel, $servermask) */
|
|
|
|
#define ROUTE_MESSAGE(x) (RouteDescriptor(ROUTE_TYPE_MESSAGE, x))
|
2009-09-02 01:06:02 +00:00
|
|
|
/** Route this command to all servers wrapped via ENCAP, so ignored if not understood */
|
2009-09-02 00:44:59 +00:00
|
|
|
#define ROUTE_OPT_BCAST (RouteDescriptor(ROUTE_TYPE_OPT_BCAST, ""))
|
2009-09-02 01:06:02 +00:00
|
|
|
/** Route this command to a single server wrapped via ENCAP, so ignored if not understood */
|
2009-09-02 00:44:59 +00:00
|
|
|
#define ROUTE_OPT_UCAST(x) (RouteDescriptor(ROUTE_TYPE_OPT_UCAST, x))
|
2007-07-16 17:30:04 +00:00
|
|
|
|
|
|
|
/** A structure that defines a command. Every command available
|
2007-10-15 20:55:55 +00:00
|
|
|
* in InspIRCd must be defined as derived from Command.
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
2009-10-18 16:18:44 +00:00
|
|
|
class CoreExport Command : public classbase
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** Command name
|
|
|
|
*/
|
2009-10-13 21:34:29 +00:00
|
|
|
const std::string command;
|
2009-09-02 00:48:48 +00:00
|
|
|
|
2009-09-13 20:32:27 +00:00
|
|
|
/** Creator module - never NULL */
|
2009-10-19 20:12:22 +00:00
|
|
|
ModuleRef creator;
|
2008-10-25 16:41:09 +00:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** User flags needed to execute the command or 0
|
|
|
|
*/
|
|
|
|
char flags_needed;
|
2008-10-25 16:41:09 +00:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Minimum number of parameters command takes
|
|
|
|
*/
|
2008-10-25 16:41:09 +00:00
|
|
|
const unsigned int min_params;
|
|
|
|
|
|
|
|
/** Maximum number of parameters command takes.
|
|
|
|
* This is used by the command parser to join extra parameters into one last param.
|
|
|
|
* If not set, no munging is done to this command.
|
|
|
|
*/
|
|
|
|
const unsigned int max_params;
|
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** used by /stats m
|
|
|
|
*/
|
2007-09-27 15:48:05 +00:00
|
|
|
long double use_count;
|
2008-10-25 16:41:09 +00:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** used by /stats m
|
|
|
|
*/
|
2009-09-02 00:48:48 +00:00
|
|
|
long double total_bytes;
|
2008-10-25 16:41:09 +00:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** True if the command is disabled to non-opers
|
|
|
|
*/
|
|
|
|
bool disabled;
|
2008-10-25 16:41:09 +00:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** True if the command can be issued before registering
|
|
|
|
*/
|
|
|
|
bool works_before_reg;
|
2008-10-25 16:41:09 +00:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Syntax string for the command, displayed if non-empty string.
|
|
|
|
* This takes place of the text in the 'not enough parameters' numeric.
|
|
|
|
*/
|
|
|
|
std::string syntax;
|
|
|
|
|
2008-09-20 21:14:25 +00:00
|
|
|
/** Translation type list for possible parameters, used to tokenize
|
|
|
|
* parameters into UIDs and SIDs etc.
|
|
|
|
*/
|
2007-08-27 15:01:14 +00:00
|
|
|
std::vector<TranslateType> translation;
|
|
|
|
|
2007-10-21 12:50:58 +00:00
|
|
|
/** How many seconds worth of penalty does this command have?
|
|
|
|
*/
|
2009-09-13 20:32:27 +00:00
|
|
|
int Penalty;
|
2007-10-21 12:50:58 +00:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Create a new command.
|
|
|
|
* @param Instance Pointer to creator class
|
|
|
|
* @param cmd Command name. This must be UPPER CASE.
|
2008-02-13 10:39:25 +00:00
|
|
|
* @param flags User mode required to execute the command. May ONLY be one mode - it's a string to give warnings if people mix params up.
|
2007-07-16 17:30:04 +00:00
|
|
|
* For oper only commands, set this to 'o', otherwise use 0.
|
|
|
|
* @param minpara Minimum parameters required for the command.
|
2008-10-25 16:41:09 +00:00
|
|
|
* @param maxpara Maximum number of parameters this command may have - extra parameters will be tossed into one last space-seperated param.
|
2007-07-16 17:30:04 +00:00
|
|
|
* @param before_reg If this is set to true, the command will
|
|
|
|
* be allowed before the user is 'registered' (has sent USER,
|
|
|
|
* NICK, optionally PASS, and been resolved).
|
|
|
|
*/
|
2009-09-13 20:32:27 +00:00
|
|
|
Command(Module* me, const std::string &cmd, int minpara = 0, int maxpara = 0) :
|
|
|
|
command(cmd), creator(me), flags_needed(0), min_params(minpara), max_params(maxpara),
|
|
|
|
use_count(0), total_bytes(0), disabled(false), works_before_reg(false), Penalty(1)
|
2008-10-25 16:41:09 +00:00
|
|
|
{
|
2007-07-16 17:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Handle the command from a user.
|
|
|
|
* @param parameters The parameters for the command.
|
|
|
|
* @param user The user who issued the command.
|
|
|
|
* @return Return CMD_SUCCESS on success, or CMD_FAILURE on failure.
|
|
|
|
*/
|
2008-05-04 21:37:36 +00:00
|
|
|
virtual CmdResult Handle(const std::vector<std::string>& parameters, User* user) = 0;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2009-09-02 00:44:50 +00:00
|
|
|
virtual RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
|
|
|
|
{
|
2009-09-03 15:53:15 +00:00
|
|
|
return ROUTE_LOCALONLY;
|
2009-09-02 00:44:50 +00:00
|
|
|
}
|
|
|
|
|
2008-08-09 17:15:43 +00:00
|
|
|
/** Encode a parameter for server->server transmission.
|
|
|
|
* Used for parameters for which the translation type is TR_CUSTOM.
|
|
|
|
* @param parameter The parameter to encode. Can be modified in place.
|
|
|
|
* @param index The parameter index (0 == first parameter).
|
|
|
|
*/
|
|
|
|
virtual void EncodeParameter(std::string& parameter, int index)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Decode a parameter from server->server transmission.
|
|
|
|
* Not currently used in this version of InspIRCd.
|
|
|
|
* Used for parameters for which the translation type is TR_CUSTOM.
|
|
|
|
* @param parameter The parameter to decode. Can be modified in place.
|
|
|
|
* @param index The parameter index (0 == first parameter).
|
|
|
|
*/
|
|
|
|
virtual void DecodeParameter(std::string& parameter, int index)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Disable or enable this command.
|
|
|
|
* @param setting True to disable the command.
|
|
|
|
*/
|
|
|
|
void Disable(bool setting)
|
|
|
|
{
|
|
|
|
disabled = setting;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Obtain this command's disable state.
|
|
|
|
* @return true if the command is currently disabled
|
|
|
|
* (disabled commands can be used only by operators)
|
|
|
|
*/
|
|
|
|
bool IsDisabled()
|
|
|
|
{
|
|
|
|
return disabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @return true if the command works before registration.
|
|
|
|
*/
|
|
|
|
bool WorksBeforeReg()
|
|
|
|
{
|
|
|
|
return works_before_reg;
|
|
|
|
}
|
|
|
|
|
2009-10-13 21:34:29 +00:00
|
|
|
virtual ~Command();
|
2007-07-16 17:30:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** A hash of commands used by the core
|
|
|
|
*/
|
2008-06-06 15:47:39 +00:00
|
|
|
typedef nspace::hash_map<std::string,Command*> Commandtable;
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2008-09-20 21:14:25 +00:00
|
|
|
/** Shortcut macros for defining translation lists
|
|
|
|
*/
|
2007-08-27 15:35:14 +00:00
|
|
|
#define TRANSLATE1(x1) translation.push_back(x1);
|
|
|
|
#define TRANSLATE2(x1,x2) translation.push_back(x1);translation.push_back(x2);
|
|
|
|
#define TRANSLATE3(x1,x2,x3) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);
|
|
|
|
#define TRANSLATE4(x1,x2,x3,x4) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);
|
|
|
|
#define TRANSLATE5(x1,x2,x3,x4,x5) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
|
|
|
|
translation.push_back(x5);
|
|
|
|
#define TRANSLATE6(x1,x2,x3,x4,x5,x6) translation.push_back(x1);translation.push_back(x2);translation.push_back(x3);translation.push_back(x4);\
|
|
|
|
translation.push_back(x5);translation.push_back(x6);
|
|
|
|
#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);\
|
|
|
|
translation.push_back(x5);translation.push_back(x6);translation.push_back(x7);
|
|
|
|
#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);\
|
|
|
|
translation.push_back(x5);translation.push_back(x6);translation.push_back(x7);translation.push_back(x8);
|
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
#endif
|