00001
00002
00003
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;
00032 int number;
00033 int flags;
00034 };
00035
00036 #ifdef MEMORY_BASED
00037 typedef struct atrlist ATRLIST;
00038 struct atrlist
00039 {
00040 char *data;
00041 int size;
00042 int 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'
00067
00068
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;
00087 };
00088
00089 #define TRUE_BOOLEXP ((BOOLEXP *) 0)
00090
00091
00092
00093 #define F_UNKNOWN 0
00094 #define F_MUX 5
00095
00096 #define V_MASK 0x000000ff
00097 #define V_ZONE 0x00000100
00098 #define V_LINK 0x00000200
00099 #define V_DATABASE 0x00000400
00100 #define V_ATRNAME 0x00000800
00101 #define V_ATRKEY 0x00001000
00102 #define V_PARENT 0x00002000
00103 #define V_ATRMONEY 0x00008000
00104 #define V_XFLAGS 0x00010000
00105 #define V_POWERS 0x00020000
00106 #define V_3FLAGS 0x00040000
00107 #define V_QUOTED 0x00080000
00108
00109
00110 #define DB_CHANNELS 0x2
00111 #define DB_SLOCK 0x4
00112 #define DB_MC 0x8
00113 #define DB_MPAR 0x10
00114 #define DB_CLASS 0x20
00115 #define DB_RANK 0x40
00116 #define DB_DROPLOCK 0x80
00117 #define DB_GIVELOCK 0x100
00118 #define DB_GETLOCK 0x200
00119 #define DB_THREEPOW 0x400
00120
00121
00122 #define NOTHING (-1)
00123 #define AMBIGUOUS (-2)
00124 #define HOME (-3)
00125 #define NOPERM (-4)
00126 extern char *aszSpecialDBRefNames[1-NOPERM];
00127
00128 typedef struct object OBJ;
00129 struct object
00130 {
00131 dbref location;
00132
00133
00134 dbref contents;
00135
00136 dbref exits;
00137
00138 dbref next;
00139
00140
00141 dbref link;
00142
00143 dbref parent;
00144 dbref owner;
00145
00146
00147 dbref zone;
00148
00149 FLAGSET fs;
00150
00151 POWER powers;
00152 POWER powers2;
00153
00154 STACK *stackhead;
00155
00156 CLinearTimeDelta cpu_time_used;
00157
00158
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;
00169 int nALAlloc;
00170 int nALUsed;
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