Exemplo n.º 1
0
WaveStream::~WaveStream()
{
	PAGED_CODE();

	ASSERT(valid_object(this,WaveStream));

    debug("WaveStream[%d]::~WaveStream [%p]\n",Pin,this);

    enabled=false;

    if(NotificationEvent)
    {
    	debug("!! WaveStream[%d]::~WaveStream: notification event %p still allocated\n",Pin,NotificationEvent);
    	NotificationEvent=NULL;
    }

    if(wave)
    {
        // just in case
        if(valid_object(wave->GetAdapter()->hal,Hal))
        	wave->GetAdapter()->hal->remove_notification(this);

    	wave=NULL;
    }

    memset(&current_pin_format,0,sizeof(current_pin_format));

    magic=NULL;
}
Exemplo n.º 2
0
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;
    }

}
Exemplo n.º 3
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;
    }

}
Exemplo n.º 4
0
void
prim_ignore_del(PRIM_PROTOTYPE)
{
    CHECKOP(2);
    oper1 = POP();
    oper2 = POP();
    if (mlev < 3)
	abort_interp("Permission Denied.");
    if (!valid_object(oper1))
	abort_interp("Invalid object. (2)");
    if (!valid_object(oper2))
	abort_interp("Invalid object. (1)");
    ignore_remove_player(oper2->data.objref, oper1->data.objref);
    CLEAR(oper1);
    CLEAR(oper2);
}
Exemplo n.º 5
0
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);
}
Exemplo n.º 6
0
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);
}
Exemplo n.º 7
0
void
prim_propdirp(PRIM_PROTOTYPE)
{
	/* dbref dir -- int */
	CHECKOP(2);
	oper2 = POP();				/* prop name */
	oper1 = POP();				/* dbref */
	if (mlev < 2)
		abort_interp("Permission denied.");
	if (oper1->type != PROG_OBJECT)
		abort_interp("Argument must be a dbref (1)");
	if (!valid_object(oper1))
		abort_interp("Invalid dbref (1)");
	if (oper2->type != PROG_STRING)
		abort_interp("Argument not a string. (2)");
	if (!oper2->data.string)
		abort_interp("Null string not allowed. (2)");
	ref = oper1->data.objref;
	(void) strcpyn(buf, sizeof(buf), oper2->data.string->data);
	CLEAR(oper1);
	CLEAR(oper2);

	result = is_propdir(ref, buf);

#ifdef LOG_PROPS
	log2file("props.log", "#%d (%d) PROPDIR?: o=%d n=\"%s\" v=%d",
			 program, pc->line, ref, buf, result);
#endif

	PushInt(result);
}
Exemplo n.º 8
0
void 
prim_ignoringp(PRIM_PROTOTYPE)
{
    CHECKOP(2);
    oper2 = POP();
    oper1 = POP();
    if (!valid_object(oper1))
	abort_interp("invalid argument (1)");
    if (!valid_object(oper2))
	abort_interp("invalid argument (2)");
    ref = oper1->data.objref;
    ref = OWNER(ref);
    if (Typeof(ref) != TYPE_PLAYER)
	abort_interp("invalid argument (1)");
    result = ignoring(ref, OWNER(oper2->data.objref));
    PushInt(result);
}
Exemplo n.º 9
0
void
prim_ignoringp(PRIM_PROTOTYPE)
{
    CHECKOP(2);
    oper1 = POP();
    oper2 = POP();
    if (mlev < 3)
	abort_interp("Permission Denied.");
    if (!valid_object(oper1))
	abort_interp("Invalid object. (2)");
    if (!valid_object(oper2))
	abort_interp("Invalid object. (1)");
    result = ignore_is_ignoring(oper2->data.objref, oper1->data.objref);
    CLEAR(oper1);
    CLEAR(oper2);
    PushInt(result);
}
Exemplo n.º 10
0
NTSTATUS WaveStream::PropertyPrivate(IN PPCPROPERTY_REQUEST   PropertyRequest)
{
	PAGED_CODE();

	ASSERT(PropertyRequest);

    Wave *wave = (Wave *)(PMINIPORTWAVERT)PropertyRequest->MajorTarget;
    WaveStream *wave_stream = (WaveStream *)PMINIPORTWAVERTSTREAM(PropertyRequest->MinorTarget);

    if(valid_object(wave,Wave) || valid_object(wave_stream,WaveStream))
    {
    	return wave->GetAdapter()->PropertyPrivate(PropertyRequest, wave, wave_stream);
    }
    else
    {
    	debug("!! WaveStream::Private: invalid property targets: %p / %p\n",wave,wave_stream);
    	return STATUS_INVALID_PARAMETER;
    }
}
Exemplo n.º 11
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;
    }

}
Exemplo n.º 12
0
void
prim_nextprop(PRIM_PROTOTYPE)
{
	/* dbref pname -- pname */
	char *pname;
	char exbuf[BUFFER_LEN];

	CHECKOP(2);
	oper2 = POP();				/* pname */
	oper1 = POP();				/* dbref */
	if (mlev < 3)
		abort_interp("Permission denied.");
	if (oper2->type != PROG_STRING)
		abort_interp("String required. (2)");
	if (oper1->type != PROG_OBJECT)
		abort_interp("Dbref required. (1)");
	if (!valid_object(oper1))
		abort_interp("Invalid dbref. (1)");

	ref = oper1->data.objref;
	(void) strcpyn(buf, sizeof(buf), DoNullInd(oper2->data.string));

	CLEAR(oper1);
	CLEAR(oper2);

	{
		char *tmpname;

		pname = next_prop_name(ref, exbuf, sizeof(exbuf), buf);

#ifdef LOG_PROPS
		log2file("props.log", "#%d (%d) NEXTPROP: o=%d n=\"%s\" on=\"%s\"",
				 program, pc->line, ref, pname, buf);
#endif

		while (pname && !prop_read_perms(ProgUID, ref, pname, mlev)) {
			tmpname = next_prop_name(ref, exbuf, sizeof(exbuf), pname);

#ifdef LOG_PROPS
			log2file("props.log", "#%d (%d) NEXTPROP: o=%d n=\"%s\" on=\"%s\"",
					 program, pc->line, ref, tmpname, pname);
#endif

			pname = tmpname;
		}
	}
	if (pname) {
		PushString(pname);
	} else {
		PushNullStr;
	}
}
Exemplo n.º 13
0
void 
prim_awakep(PRIM_PROTOTYPE)
{
    CHECKOP(1);
    oper1 = POP();
    if (!valid_object(oper1))
	abort_interp("invalid argument");
    ref = oper1->data.objref;
    if (Typeof(ref) == TYPE_THING && (FLAGS(ref) & ZOMBIE))
	ref = OWNER(ref);
    if (Typeof(ref) != TYPE_PLAYER)
	abort_interp("invalid argument");
    result = online(ref);
    PushInt(result);
}
Exemplo n.º 14
0
void 
prim_descriptors(PRIM_PROTOTYPE)
{
    int  mydescr, mycount = 0;
    int  di, dcount, descr;
    int* darr;

    CHECKOP(1);
    oper1 = POP();
    if (mlev < LM3)
	abort_interp("M3 prim");
    if (oper1->type != PROG_OBJECT)
	abort_interp("Argument not a dbref");
    if (oper1->data.objref != NOTHING && !valid_object(oper1))
	abort_interp("Bad dbref");
    ref = oper1->data.objref;
    if ((ref != NOTHING) && (!valid_player(oper1)))
	abort_interp("Non-player argument");
    CLEAR(oper1);
    CHECKOP(0);

    if (ref == NOTHING) {
        for (result = pcount(); result; result--) {
            CHECKOFLOW(1);
            mydescr = pdescr(result);
            PushInt(mydescr);
            mycount++;
        }
    } else {
        if (Typeof(ref) == TYPE_PLAYER) {
            darr   = DBFETCH(ref)->sp.player.descrs;
            dcount = DBFETCH(ref)->sp.player.descr_count;
            if (!darr)
                dcount = 0;
        } else {
            darr = NULL;
            dcount = 0;
        }
        for (di = 0; di < dcount; di++) {
            CHECKOFLOW(1);
            descr = index_descr(darr[di]);
            PushInt(descr);
            mycount++;
        }
    }
    CHECKOFLOW(1);
    PushInt(mycount);
}
Exemplo n.º 15
0
void
prim_cancallp(PRIM_PROTOTYPE)
{
    CHECKOP(2);
    oper2 = POP();		/* string: public function name */
    oper1 = POP();		/* dbref: Program dbref to check */
    if (oper1->type != PROG_OBJECT)
	abort_interp("Expected dbref argument. (1)");
    if (!valid_object(oper1))
	abort_interp("Invalid dbref (1)");
    if (Typeof(oper1->data.objref) != TYPE_PROGRAM)
	abort_interp("Object is not a MUF Program. (1)");
    if (oper2->type != PROG_STRING)
	abort_interp("Expected string argument. (2)");
    if (!oper2->data.string)
	abort_interp("Invalid Null string argument. (2)");

    if (!(PROGRAM_CODE(oper1->data.objref))) {
	struct line *tmpline;

	tmpline = PROGRAM_FIRST(oper1->data.objref);
	PROGRAM_SET_FIRST(oper1->data.objref,
			  (struct line *) read_program(oper1->data.objref));
	do_compile(-1, OWNER(oper1->data.objref), oper1->data.objref, 0);
	free_prog_text(PROGRAM_FIRST(oper1->data.objref));
	PROGRAM_SET_FIRST(oper1->data.objref, tmpline);
    }

    result = 0;
    if (ProgMLevel(oper1->data.objref) > 0 &&
	(mlev >= 4 || OWNER(oper1->data.objref) == ProgUID || Linkable(oper1->data.objref))
	    ) {
	struct publics *pbs;

	pbs = PROGRAM_PUBS(oper1->data.objref);
	while (pbs) {
	    if (!strcasecmp(oper2->data.string->data, pbs->subname))
		break;
	    pbs = pbs->next;
	}
	if (pbs && mlev >= pbs->mlev)
	    result = 1;
    }
    CHECKOFLOW(1);
    CLEAR(oper1);
    CLEAR(oper2);
    PushInt(result);
}
Exemplo n.º 16
0
void Track_station_now(Widget w, XtPointer clientData, XtPointer callData) {
    char temp[MAX_CALLSIGN+1];
    char temp2[200];
    int found = 0;
    char *temp_ptr;


    temp_ptr = XmTextFieldGetString(track_station_data);
    xastir_snprintf(temp,
        sizeof(temp),
        "%s",
        temp_ptr);
    XtFree(temp_ptr);

    (void)remove_trailing_spaces(temp);
    (void)remove_trailing_dash_zero(temp);

    xastir_snprintf(tracking_station_call,
        sizeof(tracking_station_call),
        "%s",
        temp);
    track_case  = (int)XmToggleButtonGetState(track_case_data);
    track_match = (int)XmToggleButtonGetState(track_match_data);
    found = locate_station(da, temp, track_case, track_match, 0);

    if ( valid_object(tracking_station_call)    // Name of object is legal
            || valid_call(tracking_station_call)
            || valid_item(tracking_station_call ) ) {
        track_station_on = 1;   // Track it whether we've seen it yet or not
        if (!found) {
            xastir_snprintf(temp2, sizeof(temp2), langcode("POPEM00026"), temp);
            popup_message_always(langcode("POPEM00025"),temp2);
        }
        // Check for exact match, includes SSID
        if ( track_me & !is_my_call( tracking_station_call, 1) ) {
            XmToggleButtonSetState( trackme_button, FALSE, FALSE );
            track_me = 0;
        }
    } else {
        tracking_station_call[0] = '\0';    // Empty it out again
        track_station_on = 0;
        xastir_snprintf(temp2, sizeof(temp2), langcode("POPEM00002"), temp);
        popup_message_always(langcode("POPEM00003"),temp2);
    }

    track_station_destroy_shell(w, clientData, callData);
    display_zoom_status();
}
Exemplo n.º 17
0
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);
}
Exemplo n.º 18
0
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);
}
Exemplo n.º 19
0
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);
}
Exemplo n.º 20
0
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);
}
Exemplo n.º 21
0
void 
prim_queue(PRIM_PROTOTYPE)
{
    dbref temproom;

    /* int dbref string -- */
    CHECKOP(3);
    oper1 = POP();
    oper2 = POP();
    oper3 = POP();
    if (mlev < LM3)
	abort_interp("M3 prim");
    if (oper3->type != PROG_INTEGER)
	abort_interp("Non-integer argument (1)");
    if (oper2->type != PROG_OBJECT)
	abort_interp("Argument must be a dbref (2)");
    if (!valid_object(oper2))
	abort_interp("Invalid dbref (2)");
    if (Typeof(oper2->data.objref) != TYPE_PROGRAM)
	abort_interp("Object must be a program (2)");
    if (oper1->type != PROG_STRING)
	abort_interp("Non-string argument (3)");

    if ((oper4 = fr->variables + 1)->type != PROG_OBJECT)
	temproom = DBFETCH(player)->location;
    else
	temproom = oper4->data.objref;

    result = add_muf_delayq_event(oper3->data.number, fr->descr, player, temproom,
		    NOTHING, oper2->data.objref, DoNullInd(oper1->data.string),
		     "Queued Event.", 0);

    CLEAR(oper1);
    CLEAR(oper2);
    CLEAR(oper3);
    PushInt(result);
}
Exemplo n.º 22
0
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);
}
Exemplo n.º 23
0
struct inst *
interp_loop(dbref player, dbref program, struct frame *fr, int rettyp)
{
	register struct inst *pc;
	register int atop;
	register struct inst *arg;
	register struct inst *temp1;
	register struct inst *temp2;
	register struct stack_addr *sys;
	register int instr_count;
	register int stop;
	int i = 0, tmp, writeonly, mlev;
	static struct inst retval;
	char dbuf[BUFFER_LEN];
	int instno_debug_line = get_primitive("debug_line");


	fr->level = ++interp_depth;	/* increment interp level */

	/* load everything into local stuff */
	pc = fr->pc;
	atop = fr->argument.top;
	stop = fr->system.top;
	arg = fr->argument.st;
	sys = fr->system.st;
	writeonly = fr->writeonly;
	already_created = 0;
	fr->brkpt.isread = 0;

	if (!pc) {
		struct line *tmpline;

		tmpline = PROGRAM_FIRST(program);
		PROGRAM_SET_FIRST(program, (struct line *) read_program(program));
		do_compile(-1, OWNER(program), program, 0);
		free_prog_text(PROGRAM_FIRST(program));
		PROGRAM_SET_FIRST(program, tmpline);
		pc = fr->pc = PROGRAM_START(program);
		if (!pc) {
			abort_loop_hard("Program not compilable. Cannot run.", NULL, NULL);
		}
		PROGRAM_INC_PROF_USES(program);
		PROGRAM_INC_INSTANCES(program);
	}
	ts_useobject(program);
	err = 0;

	instr_count = 0;
	mlev = ProgMLevel(program);
	gettimeofday(&fr->proftime, NULL);

	/* This is the 'natural' way to exit a function */
	while (stop) {

		/* Abort program if player/thing running it is recycled */
		if ((player < 0) || (player >= db_top) || ((Typeof(player) != TYPE_PLAYER) && (Typeof(player) != TYPE_THING)))
		{
			reload(fr, atop, stop);
			prog_clean(fr);
			interp_depth--;
			calc_profile_timing(program,fr);

			return NULL;
		}

		fr->instcnt++;
		instr_count++;

		if ((fr->multitask == PREEMPT) || (FLAGS(program) & BUILDER)) {
			if (mlev == 4) {
				if (tp_max_ml4_preempt_count)
				{
					if (instr_count >= tp_max_ml4_preempt_count)
						abort_loop_hard("Maximum preempt instruction count exceeded", NULL, NULL);
				}
				else
					instr_count = 0;
			} else {
				/* else make sure that the program doesn't run too long */
				if (instr_count >= tp_max_instr_count)
					abort_loop_hard("Maximum preempt instruction count exceeded", NULL, NULL);
			}
		} else {
			/* if in FOREGROUND or BACKGROUND mode, '0 sleep' every so often. */
			if ((fr->instcnt > tp_instr_slice * 4) && (instr_count >= tp_instr_slice)) {
				fr->pc = pc;
				reload(fr, atop, stop);
				PLAYER_SET_BLOCK(player, (!fr->been_background));
				add_muf_delay_event(0, fr->descr, player, NOTHING, NOTHING, program, fr,
									(fr->multitask ==
									 FOREGROUND) ? "FOREGROUND" : "BACKGROUND");
				interp_depth--;
				calc_profile_timing(program,fr);
				return NULL;
			}
		}
		if (((FLAGS(program) & ZOMBIE) || fr->brkpt.force_debugging) &&
				!fr->been_background &&
				controls(player, program)
		) {
			fr->brkpt.debugging = 1;
		} else {
			fr->brkpt.debugging = 0;
		}
		if (FLAGS(program) & DARK ||
			(fr->brkpt.debugging && fr->brkpt.showstack && !fr->brkpt.bypass)) {

			if ((pc->type != PROG_PRIMITIVE) || (pc->data.number != instno_debug_line))
			{
				char *m = debug_inst(fr, 0, pc, fr->pid, arg, dbuf, sizeof(dbuf), atop, program);

				notify_nolisten(player, m, 1);
			}
		}
		if (fr->brkpt.debugging) {
			short breakflag = 0;
			if (stop == 1 &&
					!fr->brkpt.bypass &&
					pc->type == PROG_PRIMITIVE &&
					pc->data.number == IN_RET
			) {
				/* Program is about to EXIT */
				notify_nolisten(player, "Program is about to EXIT.", 1);
				breakflag = 1;
			} else if (fr->brkpt.count) {
				for (i = 0; i < fr->brkpt.count; i++) {
					if ((!fr->brkpt.pc[i] || pc == fr->brkpt.pc[i]) &&
						/* pc matches */
						(fr->brkpt.line[i] == -1 ||
						 (fr->brkpt.lastline != pc->line &&
						  fr->brkpt.line[i] == pc->line)) &&
						/* line matches */
						(fr->brkpt.level[i] == -1 ||
						 stop <= fr->brkpt.level[i]) &&
						/* level matches */
						(fr->brkpt.prog[i] == NOTHING ||
						 fr->brkpt.prog[i] == program) &&
						/* program matches */
						(fr->brkpt.linecount[i] == -2 ||
						 (fr->brkpt.lastline != pc->line &&
						  fr->brkpt.linecount[i]-- <= 0)) &&
						/* line count matches */
						(fr->brkpt.pccount[i] == -2 ||
						 (fr->brkpt.lastpc != pc &&
						  fr->brkpt.pccount[i]-- <= 0))
						/* pc count matches */
					) {
						if (fr->brkpt.bypass) {
							if (fr->brkpt.pccount[i] == -1)
								fr->brkpt.pccount[i] = 0;
							if (fr->brkpt.linecount[i] == -1)
								fr->brkpt.linecount[i] = 0;
						} else {
							breakflag = 1;
							break;
						}
					}
				}
			}
			if (breakflag) {
				char *m;
				char buf[BUFFER_LEN];

				if (fr->brkpt.dosyspop) {
					program = sys[--stop].progref;
					pc = sys[stop].offset;
				}
				add_muf_read_event(fr->descr, player, program, fr);
				reload(fr, atop, stop);
				fr->pc = pc;
				fr->brkpt.isread = 0;
				fr->brkpt.breaknum = i;
				fr->brkpt.lastlisted = 0;
				fr->brkpt.bypass = 0;
				fr->brkpt.dosyspop = 0;
				PLAYER_SET_CURR_PROG(player, program);
				PLAYER_SET_BLOCK(player, 0);
				interp_depth--;
				if (!fr->brkpt.showstack) {
					m = debug_inst(fr, 0, pc, fr->pid, arg, dbuf, sizeof(dbuf), atop, program);
					notify_nolisten(player, m, 1);
				}
				if (pc <= PROGRAM_CODE(program) || (pc - 1)->line != pc->line) {
					list_proglines(player, program, fr, pc->line, 0);
				} else {
					m = show_line_prims(fr, program, pc, 15, 1);
					snprintf(buf, sizeof(buf), "     %s", m);
					notify_nolisten(player, buf, 1);
				}
				calc_profile_timing(program,fr);
				return NULL;
			}
			fr->brkpt.lastline = pc->line;
			fr->brkpt.lastpc = pc;
			fr->brkpt.bypass = 0;
		}
		if (mlev < 3) {
			if (fr->instcnt > (tp_max_instr_count * ((mlev == 2) ? 4 : 1)))
				abort_loop_hard("Maximum total instruction count exceeded.", NULL, NULL);
		}
		switch (pc->type) {
		case PROG_INTEGER:
		case PROG_FLOAT:
		case PROG_ADD:
		case PROG_OBJECT:
		case PROG_VAR:
		case PROG_LVAR:
		case PROG_SVAR:
		case PROG_STRING:
		case PROG_LOCK:
		case PROG_MARK:
		case PROG_ARRAY:
			if (atop >= STACK_SIZE)
				abort_loop("Stack overflow.", NULL, NULL);
			copyinst(pc, arg + atop);
			pc++;
			atop++;
			break;

		case PROG_LVAR_AT:
		case PROG_LVAR_AT_CLEAR:
			{
				struct inst *tmp;
				struct localvars *lv;

				if (atop >= STACK_SIZE)
					abort_loop("Stack overflow.", NULL, NULL);

				if (pc->data.number >= MAX_VAR || pc->data.number < 0)
					abort_loop("Scoped variable number out of range.", NULL, NULL);

				lv = localvars_get(fr, program);
				tmp = &(lv->lvars[pc->data.number]);

				copyinst(tmp, arg + atop);

				if (pc->type == PROG_LVAR_AT_CLEAR) {
					CLEAR(tmp);
					tmp->type			= PROG_INTEGER;
					tmp->data.number	= 0;
				}

				pc++;
				atop++;
			}
			break;

		case PROG_LVAR_BANG:
			{
				struct inst *the_var;
				struct localvars *lv;
				if (atop < 1)
					abort_loop("Stack Underflow.", NULL, NULL);
				if (fr->trys.top && atop - fr->trys.st->depth < 1)
					abort_loop("Stack protection fault.", NULL, NULL);

				if (pc->data.number >= MAX_VAR || pc->data.number < 0)
					abort_loop("Scoped variable number out of range.", NULL, NULL);

				lv = localvars_get(fr, program);
				the_var = &(lv->lvars[pc->data.number]);

				CLEAR(the_var);
				temp1 = arg + --atop;
				*the_var = *temp1;
				pc++;
			}
			break;

		case PROG_SVAR_AT:
		case PROG_SVAR_AT_CLEAR:
			{
				struct inst *tmp;

				if (atop >= STACK_SIZE)
					abort_loop("Stack overflow.", NULL, NULL);

				tmp = scopedvar_get(fr, 0, pc->data.number);
				if (!tmp)
					abort_loop("Scoped variable number out of range.", NULL, NULL);

				copyinst(tmp, arg + atop);

				if (pc->type == PROG_SVAR_AT_CLEAR) {
					CLEAR(tmp);

					tmp->type			= PROG_INTEGER;
					tmp->data.number	= 0;
				}

				pc++;
				atop++;
			}
			break;

		case PROG_SVAR_BANG:
			{
				struct inst *the_var;
				if (atop < 1)
					abort_loop("Stack Underflow.", NULL, NULL);
				if (fr->trys.top && atop - fr->trys.st->depth < 1)
					abort_loop("Stack protection fault.", NULL, NULL);

				the_var = scopedvar_get(fr, 0, pc->data.number);
				if (!the_var)
					abort_loop("Scoped variable number out of range.", NULL, NULL);

				CLEAR(the_var);
				temp1 = arg + --atop;
				*the_var = *temp1;
				pc++;
			}
			break;

		case PROG_FUNCTION:
			{
				int i = pc->data.mufproc->args;
				if (atop < i)
					abort_loop("Stack Underflow.", NULL, NULL);
				if (fr->trys.top && atop - fr->trys.st->depth < i)
					abort_loop("Stack protection fault.", NULL, NULL);
				if (fr->skip_declare)
					fr->skip_declare = 0;
				else
					scopedvar_addlevel(fr, pc, pc->data.mufproc->vars);
				while (i-->0)
				{
					struct inst *tmp;
					temp1 = arg + --atop;
					tmp = scopedvar_get(fr, 0, i);
					if (!tmp)
						abort_loop_hard("Internal error: Scoped variable number out of range in FUNCTION init.", temp1, NULL);
					CLEAR(tmp);
					copyinst(temp1, tmp);
					CLEAR(temp1);
				}
				pc++;
			}
			break;

		case PROG_IF:
			if (atop < 1)
				abort_loop("Stack Underflow.", NULL, NULL);
			if (fr->trys.top && atop - fr->trys.st->depth < 1)
				abort_loop("Stack protection fault.", NULL, NULL);
			temp1 = arg + --atop;
			if (false_inst(temp1))
				pc = pc->data.call;
			else
				pc++;
			CLEAR(temp1);
			break;

		case PROG_EXEC:
			if (stop >= STACK_SIZE)
				abort_loop("System Stack Overflow", NULL, NULL);
			sys[stop].progref = program;
			sys[stop++].offset = pc + 1;
			pc = pc->data.call;
			fr->skip_declare = 0;  /* Make sure we DON'T skip var decls */
			break;

		case PROG_JMP:
			/* Don't need to worry about skipping scoped var decls here. */
			/* JMP to a function header can only happen in IN_JMP */
			pc = pc->data.call;
			break;

		case PROG_TRY:
			if (atop < 1)
				abort_loop("Stack Underflow.", NULL, NULL);
			if (fr->trys.top && atop - fr->trys.st->depth < 1)
				abort_loop("Stack protection fault.", NULL, NULL);
			temp1 = arg + --atop;
			if (temp1->type != PROG_INTEGER || temp1->data.number < 0)
				abort_loop("Argument is not a positive integer.", temp1, NULL);
			if (fr->trys.top && atop - fr->trys.st->depth < temp1->data.number)
				abort_loop("Stack protection fault.", NULL, NULL);
			if (temp1->data.number > atop)
				abort_loop("Stack Underflow.", temp1, NULL);

			fr->trys.top++;
			fr->trys.st = push_try(fr->trys.st);
			fr->trys.st->depth = atop - temp1->data.number;
			fr->trys.st->call_level = stop;
			fr->trys.st->for_count = 0;
			fr->trys.st->addr = pc->data.call;

			pc++;
			CLEAR(temp1);
			break;

		case PROG_PRIMITIVE:
			/*
			 * All pc modifiers and stuff like that should stay here,
			 * everything else call with an independent dispatcher.
			 */
			switch (pc->data.number) {
			case IN_JMP:
				if (atop < 1)
					abort_loop("Stack underflow.  Missing address.", NULL, NULL);
				if (fr->trys.top && atop - fr->trys.st->depth < 1)
					abort_loop("Stack protection fault.", NULL, NULL);
				temp1 = arg + --atop;
				if (temp1->type != PROG_ADD)
					abort_loop("Argument is not an address.", temp1, NULL);
				if (temp1->data.addr->progref >= db_top ||
					temp1->data.addr->progref < 0 ||
					(Typeof(temp1->data.addr->progref) != TYPE_PROGRAM))
							abort_loop_hard("Internal error.  Invalid address.", temp1, NULL);
				if (program != temp1->data.addr->progref) {
					abort_loop("Destination outside current program.", temp1, NULL);
				}
				if (temp1->data.addr->data->type == PROG_FUNCTION) {
					fr->skip_declare = 1;
				}
				pc = temp1->data.addr->data;
				CLEAR(temp1);
				break;

			case IN_EXECUTE:
				if (atop < 1)
					abort_loop("Stack Underflow. Missing address.", NULL, NULL);
				if (fr->trys.top && atop - fr->trys.st->depth < 1)
					abort_loop("Stack protection fault.", NULL, NULL);
				temp1 = arg + --atop;
				if (temp1->type != PROG_ADD)
					abort_loop("Argument is not an address.", temp1, NULL);
				if (temp1->data.addr->progref >= db_top ||
					temp1->data.addr->progref < 0 ||
					(Typeof(temp1->data.addr->progref) != TYPE_PROGRAM))
							abort_loop_hard("Internal error.  Invalid address.", temp1, NULL);
				if (stop >= STACK_SIZE)
					abort_loop("System Stack Overflow", temp1, NULL);
				sys[stop].progref = program;
				sys[stop++].offset = pc + 1;
				if (program != temp1->data.addr->progref) {
					program = temp1->data.addr->progref;
					fr->caller.st[++fr->caller.top] = program;
					mlev = ProgMLevel(program);
					PROGRAM_INC_INSTANCES(program);
				}
				pc = temp1->data.addr->data;
				CLEAR(temp1);
				break;

			case IN_CALL:
				if (atop < 1)
					abort_loop("Stack Underflow. Missing dbref argument.", NULL, NULL);
				if (fr->trys.top && atop - fr->trys.st->depth < 1)
					abort_loop("Stack protection fault.", NULL, NULL);
				temp1 = arg + --atop;
				temp2 = 0;
				if (temp1->type != PROG_OBJECT) {
					temp2 = temp1;
					if (atop < 1)
						abort_loop("Stack Underflow. Missing dbref of func.", temp1, NULL);
					if (fr->trys.top && atop - fr->trys.st->depth < 1)
						abort_loop("Stack protection fault.", NULL, NULL);
					temp1 = arg + --atop;
					if (temp2->type != PROG_STRING)
						abort_loop("Public Func. name string required. (2)", temp1, temp2);
					if (!temp2->data.string)
						abort_loop("Null string not allowed. (2)", temp1, temp2);
				}
				if (temp1->type != PROG_OBJECT)
					abort_loop("Dbref required. (1)", temp1, temp2);
				if (!valid_object(temp1)
					|| Typeof(temp1->data.objref) != TYPE_PROGRAM)
					abort_loop("Invalid object.", temp1, temp2);
				if (!(PROGRAM_CODE(temp1->data.objref))) {
					struct line *tmpline;

					tmpline = PROGRAM_FIRST(temp1->data.objref);
					PROGRAM_SET_FIRST(temp1->data.objref,
									  (struct line *) read_program(temp1->data.objref));
					do_compile(-1, OWNER(temp1->data.objref), temp1->data.objref, 0);
					free_prog_text(PROGRAM_FIRST(temp1->data.objref));
					PROGRAM_SET_FIRST(temp1->data.objref, tmpline);
					if (!(PROGRAM_CODE(temp1->data.objref)))
						abort_loop("Program not compilable.", temp1, temp2);
				}
				if (ProgMLevel(temp1->data.objref) == 0)
					abort_loop("Permission denied", temp1, temp2);
				if (mlev < 4 && OWNER(temp1->data.objref) != ProgUID
					&& !Linkable(temp1->data.objref))
							abort_loop("Permission denied", temp1, temp2);
				if (stop >= STACK_SIZE)
					abort_loop("System Stack Overflow", temp1, temp2);
				sys[stop].progref = program;
				sys[stop].offset = pc + 1;
				if (!temp2) {
					pc = PROGRAM_START(temp1->data.objref);
				} else {
					struct publics *pbs;
					int tmpint;

					pbs = PROGRAM_PUBS(temp1->data.objref);
					while (pbs) {
						tmpint = string_compare(temp2->data.string->data, pbs->subname);
						if (!tmpint)
							break;
						pbs = pbs->next;
					}
					if (!pbs)
						abort_loop("PUBLIC or WIZCALL function not found. (2)", temp2, temp2);
					if (mlev < pbs->mlev)
						abort_loop("Insufficient permissions to call WIZCALL function. (2)",
								   temp2, temp2);
					pc = pbs->addr.ptr;
				}
				stop++;
				if (temp1->data.objref != program) {
					calc_profile_timing(program,fr);
					gettimeofday(&fr->proftime, NULL);
					program = temp1->data.objref;
					fr->caller.st[++fr->caller.top] = program;
					PROGRAM_INC_INSTANCES(program);
					mlev = ProgMLevel(program);
				}
				PROGRAM_INC_PROF_USES(program);
				ts_useobject(program);
				CLEAR(temp1);
				if (temp2)
					CLEAR(temp2);
				break;

			case IN_RET:
				if (stop > 1 && program != sys[stop - 1].progref) {
					if (sys[stop - 1].progref >= db_top ||
						sys[stop - 1].progref < 0 ||
						(Typeof(sys[stop - 1].progref) != TYPE_PROGRAM))
								abort_loop_hard("Internal error.  Invalid address.", NULL, NULL);
					calc_profile_timing(program,fr);
					gettimeofday(&fr->proftime, NULL);
					PROGRAM_DEC_INSTANCES(program);
					program = sys[stop - 1].progref;
					mlev = ProgMLevel(program);
					fr->caller.top--;
				}
				scopedvar_poplevel(fr);
				pc = sys[--stop].offset;
				break;

			case IN_CATCH:
			case IN_CATCH_DETAILED:
				{
					int depth;

					if (!(fr->trys.top))
						abort_loop_hard("Internal error.  TRY stack underflow.", NULL, NULL);

					depth = fr->trys.st->depth;
					while (atop > depth) {
						temp1 = arg + --atop;
						CLEAR(temp1);
					}

					while (fr->trys.st->for_count-->0) {
						CLEAR(&fr->fors.st->cur);
						CLEAR(&fr->fors.st->end);
						fr->fors.top--;
						fr->fors.st = pop_for(fr->fors.st);
					}

					fr->trys.top--;
					fr->trys.st = pop_try(fr->trys.st);

					if (pc->data.number == IN_CATCH) {
						/* IN_CATCH */
						if (fr->errorstr) {
							arg[atop].type = PROG_STRING;
							arg[atop++].data.string = alloc_prog_string(fr->errorstr);
							free(fr->errorstr);
							fr->errorstr = NULL;
						} else {
							arg[atop].type = PROG_STRING;
							arg[atop++].data.string = NULL;
						}
						if (fr->errorinst) {
							free(fr->errorinst);
							fr->errorinst = NULL;
						}
					} else {
						/* IN_CATCH_DETAILED */
						stk_array *nu = new_array_dictionary();
						if (fr->errorstr) {
							array_set_strkey_strval(&nu, "error", fr->errorstr);
							free(fr->errorstr);
							fr->errorstr = NULL;
						}
						if (fr->errorinst) {
							array_set_strkey_strval(&nu, "instr", fr->errorinst);
							free(fr->errorinst);
							fr->errorinst = NULL;
						}
						array_set_strkey_intval(&nu, "line", fr->errorline);
						array_set_strkey_refval(&nu, "program", fr->errorprog);
						arg[atop].type = PROG_ARRAY;
						arg[atop++].data.array = nu;
					}
					reload(fr, atop, stop);
				}
				pc++;
				break;

			case IN_EVENT_WAITFOR:
				if (atop < 1)
					abort_loop("Stack Underflow. Missing eventID list array argument.", NULL, NULL);
				if (fr->trys.top && atop - fr->trys.st->depth < 1)
					abort_loop("Stack protection fault.", NULL, NULL);
				temp1 = arg + --atop;
				if (temp1->type != PROG_ARRAY)
					abort_loop("EventID string list array expected.", temp1, NULL);
				if (temp1->data.array && temp1->data.array->type != ARRAY_PACKED)
					abort_loop("Argument must be a list array of eventid strings.", temp1, NULL);
				if (!array_is_homogenous(temp1->data.array, PROG_STRING))
					abort_loop("Argument must be a list array of eventid strings.", temp1, NULL);
				fr->pc = pc + 1;
				reload(fr, atop, stop);

				{
					int i, outcount;
					int count = array_count(temp1->data.array);
					char** events = (char**)malloc(count * sizeof(char**));
					for (outcount = i = 0; i < count; i++) {
						char *val = array_get_intkey_strval(temp1->data.array, i);
						if (val != NULL) {
							int found = 0;
							int j;
							for (j = 0; j < outcount; j++) {
								if (!strcmp(events[j], val)) {
									found = 1;
									break;
								}
							}
							if (!found) {
								events[outcount++] = val;
							}
						}
					}
					muf_event_register_specific(player, program, fr, outcount, events);
					free(events);
				}

				PLAYER_SET_BLOCK(player, (!fr->been_background));
				CLEAR(temp1);
				interp_depth--;
				calc_profile_timing(program,fr);
				return NULL;
				/* NOTREACHED */
				break;

			case IN_READ:
				if (writeonly)
					abort_loop("Program is write-only.", NULL, NULL);
				if (fr->multitask == BACKGROUND)
					abort_loop("BACKGROUND programs are write only.", NULL, NULL);
				reload(fr, atop, stop);
				fr->brkpt.isread = 1;
				fr->pc = pc + 1;
				PLAYER_SET_CURR_PROG(player, program);
				PLAYER_SET_BLOCK(player, 0);
				add_muf_read_event(fr->descr, player, program, fr);
				interp_depth--;
				calc_profile_timing(program,fr);
				return NULL;
				/* NOTREACHED */
				break;

			case IN_SLEEP:
				if (atop < 1)
					abort_loop("Stack Underflow.", NULL, NULL);
				if (fr->trys.top && atop - fr->trys.st->depth < 1)
					abort_loop("Stack protection fault.", NULL, NULL);
				temp1 = arg + --atop;
				if (temp1->type != PROG_INTEGER)
					abort_loop("Invalid argument type.", temp1, NULL);
				fr->pc = pc + 1;
				reload(fr, atop, stop);
				if (temp1->data.number < 0)
					abort_loop("Timetravel beyond scope of muf.", temp1, NULL);
				add_muf_delay_event(temp1->data.number, fr->descr, player,
									NOTHING, NOTHING, program, fr, "SLEEPING");
				PLAYER_SET_BLOCK(player, (!fr->been_background));
				interp_depth--;
				calc_profile_timing(program,fr);
				return NULL;
				/* NOTREACHED */
				break;

			default:
				nargs = 0;
				reload(fr, atop, stop);
				tmp = atop;
				prim_func[pc->data.number - 1] (player, program, mlev, pc, arg, &tmp, fr);
				atop = tmp;
				pc++;
				break;
			}					/* switch */
			break;
		case PROG_CLEARED:
			log_status("WARNING: attempt to execute instruction cleared by %s:%hd in program %d",
					   (char*)pc->data.addr, pc->line, program);
			pc = NULL;
			abort_loop_hard("Program internal error. Program erroneously freed from memory.",
							NULL, NULL);
		default:
			pc = NULL;
			abort_loop_hard("Program internal error. Unknown instruction type.",
							NULL, NULL);
		}						/* switch */
		if (err) {
			if (err != ERROR_DIE_NOW && fr->trys.top) {
				while (fr->trys.st->call_level < stop) {
					if (stop > 1 && program != sys[stop - 1].progref) {
						if (sys[stop - 1].progref >= db_top ||
							sys[stop - 1].progref < 0 ||
							(Typeof(sys[stop - 1].progref) != TYPE_PROGRAM))
									abort_loop_hard("Internal error.  Invalid address.", NULL, NULL);
						calc_profile_timing(program,fr);
						gettimeofday(&fr->proftime, NULL);
						PROGRAM_DEC_INSTANCES(program);
						program = sys[stop - 1].progref;
						mlev = ProgMLevel(program);
						fr->caller.top--;
					}
					scopedvar_poplevel(fr);
					stop--;
				}

				pc = fr->trys.st->addr;
				err = 0;
			} else {
				reload(fr, atop, stop);
				prog_clean(fr);
				PLAYER_SET_BLOCK(player, 0);
				interp_depth--;
				calc_profile_timing(program,fr);
				return NULL;
			}
		}
	}							/* while */

	PLAYER_SET_BLOCK(player, 0);
	if (atop) {
		struct inst *rv;

		if (rettyp) {
			copyinst(arg + atop - 1, &retval);
			rv = &retval;
		} else {
			if (!false_inst(arg + atop - 1)) {
				rv = (struct inst *) 1;
			} else {
				rv = NULL;
			}
		}
		reload(fr, atop, stop);
		prog_clean(fr);
		interp_depth--;
		calc_profile_timing(program,fr);
		return rv;
	}
	reload(fr, atop, stop);
	prog_clean(fr);
	interp_depth--;
	calc_profile_timing(program,fr);
	return NULL;
}
Exemplo n.º 24
0
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);
	}
}
Exemplo n.º 25
0
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);
}
Exemplo n.º 26
0
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);
}
Exemplo n.º 27
0
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);
}
Exemplo n.º 28
0
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;
	}
}
Exemplo n.º 29
0
void
prim_ext_name_okp(PRIM_PROTOTYPE)
{
    /* These are function pointers */
    int (*ok1) (const char *) = NULL;
    int (*ok2) (const char *) = NULL;

    CHECKOP(2);
    oper2 = POP();
    oper1 = POP();

    if (oper1->type != PROG_STRING)
	abort_interp("Object name string expected (1).");
    if (!oper1->data.string)
	abort_interp("Cannot be an empty string (1).");

    if (oper2->type == PROG_STRING) {
	if (!oper2->data.string)
	    abort_interp("Cannot be an empty string (2).");
	strcpyn(buf, sizeof(buf), oper2->data.string->data);
	for (ref = 0; buf[ref]; ref++)
	    buf[ref] = tolower(buf[ref]);
	if (!strcmp(buf, "e") || !strcmp(buf, "exit")) {
	    ok1 = ok_ascii_other;
	    ok2 = ok_name;
	} else if (!strcmp(buf, "r") || !strcmp(buf, "room")) {
	    ok1 = ok_ascii_other;
	    ok2 = ok_name;
	} else if (!strcmp(buf, "t") || !strcmp(buf, "thing")) {
	    ok1 = ok_ascii_thing;
	    ok2 = ok_name;
	} else if (!strcmp(buf, "p") || !strcmp(buf, "player")) {
	    ok1 = ok_player_name;
	} else if (!strcmp(buf, "f") || !strcmp(buf, "muf")
		   || !strcmp(buf, "program")) {
	    ok1 = ok_ascii_other;
	    ok2 = ok_name;
	} else {
	    abort_interp("String must be a valid object type (2).");
	}
    } else if (oper2->type == PROG_OBJECT) {
	if (!valid_object(oper2))
	    abort_interp("Invalid argument (2).");
	switch (Typeof(oper2->data.objref)) {
	case TYPE_EXIT:
	case TYPE_ROOM:
	case TYPE_PROGRAM:
	    ok1 = ok_ascii_other;
	    ok2 = ok_name;
	    break;
	case TYPE_THING:
	    ok1 = ok_ascii_thing;
	    ok2 = ok_name;
	    break;
	case TYPE_PLAYER:
	    ok1 = ok_player_name;
	    break;
	}

    } else {
	abort_interp("Dbref or object type name expected (2).");
    }

    result = ok1 && ok1(oper1->data.string->data);
    if (ok2 && result)
	result = ok2(oper1->data.string->data);
    CLEAR(oper1);
    CLEAR(oper2);
    PushInt(result);
}
Exemplo n.º 30
0
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);
}