root/1.8.3/tags/p6/hdrs/dbdefs.h

Revision 919, 12.3 KB (checked in by shawnw, 19 months ago)

1.8.3p3

Line 
1/* dbdefs.h */
2
3
4#ifndef __DBDEFS_H
5#define __DBDEFS_H
6
7#include <stdio.h>
8#ifdef I_SYS_TIME
9#include <sys/time.h>
10#ifdef TIME_WITH_SYS_TIME
11#include <time.h>
12#endif
13#else
14#include <time.h>
15#endif
16#include "mushdb.h"
17#include "htab.h"
18#include "chunk.h"
19
20extern dbref first_free;        /* pointer to free list */
21
22/*-------------------------------------------------------------------------
23 * Database access macros
24 */
25
26/* References an whole object */
27#define REFDB(x)        &db[x]
28
29#define Name(x)         (db[(x)].name)
30#define Flags(x)        (db[(x)].flags)
31#define Owner(x)        (db[(x)].owner)
32
33#define Location(x)     (db[(x)].location)
34#define Zone(x)         (db[(x)].zone)
35
36#define Contents(x) (db[(x)].contents)
37#define Next(x)     (db[(x)].next)
38#define Home(x)     (db[(x)].exits)
39#define Exits(x)    (db[(x)].exits)
40#define List(x)     (db[(x)].list)
41
42/* These are only for exits */
43#define Source(x)   (db[(x)].exits)
44#define Destination(x) (db[(x)].location)
45
46#define Locks(x)        (db[(x)].locks)
47
48#define CreTime(x)      (db[(x)].creation_time)
49#define ModTime(x)      (db[(x)].modification_time)
50
51#define AttrCount(x)    (db[(x)].attrcount)
52
53/* Moved from warnings.c because create.c needs it. */
54#define Warnings(x)      (db[(x)].warnings)
55
56#define Pennies(thing) (db[thing].penn)
57
58#define Parent(x)  (db[(x)].parent)
59#define Powers(x)  (db[(x)].powers)
60
61/* Generic type check */
62#define Type(x)   (db[(x)].type)
63#define Typeof(x) (Type(x) & ~TYPE_MARKED)
64
65/* Check for a specific one */
66#define IsPlayer(x)     ((Typeof(x) & TYPE_PLAYER) == TYPE_PLAYER)
67#define IsRoom(x)       ((Typeof(x) & TYPE_ROOM) == TYPE_ROOM)
68#define IsThing(x)      ((Typeof(x) & TYPE_THING) == TYPE_THING)
69#define IsExit(x)       ((Typeof(x) & TYPE_EXIT) == TYPE_EXIT)
70/* Was Destroyed() */
71#define IsGarbage(x)    ((Typeof(x) & TYPE_GARBAGE) == TYPE_GARBAGE)
72#define Marked(x)       ((db[(x)].type & TYPE_MARKED) == TYPE_MARKED)
73
74#define IS(thing,type,flag) \
75                     ((Typeof(thing) == type) && has_flag_by_name(thing,flag,type))
76
77#define GoodObject(x) ((x >= 0) && (x < db_top))
78
79
80
81/******* Player toggles */
82#define Connected(x)    (IS(x, TYPE_PLAYER, "CONNECTED"))
83#define Track_Money(x)       (IS(x, TYPE_PLAYER, "TRACK_MONEY"))
84#define ZMaster(x)      (IS(x, TYPE_PLAYER, "ZONE"))
85#define Unregistered(x) (IS(x, TYPE_PLAYER, "UNREGISTERED"))
86#define Fixed(x)        (IS(Owner(x), TYPE_PLAYER, "FIXED"))
87#define Vacation(x)     (IS(x, TYPE_PLAYER, "ON-VACATION"))
88
89/* Flags that apply to players, and all their stuff,
90 * so check the Owner() of the object.
91 */
92
93#define Terse(x)        (IS(Owner(x), TYPE_PLAYER, "TERSE") || IS(x, TYPE_THING, "TERSE"))
94#define Myopic(x)       (IS(Owner(x), TYPE_PLAYER, "MYOPIC"))
95#define Nospoof(x)      (IS(Owner(x),TYPE_PLAYER,"NOSPOOF") || has_flag_by_name(x,"NOSPOOF",NOTYPE))
96#define Paranoid(x)      (IS(Owner(x),TYPE_PLAYER,"PARANOID") || has_flag_by_name(x,"PARANOID",NOTYPE))
97#define Gagged(x)       (IS(Owner(x), TYPE_PLAYER, "GAGGED"))
98#define ShowAnsi(x)     (IS(Owner(x), TYPE_PLAYER, "ANSI"))
99#define ShowAnsiColor(x) (IS(Owner(x), TYPE_PLAYER, "COLOR"))
100
101/******* Thing toggles */
102#define DestOk(x)       (IS(x, TYPE_THING, "DESTROY_OK"))
103#define NoLeave(x)      (IS(x, TYPE_THING, "NOLEAVE"))
104#define ThingListen(x)  (IS(x, TYPE_THING, "MONITOR"))
105#define ThingInhearit(x) \
106                        (IS(x, TYPE_THING, "LISTEN_PARENT"))    /* 0x80 */
107#define ThingZTel(x)            (IS(x, TYPE_THING, "Z_TEL"))
108
109/******* Room toggles */
110#define Floating(x)     (IS(x, TYPE_ROOM, "FLOATING"))  /* 0x8 */
111#define Abode(x)        (IS(x, TYPE_ROOM, "ABODE"))     /* 0x10 */
112#define JumpOk(x)       (IS(x, TYPE_ROOM, "JUMP_OK"))   /* 0x20 */
113#define NoTel(x)        (IS(x, TYPE_ROOM, "NO_TEL"))    /* 0x40 */
114#define RoomListen(x)   (IS(x, TYPE_ROOM, "LISTENER"))  /* 0x100 */
115#define RoomZTel(x)             (IS(x, TYPE_ROOM, "Z_TEL"))     /* 0x200 */
116#define RoomInhearit(x) (IS(x, TYPE_ROOM, "LISTEN_PARENT"))     /* 0x400 */
117
118#define Uninspected(x)  (IS(x, TYPE_ROOM, "UNINSPECTED"))       /* 0x1000 */
119
120#define ZTel(x) (ThingZTel(x) || RoomZTel(x))
121
122/******* Exit toggles */
123#define Cloudy(x)       (IS(x, TYPE_EXIT, "CLOUDY"))    /* 0x8 */
124
125/* Flags anything can have */
126
127#define Audible(x)      (has_flag_by_name(x, "AUDIBLE", NOTYPE))
128#define ChanUseFirstMatch(x) (has_flag_by_name(x, "CHAN_USEFIRSTMATCH", NOTYPE))
129#define ChownOk(x)      (has_flag_by_name(x, "CHOWN_OK", NOTYPE))
130#define Dark(x)         (has_flag_by_name(x, "DARK", NOTYPE))
131#define Debug(x)        (has_flag_by_name(x, "DEBUG", NOTYPE))
132#define EnterOk(x)      (has_flag_by_name(x, "ENTER_OK", NOTYPE))
133#define Going(x)        (has_flag_by_name(x, "GOING", NOTYPE))
134#define Going_Twice(x)  (has_flag_by_name(x, "GOING_TWICE", NOTYPE))
135#define Halted(x)       (has_flag_by_name(x, "HALT", NOTYPE))
136#define Haven(x)        (has_flag_by_name(x, "HAVEN", NOTYPE))
137#define Heavy(x)        (has_flag_by_name(x, "HEAVY", NOTYPE))
138#define Inherit(x)      (has_flag_by_name(x, "TRUST", NOTYPE))
139#define Light(x)        (has_flag_by_name(x, "LIGHT", NOTYPE))
140#define LinkOk(x)       (has_flag_by_name(x, "LINK_OK", NOTYPE))
141#define Loud(x)         (has_flag_by_name(x, "LOUD", NOTYPE))
142#define Mistrust(x)     (has_flag_by_name(x, "MISTRUST", TYPE_THING|TYPE_EXIT|TYPE_ROOM))
143#define NoCommand(x)    (has_flag_by_name(x, "NO_COMMAND", NOTYPE))
144#define NoWarn(x)       (has_flag_by_name(x, "NO_WARN", NOTYPE))
145#define Opaque(x)       (has_flag_by_name(x, "OPAQUE", NOTYPE))
146#define Orphan(x)       (has_flag_by_name(x, "ORPHAN", NOTYPE))
147#define Puppet(x)       (has_flag_by_name(x, "PUPPET", TYPE_THING|TYPE_ROOM))
148#define Quiet(x)        (has_flag_by_name(x, "QUIET", NOTYPE))
149#define Safe(x)         (has_flag_by_name(x, "SAFE", NOTYPE))
150#define Sticky(x)       (has_flag_by_name(x, "STICKY", NOTYPE))
151#define Suspect(x)      (has_flag_by_name(x,"SUSPECT", NOTYPE))
152#define Transparented(x)      (has_flag_by_name(x, "TRANSPARENT", NOTYPE))
153#define Unfind(x)       (has_flag_by_name(x, "UNFINDABLE", NOTYPE))
154#define Verbose(x)      (has_flag_by_name(x, "VERBOSE", NOTYPE))
155#define Visual(x)       (has_flag_by_name(x, "VISUAL", NOTYPE))
156
157/* Attribute flags */
158#define AF_Internal(a) ((a)->flags & AF_INTERNAL)
159#define AF_Wizard(a) ((a)->flags & AF_WIZARD)
160#define AF_Locked(a) ((a)->flags & AF_LOCKED)
161#define AF_Noprog(a) ((a)->flags & AF_NOPROG)
162#define AF_Mdark(a) ((a)->flags & AF_MDARK)
163#define AF_Private(a) ((a)->flags & AF_PRIVATE)
164#define AF_Nocopy(a) ((a)->flags & AF_NOCOPY)
165#define AF_Visual(a) ((a)->flags & AF_VISUAL)
166#define AF_Regexp(a) ((a)->flags & AF_REGEXP)
167#define AF_Case(a) ((a)->flags & AF_CASE)
168#define AF_Safe(a) ((a)->flags & AF_SAFE)
169#define AF_Command(a) ((a)->flags & AF_COMMAND)
170#define AF_Listen(a) ((a)->flags & AF_LISTEN)
171#define AF_Nodump(a) ((a)->flags & AF_NODUMP)
172#define AF_Listed(a) ((a)->flags & AF_LISTED)
173#define AF_Prefixmatch(a) ((a)->flags & AF_PREFIXMATCH)
174#define AF_Veiled(a) ((a)->flags & AF_VEILED)
175#define AF_Debug(a) ((a)->flags & AF_DEBUG)
176#define AF_Nearby(a) ((a)->flags & AF_NEARBY)
177#define AF_Public(a) ((a)->flags & AF_PUBLIC)
178#define AF_Mhear(a) ((a)->flags & AF_MHEAR)
179#define AF_Ahear(a) ((a)->flags & AF_AHEAR)
180
181/* Non-mortal checks */
182#define God(x)  ((x) == GOD)
183#define Royalty(x)      (has_flag_by_name(x, "ROYALTY", NOTYPE))
184#define Wizard(x)       (God(x) || has_flag_by_name(x,"WIZARD", NOTYPE))
185#define Hasprivs(x)     (God(x) || Royalty(x) || Wizard(x))
186
187#define IsQuiet(x)      (Quiet(x) || Quiet(Owner(x)))
188#define AreQuiet(x,y)   (Quiet(x) || (Quiet(y) && (Owner(y) == x)))
189#define Mobile(x)       (IsPlayer(x) || IsThing(x))
190#define Alive(x)        (IsPlayer(x) || Puppet(x) || \
191   (Audible(x) && atr_get_noparent(x,"FORWARDLIST")))
192/* Was Dark() */
193#define DarkLegal(x)    (Dark(x) && (Wizard(x) || !Alive(x)))
194
195
196
197/* This is carefully ordered, from most to least likely. Hopefully. */
198#define CanEval(x,y)    (!(SAFER_UFUN) || !Hasprivs(y) || God(x) || \
199        ((Wizard(x) || (Royalty(x) && !Wizard(y))) && !God(y)))
200
201/* AF_PUBLIC overrides SAFER_UFUN */
202#define CanEvalAttr(x,y,a) (CanEval(x,y) || AF_Public(a))
203
204/* Note that this is a utility to determine the objects which may or may */
205/* not be controlled, rather than a strict check for the INHERIT flag */
206#define Owns(p,x) (Owner(p) == Owner(x))
207
208
209/* Was Inherit() */
210#define Inheritable(x)  (IsPlayer(x) || Inherit(x) || \
211                        Inherit(Owner(x)) || Wizard(x))
212
213#define NoWarnable(x) (NoWarn(x) || NoWarn(Owner(x)))
214
215/* Ancestor_Parent() - returns appropriate ancestor object */
216#define Ancestor_Parent(x) (Orphan(x) ? NOTHING : \
217    (IsRoom(x) ? ANCESTOR_ROOM : \
218     (IsExit(x) ? ANCESTOR_EXIT : \
219      (IsPlayer(x) ? ANCESTOR_PLAYER : \
220       (IsThing(x) ? ANCESTOR_THING : NOTHING )))))
221
222
223/*--------------------------------------------------------------------------
224 * Other db stuff
225 */
226
227/** An object in the database.
228 *
229 */
230struct object {
231  const char *name;             /**< The name of the object */
232  /** An overloaded pointer.
233   * For things and players, points to container object.
234   * For exits, points to destination.
235   * For rooms, points to drop-to.
236   */
237  dbref location;
238  dbref contents;               /**< Pointer to first item */
239  /** An overloaded pointer.
240   * For things and players, points to home.
241   * For rooms, points to first exit.
242   * For exits, points to source room.
243   */
244  dbref exits;
245  dbref next;                   /**< pointer to next in contents/exits chain */
246  dbref parent;                 /**< pointer to parent object */
247  struct lock_list *locks;      /**< list of locks set on the object */
248  dbref owner;                  /**< who controls this object */
249  dbref zone;                   /**< zone master object number */
250  int penn;                     /**< number of pennies object contains */
251  warn_type warnings;           /**< bitflags of warning types */
252  time_t creation_time;         /**< Time/date of object creation */
253  /** Last modifiction time.
254   * For players, the number of failed logins.
255   * For other objects, the time/date of last modification to its attributes.
256   */
257  time_t modification_time;
258  int attrcount;                /**< Number of attribs on the object */
259  int type;                     /**< Object's type */
260  object_flag_type flags;       /**< Pointer to flag bit array */
261  object_flag_type powers;      /**< Pointer to power bit array */
262  ALIST *list;                  /**< list of attributes on the object */
263};
264
265/** A structure to hold database statistics.
266 * This structure is used by get_stats() in wiz.c to group
267 * counts of various objects in the database.
268 */
269struct db_stat_info {
270  int total;    /**< Total count */
271  int players;  /**< Player count */
272  int rooms;    /**< Room count */
273  int exits;    /**< Exit count */
274  int things;   /**< Thing count */
275  int garbage;  /**< Garbage count */
276};
277
278extern struct object *db;
279extern dbref db_top;
280
281extern void *get_objdata(dbref thing, const char *keybase);
282extern void *set_objdata(dbref thing, const char *keybase, void *data);
283extern void clear_objdata(dbref thing);
284
285#define DOLIST(var, first)\
286    for((var) = (first); GoodObject((var)); (var) = Next(var))
287
288#define PUSH(thing, locative) \
289    ((Next(thing) = (locative)), (locative) = (thing))
290
291#define DOLIST_VISIBLE(var, first, player)\
292    for((var) = first_visible((player), (first)); GoodObject((var)); (var) = first_visible((player), Next(var)))
293
294typedef uint32_t mail_flag;
295
296/** A mail message.
297 * This structure represents a single mail message in the linked list
298 * of messages that comprises the mail database. Mail messages are
299 * stored in a doubly-linked list sorted by message recipient.
300 */
301struct mail {
302  struct mail *next;            /**< Pointer to next message */
303  struct mail *prev;            /**< Pointer to previous message */
304  dbref to;                     /**< Recipient dbref */
305  dbref from;                   /**< Sender's dbref */
306  time_t from_ctime;            /**< Sender's creation time */
307  chunk_reference_t msgid;      /**< Message text, compressed */
308  time_t time;                  /**< Message date/time */
309  unsigned char *subject;       /**< Message subject, compressed */
310  mail_flag read;               /**< Bitflags of message status */
311};
312
313typedef struct mail MAIL;
314
315
316extern const char *EOD;
317
318#define SPOOF(player, cause, sw) \
319  if (SW_ISSET(sw, SWITCH_SPOOF) && (controls(player, cause) || Can_Nspemit(player))) \
320    player = cause;
321
322#endif                          /* __DBDEFS_H */
Note: See TracBrowser for help on using the browser.