mirror of
https://github.com/anope/anope.git
synced 2026-06-30 15:46:39 +02:00
Moved Commands stuff to its own file and changed Command::name to be ci::string - Will be used after hashing system is rewritten
This commit is contained in:
+106
-7
@@ -11,17 +11,116 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "modules.h"
|
||||
#ifndef COMMAND_H_
|
||||
#define COMMAND_H_
|
||||
|
||||
/*************************************************************************/
|
||||
#define MAX_CMD_HASH 1024
|
||||
#define CMD_HASH(x) (((x)[0]&31)<<5 | ((x)[1]&31)) /* Will gen a hash from a string :) */
|
||||
|
||||
/* Routines for looking up commands. Command lists are arrays that must be
|
||||
* terminated with a NULL name.
|
||||
*/
|
||||
#define HOSTSERV HS_cmdTable /* using HOSTSERV etc. looks nicer than HS_cmdTable for modules */
|
||||
#define BOTSERV BS_cmdTable
|
||||
#define MEMOSERV MS_cmdTable
|
||||
#define NICKSERV NS_cmdTable
|
||||
#define CHANSERV CS_cmdTable
|
||||
#define OPERSERV OS_cmdTable
|
||||
|
||||
#ifndef _WIN32
|
||||
#define MDE
|
||||
#else
|
||||
#ifndef MODULE_COMPILE
|
||||
#define MDE __declspec(dllexport)
|
||||
#else
|
||||
#define MDE __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** The return value from commands.
|
||||
* */
|
||||
enum CommandReturn
|
||||
{
|
||||
MOD_CONT,
|
||||
MOD_STOP
|
||||
};
|
||||
|
||||
class Command;
|
||||
|
||||
extern MDE Command *lookup_cmd(Command *list, char *name);
|
||||
extern MDE void mod_help_cmd(char *service, User *u, CommandHash *cmdTable[], const char *cmd);
|
||||
extern MDE void mod_run_cmd(const std::string &service, User *u, CommandHash *cmdTable[], const char *cmd);
|
||||
//extern MDE void do_help_limited(char *service, User * u, Command * c);
|
||||
|
||||
/*************************************************************************/
|
||||
struct CommandHash {
|
||||
char *name; /* Name of the command */
|
||||
Command *c; /* Actual command */
|
||||
CommandHash *next; /* Next command */
|
||||
};
|
||||
|
||||
extern MDE CommandHash *HOSTSERV[MAX_CMD_HASH];
|
||||
extern MDE CommandHash *BOTSERV[MAX_CMD_HASH];
|
||||
extern MDE CommandHash *MEMOSERV[MAX_CMD_HASH];
|
||||
extern MDE CommandHash *NICKSERV[MAX_CMD_HASH];
|
||||
extern MDE CommandHash *CHANSERV[MAX_CMD_HASH];
|
||||
extern MDE CommandHash *OPERSERV[MAX_CMD_HASH];
|
||||
|
||||
enum CommandFlag
|
||||
{
|
||||
CFLAG_ALLOW_UNREGISTERED,
|
||||
CFLAG_ALLOW_FORBIDDEN,
|
||||
CFLAG_ALLOW_SUSPENDED,
|
||||
CFLAG_ALLOW_UNREGISTEREDCHANNEL,
|
||||
CFLAG_STRIP_CHANNEL,
|
||||
CFLAG_DISABLE_FANTASY
|
||||
};
|
||||
|
||||
/** Every services command is a class, inheriting from Command.
|
||||
*/
|
||||
class CoreExport Command : public Flags<CommandFlag>
|
||||
{
|
||||
public:
|
||||
size_t MaxParams;
|
||||
size_t MinParams;
|
||||
ci::string name;
|
||||
std::string permission;
|
||||
|
||||
/** Create a new command.
|
||||
* @param sname The command name
|
||||
* @param min_params The minimum number of parameters the parser will require to execute this command
|
||||
* @param max_params The maximum number of parameters the parser will create, after max_params, all will be combined into the last argument.
|
||||
* NOTE: If max_params is not set (default), there is no limit to the max number of params.
|
||||
*/
|
||||
Command(const ci::string &sname, size_t min_params, size_t max_params = 0, const std::string &spermission = "");
|
||||
|
||||
virtual ~Command();
|
||||
|
||||
/** Execute this command.
|
||||
* @param u The user executing the command.
|
||||
*/
|
||||
virtual CommandReturn Execute(User *u, const std::vector<ci::string> &);
|
||||
|
||||
/** Requested when the user is requesting help on this command. Help on this command should be sent to the user.
|
||||
* @param u The user requesting help
|
||||
* @param subcommand The subcommand the user is requesting help on, or an empty string. (e.g. /ns help set foo bar lol gives a subcommand of
|
||||
"FOO BAR LOL")
|
||||
* @return true if help was provided to the user, false otherwise.
|
||||
*/
|
||||
virtual bool OnHelp(User *u, const ci::string &subcommand);
|
||||
|
||||
/** Requested when the user provides bad syntax to this command (not enough params, etc).
|
||||
* @param u The user executing the command.
|
||||
* @param subcommand The subcommand the user tried to use
|
||||
*/
|
||||
virtual void OnSyntaxError(User *u, const ci::string &subcommand);
|
||||
|
||||
/** Set which command permission (e.g. chanserv/forbid) is required for this command.
|
||||
* @param reststr The permission required to successfully execute this command
|
||||
*/
|
||||
void SetPermission(const std::string &reststr);
|
||||
|
||||
/* Module related stuff */
|
||||
int core; /* Can this command be deleted? */
|
||||
char *mod_name; /* Name of the module who owns us, NULL for core's */
|
||||
char *service; /* Service we provide this command for */
|
||||
Command *next;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+1
-91
@@ -19,6 +19,7 @@
|
||||
#include "timers.h"
|
||||
#include "hashcomp.h"
|
||||
#include "version.h"
|
||||
#include "commands.h"
|
||||
|
||||
/* Cross OS compatibility macros */
|
||||
#ifdef _WIN32
|
||||
@@ -113,23 +114,7 @@ enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST, PRIORITY_BEFOR
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
#define CMD_HASH(x) (((x)[0]&31)<<5 | ((x)[1]&31)) /* Will gen a hash from a string :) */
|
||||
#define MAX_CMD_HASH 1024
|
||||
|
||||
/** The return value from commands.
|
||||
*/
|
||||
enum CommandReturn
|
||||
{
|
||||
MOD_CONT,
|
||||
MOD_STOP
|
||||
};
|
||||
|
||||
#define HOSTSERV HS_cmdTable /* using HOSTSERV etc. looks nicer than HS_cmdTable for modules */
|
||||
#define BOTSERV BS_cmdTable
|
||||
#define MEMOSERV MS_cmdTable
|
||||
#define NICKSERV NS_cmdTable
|
||||
#define CHANSERV CS_cmdTable
|
||||
#define OPERSERV OS_cmdTable
|
||||
#define IRCD IRCD_cmdTable
|
||||
#define MODULE_HASH Module_table
|
||||
#define EVENT EVENT_cmdTable
|
||||
@@ -191,7 +176,6 @@ typedef enum { MOD_OP_LOAD, MOD_OP_UNLOAD } ModuleOperation;
|
||||
/*************************************************************************/
|
||||
/* Structure for information about a *Serv command. */
|
||||
|
||||
struct CommandHash;
|
||||
typedef struct ModuleLang_ ModuleLang;
|
||||
typedef struct ModuleHash_ ModuleHash;
|
||||
typedef struct Message_ Message;
|
||||
@@ -199,15 +183,6 @@ typedef struct MessageHash_ MessageHash;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
extern MDE CommandHash *HOSTSERV[MAX_CMD_HASH];
|
||||
extern MDE CommandHash *BOTSERV[MAX_CMD_HASH];
|
||||
extern MDE CommandHash *MEMOSERV[MAX_CMD_HASH];
|
||||
extern MDE CommandHash *NICKSERV[MAX_CMD_HASH];
|
||||
extern MDE CommandHash *CHANSERV[MAX_CMD_HASH];
|
||||
extern MDE CommandHash *OPERSERV[MAX_CMD_HASH];
|
||||
extern MDE MessageHash *IRCD[MAX_CMD_HASH];
|
||||
extern MDE ModuleHash *MODULE_HASH[MAX_CMD_HASH];
|
||||
|
||||
@@ -216,65 +191,6 @@ struct ModuleLang_ {
|
||||
char **argv;
|
||||
};
|
||||
|
||||
enum CommandFlag
|
||||
{
|
||||
CFLAG_ALLOW_UNREGISTERED,
|
||||
CFLAG_ALLOW_FORBIDDEN,
|
||||
CFLAG_ALLOW_SUSPENDED,
|
||||
CFLAG_ALLOW_UNREGISTEREDCHANNEL,
|
||||
CFLAG_STRIP_CHANNEL,
|
||||
CFLAG_DISABLE_FANTASY
|
||||
};
|
||||
|
||||
/** Every services command is a class, inheriting from Command.
|
||||
*/
|
||||
class CoreExport Command : public Flags<CommandFlag>
|
||||
{
|
||||
public:
|
||||
size_t MaxParams;
|
||||
size_t MinParams;
|
||||
std::string name;
|
||||
std::string permission;
|
||||
|
||||
/** Create a new command.
|
||||
* @param min_params The minimum number of parameters the parser will require to execute this command
|
||||
* @param max_params The maximum number of parameters the parser will create, after max_params, all will be combined into the last argument.
|
||||
* NOTE: If max_params is not set (default), there is no limit to the max number of params.
|
||||
*/
|
||||
Command(const std::string &sname, size_t min_params, size_t max_params = 0, const std::string &spermission = "");
|
||||
|
||||
virtual ~Command();
|
||||
|
||||
/** Execute this command.
|
||||
* @param u The user executing the command.
|
||||
*/
|
||||
virtual CommandReturn Execute(User *u, const std::vector<ci::string> &);
|
||||
|
||||
/** Requested when the user is requesting help on this command. Help on this command should be sent to the user.
|
||||
* @param u The user requesting help
|
||||
* @param subcommand The subcommand the user is requesting help on, or an empty string. (e.g. /ns help set foo bar lol gives a subcommand of "FOO BAR LOL")
|
||||
* @return true if help was provided to the user, false otherwise.
|
||||
*/
|
||||
virtual bool OnHelp(User *u, const ci::string &subcommand);
|
||||
|
||||
/** Requested when the user provides bad syntax to this command (not enough params, etc).
|
||||
* @param u The user executing the command.
|
||||
* @param subcommand The subcommand the user tried to use
|
||||
*/
|
||||
virtual void OnSyntaxError(User *u, const ci::string &subcommand);
|
||||
|
||||
/** Set which command permission (e.g. chanserv/forbid) is required for this command.
|
||||
* @param reststr The permission required to successfully execute this command
|
||||
*/
|
||||
void SetPermission(const std::string &reststr);
|
||||
|
||||
/* Module related stuff */
|
||||
int core; /* Can this command be deleted? */
|
||||
char *mod_name; /* Name of the module who owns us, NULL for core's */
|
||||
char *service; /* Service we provide this command for */
|
||||
Command *next;
|
||||
};
|
||||
|
||||
class Version
|
||||
{
|
||||
private:
|
||||
@@ -1324,12 +1240,6 @@ struct ModuleHash_ {
|
||||
ModuleHash *next;
|
||||
};
|
||||
|
||||
struct CommandHash {
|
||||
char *name; /* Name of the command */
|
||||
Command *c; /* Actual command */
|
||||
CommandHash *next; /* Next command */
|
||||
};
|
||||
|
||||
struct Message_ {
|
||||
char *name;
|
||||
int (*func)(const char *source, int ac, const char **av);
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "commands.h"
|
||||
#include "modules.h"
|
||||
#include "language.h"
|
||||
#include "timers.h"
|
||||
#include "slist.h"
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "services.h"
|
||||
#include "modules.h"
|
||||
#include "commands.h"
|
||||
|
||||
BotInfo::BotInfo(const std::string &nnick, const std::string &nuser, const std::string &nhost, const std::string &nreal)
|
||||
{
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
#include "services.h"
|
||||
#include "modules.h"
|
||||
|
||||
Command::Command(const std::string &sname, size_t min_params, size_t max_params, const std::string &spermission) : MaxParams(max_params), MinParams(min_params), name(sname), permission(spermission)
|
||||
Command::Command(const ci::string &sname, size_t min_params, size_t max_params, const std::string &spermission) : MaxParams(max_params), MinParams(min_params), name(sname), permission(spermission)
|
||||
{
|
||||
this->core = 0;
|
||||
this->mod_name = NULL;
|
||||
|
||||
+25
-1
@@ -12,12 +12,36 @@
|
||||
*/
|
||||
|
||||
#include "services.h"
|
||||
#include "commands.h"
|
||||
#include "modules.h"
|
||||
#include "language.h"
|
||||
#include "hashcomp.h"
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Search the command table gieven for a command.
|
||||
* @param cmdTable the name of the command table to search
|
||||
* @param name the name of the command to look for
|
||||
* @return returns a pointer to the found command struct, or NULL
|
||||
*/
|
||||
Command *findCommand(CommandHash * cmdTable[], const char *name)
|
||||
{
|
||||
int idx;
|
||||
CommandHash *current = NULL;
|
||||
if (!cmdTable || !name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
idx = CMD_HASH(name);
|
||||
|
||||
for (current = cmdTable[idx]; current; current = current->next) {
|
||||
if (stricmp(name, current->name) == 0) {
|
||||
return current->c;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Command corresponding to the given name, or NULL if no such
|
||||
* command exists.
|
||||
|
||||
@@ -362,30 +362,6 @@ int Module::DelCommand(CommandHash * cmdTable[], const char *dname)
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search the command table gieven for a command.
|
||||
* @param cmdTable the name of the command table to search
|
||||
* @param name the name of the command to look for
|
||||
* @return returns a pointer to the found command struct, or NULL
|
||||
*/
|
||||
Command *findCommand(CommandHash * cmdTable[], const char *name)
|
||||
{
|
||||
int idx;
|
||||
CommandHash *current = NULL;
|
||||
if (!cmdTable || !name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
idx = CMD_HASH(name);
|
||||
|
||||
for (current = cmdTable[idx]; current; current = current->next) {
|
||||
if (stricmp(name, current->name) == 0) {
|
||||
return current->c;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Message Functions
|
||||
*******************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user