PennMUSH Community

root/1.8.3/trunk/hdrs/externs.h

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

Merge devel into trunk for p6 release

Line 
1 /**
2  * \file externs.h
3  *
4  * \brief Header file for external functions called from many source files.
5  *
6  *
7  */
8
9 #ifndef __EXTERNS_H
10 #define __EXTERNS_H
11 /* Get the time_t definition that we use in prototypes here */
12 #include <time.h>
13 #ifdef I_LIBINTL
14 #include <libintl.h>
15 #endif
16 #if defined(HAVE_GETTEXT) && !defined(DONT_TRANSLATE)
17 /** Macro for a translated string */
18 #define T(str) gettext(str)
19 /** Macro to note that a string has a translation but not to translate */
20 #define N_(str) gettext_noop(str)
21 #else
22 #define T(str) str
23 #define N_(str) str
24 #endif
25 #include "config.h"
26 #include "copyrite.h"
27 #include "compile.h"
28 #include "mushtype.h"
29 #include "dbdefs.h"
30 #include "confmagic.h"
31 #include "mypcre.h"
32
33 #ifndef HAVE_STRCASECMP
34 #ifdef HAVE__STRICMP
35 #define strcasecmp(s1,s2) _stricmp((s1), (s2))
36 #else
37 extern int strcasecmp(const char *s1, const char *s2);
38 #endif
39 #endif
40
41 #ifndef HAVE_STRNCASECMP
42 #ifdef HAVE__STRNICMP
43 #define strncasecmp(s1,s2,n) _strnicmp((s1), (s2), (n))
44 #else
45 extern int strncasecmp(const char *s1, const char *s2, size_t n);
46 #endif
47 #endif
48
49 /* these symbols must be defined by the interface */
50 extern time_t mudtime;
51
52 #define FOPEN_READ "rb"      /**< Arguments to fopen when reading */
53 #define FOPEN_WRITE "wb"     /**< Arguments to fopen when writing */
54
55 int shutdown_flag;              /* if non-zero, interface should shut down */
56 void emergency_shutdown(void);
57 void boot_desc(DESC *d);        /* remove a player */
58 DESC *player_desc(dbref player);        /* find descriptors */
59 DESC *inactive_desc(dbref player);      /* find descriptors */
60 DESC *port_desc(int port);      /* find descriptors */
61 void WIN32_CDECL flag_broadcast(const char *flag1,
62                                 const char *flag2, const char *fmt, ...)
63   __attribute__ ((__format__(__printf__, 3, 4)));
64
65 void raw_notify(dbref player, const char *msg);
66 void notify_list(dbref speaker, dbref thing, const char *atr,
67                  const char *msg, int flags);
68 dbref short_page(const char *match);
69 dbref visible_short_page(dbref player, const char *match);
70 void do_doing(dbref player, const char *message);
71
72 /* the following symbols are provided by game.c */
73 void process_command(dbref player, char *command, dbref cause, int from_port);
74 int init_game_dbs(void);
75 void init_game_postdb(const char *conf);
76 void init_game_config(const char *conf);
77 void dump_database(void);
78 void NORETURN mush_panic(const char *message);
79 void NORETURN mush_panicf(const char *fmt, ...)
80   __attribute__ ((__format__(__printf__, 1, 2)));
81 char *scan_list(dbref player, char *command);
82
83
84 #ifdef WIN32
85 /* From timer.c */
86 void init_timer(void);
87 #endif                          /* WIN32 */
88
89 /* From log.c */
90 void penn_perror(const char *);
91
92 /* From wait.c */
93 int lock_file(FILE *);
94 int unlock_file(FILE *);
95
96 /* From bsd.c */
97 extern FILE *connlog_fp;
98 extern FILE *checklog_fp;
99 extern FILE *wizlog_fp;
100 extern FILE *tracelog_fp;
101 extern FILE *cmdlog_fp;
102 extern int restarting;
103 #ifdef SUN_OS
104 extern int f_close(FILE * file);
105 /** SunOS fclose macro */
106 #define fclose(f) f_close(f);
107 #endif
108 int hidden(dbref player);
109 dbref guest_to_connect(dbref player);
110 void dump_reboot_db(void);
111 void close_ssl_connections(void);
112 int least_idle_time(dbref player);
113 int least_idle_time_priv(dbref player);
114 int most_conn_time(dbref player);
115 int most_conn_time_priv(dbref player);
116 char *least_idle_ip(dbref player);
117 char *least_idle_hostname(dbref player);
118
119 /* sql.c */
120 void sql_shutdown(void);
121
122 /* The #defs for our notify_anything hacks.. Errr. Functions */
123 #define NA_NORELAY      0x0001  /**< Don't relay sound */
124 #define NA_NOENTER      0x0002  /**< No newline at end */
125 #define NA_NOLISTEN     0x0004  /**< Implies NORELAY. Sorta. */
126 #define NA_NOPENTER     0x0010  /**< No newline, Pueblo-stylee */
127 #define NA_PONLY        0x0020  /**< Pueblo-only */
128 #define NA_PUPPET       0x0040  /**< Ok to puppet */
129 #define NA_PUPPET2      0x0080  /**< Message to a player from a puppet */
130 #define NA_MUST_PUPPET  0x0100  /**< Ok to puppet even in same room */
131 #define NA_INTER_HEAR   0x0200  /**< Message is auditory in nature */
132 #define NA_INTER_SEE    0x0400  /**< Message is visual in nature */
133 #define NA_INTER_PRESENCE  0x0800       /**< Message is about presence */
134 #define NA_NOSPOOF        0x1000        /**< Message comes via a NO_SPOOF object. */
135 #define NA_PARANOID       0x2000        /**< Message comes via a PARANOID object. */
136 #define NA_NOPREFIX 0x4000 /**< Don't use @prefix when forwarding */
137 #define NA_SPOOF        0x8000  /**< @ns* message, overrides NOSPOOF */
138 #define NA_INTER_LOCK  0x10000  /**< Message subject to @lock/interact even if not otherwise marked */
139 #define NA_INTERACTION  (NA_INTER_HEAR|NA_INTER_SEE|NA_INTER_PRESENCE|NA_INTER_LOCK)    /**< Message follows interaction rules */
140 #define NA_PROMPT       0x20000  /**< Message is a prompt, add GOAHEAD */
141
142 /** A notify_anything lookup function type definition */
143 typedef dbref (*na_lookup) (dbref, void *);
144 void notify_anything(dbref speaker, na_lookup func,
145                      void *fdata,
146                      char *(*nsfunc) (dbref,
147                                       na_lookup func,
148                                       void *, int), int flags,
149                      const char *message);
150 void notify_anything_format(dbref speaker, na_lookup func,
151                             void *fdata,
152                             char *(*nsfunc) (dbref,
153                                              na_lookup func,
154                                              void *, int), int flags,
155                             const char *fmt, ...)
156   __attribute__ ((__format__(__printf__, 6, 7)));
157 void notify_anything_loc(dbref speaker, na_lookup func,
158                          void *fdata,
159                          char *(*nsfunc) (dbref,
160                                           na_lookup func,
161                                           void *, int), int flags,
162                          const char *message, dbref loc);
163 dbref na_one(dbref current, void *data);
164 dbref na_next(dbref current, void *data);
165 dbref na_loc(dbref current, void *data);
166 dbref na_nextbut(dbref current, void *data);
167 dbref na_except(dbref current, void *data);
168 dbref na_except2(dbref current, void *data);
169 dbref na_exceptN(dbref current, void *data);
170 dbref na_channel(dbref current, void *data);
171 char *ns_esnotify(dbref speaker, na_lookup func, void *fdata, int para);
172
173 /** Basic 'notify player with message */
174 #define notify(p,m)           notify_anything(orator, na_one, &(p), NULL, 0, m)
175 /** Notify player as a prompt */
176 #define notify_prompt(p,m)           notify_anything(orator, na_one, &(p), NULL, NA_PROMPT, m)
177 /** Notify puppet with message, even if owner's there */
178 #define notify_must_puppet(p,m)           notify_anything(orator, na_one, &(p), NULL, NA_MUST_PUPPET, m)
179 /** Notify puppet with message as prompt, even if owner's there */
180 #define notify_prompt_must_puppet(p,m)           notify_anything(orator, na_one, &(p), NULL, NA_MUST_PUPPET|NA_PROMPT, m)
181 /** Notify player with message, as if from somethign specific */
182 #define notify_by(t,p,m)           notify_anything(t, na_one, &(p), NULL, 0, m)
183 /** Notfy player with message, but only puppet propagation */
184 #define notify_noecho(p,m)    notify_anything(orator, na_one, &(p), NULL, NA_NORELAY | NA_PUPPET, m)
185 /** Notify player with message if they're not set QUIET */
186 #define quiet_notify(p,m)     if (!IsQuiet(p)) notify(p,m)
187 /** Notify player but don't send \n */
188 #define notify_noenter_by(t,a,b) notify_anything(t, na_one, &(a), NULL, NA_NOENTER, b)
189 #define notify_noenter(a,b) notify_noenter_by(GOD, a, b)
190 /** Notify player but don't send <BR> if they're using Pueblo */
191 #define notify_nopenter_by(t,a,b) notify_anything(t, na_one, &(a), NULL, NA_NOPENTER, b)
192 #define notify_nopenter(a,b) notify_nopenter_by(GOD, a, b)
193 /* Notify with a printf-style format */
194 void notify_format(dbref player, const char *fmt, ...)
195   __attribute__ ((__format__(__printf__, 2, 3)));
196
197 /* From command.c */
198 void generic_command_failure(dbref player, dbref cause, char *string);
199
200 /* From compress.c */
201 /* Define this to get some statistics on the attribute compression
202  * in @stats/tables. Only for word-based compression (COMPRESSION_TYPE 3 or 4
203  */
204 /* #define COMP_STATS /* */
205 #if (COMPRESSION_TYPE != 0)
206 unsigned char *
207 text_compress(char const *s)
208   __attribute_malloc__;
209 #define compress(str) text_compress(str)
210     char *text_uncompress(unsigned char const *s);
211 #define uncompress(str) text_uncompress(str)
212     char *safe_uncompress(unsigned char const *s) __attribute_malloc__;
213 #else
214 extern char ucbuff[];
215 #define init_compress(f) 0
216 #define compress(s) ((unsigned char *)strdup(s))
217 #define uncompress(s) (strcpy(ucbuff, (char *) s))
218 #define safe_uncompress(s) (strdup((char *) s))
219 #endif
220
221 /* From cque.c */
222 struct _ansi_string;
223 struct real_pcre;
224 struct eval_context {
225   char *wenv[10];                 /**< working environment (%0-%9) */
226   char renv[NUMQ][BUFFER_LEN];    /**< working registers q0-q9,qa-qz */
227   char *wnxt[10];                 /**< environment to shove into the queue */
228   char *rnxt[NUMQ];               /**< registers to shove into the queue */
229   int process_command_port;   /**< port number that a command came from */
230   dbref cplr;                     /**< initiating player */
231   char ccom[BUFFER_LEN];          /**< raw command */
232   char ucom[BUFFER_LEN];      /**< evaluated command */
233   int break_called;           /**< Has the break command been called? */
234   char break_replace[BUFFER_LEN];  /**< What to replace the break with */
235   struct real_pcre *re_code;              /**< The compiled re */
236   int re_subpatterns;         /**< The number of re subpatterns */
237   int *re_offsets;            /**< The offsets for the subpatterns */
238   struct _ansi_string *re_from;             /**< The positions of the subpatterns */
239 };
240
241 typedef struct eval_context EVAL_CONTEXT;
242 extern EVAL_CONTEXT global_eval_context;
243
244 void do_second(void);
245 int do_top(int ncom);
246 void do_halt(dbref owner, const char *ncom, dbref victim);
247 void parse_que(dbref player, const char *command, dbref cause);
248 int queue_attribute_base
249   (dbref executor, const char *atrname, dbref enactor, int noparent);
250 ATTR *queue_attribute_getatr(dbref executor, const char *atrname, int noparent);
251 int queue_attribute_useatr(dbref executor, ATTR *a, dbref enactor);
252
253 /** Queue the code in an attribute, including parent objects */
254 #define queue_attribute(a,b,c) queue_attribute_base(a,b,c,0)
255 /** Queue the code in an attribute, excluding parent objects */
256 #define queue_attribute_noparent(a,b,c) queue_attribute_base(a,b,c,1)
257 void dequeue_semaphores(dbref thing, char const *aname, int count,
258                         int all, int drain);
259 void shutdown_queues(void);
260
261 /* Regexp saving helpers */
262 struct re_save {
263   struct real_pcre *re_code;              /**< The compiled re */
264   int re_subpatterns;         /**< The number of re subpatterns */
265   int *re_offsets;            /**< The offsets for the subpatterns */
266   struct _ansi_string *re_from;             /**< The positions of the subpatterns */
267 };
268
269 /* From create.c */
270 dbref do_dig(dbref player, const char *name, char **argv, int tport);
271 dbref do_create(dbref player, char *name, int cost);
272 dbref do_real_open(dbref player, const char *direction,
273                    const char *linkto, dbref pseudo);
274 void do_open(dbref player, const char *direction, char **links);
275 void do_link(dbref player, const char *name, const char *room_name,
276              int preserve);
277 void do_unlink(dbref player, const char *name);
278 dbref do_clone(dbref player, char *name, char *newname, int preserve);
279
280 /* From funtime.c */
281 int etime_to_secs(char *str1, int *secs);
282
283 /* From game.c */
284 void report(void);
285 int Hearer(dbref thing);
286 int Commer(dbref thing);
287 int Listener(dbref thing);
288 extern dbref orator;
289 int parse_chat(dbref player, char *command);
290 void fork_and_dump(int forking);
291 void reserve_fd(void);
292 void release_fd(void);
293
294
295 /* From look.c */
296 /** Enumeration of types of looks that can be performed */
297 enum look_type { LOOK_NORMAL, LOOK_TRANS, LOOK_AUTO, LOOK_CLOUDYTRANS,
298   LOOK_CLOUDY
299 };
300 void look_room(dbref player, dbref loc, enum look_type style);
301 void do_look_around(dbref player);
302 void do_look_at(dbref player, const char *name, int key);
303 char *decompose_str(char *what);
304
305 /* From memcheck.c */
306 void add_check(const char *ref);
307 void del_check(const char *ref, const char *filename, int line);
308 void list_mem_check(dbref player);
309 void log_mem_check(void);
310
311 /* From move.c */
312 void enter_room(dbref player, dbref loc, int nomovemsgs);
313 int can_move(dbref player, const char *direction);
314 /** Enumeration of types of movements that can be performed */
315 enum move_type { MOVE_NORMAL, MOVE_GLOBAL, MOVE_ZONE };
316 void do_move(dbref player, const char *direction, enum move_type type);
317 void moveto(dbref what, dbref where);
318 void safe_tel(dbref player, dbref dest, int nomovemsgs);
319 int global_exit(dbref player, const char *direction);
320 int remote_exit(dbref loc, const char *direction);
321 void move_wrapper(dbref player, const char *command);
322 void do_follow(dbref player, const char *arg);
323 void do_unfollow(dbref player, const char *arg);
324 void do_desert(dbref player, const char *arg);
325 void do_dismiss(dbref player, const char *arg);
326 void clear_followers(dbref leader, int noisy);
327 void clear_following(dbref follower, int noisy);
328
329 /* From mycrypt.c */
330 char *mush_crypt(const char *key);
331
332 /* From player.c */
333 int password_check(dbref player, const char *password);
334 dbref lookup_player(const char *name);
335 dbref lookup_player_name(const char *name);
336 /* from player.c */
337 dbref create_player(const char *name, const char *password,
338                     const char *host, const char *ip);
339 dbref connect_player(const char *name, const char *password,
340                      const char *host, const char *ip, char *errbuf);
341 void check_last(dbref player, const char *host, const char *ip);
342 void check_lastfailed(dbref player, const char *host);
343
344 /* From parse.c */
345 bool is_number(const char *str);
346 bool is_strict_number(const char *str);
347 bool is_strict_integer(const char *str);
348 #ifdef HAVE_ISNORMAL
349 #define is_good_number(n) isnormal((n))
350 #else
351 bool is_good_number(NVAL val);
352 #endif
353
354 /* From plyrlist.c */
355 void clear_players(void);
356 void add_player(dbref player);
357 void add_player_alias(dbref player, const char *alias);
358 void delete_player(dbref player, const char *alias);
359 void reset_player_list(dbref player, const char *oldname, const char *oldalias,
360                        const char *name, const char *alias);
361
362 /* From predicat.c */
363 char *WIN32_CDECL tprintf(const char *fmt, ...)
364   __attribute__ ((__format__(__printf__, 1, 2)));
365
366 int could_doit(dbref player, dbref thing);
367 int did_it(dbref player, dbref thing, const char *what,
368            const char *def, const char *owhat, const char *odef,
369            const char *awhat, dbref loc);
370 int did_it_with(dbref player, dbref thing, const char *what,
371                 const char *def, const char *owhat, const char *odef,
372                 const char *awhat, dbref loc, dbref env0, dbref env1,
373                 int flags);
374 int did_it_interact(dbref player, dbref thing, const char *what,
375                     const char *def, const char *owhat,
376                     const char *odef, const char *awhat, dbref loc, int flags);
377 int real_did_it(dbref player, dbref thing, const char *what,
378                 const char *def, const char *owhat, const char *odef,
379                 const char *awhat, dbref loc, char *myenv[10], int flags);
380 int can_see(dbref player, dbref thing, int can_see_loc);
381 int controls(dbref who, dbref what);
382 int can_pay_fees(dbref who, int pennies);
383 void giveto(dbref who, int pennies);
384 int payfor(dbref who, int cost);
385 int quiet_payfor(dbref who, int cost);
386 int nearby(dbref obj1, dbref obj2);
387 int get_current_quota(dbref who);
388 void change_quota(dbref who, int payment);
389 int ok_name(const char *name);
390 int ok_command_name(const char *name);
391 int ok_function_name(const char *name);
392 int ok_player_name(const char *name, dbref player, dbref thing);
393 int ok_player_alias(const char *alias, dbref player, dbref thing);
394 int ok_password(const char *password);
395 int ok_tag_attribute(dbref player, const char *params);
396 dbref parse_match_possessor(dbref player, char **str);
397 void page_return(dbref player, dbref target, const char *type,
398                  const char *message, const char *def);
399 char *grep_util(dbref player, dbref thing, char *pattern,
400                 char *lookfor, int sensitive, int wild);
401 dbref where_is(dbref thing);
402 int charge_action(dbref player, dbref thing, const char *awhat);
403 dbref first_visible(dbref player, dbref thing);
404
405 /* From rob.c */
406 void s_Pennies(dbref thing, int amount);
407
408 /* From set.c */
409 void chown_object(dbref player, dbref thing, dbref newowner, int preserve);
410
411 /* From speech.c */
412 int vmessageformat(dbref player, const char *attribute,
413                    dbref executor, int flags, int nargs, ...);
414 int messageformat(dbref player, const char *attribute,
415                   dbref executor, int flags, int nargs, char *argv[]);
416 void do_message_list(dbref player, dbref enactor, char *list, char *attrname,
417                      char *message, int flags, int numargs, char *argv[]);
418 const char *spname(dbref thing);
419 void notify_except(dbref first, dbref exception, const char *msg, int flags);
420 void notify_except2(dbref first, dbref exc1, dbref exc2,
421                     const char *msg, int flags);
422 /* Return thing/PREFIX + msg */
423 void make_prefixstr(dbref thing, const char *msg, char *tbuf1);
424 int filter_found(dbref thing, const char *msg, int flag);
425
426 /* From strutil.c */
427 char *split_token(char **sp, char sep);
428 char *chopstr(const char *str, size_t lim);
429 int string_prefix(const char *restrict string, const char *restrict prefix);
430 const char *string_match(const char *src, const char *sub);
431 char *strupper(const char *s);
432 char *strlower(const char *s);
433 char *strinitial(const char *s);