コード例 #1
0
ファイル: props.c プロジェクト: UnderSampled/RAOAMUCK
/* 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));
		 */
	}
}
コード例 #2
0
ファイル: property.c プロジェクト: CyberLeo/protomuck
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
ファイル: property.c プロジェクト: CyberLeo/protomuck
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;
    }
}