PennMUSH Community

root/1.8.3/trunk/hdrs/command.h

Revision 1167, 9.0 kB (checked in by shawnw, 8 months ago)

Merge devel into trunk for p6 release

Line 
1 #ifndef __COMMAND_H
2 #define __COMMAND_H
3
4
5 typedef uint8_t *switch_mask;
6 extern int switch_bytes;
7 #define SW_ALLOC()      mush_calloc(switch_bytes, 1, "cmd.switch.vector");
8 #define SW_FREE(s)      mush_free((s), "cmd.switch.vector");
9 #define SW_SET(m,n)     (m[(n) >> 3] |= (1 << ((n) & 0x7)))
10 #define SW_CLR(m,n)     (m[(n) >> 3] &= ~(1 << ((n) & 0x7)))
11 #define SW_ISSET(m,n)   (m[(n) >> 3] & (1 << ((n) & 0x7)))
12 bool SW_BY_NAME(switch_mask, const char *);
13 #define SW_ZERO(m)      memset(m, 0, switch_bytes)
14 #define SW_COPY(new,old) memcpy((new), (old), switch_bytes)
15
16 /* These are type restrictors */
17 #define CMD_T_ROOM      0x80000000
18 #define CMD_T_THING     0x40000000
19 #define CMD_T_EXIT      0x20000000
20 #define CMD_T_PLAYER    0x10000000
21 #define CMD_T_ANY       0xF0000000
22 #define CMD_T_GOD       0x08000000
23
24 /* Any unknown or undefined switches will be passed in switches, instead of causing error */
25 #define CMD_T_SWITCHES  0x02000000
26
27 /* Command is disabled, set with @command */
28 #define CMD_T_DISABLED  0x01000000
29
30 /* Command will fail if object is gagged */
31 #define CMD_T_NOGAGGED  0x00800000
32
33 /* Command will fail if object is a guest */
34 #define CMD_T_NOGUEST   0x00400000
35
36 /* Command will fail if object is fixed */
37 #define CMD_T_NOFIXED   0x00200000
38
39 /* INTERNAL : Command is listed in @list commands */
40 #define CMD_T_LISTED    0x00080000
41
42 /* INTERNAL : Command is an internal command, and shouldn't be matched
43  * or aliased
44  */
45 #define CMD_T_INTERNAL  0x00040000
46
47 /* Logging for commands */
48 #define CMD_T_LOGNAME   0x00020000
49 #define CMD_T_LOGARGS   0x00010000
50
51 /* Split arguments at =, but don't abort if there's no = */
52 #define CMD_T_EQSPLIT    0x0001
53
54 /* Split into argv[] at ,s */
55 #define CMD_T_ARGS       0x0010
56
57 /* Split at spaces instead of commas. CMD_T_ARGS MUST also be defined */
58 #define CMD_T_ARG_SPACE  0x0020
59
60 /* Do NOT parse arguments */
61 #define CMD_T_NOPARSE    0x0040
62
63 #define CMD_T_LS_ARGS    CMD_T_ARGS
64 #define CMD_T_LS_SPACE   CMD_T_ARG_SPACE
65 #define CMD_T_LS_NOPARSE CMD_T_NOPARSE
66 #define CMD_T_RS_ARGS    CMD_T_ARGS<<4
67 #define CMD_T_RS_SPACE   CMD_T_ARG_SPACE<<4
68 #define CMD_T_RS_NOPARSE CMD_T_NOPARSE<<4
69
70 /** COMMAND prototype.
71  * \verbatim
72    Passed arguments:
73    executor : Object issuing command.
74    sw : switch_mask, check with the SW_ macros.
75    raw : *FULL* unparsed, untouched command.
76    switches : Any unhandled switches, or NULL if none.
77    args_raw : Full argument, untouched. null-string if none.
78    arg_left : Left-side arguments, unparsed if CMD_T_NOPARSE.
79    args_left : Parsed arguments, if CMD_T_ARGS is defined.
80    args_right : Parsed right-side arguments, if CMD_T_RSARGS is defined.
81
82    Note that if you don't specify EQSPLIT, left is still the data you want. If you define EQSPLIT,
83    there are also right_XX values.
84
85    Special case:
86    If the NOEVAL switch is given, AND EQSPLIT is defined, the right-side will not be parsed.
87    If NOEVAL is givean the EQSPLIT isn't defined, the left-side won't be parsed.
88  * \endverbatim
89  */
90
91 #define COMMAND(command_name) \
92 void command_name (COMMAND_INFO *cmd, dbref player, dbref cause, \
93  switch_mask sw,char *raw, const char *switches, char *args_raw, \
94                   char *arg_left, char *args_left[MAX_ARG], \
95                   char *arg_right, char *args_right[MAX_ARG]); \
96 void command_name(COMMAND_INFO *cmd __attribute__ ((__unused__)), \
97                   dbref player __attribute__ ((__unused__)), \
98                   dbref cause __attribute__ ((__unused__)), \
99                   switch_mask sw __attribute__ ((__unused__)), \
100                   char *raw __attribute__ ((__unused__)), \
101                   const char *switches __attribute__ ((__unused__)), \
102                   char *args_raw __attribute__ ((__unused__)), \
103                   char *arg_left __attribute__ ((__unused__)), \
104                   char *args_left[MAX_ARG] __attribute__ ((__unused__)), \
105                   char *arg_right __attribute__ ((__unused__)), \
106                   char *args_right[MAX_ARG] __attribute__ ((__unused__)))
107
108 /** Common command prototype macro */
109 #define COMMAND_PROTO(command_name) \
110 void command_name (COMMAND_INFO *cmd, dbref player, dbref cause, switch_mask sw,char *raw, const char *switches, char *args_raw, \
111                   char *arg_left, char *args_left[MAX_ARG], \
112                   char *arg_right, char *args_right[MAX_ARG])
113
114 typedef struct command_info COMMAND_INFO;
115 typedef void (*command_func) (COMMAND_INFO *, dbref, dbref, switch_mask, char *,
116                               const char *, char *, char *, char *[MAX_ARG],
117                               char *, char *[MAX_ARG]);
118
119 /** A hook specification.
120  */
121 struct hook_data {
122   dbref obj;            /**< Object where the hook attribute is stored. */
123   char *attrname;       /**< Attribute name of the hook attribute */
124 };
125
126 /** A command.
127  * This structure represents a command in the table of available commands.
128  */
129 struct command_info {
130   const char *name;     /**< Canonical name of the command */
131   const char *restrict_message; /**< Message sent when command is restricted */
132   command_func func;    /**< Function to call when command is run */
133   unsigned int type;    /**< Types of objects that can use the command */
134   object_flag_type flagmask;    /**< Flags to which the command is restricted */
135   object_flag_type powers;      /**< Powers to which the command is restricted */
136   /** Switches for this command. */
137   union {
138     switch_mask mask;       /**< Bitflags of switches this command can take */
139     const char *names; /**< Space-seperated list of switches */
140   } sw;
141   /** Hooks on this command.
142    */
143   struct {
144     struct hook_data before;    /**< Hook to evaluate before command */
145     struct hook_data after;     /**< Hook to evaluate after command */
146     struct hook_data ignore;    /**< Hook to evaluate to decide if we should ignore hardcoded command */
147     struct hook_data override;  /**< Hook to override command with $command */
148   } hooks;
149 };
150
151 typedef struct command_list COMLIST;
152 /** A command list entry.
153  * This structure stores the static array of commands that are
154  * initially loaded into the command table. Commands can also be
155  * added dynamically, outside of this array.
156  */
157 struct command_list {
158   const char *name;     /**< Command name */
159   const char *switches; /**< Space-separated list of switch names */
160   command_func func;    /**< Function to call when command is run */
161   unsigned int type;    /**< Types of objects that can use the command */
162   const char *flagstr;  /**< Space-separated list of flags that can use */
163   const char *powers;   /**< Powers to which the command is restricted */
164 };
165
166 typedef struct switch_value SWITCH_VALUE;
167 /** The value associated with a switch.
168  * Command switches are given integral values at compile time when
169  * the switchinc.c and switches.h files are rebuilt. This structure
170  * associates switch names with switch numbers
171  */
172 struct switch_value {
173   const char *name;     /**< Name of the switch */
174   int value;            /**< Number of the switch */
175 };
176
177 typedef struct com_sort_struc COMSORTSTRUC;
178
179 /** Sorted linked list of commands.
180  * This structure is used to build a sorted linked list of pointers
181  * to command data.
182  */
183 struct com_sort_struc {
184   struct com_sort_struc *next;  /**< Pointer to next in list */
185   COMMAND_INFO *cmd;            /**< Command data */
186 };
187
188 /** Permissions for commands.
189  * This structure is used to associate names for command permissions
190  * (e.g. "player") with the appropriate bitmask
191  */
192 struct command_perms_t {
193   const char *name;     /**< Permission name */
194   unsigned int type;    /**< Bitmask for this permission */
195 };
196
197 #define SWITCH_NONE 0
198 #include "switches.h"
199
200 switch_mask switchmask(const char *switches);
201 COMMAND_INFO *command_find(const char *name);
202 COMMAND_INFO *command_find_exact(const char *name);
203 COMMAND_INFO *command_add
204   (const char *name, int type, const char *flagstr, const char *powers,
205    const char *switchstr, command_func func);
206 COMMAND_INFO *make_command
207   (const char *name, int type, object_flag_type flagmask,
208    object_flag_type powers, const char *sw, command_func func);
209 COMMAND_INFO *command_modify(const char *name, int type,
210                              object_flag_type flagmask,
211                              object_flag_type powers, switch_mask sw,
212                              command_func func);
213 void reserve_alias(const char *a);
214 int alias_command(const char *command, const char *alias);
215 void command_init_preconfig(void);
216 void command_init_postconfig(void);
217 void command_splitup
218   (dbref player, dbref cause, char *from, char *to, char **args,
219    COMMAND_INFO *cmd, int side);
220 void command_argparse
221   (dbref player, dbref cause, char **from, char *to, char **argv,
222    COMMAND_INFO *cmd, int side, int forcenoparse);
223 char *command_parse(dbref player, dbref cause, char *string, int fromport);
224 void do_list_commands(dbref player, int lc);
225 char *list_commands(void);
226 int command_check_byname(dbref player, const char *name);
227 int restrict_command(const char *name, const char *restriction);
228 void reserve_aliases(void);
229 void local_commands(void);
230 void do_command_add(dbref player, char *name, int flags);
231 void do_command_delete(dbref player, char *name);
232
233
234 #endif                          /* __COMMAND_H */
Note: See TracBrowser for help on using the browser.