PropPtr regenvprop(dbref *where, const char *propname, int typ) { PropPtr temp; temp = get_property(0, propname); #ifdef DISKBASE if (temp) propfetch(0, temp); #endif if (temp && (!typ || PropType(temp) == typ)) return temp; while (*where != NOTHING && *where != 0) { temp = get_property(*where, propname); #ifdef DISKBASE if (temp) propfetch(*where, temp); #endif if (temp && (!typ || PropType(temp) == typ)) return temp; *where = getparent(*where); } return NULL; }
/* checks if object has property, returns 1 if it has the property */ int has_property_strict(int descr, dbref player, dbref what, const char *type, const char *pclass, int value) { PropPtr p; const char *str; char *ptr; char buf[BUFFER_LEN]; p = get_property(what, type); if (p) { #ifdef DISKBASE propfetch(what, p); #endif if (PropType(p) == PROP_STRTYP) { str = DoNull(PropDataUNCStr(p)); ptr = do_parse_mesg(descr, player, what, str, "(Lock)", buf, (MPI_ISPRIVATE | MPI_ISLOCK)); return (equalstr((char *) pclass, ptr)); } else if (PropType(p) == PROP_INTTYP) { return (value == PropDataVal(p)); } else { return 0; } } return 0; }
int fetch_propvals(dbref obj, const char *dir) { PropPtr p, pptr; int cnt = 0; char buf[BUFFER_LEN]; char name[BUFFER_LEN]; p = first_prop_nofetch(obj, dir, &pptr, name, sizeof(name)); while (p) { cnt = (cnt || propfetch(obj, p)); if (PropDir(p) || (PropFlags(p) & PROP_DIRUNLOADED)) { strcpyn(buf, sizeof(buf), dir); strcatn(buf, sizeof(buf), name); strcatn(buf, sizeof(buf), "/"); if (PropFlags(p) & PROP_DIRUNLOADED) { SetPFlags(p, (PropFlags(p) & ~PROP_DIRUNLOADED)); getproperties(input_file, obj, buf); } fetch_propvals(obj, buf); } p = next_prop(pptr, p, name, sizeof(name)); } return cnt; }
int reflist_find(dbref obj, const char *propname, dbref tofind) { PropPtr ptr; const char *temp; int pos = 0; int count = 0; char buf[BUFFER_LEN]; ptr = get_property(obj, propname); if (ptr) { const char *pat = NULL; #ifdef DISKBASE propfetch(obj, ptr); #endif switch (PropType(ptr)) { case PROP_STRTYP: temp = PropDataUNCStr(ptr); sprintf(buf, "%d", tofind); while (*temp) { if (*temp == '#') { pat = buf; count++; } else if (pat) { if (!*pat) { if (!*temp || *temp == ' ') { break; } pat = NULL; } else if (*pat != *temp) { pat = NULL; } else { pat++; } } temp++; } if (pat && !*pat) { pos = count; } break; case PROP_REFTYP: if (PropDataRef(ptr) == tofind) pos = 1; break; default: break; } } return pos; }
char * displayprop(dbref player, dbref obj, const char *name, char *buf) { char mybuf[BUFFER_LEN], tbuf[BUFFER_LEN]; int pdflag; PropPtr p = get_property(obj, name); if (!p) { sprintf(buf, SYSGLOOM "%s: No such property.", name); return buf; } #ifdef DISKBASE propfetch(obj, p); #endif pdflag = (PropDir(p) != NULL); sprintf(tbuf, "%.*s%c", (BUFFER_LEN / 4), name, (pdflag) ? PROPDIR_DELIMITER : '\0'); tct(tbuf, mybuf); switch (PropType(p)) { case PROP_STRTYP: sprintf(buf, SYSAQUA "str " SYSGREEN "%s" SYSRED ":" SYSCYAN "%.*s", mybuf, (BUFFER_LEN / 2), tct(PropDataUNCStr(p), tbuf)); break; case PROP_REFTYP: sprintf(buf, SYSBROWN "ref " SYSGREEN "%s" SYSRED ":%s", mybuf, ansi_unparse_object(player, PropDataRef(p))); break; case PROP_INTTYP: sprintf(buf, SYSFOREST "int " SYSGREEN "%s" SYSRED ":" SYSYELLOW "%d", mybuf, PropDataVal(p)); break; case PROP_FLTTYP: sprintf(buf, SYSNAVY "flt " SYSGREEN "%s" SYSRED ":" SYSBROWN "%.15g", mybuf, PropDataFVal(p)); break; case PROP_LOKTYP: if (PropFlags(p) & PROP_ISUNLOADED) { sprintf(buf, SYSCRIMSON "lok " SYSGREEN "%s" SYSRED ":" SYSPURPLE "*UNLOCKED*", mybuf); } else { sprintf(buf, SYSCRIMSON "lok " SYSGREEN "%s" SYSRED ":" SYSPURPLE "%.*s", mybuf, (BUFFER_LEN / 2), tct(unparse_boolexp(player, PropDataLok(p), 1), tbuf)); } break; case PROP_DIRTYP: sprintf(buf, SYSWHITE "dir " SYSGREEN "%s" SYSRED ":", mybuf); break; } return buf; }
/* return boolexp lock of property */ dbref get_property_dbref(dbref player, const char *pclass) { PropPtr p; p = get_property(player, pclass); if (!p) return NOTHING; #ifdef DISKBASE propfetch(player, p); #endif if (PropType(p) != PROP_REFTYP) return NOTHING; return PropDataRef(p); }
/* return boolexp lock of property */ struct boolexp * get_property_lock(dbref player, const char *pclass) { PropPtr p; p = get_property(player, pclass); if (!p) return TRUE_BOOLEXP; #ifdef DISKBASE propfetch(player, p); if (PropFlags(p) & PROP_ISUNLOADED) return TRUE_BOOLEXP; #endif if (PropType(p) != PROP_LOKTYP) return TRUE_BOOLEXP; return PropDataLok(p); }
/* return class (string value) of property as PTYPE */ PTYPE get_property_ptype(dbref player, const char *type) { PropPtr p; p = get_property(player, type); if (p) { #ifdef DISKBASE propfetch(player, p); #endif if (PropType(p) != PROP_STRTYP) return (char *) NULL; return (PTYPE) (PropDataStr(p)); } else { return (PTYPE) NULL; } }
/* return float value of a property */ double get_property_fvalue(dbref player, const char *pname) { PropPtr p; p = get_property(player, pname); if (p) { #ifdef DISKBASE propfetch(player, p); #endif if (PropType(p) != PROP_FLTTYP) return 0.0; return (PropDataFVal(p)); } else { return 0.0; } }
/* return value of property */ int get_property_value(dbref player, const char *type) { PropPtr p; p = get_property(player, type); if (p) { #ifdef DISKBASE propfetch(player, p); #endif if (PropType(p) != PROP_INTTYP) return 0; return (PropDataVal(p)); } else { return 0; } }
/* copies properties */ void copy_proplist(dbref obj, PropPtr * nu, PropPtr old) { PropPtr p; if (old) { #ifdef DISKBASE propfetch(obj, old); #endif p = new_prop(nu, PropName(old)); SetPFlagsRaw(p, PropFlagsRaw(old)); switch (PropType(old)) { case PROP_STRTYP: SetPDataStr(p, alloc_string(PropDataStr(old))); break; case PROP_LOKTYP: if (PropFlags(old) & PROP_ISUNLOADED) { SetPDataLok(p, TRUE_BOOLEXP); SetPFlags(p, (PropFlags(p) & ~PROP_ISUNLOADED)); } else { SetPDataLok(p, copy_bool(PropDataLok(old))); } break; case PROP_DIRTYP: SetPDataVal(p, 0); break; case PROP_FLTTYP: SetPDataFVal(p, PropDataFVal(old)); break; default: SetPDataVal(p, PropDataVal(old)); break; } copy_proplist(obj, &PropDir(p), PropDir(old)); copy_proplist(obj, &AVL_LF(p), AVL_LF(old)); copy_proplist(obj, &AVL_RT(p), AVL_RT(old)); /* copy_proplist(obj, nu, AVL_LF(old)); copy_proplist(obj, nu, AVL_RT(old)); */ } }
void db_dump_props_rec(dbref obj, FILE * f, const char *dir, PropPtr p) { char buf[BUFFER_LEN]; #ifdef DISKBASE int tpos = 0; int flg; short wastouched = 0; #endif if (!p) return; db_dump_props_rec(obj, f, dir, AVL_LF(p)); #ifdef DISKBASE if (tp_diskbase_propvals) { tpos = ftell(f); wastouched = (PropFlags(p) & PROP_TOUCHED); } if (propfetch(obj, p)) { fseek(f, 0L, 2); } #endif db_putprop(f, dir, p); #ifdef DISKBASE if (tp_diskbase_propvals && !wastouched) { if (PropType(p) == PROP_STRTYP || PropType(p) == PROP_LOKTYP) { flg = PropFlagsRaw(p) | PROP_ISUNLOADED; clear_propnode(p); SetPFlagsRaw(p, flg); SetPDataVal(p, tpos); } } #endif if (PropDir(p)) { sprintf(buf, "%s%s%c", dir, PropName(p), PROPDIR_DELIMITER); db_dump_props_rec(obj, f, buf, PropDir(p)); } db_dump_props_rec(obj, f, dir, AVL_RT(p)); }
PropPtr envprop_cmds(dbref *where, const char *propname, int typ) { PropPtr temp; while (*where != NOTHING) { if (typ ? 1 : ((FLAG2(*where) & F2COMMAND) && !(FLAG2(*where) & F2NO_COMMAND) && ((FLAGS(OWNER(*where)) & BUILDER) || (MLevel(OWNER(*where)) >= LMAGE)))) { temp = get_property(*where, propname); #ifdef DISKBASE if (temp) propfetch(*where, temp); #endif if (temp) return temp; } *where = getparent(*where); } return NULL; }
void prim_envprop(PRIM_PROTOTYPE) { double fresult; CHECKOP(2); oper1 = POP(); oper2 = POP(); if (oper1->type != PROG_STRING) abort_interp("Non-string argument (2)"); if (!oper1->data.string) abort_interp("Empty string argument (2)"); if (!valid_object(oper2)) abort_interp("Non-object argument (1)"); CHECKREMOTE(oper2->data.objref); { char tname[BUFFER_LEN]; dbref what; PropPtr ptr; int len = oper1->data.string->length; strcpyn(tname, sizeof(tname), oper1->data.string->data); while (len-- > 0 && tname[len] == PROPDIR_DELIMITER) { tname[len] = '\0'; } what = oper2->data.objref; ptr = envprop(&what, tname, 0); if (what != NOTHING) { if (!prop_read_perms(ProgUID, what, oper1->data.string->data, mlev)) abort_interp("Permission denied."); } CLEAR(oper1); CLEAR(oper2); PushObject(what); if (!ptr) { result = 0; PushInt(result); } else { #ifdef DISKBASE propfetch(what, ptr); #endif switch (PropType(ptr)) { case PROP_STRTYP: PushString(PropDataStr(ptr)); break; case PROP_INTTYP: result = PropDataVal(ptr); PushInt(result); break; case PROP_FLTTYP: fresult = PropDataFVal(ptr); PushFloat(fresult); break; case PROP_REFTYP: ref = PropDataRef(ptr); PushObject(ref); break; case PROP_LOKTYP: if (PropFlags(ptr) & PROP_ISUNLOADED) { PushLock(TRUE_BOOLEXP); } else { PushLock(PropDataLok(ptr)); } break; default: result = 0; PushInt(result); break; } } } }
void prim_envpropstr(PRIM_PROTOTYPE) { CHECKOP(2); oper1 = POP(); oper2 = POP(); if (oper1->type != PROG_STRING) abort_interp("Non-string argument (2)"); if (!oper1->data.string) abort_interp("Empty string argument (2)"); if (!valid_object(oper2)) abort_interp("Non-object argument (1)"); CHECKREMOTE(oper2->data.objref); { char tname[BUFFER_LEN]; dbref what; PropPtr ptr; const char *temp; int len = oper1->data.string->length; strcpyn(tname, sizeof(tname), oper1->data.string->data); while (len-- > 0 && tname[len] == PROPDIR_DELIMITER) { tname[len] = '\0'; } what = oper2->data.objref; ptr = envprop(&what, tname, 0); if (!ptr) { temp = ""; } else { #ifdef DISKBASE propfetch(what, ptr); #endif switch (PropType(ptr)) { case PROP_STRTYP: temp = PropDataStr(ptr); break; /* *case PROP_INTTYP: * snprintf(buf, sizeof(buf), "%d", PropDataVal(ptr)); * temp = buf; * break; */ case PROP_REFTYP: snprintf(buf, sizeof(buf), "#%d", PropDataRef(ptr)); temp = buf; break; case PROP_LOKTYP: if (PropFlags(ptr) & PROP_ISUNLOADED) { temp = "*UNLOCKED*"; } else { temp = unparse_boolexp(ProgUID, PropDataLok(ptr), 1); } break; default: temp = ""; break; } } #ifdef LOG_PROPS log2file("props.log", "#%d (%d) ENVPROPSTR: o=%d so=%d n=\"%s\" s=\"%s\"", program, pc->line, what, oper2->data.objref, tname, temp); #endif if (what != NOTHING) { if (!prop_read_perms(ProgUID, what, oper1->data.string->data, mlev)) abort_interp("Permission denied."); /* if (Typeof(what) != TYPE_PLAYER) * ts_lastuseobject(what); */ } CLEAR(oper1); CLEAR(oper2); PushObject(what); PushString(temp); } }
void prim_getprop(PRIM_PROTOTYPE) { const char *temp; PropPtr prptr; dbref obj2; CHECKOP(2); oper1 = POP(); oper2 = POP(); if (oper1->type != PROG_STRING) abort_interp("Non-string argument (2)"); if (!oper1->data.string) abort_interp("Empty string argument (2)"); if (!valid_object(oper2)) abort_interp("Non-object argument (1)"); CHECKREMOTE(oper2->data.objref); { char type[BUFFER_LEN]; int len = oper1->data.string->length; if (!prop_read_perms(ProgUID, oper2->data.objref, oper1->data.string->data, mlev)) abort_interp("Permission denied."); strcpyn(type, sizeof(type), oper1->data.string->data); while (len-- > 0 && type[len] == PROPDIR_DELIMITER) { type[len] = '\0'; } obj2 = oper2->data.objref; prptr = get_property(obj2, type); #ifdef LOG_PROPS log2file("props.log", "#%d (%d) GETPROP: o=%d n=\"%s\"", program, pc->line, oper2->data.objref, type); #endif CLEAR(oper1); CLEAR(oper2); if (prptr) { #ifdef DISKBASE propfetch(obj2, prptr); #endif switch (PropType(prptr)) { case PROP_STRTYP: temp = PropDataStr(prptr); PushString(temp); break; case PROP_LOKTYP: if (PropFlags(prptr) & PROP_ISUNLOADED) { PushLock(TRUE_BOOLEXP); } else { PushLock(PropDataLok(prptr)); } break; case PROP_REFTYP: PushObject(PropDataRef(prptr)); break; case PROP_INTTYP: PushInt(PropDataVal(prptr)); break; case PROP_FLTTYP: PushFloat(PropDataFVal(prptr)); break; default: result = 0; PushInt(result); break; } } else { result = 0; PushInt(result); } /* if (Typeof(oper2->data.objref) != TYPE_PLAYER) ts_lastuseobject(oper2->data.objref); */ } }
void reflist_del(dbref obj, const char *propname, dbref todel) { PropPtr ptr; const char *temp; const char *list; int count = 0; int charcount = 0; char buf[BUFFER_LEN]; char outbuf[BUFFER_LEN]; ptr = get_property(obj, propname); if (ptr) { const char *pat = NULL; #ifdef DISKBASE propfetch(obj, ptr); #endif switch (PropType(ptr)) { case PROP_STRTYP: *outbuf = '\0'; list = temp = PropDataUNCStr(ptr); sprintf(buf, "%d", todel); while (*temp) { if (*temp == '#') { pat = buf; count++; charcount = temp - list; } else if (pat) { if (!*pat) { if (!*temp || *temp == ' ') { break; } pat = NULL; } else if (*pat != *temp) { pat = NULL; } else { pat++; } } temp++; } if (pat && !*pat) { if (charcount > 0) { strncpy(outbuf, list, charcount - 1); outbuf[charcount - 1] = '\0'; } strcat(outbuf, temp); for (temp = outbuf; isspace(*temp); temp++) ; add_property(obj, propname, temp, 0); } break; case PROP_REFTYP: if (PropDataRef(ptr) == todel) { add_property(obj, propname, "", 0); } break; default: break; } } }