mux/src/db.h

Go to the documentation of this file.
00001 // db.h
00002 //
00003 // $Id: db.h,v 1.10 2007/02/03 04:32:52 sdennis Exp $
00004 //
00005 
00006 #ifndef __DB_H
00007 #define __DB_H
00008 
00009 #ifndef MEMORY_BASED
00010 #define SYNC                    cache_sync()
00011 #define CLOSE                   cache_close()
00012 #else // !MEMORY_BASED
00013 #define SYNC
00014 #define CLOSE
00015 #endif // !MEMORY_BASED
00016 
00017 #include "attrcache.h"
00018 #include "flags.h"
00019 #include "timeutil.h"
00020 
00021 #define ITER_PARENTS(t,p,l) for ((l)=0, (p)=(t); \
00022                      (Good_obj(p) && \
00023                       ((l) < mudconf.parent_nest_lim)); \
00024                      (p)=Parent(p), (l)++)
00025 
00026 int get_atr(char *name);
00027 
00028 typedef struct attr ATTR;
00029 struct attr
00030 {
00031     const char *name;   // This has to be first.  braindeath.
00032     int number;         // attr number
00033     int flags;
00034 };
00035 
00036 #ifdef MEMORY_BASED
00037 typedef struct atrlist ATRLIST;
00038 struct atrlist
00039 {
00040     char *data;     /* Attribute text. */
00041     int size;       /* Length of attribute */
00042     int number;     /* Attribute number. */
00043 };
00044 #endif // MEMORY_BASED
00045 
00046 extern char *MakeCanonicalAttributeName(const char *pName, int *pnName, bool *pbValid);
00047 extern char *MakeCanonicalAttributeCommand(const char *pName, int *pnName, bool *pbValid);
00048 
00049 typedef struct stack STACK;
00050 struct stack
00051  {
00052     char *data;
00053     STACK *next;
00054 };
00055 
00056 extern ATTR *atr_num(int anum);
00057 extern ATTR *atr_str(char *s);
00058 
00059 extern ATTR attr[];
00060 
00061 extern ATTR **anum_table;
00062 #define anum_get(x) (anum_table[(x)])
00063 #define anum_set(x,v)   anum_table[(x)] = v
00064 extern void anum_extend(int);
00065 
00066 #define ATR_INFO_CHAR   '\1'    /* Leadin char for attr control data */
00067 
00068 /* Boolean expressions, for locks */
00069 #define BOOLEXP_AND     0
00070 #define BOOLEXP_OR      1
00071 #define BOOLEXP_NOT     2
00072 #define BOOLEXP_CONST   3
00073 #define BOOLEXP_ATR     4
00074 #define BOOLEXP_INDIR   5
00075 #define BOOLEXP_CARRY   6
00076 #define BOOLEXP_IS      7
00077 #define BOOLEXP_OWNER   8
00078 #define BOOLEXP_EVAL    9
00079 
00080 typedef struct boolexp BOOLEXP;
00081 struct boolexp
00082 {
00083   boolexp_type type;
00084   struct boolexp *sub1;
00085   struct boolexp *sub2;
00086   dbref thing;          /* thing refers to an object */
00087 };
00088 
00089 #define TRUE_BOOLEXP ((BOOLEXP *) 0)
00090 
00091 /* Database format information */
00092 
00093 #define F_UNKNOWN   0   /* Unknown database format */
00094 #define F_MUX       5   /* MUX format */
00095 
00096 #define V_MASK      0x000000ff  /* Database version */
00097 #define V_ZONE      0x00000100  /* ZONE/DOMAIN field */
00098 #define V_LINK      0x00000200  /* LINK field (exits from objs) */
00099 #define V_DATABASE  0x00000400  /* attrs in a separate database */
00100 #define V_ATRNAME   0x00000800  /* NAME is an attr, not in the hdr */
00101 #define V_ATRKEY    0x00001000  /* KEY is an attr, not in the hdr */
00102 #define V_PARENT    0x00002000  /* db has the PARENT field */
00103 #define V_ATRMONEY  0x00008000  /* Money is kept in an attribute */
00104 #define V_XFLAGS    0x00010000  /* An extra word of flags */
00105 #define V_POWERS    0x00020000  /* Powers? */
00106 #define V_3FLAGS    0x00040000  /* Adding a 3rd flag word */
00107 #define V_QUOTED    0x00080000  /* Quoted strings, ala PennMUSH */
00108 
00109 /* Some defines for DarkZone's flavor of PennMUSH */
00110 #define DB_CHANNELS    0x2    /*  Channel system */
00111 #define DB_SLOCK       0x4    /*  Slock */
00112 #define DB_MC          0x8    /*  Master Create Time + modifed */
00113 #define DB_MPAR        0x10   /*  Multiple Parent Code */
00114 #define DB_CLASS       0x20   /*  Class System */
00115 #define DB_RANK        0x40   /*  Rank */
00116 #define DB_DROPLOCK    0x80   /*  Drop/TelOut Lock */
00117 #define DB_GIVELOCK    0x100  /*  Give/TelIn Lock */
00118 #define DB_GETLOCK     0x200  /*  Get Lock */
00119 #define DB_THREEPOW    0x400  /*  Powers have Three Long Words */
00120 
00121 /* special dbref's */
00122 #define NOTHING     (-1)    /* null dbref */
00123 #define AMBIGUOUS   (-2)    /* multiple possibilities, for matchers */
00124 #define HOME        (-3)    /* virtual room, represents mover's home */
00125 #define NOPERM      (-4)    /* Error status, no permission */
00126 extern char *aszSpecialDBRefNames[1-NOPERM];
00127 
00128 typedef struct object OBJ;
00129 struct object
00130 {
00131     dbref   location;   /* PLAYER, THING: where it is */
00132                         /* ROOM: dropto: */
00133                         /* EXIT: where it goes to */
00134     dbref   contents;   /* PLAYER, THING, ROOM: head of contentslist */
00135                         /* EXIT: unused */
00136     dbref   exits;      /* PLAYER, THING, ROOM: head of exitslist */
00137                         /* EXIT: where it is */
00138     dbref   next;       /* PLAYER, THING: next in contentslist */
00139                         /* EXIT: next in exitslist */
00140                         /* ROOM: unused */
00141     dbref   link;       /* PLAYER, THING: home location */
00142                         /* ROOM, EXIT: unused */
00143     dbref   parent;     /* ALL: defaults for attrs, exits, $cmds, */
00144     dbref   owner;      /* PLAYER: domain number + class + moreflags */
00145                         /* THING, ROOM, EXIT: owning player number */
00146 
00147     dbref   zone;       /* Whatever the object is zoned to.*/
00148 
00149     FLAGSET fs;         // ALL: Flags set on the object.
00150 
00151     POWER   powers;     /* ALL: Powers on object */
00152     POWER   powers2;    /* ALL: even more powers */
00153 
00154     STACK   *stackhead; /* Every object has a stack. */
00155 
00156     CLinearTimeDelta cpu_time_used; /* ALL: CPU time eaten */
00157 
00158     // ALL: When to refurbish throttled counters.
00159     //
00160     CLinearTimeAbsolute tThrottleExpired;
00161     int     throttled_attributes;
00162     int     throttled_mail;
00163 
00164     char    *purename;
00165     char    *moniker;
00166 
00167 #ifdef MEMORY_BASED
00168     ATRLIST *pALHead;   /* The head of the attribute list.       */
00169     int      nALAlloc;  /* Size of the allocated attribute list. */
00170     int      nALUsed;   /* Used portion of the attribute list.   */
00171 #else
00172     char    *name;
00173 #endif // MEMORY_BASED
00174 };
00175 
00176 const int INITIAL_ATRLIST_SIZE = 10;
00177 const int ATRLIST_CHUNK        = 20;
00178 
00179 extern OBJ *db;
00180 
00181 #define Location(t)     db[t].location
00182 
00183 #define Zone(t)         db[t].zone
00184 
00185 #define Contents(t)     db[t].contents
00186 #define Exits(t)        db[t].exits
00187 #define Next(t)         db[t].next
00188 #define Link(t)         db[t].link
00189 #define Owner(t)        db[t].owner
00190 #define Parent(t)       db[t].parent
00191 #define Flags(t)        db[t].fs.word[FLAG_WORD1]
00192 #define Flags2(t)       db[t].fs.word[FLAG_WORD2]
00193 #define Flags3(t)       db[t].fs.word[FLAG_WORD3]
00194 #define Powers(t)       db[t].powers
00195 #define Powers2(t)      db[t].powers2
00196 #define Stack(t)        db[t].stackhead
00197 #define Home(t)         Link(t)
00198 #define Dropto(t)       Location(t)
00199 #define ThAttrib(t)     db[t].throttled_attributes
00200 #define ThMail(t)       db[t].throttled_mail
00201 
00202 #define s_Location(t,n)     db[t].location = (n)
00203 
00204 #define s_Zone(t,n)         db[t].zone = (n)
00205 
00206 #define s_Contents(t,n)     db[t].contents = (n)
00207 #define s_Exits(t,n)        db[t].exits = (n)
00208 #define s_Next(t,n)         db[t].next = (n)
00209 #define s_Link(t,n)         db[t].link = (n)
00210 #define s_Owner(t,n)        db[t].owner = (n)
00211 #define s_Parent(t,n)       db[t].parent = (n)
00212 #define s_Flags(t,f,n)      db[t].fs.word[f] = (n)
00213 #define s_Powers(t,n)       db[t].powers = (n)
00214 #define s_Powers2(t,n)      db[t].powers2 = (n)
00215 #define s_Stack(t,n)        db[t].stackhead = (n)
00216 #define s_Home(t,n)         s_Link(t,n)
00217 #define s_Dropto(t,n)       s_Location(t,n)
00218 #define s_ThAttrib(t,n)     db[t].throttled_attributes = (n);
00219 #define s_ThMail(t,n)       db[t].throttled_mail = (n);
00220 
00221 int  Pennies(dbref obj);
00222 void s_Pennies(dbref obj, int howfew);
00223 void s_PenniesDirect(dbref obj, int howfew);
00224 
00225 #ifndef WIN32
00226 void load_restart_db(void);
00227 #endif // !WIN32
00228 
00229 dbref    getref(FILE *);
00230 void putref(FILE *, dbref);
00231 void free_boolexp(BOOLEXP *);
00232 dbref    parse_dbref(const char *);
00233 bool ThrottleMail(dbref executor);
00234 bool ThrottleAttributeNames(dbref executor);
00235 bool ThrottlePlayerCreate(void);
00236 int  mkattr(dbref executor, char *);
00237 void al_store(void);
00238 void db_grow(dbref);
00239 void db_free(void);
00240 void db_make_minimal(void);
00241 dbref    db_read(FILE *, int *, int *, int *);
00242 dbref    db_write(FILE *, int, int);
00243 void destroy_thing(dbref);
00244 void destroy_exit(dbref);
00245 void putstring(FILE *f, const char *s);
00246 char *getstring_noalloc(FILE *f, int new_strings);
00247 void init_attrtab(void);
00248 
00249 #define DOLIST(thing,list) \
00250     for ((thing)=(list); \
00251          ((thing)!=NOTHING) && (Next(thing)!=(thing)); \
00252          (thing)=Next(thing))
00253 #define SAFE_DOLIST(thing,next,list) \
00254     for ((thing)=(list),(next)=((thing)==NOTHING ? NOTHING: Next(thing)); \
00255          (thing)!=NOTHING && (Next(thing)!=(thing)); \
00256          (thing)=(next), (next)=Next(next))
00257 #define DO_WHOLE_DB(thing) \
00258     for ((thing)=0; (thing)<mudstate.db_top; (thing)++)
00259 #define DO_WHOLE_DB_BACKWARDS(thing) \
00260     for ((thing)=mudstate.db_top-1; (thing)>=0; (thing)--)
00261 
00262 #endif // !__DB_H

Generated on Mon May 28 04:40:09 2007 for MUX by  doxygen 1.4.7