summaryrefslogtreecommitdiff
path: root/include/commands.h
diff options
context:
space:
mode:
authorAdam <Adam@drink-coca-cola.info>2010-04-24 17:18:25 -0400
committerAdam <Adam@anope.org>2010-06-18 20:55:38 -0400
commitfa82890696c498f38643df7df6891434c91c9269 (patch)
tree4b28359e75c29825586e6b2394e5334e43ea074b /include/commands.h
parent2ba89de64d3b755f731f202dd97c48d256db8031 (diff)
Moved Commands stuff to its own file and changed Command::name to be ci::string - Will be used after hashing system is rewritten
Diffstat (limited to 'include/commands.h')
-rw-r--r--include/commands.h113
1 files changed, 106 insertions, 7 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
+