/* 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; }
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; }
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); }
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); }
/* killold probably isn't necessary, but there's no sense in clearing the old * alias hint if it's going to get overwritten by the caller anyway. */ int rotate_alias(dbref target, int killold) { char *oldalias = NULL; PropPtr pptr; int valid; sprintf(abuf, ALIASDIR_LAST "%d", (int) target); pptr = get_property(0, abuf); if (pptr) { if ((valid = PropType(pptr) == PROP_STRTYP)) { oldalias = strdup(PropDataUNCStr(pptr)); } if (killold || !valid) { /* kill the old 'last' hint if we were asked to, or if it's bogus */ remove_property(0, abuf); } if (oldalias) { /* kill the old alias. */ sprintf(abuf, ALIASDIR_CUR "%s", oldalias); remove_property(0, abuf); free(oldalias); return 1; } } return 0; }
static void unparse_boolexp1(dbref player, struct boolexp * b, boolexp_type outer_type, int fullname) { if ((buftop - boolexp_buf) > (BUFFER_LEN / 2)) return; if (b == TRUE_BOOLEXP) { strcpy(buftop, "*UNLOCKED*"); buftop += strlen(buftop); } else { switch (b->type) { case BOOLEXP_AND: if (outer_type == BOOLEXP_NOT) { *buftop++ = '('; } unparse_boolexp1(player, b->sub1, b->type, fullname); *buftop++ = AND_TOKEN; unparse_boolexp1(player, b->sub2, b->type, fullname); if (outer_type == BOOLEXP_NOT) { *buftop++ = ')'; } break; case BOOLEXP_OR: if (outer_type == BOOLEXP_NOT || outer_type == BOOLEXP_AND) { *buftop++ = '('; } unparse_boolexp1(player, b->sub1, b->type, fullname); *buftop++ = OR_TOKEN; unparse_boolexp1(player, b->sub2, b->type, fullname); if (outer_type == BOOLEXP_NOT || outer_type == BOOLEXP_AND) { *buftop++ = ')'; } break; case BOOLEXP_NOT: *buftop++ = '!'; unparse_boolexp1(player, b->sub1, b->type, fullname); break; case BOOLEXP_CONST: if (fullname) { #ifndef SANITY strcpy(buftop, unparse_object(player, b->thing)); #endif } else { sprintf(buftop, "#%d", b->thing); } buftop += strlen(buftop); break; case BOOLEXP_PROP: strcpy(buftop, PropName(b->prop_check)); strcat(buftop, ":"); if (PropType(b->prop_check) == PROP_STRTYP) strcat(buftop, PropDataStr(b->prop_check)); buftop += strlen(buftop); break; default: abort(); /* bad type */ break; } } }
/** * 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; }
dbref lookup_alias(const char *name, int checkname) { dbref alias; PropPtr pptr; /* It's important to make sure that an alias lookup based on the name of an * existing target never succeeds. This should *only* be possible if an * admin manually set the prop on #0 (via @propset or a program), but things * can get pretty weird fast if cases of this behavior slip through. * * Most callers to this function will have already attempted to match the * exact target name, and this can be skipped. 'checkname' is used to signal * whether or not it's safe to skip this check. */ if (checkname && find_hash(name, player_list, PLAYER_HASH_SIZE) != NULL) { return NOTHING; } sprintf(abuf, ALIASDIR_CUR "%s", name); if (*name != '\0' && (pptr = get_property(0, abuf)) && PropType(pptr) == PROP_REFTYP) { alias = PropDataRef(pptr); if (Typeof(alias) == TYPE_PLAYER) { return alias; } else { /* bogus prop, kill it */ remove_property(0, abuf); } } return NOTHING; }
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)); }
const char * envpropstr(dbref *where, const char *propname) { PropPtr temp; temp = envprop(where, propname, PROP_STRTYP); if (!temp) return NULL; if (PropType(temp) == PROP_STRTYP) return (PropDataUNCStr(temp)); return NULL; }
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 type of property */ int get_property_type(dbref player, const char *type) { PropPtr p; p = get_property(player, type); if (p) { return (PropType(p)); } else { return 0; } }
/* 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); }
/** * 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); }
/* 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 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 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)); */ } }
/* path is the name of the property to delete */ PropPtr propdir_delete_elem(PropPtr root, char *path) { PropPtr p; char *n; if (!root) return (NULL); while (*path && *path == PROPDIR_DELIMITER) path++; if (!*path) return (root); n = index(path, PROPDIR_DELIMITER); while (n && *n == PROPDIR_DELIMITER) *(n++) = '\0'; if (n && *n) { /* just another propdir in the path */ p = locate_prop(root, path); if (p && PropDir(p)) { /* yup, found the propdir */ SetPDir(p, propdir_delete_elem(PropDir(p), n)); if (!PropDir(p) && PropType(p) == PROP_DIRTYP) { root = delete_prop(&root, PropName(p)); } } /* return the updated root pntr */ return (root); } else { /* aha, we are finally to the property itself. */ p = locate_prop(root, path); if (p && PropDir(p)) { delete_proplist(PropDir(p)); } (void) delete_prop(&root, path); return (root); } }
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; } } } }
StateProp() : m_Values() { m_Values.add(UIState::StateDefault, PropType()); }
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 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 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; } } }
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 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; } }
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); }
bool TPropertyHandler::IsClass(TComponent* comp, String prName) { Typinfo::TTypeKind kind = PropType((TObject*)comp, prName); return (kind == tkClass); }