2003-01-23 19:45:57 +00:00
|
|
|
/* +------------------------------------+
|
|
|
|
* | Inspire Internet Relay Chat Daemon |
|
|
|
|
* +------------------------------------+
|
|
|
|
*
|
2006-12-15 22:18:59 +00:00
|
|
|
* InspIRCd: (C) 2002-2007 InspIRCd Development Team
|
|
|
|
* See: http://www.inspircd.org/wiki/index.php/Credits
|
|
|
|
*
|
2003-01-23 19:45:57 +00:00
|
|
|
* This program is free but copyrighted software; see
|
|
|
|
* the file COPYING for details.
|
|
|
|
*
|
|
|
|
* ---------------------------------------------------
|
|
|
|
*/
|
2004-05-16 14:58:40 +00:00
|
|
|
|
2004-04-29 15:35:00 +00:00
|
|
|
#ifndef __CTABLES_H__
|
|
|
|
#define __CTABLES_H__
|
|
|
|
|
2006-07-19 13:50:16 +00:00
|
|
|
|
2003-01-23 19:45:57 +00:00
|
|
|
#include "inspircd_config.h"
|
2006-04-08 17:05:48 +00:00
|
|
|
#include "hash_map.h"
|
2006-07-10 18:25:17 +00:00
|
|
|
#include "base.h"
|
2005-12-16 12:00:52 +00:00
|
|
|
|
|
|
|
class userrec;
|
2006-08-11 00:15:07 +00:00
|
|
|
class InspIRCd;
|
2005-12-16 12:00:52 +00:00
|
|
|
|
2006-09-06 17:21:59 +00:00
|
|
|
/** Used to indicate command success codes
|
|
|
|
*/
|
|
|
|
enum CmdResult
|
|
|
|
{
|
|
|
|
CMD_FAILURE = 0, /* Command exists, but failed */
|
|
|
|
CMD_SUCCESS = 1, /* Command exists, and succeeded */
|
|
|
|
CMD_INVALID = 2, /* Command doesnt exist at all! */
|
2006-09-13 20:07:19 +00:00
|
|
|
CMD_USER_DELETED = 3, /* User was deleted! */
|
2006-09-06 17:21:59 +00:00
|
|
|
};
|
2005-12-14 17:44:38 +00:00
|
|
|
|
2006-12-17 14:40:34 +00:00
|
|
|
/* For commands which should not be replicated to other
|
|
|
|
* servers, we usually return CMD_FAILURE. this isnt readable,
|
|
|
|
* so we define this alias for CMD_FAILURE called
|
|
|
|
* CMD_LOCALONLY, which of course does the same thing but is
|
|
|
|
* much more readable.
|
|
|
|
*/
|
|
|
|
#define CMD_LOCALONLY CMD_FAILURE
|
|
|
|
|
|
|
|
|
2007-01-09 22:31:19 +00:00
|
|
|
/** A structure that defines a command. Every command available
|
|
|
|
* in InspIRCd must be defined as derived from command_t.
|
2003-02-09 12:49:00 +00:00
|
|
|
*/
|
2006-07-10 18:22:16 +00:00
|
|
|
class command_t : public Extensible
|
2003-01-26 23:53:03 +00:00
|
|
|
{
|
2006-08-11 00:15:07 +00:00
|
|
|
protected:
|
2007-01-09 22:31:19 +00:00
|
|
|
/** Owner/Creator object
|
|
|
|
*/
|
2006-08-11 00:15:07 +00:00
|
|
|
InspIRCd* ServerInstance;
|
2003-01-26 23:53:03 +00:00
|
|
|
public:
|
2004-04-11 13:08:31 +00:00
|
|
|
/** Command name
|
|
|
|
*/
|
2005-12-16 18:10:38 +00:00
|
|
|
std::string command;
|
2003-02-09 12:49:00 +00:00
|
|
|
/** User flags needed to execute the command or 0
|
|
|
|
*/
|
|
|
|
char flags_needed;
|
2004-04-11 13:08:31 +00:00
|
|
|
/** Minimum number of parameters command takes
|
|
|
|
*/
|
2003-02-09 12:49:00 +00:00
|
|
|
int min_params;
|
|
|
|
/** used by /stats m
|
|
|
|
*/
|
|
|
|
long use_count;
|
|
|
|
/** used by /stats m
|
|
|
|
*/
|
|
|
|
long total_bytes;
|
2005-04-07 17:04:04 +00:00
|
|
|
/** used for resource tracking between modules
|
|
|
|
*/
|
2005-12-16 18:10:38 +00:00
|
|
|
std::string source;
|
2006-07-16 13:02:38 +00:00
|
|
|
/** True if the command is disabled to non-opers
|
|
|
|
*/
|
|
|
|
bool disabled;
|
2006-09-03 00:09:38 +00:00
|
|
|
/** True if the command can be issued before registering
|
|
|
|
*/
|
|
|
|
bool works_before_reg;
|
2006-07-28 00:13:41 +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;
|
2005-12-16 18:10:38 +00:00
|
|
|
|
2007-01-09 22:31:19 +00:00
|
|
|
/** Create a new command.
|
|
|
|
* @param Instance Pointer to creator class
|
|
|
|
* @param cmd Command name. This must be UPPER CASE.
|
|
|
|
* @param flags User modes required to execute the command.
|
|
|
|
* For oper only commands, set this to 'o', otherwise use 0.
|
|
|
|
* @param minpara Minimum parameters required for the command.
|
|
|
|
* @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).
|
|
|
|
*/
|
2006-09-03 00:09:38 +00:00
|
|
|
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)
|
2005-12-16 18:10:38 +00:00
|
|
|
{
|
|
|
|
use_count = total_bytes = 0;
|
|
|
|
source = "<core>";
|
2006-07-28 00:13:41 +00:00
|
|
|
syntax = "";
|
2005-12-16 18:10:38 +00:00
|
|
|
}
|
|
|
|
|
2007-01-09 22:31:19 +00:00
|
|
|
/** Handle the command from a user.
|
|
|
|
* @param parameters The parameters for the command.
|
|
|
|
* @param pcnt The number of parameters available in 'parameters'
|
|
|
|
* @param user The user who issued the command.
|
|
|
|
* @return Return CMD_SUCCESS on success, or CMD_FAILURE on failure.
|
|
|
|
* If the command succeeds but should remain local to this server,
|
|
|
|
* return CMD_LOCALONLY.
|
|
|
|
*/
|
2006-09-06 17:21:59 +00:00
|
|
|
virtual CmdResult Handle(const char** parameters, int pcnt, userrec* user) = 0;
|
2005-12-16 18:10:38 +00:00
|
|
|
|
2007-01-09 22:31:19 +00:00
|
|
|
/** Handle an internal request from another command, the core, or a module
|
|
|
|
* @param Command ID
|
|
|
|
* @param Zero or more parameters, whos form is specified by the command ID.
|
|
|
|
* @return Return CMD_SUCCESS on success, or CMD_FAILURE on failure.
|
|
|
|
* If the command succeeds but should remain local to this server,
|
|
|
|
* return CMD_LOCALONLY.
|
|
|
|
*/
|
2007-01-07 01:24:44 +00:00
|
|
|
virtual CmdResult HandleInternal(const unsigned int id, const std::deque<classbase*> ¶ms)
|
|
|
|
{
|
|
|
|
return CMD_INVALID;
|
|
|
|
}
|
|
|
|
|
2007-01-09 22:31:19 +00:00
|
|
|
/** Handle the command from a server.
|
|
|
|
* Not currently used in this version of InspIRCd.
|
|
|
|
* @param parameters The parameters given
|
|
|
|
* @param pcnt The number of parameters available
|
|
|
|
* @param servername The server name which issued the command
|
|
|
|
* @return Return CMD_SUCCESS on success, or CMD_FAILURE on failure.
|
|
|
|
* If the command succeeds but should remain local to this server,
|
|
|
|
* return CMD_LOCALONLY.
|
|
|
|
*/
|
2006-10-31 17:42:09 +00:00
|
|
|
virtual CmdResult HandleServer(const char** parameters, int pcnt, const std::string &servername)
|
|
|
|
{
|
|
|
|
return CMD_INVALID;
|
|
|
|
}
|
|
|
|
|
2007-01-09 22:31:19 +00:00
|
|
|
/** Disable or enable this command.
|
|
|
|
* @param setting True to disable the command.
|
|
|
|
*/
|
2006-07-16 13:02:38 +00:00
|
|
|
void Disable(bool setting)
|
|
|
|
{
|
|
|
|
disabled = setting;
|
|
|
|
}
|
|
|
|
|
2007-01-09 22:31:19 +00:00
|
|
|
/** Obtain this command's disable state.
|
|
|
|
* @return true if the command is currently disabled
|
|
|
|
* (disabled commands can be used only by operators)
|
|
|
|
*/
|
2006-07-16 13:02:38 +00:00
|
|
|
bool IsDisabled()
|
|
|
|
{
|
|
|
|
return disabled;
|
|
|
|
}
|
|
|
|
|
2007-01-09 22:31:19 +00:00
|
|
|
/** @return true if the command works before registration.
|
|
|
|
*/
|
2006-09-03 00:09:38 +00:00
|
|
|
bool WorksBeforeReg()
|
|
|
|
{
|
|
|
|
return works_before_reg;
|
|
|
|
}
|
|
|
|
|
2007-01-09 22:31:19 +00:00
|
|
|
/** Standard constructor gubbins
|
|
|
|
*/
|
2005-12-16 18:10:38 +00:00
|
|
|
virtual ~command_t() {}
|
2003-01-23 19:45:57 +00:00
|
|
|
};
|
|
|
|
|
2007-01-09 22:31:19 +00:00
|
|
|
/** A hash of commands used by the core
|
|
|
|
*/
|
2005-12-28 21:21:54 +00:00
|
|
|
typedef nspace::hash_map<std::string,command_t*> command_table;
|
2005-12-16 12:00:52 +00:00
|
|
|
|
2003-01-23 19:45:57 +00:00
|
|
|
#endif
|
2007-01-09 22:31:19 +00:00
|
|
|
|