Пример #1
0
/*
 * returns pointer to the new property node.  Returns a pointer to an
 *   existing elem of the given name, if one already exists.  Returns
 *   NULL if the name given is bad.
 * root is the pointer to the root propdir node.  This is updated in this
 *   routine to point to the new root node of the structure.
 * path is the name of the property to insert
 */
PropPtr
propdir_new_elem(PropPtr * root, char *path)
{
	PropPtr p;
	char *n;

	while (*path && *path == PROPDIR_DELIMITER)
		path++;
	if (!*path)
		return (NULL);
	n = index(path, PROPDIR_DELIMITER);
	while (n && *n == PROPDIR_DELIMITER)
		*(n++) = '\0';
	if (n && *n) {
		/* just another propdir in the path */
		p = new_prop(root, path);
		return (propdir_new_elem(&PropDir(p), n));
	} else {
		/* aha, we are finally to the property itself. */
		p = new_prop(root, path);
		return (p);
	}
}
Пример #2
0
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;
    }
}
Пример #3
0
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;
    }
}