예제 #1
0
파일: p_misc.c 프로젝트: foxbird/fuzzball
void
prim_testlock(PRIM_PROTOTYPE)
{
    struct inst *oper1 = NULL;	/* prevents re-entrancy issues! */
    struct inst *oper2 = NULL;	/* prevents re-entrancy issues! */


    /* d d - i */
    CHECKOP(2);
    oper1 = POP();		/* boolexp lock */
    oper2 = POP();		/* player dbref */
    if (fr->level > 8)
	abort_interp("Interp call loops not allowed.");
    if (!valid_object(oper2))
	abort_interp("Invalid argument (1).");
    if (Typeof(oper2->data.objref) != TYPE_PLAYER && Typeof(oper2->data.objref) != TYPE_THING) {
	abort_interp("Invalid object type (1).");
    }
    CHECKREMOTE(oper2->data.objref);
    if (oper1->type != PROG_LOCK)
	abort_interp("Invalid argument (2).");
    result = eval_boolexp(fr->descr, oper2->data.objref, oper1->data.lock,
			  tp_consistent_lock_source ? fr->trig : player);
    CLEAR(oper1);
    CLEAR(oper2);
    PushInt(result);
}
예제 #2
0
파일: p_misc.c 프로젝트: CyberLeo/protomuck
void 
prim_timestamps(PRIM_PROTOTYPE)
{
    CHECKOP(1);
    oper1 = POP();
    if (mlev < LM2)
	abort_interp("M2 prim");
    if (oper1->type != PROG_OBJECT)
	abort_interp("Non-object argument (1)");
    ref = oper1->data.objref;
    if (ref >= db_top || ref <= NOTHING)
      abort_interp("Dbref is not an object nor garbage.");
/*    if (!valid_object(oper1))
	abort_interp("Invalid object"); */
/*    CHECKREMOTE(oper1->data.objref); */
    CHECKREMOTE(ref);
    CHECKOFLOW(4);
/*    ref = oper1->data.objref; */
    CLEAR(oper1);
    result = DBFETCH(ref)->ts.created;
    PushInt(result);
    result = DBFETCH(ref)->ts.modified;
    PushInt(result);
    result = DBFETCH(ref)->ts.lastused;
    PushInt(result);
    result = DBFETCH(ref)->ts.usecount;
    PushInt(result);
}
예제 #3
0
파일: p_props.c 프로젝트: hyena/fuzzball
void
prim_reflist_del(PRIM_PROTOTYPE)
{
	CHECKOP(3);
	oper3 = POP();   /* dbref */
	oper2 = POP();   /* propname */
	oper1 = POP();   /* propobj */
	if (!valid_object(oper1))
		abort_interp("Non-object argument (1)");
	if (oper2->type != PROG_STRING)
		abort_interp("Non-string argument (2)");
	if (!oper2->data.string)
		abort_interp("Empty string argument (2)");
	if (oper3->type != PROG_OBJECT)
		abort_interp("Non-object argument (3)");
	if (!prop_write_perms(ProgUID, oper1->data.objref, oper2->data.string->data, mlev))
		abort_interp("Permission denied.");
	CHECKREMOTE(oper1->data.objref);

	reflist_del(oper1->data.objref, oper2->data.string->data, oper3->data.objref);

	CLEAR(oper1);
	CLEAR(oper2);
	CLEAR(oper3);
}
예제 #4
0
파일: p_stack.c 프로젝트: foxbird/fuzzball
void
prim_interp(PRIM_PROTOTYPE)
{
    struct inst *oper1 = NULL;	/* prevents re-entrancy issues! */
    struct inst *oper2 = NULL;	/* prevents re-entrancy issues! */
    struct inst *oper3 = NULL;	/* prevents re-entrancy issues! */

    struct inst *rv = NULL;
    char buf[BUFFER_LEN];
    struct frame *tmpfr;

    CHECKOP(3);
    oper3 = POP();		/* string -- top stack argument */
    oper2 = POP();		/* dbref  --  trigger */
    oper1 = POP();		/* dbref  --  Program to run */

    if (!valid_object(oper1) || Typeof(oper1->data.objref) != TYPE_PROGRAM)
	abort_interp("Bad program reference. (1)");
    if (!valid_object(oper2))
	abort_interp("Bad object. (2)");
    if (oper3->type != PROG_STRING)
	abort_interp("Expected a string. (3)");
    if ((mlev < 3) && !permissions(ProgUID, oper2->data.objref))
	abort_interp("Permission denied.");
    if (fr->level > 8)
	abort_interp("Interp call loops not allowed.");
    CHECKREMOTE(oper2->data.objref);

    strcpyn(buf, sizeof(buf), match_args);
    strcpyn(match_args, sizeof(match_args), DoNullInd(oper3->data.string));
    tmpfr = interp(fr->descr, player, LOCATION(player), oper1->data.objref,
		   oper2->data.objref, PREEMPT, STD_HARDUID, 0);
    if (tmpfr) {
	rv = interp_loop(player, oper1->data.objref, tmpfr, 1);
    }
    strcpyn(match_args, sizeof(match_args), buf);

    CLEAR(oper3);
    CLEAR(oper2);
    CLEAR(oper1);

    if (rv) {
	if (rv->type < PROG_STRING) {
	    push(arg, top, rv->type, MIPSCAST(&rv->data.number));
	} else {
	    push(arg, top, rv->type, MIPSCAST(rv->data.string));
	}
    } else {
	PushNullStr;
    }

}
예제 #5
0
void
prim_interp(PRIM_PROTOTYPE)
{
    struct inst *oper1, *oper2, *oper3, *rv = NULL;
    char buf[BUFFER_LEN];
    struct frame *tmpfr;

    CHECKOP(3);
    oper3 = POP();              /* string -- top stack argument */
    oper2 = POP();              /* dbref  --  trigger */
    oper1 = POP();              /* dbref  --  Program to run */

    if (!valid_object(oper1) || Typeof(oper1->data.objref) != TYPE_PROGRAM)
        abort_interp("Bad program reference. (1)");
    if (!valid_object(oper2))
        abort_interp("Bad object. (2)");
    if (oper3->type != PROG_STRING)
        abort_interp("Need string arguement. (3)");
    if (!permissions(mlev, ProgUID, oper2->data.objref))
        abort_interp(tp_noperm_mesg);
    if (fr->level > 8)
        abort_interp("Interp call loops not allowed.");
    CHECKREMOTE(oper2->data.objref);

    strcpy(buf, match_args);
    strcpy(match_args, oper3->data.string ? oper3->data.string->data : "");
    interp_set_depth(fr);
    tmpfr = interp(fr->descr, player, DBFETCH(player)->location,
                   oper1->data.objref, oper2->data.objref, PREEMPT,
                   STD_HARDUID, 0);
    if (tmpfr) {
        rv = interp_loop(player, oper1->data.objref, tmpfr, 1);
    }
    strcpy(match_args, buf);

    CLEAR(oper3);
    CLEAR(oper2);
    CLEAR(oper1);

    if (rv) {
        if (rv->type < PROG_STRING) {
            push(arg, top, rv->type, MIPSCAST(&rv->data.number));
        } else {
            push(arg, top, rv->type, MIPSCAST(rv->data.string));
        }
    } else {
        PushNullStr;
    }

}
예제 #6
0
파일: p_props.c 프로젝트: hyena/fuzzball
void
prim_unblessprop(PRIM_PROTOTYPE)
{
	CHECKOP(2);
	oper2 = POP();
	oper1 = POP();
	if (oper2->type != PROG_STRING)
		abort_interp("Non-string argument (2)");
	if (!oper2->data.string)
		abort_interp("Empty string argument (2)");
	if (!valid_object(oper1))
		abort_interp("Non-object argument (1)");
	CHECKREMOTE(oper1->data.objref);

	if (mlev < 4)
		abort_interp("Permission denied.");

	{
		char *tmpe;
		char tname[BUFFER_LEN];
		int len = oper2->data.string->length;

		tmpe = oper2->data.string->data;
		while (*tmpe && *tmpe != '\r' && *tmpe != ':')
			tmpe++;
		if (*tmpe)
			abort_interp("Illegal propname");

		strcpyn(tname, sizeof(tname), oper2->data.string->data);
		while (len-- > 0 && tname[len] == PROPDIR_DELIMITER) {
			tname[len] = '\0';
		}

		clear_property_flags(oper1->data.objref, tname, PROP_BLESSED);

#ifdef LOG_PROPS
		log2file("props.log", "#%d (%d) BLESSPROP: o=%d n=\"%s\"",
				 program, pc->line, oper1->data.objref, tname);
#endif

		ts_modifyobject(oper1->data.objref);
	}
	CLEAR(oper1);
	CLEAR(oper2);
}
예제 #7
0
void
prim_interp(PRIM_PROTOTYPE)
{
    struct inst *oper1, *oper2, *oper3, *rv;
    char buf[BUFFER_LEN];

    CHECKOP(3);
    oper3 = POP();    /* string -- top stack argument */
    oper2 = POP();    /* dbref  --  trigger */
    oper1 = POP();    /* dbref  --  Program to run */

    if (!valid_object(oper1) || Typeof(oper1->data.objref) != TYPE_PROGRAM)
        abort_interp("Bad program reference. (1)");
    if (!valid_object(oper2))
        abort_interp("Bad object. (2)");
    if ((mlev < 3) && !permissions(ProgUID, oper2->data.objref))
	abort_interp("Permission denied.");
    if (fr->level > 8)
        abort_interp("Interp call loops not allowed.");
    CHECKREMOTE(oper2->data.objref);

    strcpy(buf, match_args);
    strcpy(match_args, oper3->data.string? oper3->data.string->data : "");
    rv = interp(player, DBFETCH(player)->location, oper1->data.objref,
			oper2->data.objref, PREEMPT, STD_HARDUID, 1);
    strcpy(match_args, buf);

    CLEAR(oper3);
    CLEAR(oper2);
    CLEAR(oper1);

    if (rv) {
	if (rv->type < PROG_STRING) {
	    push(arg, top, rv->type, MIPSCAST (&rv->data.number));
	} else {
	    push(arg, top, rv->type, MIPSCAST (rv->data.string));
	}
    } else {
        PushNullStr;
    }

}
예제 #8
0
파일: p_props.c 프로젝트: hyena/fuzzball
void
prim_remove_prop(PRIM_PROTOTYPE)
{
	CHECKOP(2);
	oper1 = POP();
	oper2 = POP();
	if (oper1->type != PROG_STRING)
		abort_interp("Non-string argument (2)");
	if (!valid_object(oper2))
		abort_interp("Non-object argument (1)");

	CHECKREMOTE(oper2->data.objref);

	strncpy(buf, DoNullInd(oper1->data.string), BUFFER_LEN);
	buf[BUFFER_LEN - 1] = '\0';

	{
		int	len = strlen(buf);
		char*	ptr = buf + len;

		while((--len >= 0) && (*--ptr == PROPDIR_DELIMITER))
			*ptr = '\0';
	}

	if (!*buf)
		abort_interp("Can't remove root propdir (2)");

	if (!prop_write_perms(ProgUID, oper2->data.objref, buf, mlev))
		abort_interp("Permission denied.");

	remove_property(oper2->data.objref, buf);

#ifdef LOG_PROPS
	log2file("props.log", "#%d (%d) REMOVEPROP: o=%d n=\"%s\"",
		program, pc->line, oper2->data.objref, buf);
#endif

	ts_modifyobject(oper2->data.objref);

	CLEAR(oper1);
	CLEAR(oper2);
}
예제 #9
0
파일: p_props.c 프로젝트: hyena/fuzzball
void
prim_getpropfval(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);

	if (!prop_read_perms(ProgUID, oper2->data.objref, oper1->data.string->data, mlev))
		abort_interp("Permission denied.");

	{
		char type[BUFFER_LEN];
		int len = oper1->data.string->length;

		strcpyn(type, sizeof(type), oper1->data.string->data);
		while (len-- > 0 && type[len] == PROPDIR_DELIMITER) {
			type[len] = '\0';
		}
		fresult = get_property_fvalue(oper2->data.objref, type);

#ifdef LOG_PROPS
		log2file("props.log", "#%d (%d) GETPROPFVAL: o=%d n=\"%s\" v=%d",
				 program, pc->line, oper2->data.objref, type, result);
#endif

		/* if (Typeof(oper2->data.objref) != TYPE_PLAYER)
		   ts_lastuseobject(oper2->data.objref); */
	}
	CLEAR(oper1);
	CLEAR(oper2);
	PushFloat(fresult);
}
예제 #10
0
파일: p_misc.c 프로젝트: foxbird/fuzzball
void
prim_timestamps(PRIM_PROTOTYPE)
{
    CHECKOP(1);
    oper1 = POP();
    if (oper1->type != PROG_OBJECT)
	abort_interp("Non-object argument (1).");
    if (!valid_object(oper1))
	abort_interp("Invalid object.");
    CHECKREMOTE(oper1->data.objref);
    CHECKOFLOW(4);
    ref = oper1->data.objref;
    CLEAR(oper1);
    result = (int)DBFETCH(ref)->ts_created;
    PushInt(result);
    result = (int)DBFETCH(ref)->ts_modified;
    PushInt(result);
    result = (int)DBFETCH(ref)->ts_lastused;
    PushInt(result);
    result = DBFETCH(ref)->ts_usecount;
    PushInt(result);
}
예제 #11
0
파일: p_misc.c 프로젝트: CyberLeo/protomuck
void 
prim_testlock(PRIM_PROTOTYPE)
{
    /* d d - i */
    CHECKOP(2);
    oper1 = POP();		/* boolexp lock */
    oper2 = POP();		/* player dbref */
    if (fr->level > 8)
	abort_interp("Interp call loops not allowed");
    if (!valid_object(oper2))
	abort_interp("Invalid argument (1).");
    if (Typeof(oper2->data.objref) != TYPE_PLAYER &&
        Typeof(oper2->data.objref) != TYPE_THING )
    {
	abort_interp("Invalid object type (1).");
    }
    CHECKREMOTE(oper2->data.objref);
    if (oper1->type != PROG_LOCK)
	abort_interp("Invalid argument (2)");
    result = eval_boolexp(fr->descr, oper2->data.objref, oper1->data.lock, player);
    CLEAR(oper1);
    CLEAR(oper2);
    PushInt(result);
}
예제 #12
0
파일: p_props.c 프로젝트: hyena/fuzzball
void
prim_parsepropex(PRIM_PROTOTYPE)
{
	struct inst*	oper1 = NULL; /* prevents reentrancy issues! */
	struct inst*	oper2 = NULL; /* prevents reentrancy issues! */
	struct inst*	oper3 = NULL; /* prevents reentrancy issues! */
	struct inst*	oper4 = NULL; /* prevents reentrancy issues! */
	stk_array*		vars;
	const char*		mpi;
	char*			str = 0;
	array_iter		idx;
	extern int		varc; /* from msgparse.c */
	int				mvarcnt = 0;
	char*			buffers = NULL;
	int				novars;
	int				hashow = 0;
	int				i;
	int             len;
	char			tname[BUFFER_LEN];
	char			buf[BUFFER_LEN];

	CHECKOP(4);

	oper4 = POP(); /* int:Private */
	oper3 = POP(); /* dict:Vars */
	oper2 = POP(); /* str:Prop */
	oper1 = POP(); /* ref:Object */

	if (mlev < 3)
		abort_interp("Mucker level 3 or greater required.");

	if (oper1->type != PROG_OBJECT)
		abort_interp("Non-object argument. (1)");
	if (oper2->type != PROG_STRING)
		abort_interp("Non-string argument. (2)");
	if (oper3->type != PROG_ARRAY)
		abort_interp("Non-array argument. (3)");
	if (oper3->data.array && (oper3->data.array->type != ARRAY_DICTIONARY))
		abort_interp("Dictionary array expected. (3)");
	if (oper4->type != PROG_INTEGER)
		abort_interp("Non-integer argument. (4)");

	if (!valid_object(oper1))
		abort_interp("Invalid object. (1)");
	if (!oper2->data.string)
		abort_interp("Empty string argument. (2)");
	if ((oper4->data.number != 0) && (oper4->data.number != 1))
		abort_interp("Integer of 0 or 1 expected. (4)");

	CHECKREMOTE(oper1->data.objref);

	if (!prop_read_perms(ProgUID, oper1->data.objref, oper2->data.string->data, mlev))
		abort_interp("Permission denied.");

	len = oper2->data.string->length;
	strcpyn(tname, sizeof(tname), oper2->data.string->data);
	while (len-- > 0 && tname[len] == PROPDIR_DELIMITER) {
		tname[len] = '\0';
	}

	mpi		= get_property_class(oper1->data.objref, tname);
	vars	= oper3->data.array;
	novars	= array_count(vars);

	if (check_mvar_overflow(novars))
		abort_interp("Out of MPI variables. (3)");

	if (array_first(vars, &idx))
	{
		do
		{
			array_data*	val = array_getitem(vars, &idx);

			if (idx.type != PROG_STRING)
			{
				CLEAR(&idx);
				abort_interp("Only string keys supported. (3)");
			}

			if (idx.data.string == NULL)
			{
				CLEAR(&idx);
				abort_interp("Empty string keys not supported. (3)");
			}

			if (strlen(idx.data.string->data) > MAX_MFUN_NAME_LEN)
			{
				CLEAR(&idx);
				abort_interp("Key too long to be an MPI variable. (3)");
			}

			switch(val->type)
			{
				case PROG_INTEGER:
				case PROG_FLOAT:
				case PROG_OBJECT:
				case PROG_STRING:
				case PROG_LOCK:
				break;

				default:
					CLEAR(&idx);
					abort_interp("Only integer, float, dbref, string and lock values supported. (3)");
				break;
			}

			if (string_compare(idx.data.string->data, "how") == 0)
				hashow = 1;
		}
		while(array_next(vars, &idx));
	}

	if (mpi && *mpi)
	{
		if (novars > 0)
		{
			mvarcnt = varc;

			if ((buffers = (char*)malloc(novars * BUFFER_LEN)) == NULL)
				abort_interp("Out of memory.");

			if (array_first(vars, &idx))
			{
				i = 0;

				do
				{
					char*		var_buf = buffers + (i++ * BUFFER_LEN);
					array_data*	val;

					val = array_getitem(vars, &idx);

					switch(val->type)
					{
						case PROG_INTEGER:
							snprintf(var_buf, BUFFER_LEN, "%i", val->data.number);
						break;

						case PROG_FLOAT:
							snprintf(var_buf, BUFFER_LEN, "%g", val->data.fnumber);
						break;

						case PROG_OBJECT:
							snprintf(var_buf, BUFFER_LEN, "#%i", val->data.objref);
						break;

						case PROG_STRING:
							strncpy(var_buf, DoNullInd(val->data.string), BUFFER_LEN);
						break;

						case PROG_LOCK:
							strncpy(var_buf, unparse_boolexp(ProgUID, val->data.lock, 1), BUFFER_LEN);
						break;

						default:
							var_buf[0] = '\0';
						break;
					}

					var_buf[BUFFER_LEN - 1] = '\0';

					new_mvar(idx.data.string->data, var_buf);
				}
				while(array_next(vars, &idx));
			}
		}

		result = 0;

		if (oper4->data.number)
			result |= MPI_ISPRIVATE;

		if (Prop_Blessed(oper1->data.objref, oper2->data.string->data))
			result |= MPI_ISBLESSED;

		if (hashow)
			result |= MPI_NOHOW;

		str = do_parse_mesg(fr->descr, player, oper1->data.objref, mpi, "(parsepropex)", buf, sizeof(buf), result);

		if (novars > 0)
		{
			if (array_first(vars, &idx))
			{
				i = 0;

				do
				{
					char*		var_buf = buffers + (i++ * BUFFER_LEN);
					struct inst	temp;

					temp.type			= PROG_STRING;
					temp.data.string	= alloc_prog_string(var_buf);

					array_setitem(&vars, &idx, &temp);

					CLEAR(&temp);
				}
				while(array_next(vars, &idx));
			}

			free(buffers);

			varc = mvarcnt;
		}
	}

	oper3->data.array = NULL;

	CLEAR(oper1);
	CLEAR(oper2);
	CLEAR(oper3);
	CLEAR(oper4);

	PushArrayRaw(vars);
	PushString(str);
}
예제 #13
0
파일: p_props.c 프로젝트: hyena/fuzzball
void
prim_addprop(PRIM_PROTOTYPE)
{
	CHECKOP(4);
	oper1 = POP();
	oper2 = POP();
	oper3 = POP();
	oper4 = POP();
	if (oper1->type != PROG_INTEGER)
		abort_interp("Non-integer argument (4)");
	if (oper2->type != PROG_STRING)
		abort_interp("Non-string argument (3)");
	if (oper3->type != PROG_STRING)
		abort_interp("Non-string argument (2)");
	if (!oper3->data.string)
		abort_interp("Empty string argument (2)");
	if (!valid_object(oper4))
		abort_interp("Non-object argument (1)");
	CHECKREMOTE(oper4->data.objref);

	if ((mlev < 2) && (!permissions(ProgUID, oper4->data.objref)))
		abort_interp("Permission denied.");

	if (!prop_write_perms(ProgUID, oper4->data.objref, oper3->data.string->data, mlev))
		abort_interp("Permission denied.");

	{
		const char *temp;
		char *tmpe;
		char tname[BUFFER_LEN];
		int len = oper3->data.string->length;

		temp = (oper2->data.string ? oper2->data.string->data : 0);
		tmpe = oper3->data.string->data;
		while (*tmpe && *tmpe != '\r')
			tmpe++;
		if (*tmpe)
			abort_interp("CRs not allowed in propname");

		strcpyn(tname, sizeof(tname), oper3->data.string->data);
		while (len-- > 0 && tname[len] == PROPDIR_DELIMITER) {
			tname[len] = '\0';
		}

		/* if ((temp) || (oper1->data.number)) */
		{
			add_property(oper4->data.objref, tname, temp, oper1->data.number);

#ifdef LOG_PROPS
			log2file("props.log", "#%d (%d) ADDPROP: o=%d n=\"%s\" s=\"%s\" v=%d",
					 program, pc->line, oper4->data.objref, tname, temp, oper1->data.number);
#endif

			ts_modifyobject(oper4->data.objref);
		}
	}
	CLEAR(oper1);
	CLEAR(oper2);
	CLEAR(oper3);
	CLEAR(oper4);
}
예제 #14
0
파일: p_props.c 프로젝트: hyena/fuzzball
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); */
	}
}
예제 #15
0
파일: p_props.c 프로젝트: hyena/fuzzball
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;
			}
		}
	}
}
예제 #16
0
파일: p_props.c 프로젝트: hyena/fuzzball
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);
	}
}
예제 #17
0
파일: p_props.c 프로젝트: hyena/fuzzball
void
prim_setprop(PRIM_PROTOTYPE)
{
	CHECKOP(3);
	oper1 = POP();
	oper2 = POP();
	oper3 = POP();
	if ((oper1->type != PROG_STRING) &&
		(oper1->type != PROG_INTEGER) &&
		(oper1->type != PROG_LOCK) &&
		(oper1->type != PROG_OBJECT) &&
		(oper1->type != PROG_FLOAT)) abort_interp("Invalid argument type (3)");
	if (oper2->type != PROG_STRING)
		abort_interp("Non-string argument (2)");
	if (!oper2->data.string)
		abort_interp("Empty string argument (2)");
	if (!valid_object(oper3))
		abort_interp("Non-object argument (1)");
	CHECKREMOTE(oper3->data.objref);

	if ((mlev < 2) && (!permissions(ProgUID, oper3->data.objref)))
		abort_interp("Permission denied.");

	if (!prop_write_perms(ProgUID, oper3->data.objref, oper2->data.string->data, mlev))
		abort_interp("Permission denied.");

	{
		char *tmpe;
		char tname[BUFFER_LEN];
		PData propdat;
		int len = oper2->data.string->length;

		tmpe = oper2->data.string->data;
		while (*tmpe && *tmpe != '\r' && *tmpe != ':')
			tmpe++;
		if (*tmpe)
			abort_interp("Illegal propname");

		strcpyn(tname, sizeof(tname), oper2->data.string->data);
		while (len-- > 0 && tname[len] == PROPDIR_DELIMITER) {
			tname[len] = '\0';
		}

		switch (oper1->type) {
		case PROG_STRING:
			propdat.flags = PROP_STRTYP;
			propdat.data.str = oper1->data.string ? oper1->data.string->data : 0;
			break;
		case PROG_INTEGER:
			propdat.flags = PROP_INTTYP;
			propdat.data.val = oper1->data.number;
			break;
		case PROG_FLOAT:
			propdat.flags = PROP_FLTTYP;
			propdat.data.fval = oper1->data.fnumber;
			break;
		case PROG_OBJECT:
			propdat.flags = PROP_REFTYP;
			propdat.data.ref = oper1->data.objref;
			break;
		case PROG_LOCK:
			propdat.flags = PROP_LOKTYP;
			propdat.data.lok = copy_bool(oper1->data.lock);
			break;
		}
		set_property(oper3->data.objref, tname, &propdat);

#ifdef LOG_PROPS
		log2file("props.log", "#%d (%d) SETPROP: o=%d n=\"%s\"",
				 program, pc->line, oper3->data.objref, tname);
#endif

		ts_modifyobject(oper3->data.objref);
	}
	CLEAR(oper1);
	CLEAR(oper2);
	CLEAR(oper3);
}
예제 #18
0
파일: p_props.c 프로젝트: hyena/fuzzball
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);
}
예제 #19
0
파일: p_regex.c 프로젝트: CyberLeo/zetamuck
void
prim_array_regfilter_prop(PRIM_PROTOTYPE)
{
    char buf[BUFFER_LEN];
    struct inst *in;
    stk_array *arr;
    stk_array *nu;
    char* prop;
    const char* ptr;
    muf_re* re;
    int flags;
    int matchcnt = 0;
    const char* errstr = NULL;

    CHECKOP(4);
    oper4 = POP();    /* int     pcreflags */
    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)");
    if (oper4->type != PROG_INTEGER)
        abort_interp("Non-integer argument (4)");


    ptr = oper2->data.string->data;
    while ((ptr = index(ptr, PROPDIR_DELIMITER)))
        if (!(*(++ptr)))
            abort_interp("Cannot access a propdir directly.");
    nu = new_array_packed(0);
    arr = oper1->data.array;

    flags = PCRE_NO_AUTO_CAPTURE;

    if (oper4->data.number & MUF_RE_ICASE)
        flags |= PCRE_CASELESS;
    if (oper4->data.number & MUF_RE_EXTENDED)
        flags |= PCRE_EXTENDED;

    re = regmatch_re_get(oper3->data.string, flags, &errstr);
    if (errstr)
        abort_interp(errstr)

    if (re && !re->extra && array_count(arr) > 2) {
        /* This pattern is getting used 3 or more times, let's study it. A null
         * return is okay, that just means there's nothing to optimize. */
        re->extra = pcre_study(re->re, 0, &errstr);
        if (errstr)
            abort_interp(errstr);
    }

    prop = (char *) DoNullInd(oper2->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)) {
                    ptr = get_property_class(ref, prop);
                    if (ptr)
                        strcpy(buf, ptr);
                    else
                        strcpy(buf, "");
                    if ((matchcnt = regmatch_exec(re, buf)) < 0) {
                        if (matchcnt != PCRE_ERROR_NOMATCH)
                            abort_interp(muf_re_error(matchcnt));
                    } else {
                        array_appenditem(&nu, in);
                    }
                }
            }
        } while (array_next(arr, &temp1));
    }


    CLEAR(oper4);
    CLEAR(oper3);
    CLEAR(oper2);
    CLEAR(oper1);
    PushArrayRaw(nu);
}
예제 #20
0
파일: p_props.c 프로젝트: hyena/fuzzball
void
prim_parseprop(PRIM_PROTOTYPE)
{
	const char *temp;
	char *ptr;
	struct inst *oper1 = NULL; /* prevents re-entrancy issues! */
	struct inst *oper2 = NULL; /* prevents re-entrancy issues! */
	struct inst *oper3 = NULL; /* prevents re-entrancy issues! */
	struct inst *oper4 = NULL; /* prevents re-entrancy issues! */

	char buf[BUFFER_LEN];
	char type[BUFFER_LEN];

	CHECKOP(4);
	oper4 = POP();				/* int */
	oper2 = POP();				/* arg str */
	oper1 = POP();				/* propname str */
	oper3 = POP();				/* object dbref */
	if (mlev < 3)
		abort_interp("Mucker level 3 or greater required.");
	if (oper3->type != PROG_OBJECT)
		abort_interp("Non-object argument. (1)");
	if (!valid_object(oper3))
		abort_interp("Invalid object. (1)");
	if (oper2->type != PROG_STRING)
		abort_interp("String expected. (3)");
	if (oper1->type != PROG_STRING)
		abort_interp("String expected. (2)");
	if (!oper1->data.string)
		abort_interp("Empty string argument (2)");
	if (oper4->type != PROG_INTEGER)
		abort_interp("Integer expected. (4)");
	if (oper4->data.number < 0 || oper4->data.number > 1)
		abort_interp("Integer of 0 or 1 expected. (4)");
	CHECKREMOTE(oper3->data.objref);
	{
		int len = oper1->data.string->length;

		if (!prop_read_perms(ProgUID, oper3->data.objref, oper1->data.string->data, mlev))
			abort_interp("Permission denied.");

		if (mlev < 3 && !permissions(player, oper3->data.objref) &&
			prop_write_perms(ProgUID, oper3->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';
		}

		temp = get_property_class(oper3->data.objref, type);
#ifdef LOG_PROPS
		log2file("props.log", "#%d (%d) GETPROPSTR: o=%d n=\"%s\" s=\"%s\"",
				 program, pc->line, oper3->data.objref, type, temp);
#endif

	}
	ptr = (oper2->data.string) ? oper2->data.string->data : "";
	if (temp) {
		result = 0;
		if (oper4->data.number)
			result |= MPI_ISPRIVATE;
		if (Prop_Blessed(oper3->data.objref, type))
			result |= MPI_ISBLESSED;
		ptr = do_parse_mesg(fr->descr, player, oper3->data.objref, temp, ptr, buf, sizeof(buf), result);
		CLEAR(oper1);
		CLEAR(oper2);
		CLEAR(oper3);
		CLEAR(oper4);
		PushString(ptr);
	} else {
		CLEAR(oper1);
		CLEAR(oper2);
		CLEAR(oper3);
		CLEAR(oper4);
		PushNullStr;
	}
}