diff options
-rw-r--r-- | include/commands.h | 113 | ||||
-rw-r--r-- | include/modules.h | 92 | ||||
-rw-r--r-- | include/pseudo.h | 2 | ||||
-rw-r--r-- | src/bots.cpp | 1 | ||||
-rw-r--r-- | src/command.cpp | 2 | ||||
-rw-r--r-- | src/commands.c | 26 | ||||
-rw-r--r-- | src/modules.c | 24 |
7 files changed, 135 insertions, 125 deletions
diff --git a/include/commands.h b/include/commands.h index d139fa01a..5d43f556b 100644 --- a/include/commands.h +++ b/include/commands.h @@ -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 + diff --git a/include/modules.h b/include/modules.h index bd553c2cc..dcaac342c 100644 --- a/include/modules.h +++ b/include/modules.h @@ -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); diff --git a/include/pseudo.h b/include/pseudo.h index d24c43963..3ad6b518a 100644 --- a/include/pseudo.h +++ b/include/pseudo.h @@ -11,7 +11,7 @@ * */ -#include "commands.h" +#include "modules.h" #include "language.h" #include "timers.h" #include "slist.h" diff --git a/src/bots.cpp b/src/bots.cpp index 37cd553d1..e663d9225 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -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) { diff --git a/src/command.cpp b/src/command.cpp index ea66a7261..fc745fe46 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -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; diff --git a/src/commands.c b/src/commands.c index 19d668137..40363a7d1 100644 --- a/src/commands.c +++ b/src/commands.c @@ -12,13 +12,37 @@ */ #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. * @param list Command struct diff --git a/src/modules.c b/src/modules.c index 40c10144f..af3aa2f4d 100644 --- a/src/modules.c +++ b/src/modules.c @@ -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 *******************************************************************************/ |