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 propfetch(dbref obj, PropPtr p) { if (!p) return 0; SetPFlags(p, (PropFlags(p) | PROP_TOUCHED)); if (PropFlags(p) & PROP_ISUNLOADED) { db_get_single_prop(input_file, obj, (long) PropDataVal(p), p, NULL); return 1; } return 0; }
void clear_propnode(PropPtr p) { if (!(PropFlags(p) & PROP_ISUNLOADED)) { if (PropType(p) == PROP_STRTYP) { free((void *) PropDataStr(p)); PropDataStr(p) = NULL; } if (PropType(p) == PROP_LOKTYP) free_boolexp(PropDataLok(p)); } SetPDataVal(p, 0); SetPFlags(p, (PropFlags(p) & ~PROP_ISUNLOADED)); SetPType(p, PROP_DIRTYP); }
int propfetch(dbref obj, PropPtr p) { FILE *f; if (!p) return 0; SetPFlags(p, (PropFlags(p) | PROP_TOUCHED)); if (PropFlags(p) & PROP_ISUNLOADED) { f = (FLAGS(obj) & SAVED_DELTA) ? delta_infile : input_file; db_get_single_prop(f, obj, (long) PropDataVal(p), p, NULL); return 1; } return 0; }
/** * Calculates the size of the given property directory AVL list. This * will iterate over the entire structure to give the entire size. It * is the low level equivalent of size_properties * * @see size_properties * * @param avl the Property directory AVL to check * @return the size of the loaded properties in memory -- this does NOT * do any diskbase loading. */ size_t size_proplist(PropPtr avl) { size_t bytes = 0; if (!avl) return 0; bytes += sizeof(struct plist); bytes += strlen(PropName(avl)); if (!(PropFlags(avl) & PROP_ISUNLOADED)) { switch (PropType(avl)) { case PROP_STRTYP: bytes += strlen(PropDataStr(avl)) + 1; break; case PROP_LOKTYP: bytes += size_boolexp(PropDataLok(avl)); break; default: break; } } bytes += size_proplist(avl->left); bytes += size_proplist(avl->right); bytes += size_proplist(PropDir(avl)); return bytes; }
int blessprops_wildcard(dbref player, dbref thing, const char *dir, const char *wild, int blessp) { char propname[BUFFER_LEN]; char wld[BUFFER_LEN]; char buf[BUFFER_LEN]; char buf2[BUFFER_LEN]; char *ptr, *wldcrd = wld; PropPtr propadr, pptr; int i, cnt = 0; int recurse = 0; #ifdef GOD_PRIV if(tp_strict_god_priv && !God(player) && God(OWNER(thing))) { notify(player,"Only God may touch what is God's."); return 0; } #endif strcpyn(wld, sizeof(wld), wild); i = strlen(wld); if (i && wld[i - 1] == PROPDIR_DELIMITER) strcatn(wld, sizeof(wld), "*"); for (wldcrd = wld; *wldcrd == PROPDIR_DELIMITER; wldcrd++) ; if (!strcmp(wldcrd, "**")) recurse = 1; for (ptr = wldcrd; *ptr && *ptr != PROPDIR_DELIMITER; ptr++) ; if (*ptr) *ptr++ = '\0'; propadr = first_prop(thing, (char *) dir, &pptr, propname, sizeof(propname)); while (propadr) { if (equalstr(wldcrd, propname)) { snprintf(buf, sizeof(buf), "%s%c%s", dir, PROPDIR_DELIMITER, propname); if (!Prop_System(buf) && ((!Prop_Hidden(buf) && !(PropFlags(propadr) & PROP_SYSPERMS)) || Wizard(OWNER(player)))) { if (!*ptr || recurse) { cnt++; if (blessp) { set_property_flags(thing, buf, PROP_BLESSED); snprintf(buf2, sizeof(buf2), "Blessed %s", buf); } else { clear_property_flags(thing, buf, PROP_BLESSED); snprintf(buf2, sizeof(buf2), "Unblessed %s", buf); } notify(player, buf2); } if (recurse) ptr = "**"; cnt += blessprops_wildcard(player, thing, buf, ptr, blessp); } } propadr = next_prop(pptr, propadr, propname, sizeof(propname)); } return cnt; }
void untouchprop_rec(PropPtr p) { if (!p) return; SetPFlags(p, (PropFlags(p) & ~PROP_TOUCHED)); untouchprop_rec(AVL_LF(p)); untouchprop_rec(AVL_RT(p)); untouchprop_rec(PropDir(p)); }
/* 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 free_propnode(PropPtr p) { if (!(PropFlags(p) & PROP_ISUNLOADED)) { if (PropType(p) == PROP_STRTYP) free((void *) PropDataStr(p)); if (PropType(p) == PROP_LOKTYP) free_boolexp(PropDataLok(p)); } free(p); }
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 flags of property */ int get_property_flags(dbref player, const char *type) { PropPtr p; p = get_property(player, type); if (p) { return (PropFlags(p)); } else { return 0; } }
/* path is the name of the propdir to find */ const char * propdir_unloaded(PropPtr root, const char *path) { PropPtr p; const char *n; char *o, *l; static char buf[BUFFER_LEN]; if (!root) return NULL; n = path; o = buf; while (*n == PROPDIR_DELIMITER) n++; if (!*n) return NULL; while (*n) { *o++ = '/'; l = o; while (*n && *n != PROPDIR_DELIMITER) *o++ = *n++; while (*n == PROPDIR_DELIMITER) n++; *o = '\0'; p = locate_prop(root, l); if (!p) { return NULL; } if (PropFlags(p) & PROP_DIRUNLOADED) { SetPFlags(p, (PropFlags(p) & ~PROP_DIRUNLOADED)); return buf + 1; } root = PropDir(p); } return NULL; }
/* 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); }
const char * mfn_dirprops(MFUNARGS) { char propname[BUFFER_LEN]; PropPtr propadr, pptr; char buf2[BUFFER_LEN]; int list_limit = MAX_MFUN_LIST_LEN; dbref obj; int outlen, nextlen; if(argc > 1) { obj = mesg_dbref_local(player, what, perms, argv[1]); if (obj == AMBIGUOUS || obj == UNKNOWN || obj == NOTHING || obj == HOME) ABORT_MPI("DIRPROPS","Match failed"); if (obj == PERMDENIED) ABORT_MPI("DIRPROPS",NOPERM_MESG); } else obj = what; buf[0] = '\0'; outlen = 0; #ifdef DISKBASE fetchprops(obj); #endif propadr = first_prop(obj, argv[0], &pptr, propname); while ((propadr > 0) && *propname) { if ( ( !Prop_Hidden(propname) && !(PropFlags(propadr) & PROP_SYSPERMS)) || (Permlevel(perms) >= tp_hidden_prop_mlevel)) { sprintf(buf2, "%s", propname); nextlen = strlen(buf2); if ((outlen + nextlen) >= (BUFFER_LEN - 3)) break; if (outlen) strcat((buf+(outlen++)), "\r"); strcat((buf + outlen), buf2); outlen += nextlen; list_limit--; } propadr = next_prop(pptr, propadr, propname); } return buf; }
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)); }
/** * This is the opposite of alloc_propnode, and is used to free the * PropPtr datastructure. It will free whatever data is associated * with the prop as well as the PropPtr as well. * * @param node the prop to free */ void free_propnode(PropPtr p) { if (!(PropFlags(p) & PROP_ISUNLOADED)) { if (PropType(p) == PROP_STRTYP) free(PropDataStr(p)); if (PropType(p) == PROP_LOKTYP) free_boolexp(PropDataLok(p)); } /* @TODO: The PropPtr object has a 'key' field which is * set up like char key[1]; In alloc_propnode, we use * strncpy to copy the name of the prop to the key field. * * I should think we would need to free the key or we would * have a leak. However, I should have also thought the key * should be a char* ... I don't actually understand how this * works. It seems like it should be segfaulting and/or * leaking memory. I want to review this in greater depth * later. */ free(p); }
void remove_proplist_item(dbref player, PropPtr p, int allp) { const char *ptr; /* if( tp_db_readonly ) return; *//* Why did we remove this? */ if (!p) return; ptr = PropName(p); if (!allp) { if (Prop_SeeOnly(ptr)) return; if (Prop_Hidden(ptr)) return; if (ptr[0] == '_' && ptr[1] == '\0') return; if (PropFlags(p) & PROP_SYSPERMS) return; } /* notify(player, ptr); *//* Why did we put this here? */ remove_property(player, ptr); }
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 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 set_property_nofetch(dbref object, const char *pname, PData * dat, bool pure) { char buf[BUFFER_LEN]; char *n; PropPtr p; /* Make sure that we are passed a valid property name */ if (!pname) return; while (*pname == PROPDIR_DELIMITER) pname++; strcpy(buf, pname); /* truncate propnames with a ':' in them at the ':' */ if ((n = index(buf, PROP_DELIMITER))) *n = '\0'; /* truncate propnames with a '\n' in them at the '\n' */ if ((n = index(buf, '\n'))) *n = '\0'; if (!*buf) return; if ((!(FLAGS(object) & LISTENER)) && (string_prefix(buf, "_listen") || string_prefix(buf, "~listen") || string_prefix(buf, "@listen") || string_prefix(buf, "_olisten") || string_prefix(buf, "~olisten") || string_prefix(buf, "@olisten") || string_prefix(buf, "_alisten") || string_prefix(buf, "~alisten") || string_prefix(buf, "@alisten") || string_prefix(buf, "_aolisten") || string_prefix(buf, "~aolisten") || string_prefix(buf, "@aolisten"))) { FLAGS(object) |= LISTENER; } if ((!(FLAG2(object) & F2COMMAND)) && (string_prefix(buf, "_command") || string_prefix(buf, "~command") || string_prefix(buf, "@command") || string_prefix(buf, "_ocommand") || string_prefix(buf, "~ocommand") || string_prefix(buf, "@ocommand"))) { FLAG2(object) |= F2COMMAND; } p = propdir_new_elem(&(DBFETCH(object)->properties), buf); /* free up any old values */ clear_propnode(p); SetPFlagsRaw(p, dat->flags); if (PropFlags(p) & PROP_ISUNLOADED) { SetPDataUnion(p, dat->data); return; } switch (PropType(p)) { case PROP_STRTYP: if (!dat->data.str || !*dat->data.str) { SetPType(p, PROP_DIRTYP); SetPDataStr(p, NULL); if (!PropDir(p)) { remove_property_nofetch(object, pname); } } else { #ifdef COMPRESS if (!pure) { if (!(dat->flags & PROP_NOCOMPRESS) && isascii_str(dat->data.str)) { SetPDataStr(p, alloc_compressed(dat->data.str)); } else { dat->flags |= PROP_NOCOMPRESS; SetPDataStr(p, alloc_string(dat->data.str)); } SetPFlagsRaw(p, (dat->flags | PROP_COMPRESSED)); } else #endif SetPDataStr(p, alloc_string(dat->data.str)); } break; case PROP_INTTYP: SetPDataVal(p, dat->data.val); if (!dat->data.val) { SetPType(p, PROP_DIRTYP); if (!PropDir(p)) remove_property_nofetch(object, pname); } break; case PROP_FLTTYP: SetPDataFVal(p, dat->data.fval); if (dat->data.fval == 0.0) { SetPType(p, PROP_DIRTYP); if (!PropDir(p)) remove_property_nofetch(object, pname); } break; case PROP_REFTYP: SetPDataRef(p, dat->data.ref); if (dat->data.ref == NOTHING) { SetPType(p, PROP_DIRTYP); SetPDataRef(p, 0); if (!PropDir(p)) remove_property_nofetch(object, pname); } break; case PROP_LOKTYP: SetPDataLok(p, dat->data.lok); break; case PROP_DIRTYP: SetPDataVal(p, 0); if (!PropDir(p)) remove_property_nofetch(object, pname); break; } }
void prim_array_filter_prop(PRIM_PROTOTYPE) { char pattern[BUFFER_LEN]; char tname[BUFFER_LEN]; struct inst *in; struct inst temp1; stk_array *arr; stk_array *nu; char* prop; int len; CHECKOP(3); oper3 = POP(); /* str pattern */ oper2 = POP(); /* str propname */ oper1 = POP(); /* refarr Array */ if (oper1->type != PROG_ARRAY) abort_interp("Argument not an array. (1)"); if (!array_is_homogenous(oper1->data.array, PROG_OBJECT)) abort_interp("Argument not an array of dbrefs. (1)"); if (oper2->type != PROG_STRING || !oper2->data.string) abort_interp("Argument not a non-null string. (2)"); if (oper3->type != PROG_STRING) abort_interp("Argument not a string pattern. (3)"); len = oper2->data.string ? oper2->data.string->length : 0; strcpyn(tname, sizeof(tname), DoNullInd(oper2->data.string)); while (len-- > 0 && tname[len] == PROPDIR_DELIMITER) { tname[len] = '\0'; } nu = new_array_packed(0); arr = oper1->data.array; prop = tname; strcpyn(pattern, sizeof(pattern), DoNullInd(oper3->data.string)); if (array_first(arr, &temp1)) { do { in = array_getitem(arr, &temp1); if (valid_object(in)) { ref = in->data.objref; CHECKREMOTE(ref); if (prop_read_perms(ProgUID, ref, prop, mlev)) { PropPtr pptr = get_property(ref, prop); if (pptr) { switch(PropType(pptr)) { case PROP_STRTYP: strncpy(buf, PropDataStr(pptr), BUFFER_LEN); break; case PROP_LOKTYP: if (PropFlags(pptr) & PROP_ISUNLOADED) { strncpy(buf, "*UNLOCKED*", BUFFER_LEN); } else { strncpy(buf, unparse_boolexp(ProgUID, PropDataLok(pptr), 0), BUFFER_LEN); } break; case PROP_REFTYP: snprintf(buf, BUFFER_LEN, "#%i", PropDataRef(pptr)); break; case PROP_INTTYP: snprintf(buf, BUFFER_LEN, "%i", PropDataVal(pptr)); break; case PROP_FLTTYP: snprintf(buf, BUFFER_LEN, "%g", PropDataFVal(pptr)); break; default: strncpy(buf, "", BUFFER_LEN); break; } } else strncpy(buf, "", BUFFER_LEN); if (equalstr(pattern, buf)) { array_appenditem(&nu, in); } } } } while (array_next(arr, &temp1)); } CLEAR(oper3); CLEAR(oper2); CLEAR(oper1); PushArrayRaw(nu); }
void db_putprop(FILE * f, const char *dir, PropPtr p) { char buf[BUFFER_LEN * 2]; char fbuf[BUFFER_LEN]; char num[16]; char *ptr; const char *ptr2; if (PropType(p) == PROP_DIRTYP) return; for (ptr = buf, ptr2 = dir + 1; *ptr2;) *ptr++ = *ptr2++; for (ptr2 = PropName(p); *ptr2;) *ptr++ = *ptr2++; *ptr++ = PROP_DELIMITER; ptr2 = intostr(num, PropFlagsRaw(p) & ~(PROP_TOUCHED | PROP_ISUNLOADED | PROP_NOASCIICHK)); while (*ptr2) *ptr++ = *ptr2++; *ptr++ = PROP_DELIMITER; ptr2 = ""; switch (PropType(p)) { case PROP_INTTYP: if (!PropDataVal(p)) return; ptr2 = intostr(num, PropDataVal(p)); break; case PROP_FLTTYP: if (!PropDataFVal(p)) return; ptr2 = fltostr(fbuf, PropDataFVal(p)); break; case PROP_REFTYP: if (PropDataRef(p) == NOTHING) return; ptr2 = intostr(num, (int) PropDataRef(p)); break; case PROP_STRTYP: if (!*PropDataStr(p)) return; if (db_decompression_flag) { ptr2 = PropDataUNCStr(p); } else { ptr2 = PropDataStr(p); } break; case PROP_LOKTYP: if (PropFlags(p) & PROP_ISUNLOADED) return; if (PropDataLok(p) == TRUE_BOOLEXP) return; ptr2 = unparse_boolexp((dbref) 1, PropDataLok(p), 0); break; } while (*ptr2) if (*ptr2 != '\n') *ptr++ = *ptr2++; else { *ptr++ = '\\'; *ptr++ = 'n'; ptr2++; } *ptr++ = '\n'; *ptr++ = '\0'; if (fputs(buf, f) == EOF) { fprintf(stderr, "PANIC: Unable to write to db to write prop.\n"); abort(); } }
void set_property_nofetch(dbref player, const char *type, int flags, PTYPE value) { PropPtr p; char buf[BUFFER_LEN]; char *n, *w; /* Make sure that we are passed a valid property name */ if (!type) return; /* if (tp_db_readonly) return; *//* Why did we remove this? */ while (*type == PROPDIR_DELIMITER) type++; if ((!(FLAGS(player) & LISTENER)) && (string_prefix(type, "_listen") || string_prefix(type, "~listen") || string_prefix(type, "@listen") || string_prefix(type, "_olisten") || string_prefix(type, "~olisten") || string_prefix(type, "@olisten") || string_prefix(type, "_alisten") || string_prefix(type, "~alisten") || string_prefix(type, "@alisten") || string_prefix(type, "_aolisten") || string_prefix(type, "~aolisten") || string_prefix(type, "@aolisten"))) { FLAGS(player) |= LISTENER; } if ((!(FLAG2(player) & F2COMMAND)) && (string_prefix(type, "_command") || string_prefix(type, "~command") || string_prefix(type, "@command") || string_prefix(type, "_ocommand") || string_prefix(type, "~ocommand") || string_prefix(type, "@ocommand"))) { FLAG2(player) |= F2COMMAND; } w = strcpy(buf, type); /* truncate propnames with a ':' in them at the ':' */ n = index(buf, PROP_DELIMITER); if (n) *n = '\0'; if (!*buf) return; p = propdir_new_elem(&(DBFETCH(player)->properties), w); /* free up any old values */ clear_propnode(p); SetPFlagsRaw(p, flags); if (PropFlags(p) & PROP_ISUNLOADED) { SetPDataVal(p, (int) value); return; } switch (PropType(p)) { case PROP_STRTYP: if (!value || !*((char *) value)) { SetPType(p, PROP_DIRTYP); SetPDataVal(p, 0); if (!PropDir(p)) remove_property_nofetch(player, type); } else { /* char *cptr = (char *) value; while (cptr) { if (*cptr == '\n') *cptr = '\r'; ++cptr; } */ SetPDataStr(p, alloc_compressed((char *) value)); #ifdef COMPRESS SetPFlagsRaw(p, (flags | PROP_COMPRESSED)); #endif } break; case PROP_INTTYP: SetPDataVal(p, (int) value); if (!value) { SetPType(p, PROP_DIRTYP); if (!PropDir(p)) remove_property_nofetch(player, type); } break; case PROP_FLTTYP: SetPDataFVal(p, strtod(value, NULL)); if (strtod(value, NULL) == 0) { SetPType(p, PROP_DIRTYP); if (!PropDir(p)) { remove_property_nofetch(player, type); } } break; case PROP_REFTYP: if (((dbref) value) == NOTHING) { SetPType(p, PROP_DIRTYP); SetPDataVal(p, 0); if (!PropDir(p)) remove_property_nofetch(player, type); } else { SetPDataRef(p, (dbref) value); } break; case PROP_LOKTYP: SetPDataLok(p, (struct boolexp *) value); /* * if ((struct boolexp *)value == TRUE_BOOLEXP) { * SetPType(p, PROP_DIRTYP); * SetPDataVal(p, 0); * if (!PropDir(p)) * remove_property_nofetch(player, type); * } else { * SetPDataLok(p, (struct boolexp *)value); * } */ break; case PROP_DIRTYP: SetPDataVal(p, 0); if (!PropDir(p)) remove_property_nofetch(player, type); break; } }