Esempio n. 1
0
const char *
mfn_lexec(MFUNARGS)
{
	dbref trg = (dbref) 0, obj = what;
	char *pname;
	const char *ptr;
	int blessed = 0;

	pname = argv[0];
	if (argc == 2) {
		obj = mesg_dbref(descr, player, what, perms, argv[1], mesgtyp);
	}
	if (obj == PERMDENIED)
		ABORT_MPI("LEXEC", "Permission denied.");
	if (obj == UNKNOWN || obj == AMBIGUOUS || obj == NOTHING || obj == HOME)
		ABORT_MPI("LEXEC", "Match failed.");
	while (*pname == PROPDIR_DELIMITER)
		pname++;
	ptr = get_concat_list(player, what, perms, obj, (char *)pname, buf, BUFFER_LEN, 2, mesgtyp, &blessed);
	if (!ptr)
		ptr = "";
	trg = what;
	if (blessed) {
		mesgtyp |= MPI_ISBLESSED;
	} else {
		mesgtyp &= ~MPI_ISBLESSED;
	}
	if (Prop_ReadOnly(pname) || Prop_Private(pname) || Prop_SeeOnly(pname) || Prop_Hidden(pname))
		trg = obj;
	ptr = mesg_parse(descr, player, obj, trg, ptr, buf, BUFFER_LEN, mesgtyp);
	CHECKRETURN(ptr, "LEXEC", "listval");
	return ptr;
}
Esempio n. 2
0
const char *
mfn_rand(MFUNARGS)
{
	int num = 0;
	dbref trg = (dbref) 0, obj = what;
	const char *pname, *ptr;
	int blessed = 0;

	pname = argv[0];
	if (argc == 2) {
		obj = mesg_dbref(descr, player, what, perms, argv[1], mesgtyp);
	}
	if (obj == PERMDENIED)
		ABORT_MPI("RAND", "Permission denied.");
	if (obj == UNKNOWN || obj == AMBIGUOUS || obj == NOTHING || obj == HOME)
		ABORT_MPI("RAND", "Match failed.");
	num = get_list_count(what, obj, perms, (char *)pname, mesgtyp, &blessed);
	if (!num)
		ABORT_MPI("RAND", "Failed list read.");
	ptr = get_list_item(what, obj, perms, (char *)pname, (((RANDOM() / 256) % num) + 1), mesgtyp, &blessed);
	if (!ptr)
		ABORT_MPI("RAND", "Failed list read.");
	trg = what;
	if (blessed) {
		mesgtyp |= MPI_ISBLESSED;
	} else {
		mesgtyp &= ~MPI_ISBLESSED;
	}
	if (Prop_ReadOnly(ptr) || Prop_Private(ptr) || Prop_SeeOnly(ptr) || Prop_Hidden(ptr))
		trg = obj;
	ptr = mesg_parse(descr, player, obj, trg, ptr, buf, BUFFER_LEN, mesgtyp);
	CHECKRETURN(ptr, "RAND", "listval");
	return ptr;
}
Esempio n. 3
0
const char *
mfn_usecount(MFUNARGS)
{
	dbref obj;

	obj = mesg_dbref(descr, player, what, perms, argv[0], mesgtyp);
	if (obj == UNKNOWN || obj == AMBIGUOUS || obj == NOTHING || obj == HOME)
		ABORT_MPI("USECOUNT", "Match failed.");
	if (obj == PERMDENIED)
		ABORT_MPI("USECOUNT", "Permission denied.");

	snprintf(buf, BUFFER_LEN, "%d", DBFETCH(obj)->ts.usecount);

	return buf;
}
Esempio n. 4
0
const char *
mfn_links(MFUNARGS)
{
    char buf2[BUFFER_LEN];
    dbref   obj;
    int i, cnt;

    obj = mesg_dbref(player, what, perms, argv[0]);
    if (obj == AMBIGUOUS || obj == UNKNOWN || obj == NOTHING || obj == HOME)
	ABORT_MPI("LINKS","Match failed");
    if (obj == PERMDENIED)
	ABORT_MPI("LINKS",NOPERM_MESG);
    switch (Typeof(obj)) {
	case TYPE_ROOM:
	    obj = DBFETCH(obj)->sp.room.dropto;
	    break;
	case TYPE_PLAYER:
	    obj = DBFETCH(obj)->sp.player.home;
	    break;
	case TYPE_THING:
	    obj = DBFETCH(obj)->sp.thing.home;
	    break;
	case TYPE_EXIT: {
	    dbref obj2;
	    *buf = '\0';
	    cnt = DBFETCH(obj)->sp.exit.ndest;
	    if (cnt) {
		for (i = 0; i < cnt; i++) {
		    obj2 = DBFETCH(obj)->sp.exit.dest[i];
		    ref2str(obj2, buf2);
		    if (strlen(buf) + strlen(buf2) + 2 < BUFFER_LEN) {
			if (*buf) strcat(buf, "\r");
			strcat(buf, buf2);
		    } else break;
		}
		return buf;
	    } else {
		return "#-1";
	    }
	    break;
	}
	case TYPE_PROGRAM:
	default:
	    return "#-1";
	    break;
    }
    return ref2str(obj, buf);
}
Esempio n. 5
0
const char *
mfn_timesub(MFUNARGS)
{
	int num = 0;
	dbref trg = (dbref) 0, obj = what;
	const char *pname, *ptr;
	int period = 0, offset = 0;
	int blessed = 0;

	period = atoi(argv[0]);
	offset = atoi(argv[1]);
	pname = argv[2];
	if (argc == 4) {
		obj = mesg_dbref(descr, player, what, perms, argv[3], mesgtyp);
	}
	if (obj == PERMDENIED)
		ABORT_MPI("TIMESUB", "Permission denied.");
	if (obj == UNKNOWN || obj == AMBIGUOUS || obj == NOTHING || obj == HOME)
		ABORT_MPI("TIMESUB", "Match failed.");
	num = get_list_count(what, obj, perms, (char *)pname, mesgtyp, &blessed);
	if (!num)
		ABORT_MPI("TIMESUB", "Failed list read.");
	if (period < 1)
		ABORT_MPI("TIMESUB", "Time period too short.");
	offset = (int)((((long) time(NULL) + offset) % period) * num) / period;
	if (offset < 0)
		offset = -offset;
	ptr = get_list_item(what, obj, perms, (char *)pname, offset + 1, mesgtyp, &blessed);
	if (!ptr)
		ABORT_MPI("TIMESUB", "Failed list read.");
	trg = what;
	if (blessed) {
		mesgtyp |= MPI_ISBLESSED;
	} else {
		mesgtyp &= ~MPI_ISBLESSED;
	}
	if (Prop_ReadOnly(ptr) || Prop_Private(ptr) || Prop_SeeOnly(ptr) || Prop_Hidden(ptr))
		trg = obj;
	ptr = mesg_parse(descr, player, obj, trg, ptr, buf, BUFFER_LEN, mesgtyp);
	CHECKRETURN(ptr, "TIMESUB", "listval");
	return ptr;
}
Esempio n. 6
0
const char *
mfn_propbang(MFUNARGS)
{
	dbref obj = what;
	const char *ptr, *pname;
	int blessed = 0;

	pname = argv[0];
	if (argc == 2) {
		obj = mesg_dbref(descr, player, what, perms, argv[1], mesgtyp);
	}
	if (obj == UNKNOWN || obj == AMBIGUOUS || obj == NOTHING || obj == HOME)
		ABORT_MPI("PROP!", "Match failed.");
	if (obj == PERMDENIED)
		ABORT_MPI("PROP!", "Permission denied.");
	ptr = safegetprop_strict(player, obj, perms, pname, mesgtyp, &blessed);
	if (!ptr)
		ABORT_MPI("PROP!", "Failed read.");
	return ptr;
}
Esempio n. 7
0
const char *
mfn_list(MFUNARGS)
{
	dbref obj = what;
	char *pname;
	const char *ptr;
	int blessed;

	pname = argv[0];
	if (argc == 2) {
		obj = mesg_dbref(descr, player, what, perms, argv[1], mesgtyp);
	}
	if (obj == PERMDENIED)
		ABORT_MPI("LIST", "Permission denied.");
	if (obj == UNKNOWN || obj == AMBIGUOUS || obj == NOTHING || obj == HOME)
		ABORT_MPI("LIST", "Match failed.");
	ptr = get_concat_list(player, what, perms, obj, (char *)pname, buf, BUFFER_LEN, 0, mesgtyp, &blessed);
	if (!ptr)
		ptr = "";
	return ptr;
}
Esempio n. 8
0
const char *
mfn_propdir(MFUNARGS)
{
	dbref obj = what;
	const char *pname;

	pname = argv[0];
	if (argc == 2) {
		obj = mesg_dbref(descr, player, what, perms, argv[1], mesgtyp);
	}
	if (obj == UNKNOWN || obj == AMBIGUOUS || obj == NOTHING || obj == HOME)
		ABORT_MPI("PROPDIR", "Match failed.");
	if (obj == PERMDENIED)
		ABORT_MPI("PROPDIR", "Permission denied.");

	if (is_propdir(obj, pname)) {
		return "1";
	} else {
		return "0";
	}
}
Esempio n. 9
0
const char *
mfn_indexbang(MFUNARGS)
{
	dbref trg = (dbref) 0, obj = what;
	dbref tmpobj = (dbref) 0;
	const char *pname, *ptr;
	int blessed = 0;

	pname = argv[0];
	if (argc == 2) {
		obj = mesg_dbref(descr, player, what, perms, argv[1], mesgtyp);
	}
	if (obj == UNKNOWN || obj == AMBIGUOUS || obj == NOTHING || obj == HOME)
		ABORT_MPI("INDEX!", "Match failed.");
	if (obj == PERMDENIED)
		ABORT_MPI("INDEX!", "Permission denied.");
	tmpobj = obj;
	ptr = safegetprop_strict(player, obj, perms, pname, mesgtyp, &blessed);
	if (!ptr)
		ABORT_MPI("INDEX!", "Failed read.");
	if (!*ptr)
		return "";
	obj = tmpobj;
	ptr = safegetprop_strict(player, obj, perms, ptr, mesgtyp, &blessed);
	if (!ptr)
		ABORT_MPI("INDEX!", "Failed read.");
	trg = what;
	if (blessed) {
		mesgtyp |= MPI_ISBLESSED;
	} else {
		mesgtyp &= ~MPI_ISBLESSED;
	}
	if (Prop_ReadOnly(ptr) || Prop_Private(ptr) || Prop_SeeOnly(ptr) || Prop_Hidden(ptr))
		trg = obj;
	ptr = mesg_parse(descr, player, obj, trg, ptr, buf, BUFFER_LEN, mesgtyp);
	CHECKRETURN(ptr, "INDEX!", "listval");
	return ptr;
}
Esempio n. 10
0
const char *
mfn_exits(MFUNARGS)
{
    int outlen, nextlen;
    char buf2[50];
    int list_limit = MAX_MFUN_LIST_LEN;
    dbref obj = mesg_dbref(player, what, perms, argv[0]);

    if (obj == AMBIGUOUS || obj == UNKNOWN || obj == NOTHING || obj == HOME)
	ABORT_MPI("EXITS","Match failed");
    if (obj == PERMDENIED)
	ABORT_MPI("EXITS",NOPERM_MESG);

    switch(Typeof(obj)) {
	case TYPE_ROOM:
	case TYPE_THING:
	case TYPE_PLAYER:
	    obj = DBFETCH(obj)->exits;
	    break;
	default:
	    obj = NOTHING;
	    break;
    }
    *buf = '\0';
    outlen = 0;
    while (obj != NOTHING && list_limit) {
	ref2str(obj, buf2);
	nextlen = strlen(buf2);
	if ((outlen + nextlen) >= (BUFFER_LEN - 3))
	    break;
	if (outlen) strcat((buf + (outlen++)), "\r");
	strcat((buf + outlen), buf2);
	outlen += nextlen;
	list_limit--;
	obj = DBFETCH(obj)->next;
    }
    return buf;
}
Esempio n. 11
0
const char *
mfn_money(MFUNARGS)
{
	dbref obj = mesg_dbref(descr, player, what, perms, argv[0], mesgtyp);

	if (obj == UNKNOWN || obj == AMBIGUOUS || obj == NOTHING || obj == HOME)
		ABORT_MPI("MONEY", "Match failed.");
	if (obj == PERMDENIED)
		ABORT_MPI("MONEY", "Permission denied.");
	if (tp_pennies_muf_mlev > 1 && !(mesgtyp & MPI_ISBLESSED))
		ABORT_MPI("MONEY", "Permission denied.");
	switch (Typeof(obj)) {
	case TYPE_THING:
		snprintf(buf, BUFFER_LEN, "%d", GETVALUE(obj));
		break;
	case TYPE_PLAYER:
		snprintf(buf, BUFFER_LEN, "%d", GETVALUE(obj));
		break;
	default:
		strcpyn(buf, buflen, "0");
		break;
	}
	return buf;
}
Esempio n. 12
0
const char *
mfn_select(MFUNARGS)
{
	char origprop[BUFFER_LEN];
	char propname[BUFFER_LEN];
	char bestname[BUFFER_LEN];
	dbref obj = what;
	dbref bestobj = 0;
	char *pname;
	const char *ptr;
	char *out, *in;
	int i, targval, bestval;
	int baselen;
	int limit;
	int blessed = 0;

	pname = argv[1];
	if (argc == 3) {
		obj = mesg_dbref(descr, player, what, perms, argv[2], mesgtyp);
	}
	if (obj == PERMDENIED)
		ABORT_MPI("SELECT", "Permission denied.");
	if (obj == UNKNOWN || obj == AMBIGUOUS || obj == NOTHING || obj == HOME)
		ABORT_MPI("SELECT", "Match failed.");

	/*
	 * Search contiguously for a bit, looking for a best match.
	 * This allows fast hits on LARGE lists.
	 */

	limit = 18;
	i = targval = atoi(argv[0]);
	do {
		ptr = get_list_item(player, obj, perms, (char *)pname, i--, mesgtyp, &blessed);
	} while (limit-->0 && i >= 0 && ptr && !*ptr);
	if (ptr == NULL)
		ABORT_MPI("SELECT", "Failed list read.");
	if (*ptr != '\0')
		return ptr;

	/*
	 * If we didn't find it before, search only existing props.
	 * This gets fast hits on very SPARSE lists.
	 */

	/* First, normalize the base propname */
	out = origprop;
	in = argv[1];
	while (*in != '\0') {
		*out++ = PROPDIR_DELIMITER;
		while (*in == PROPDIR_DELIMITER) in++;
		while (*in && *in != PROPDIR_DELIMITER) *out++ = *in++;
	}
	*out++ = '\0';

	i = targval;
	bestname[0] = '\0';
	bestval = 0;
	baselen = strlen(origprop);
	for (; obj != NOTHING; obj = getparent(obj)) {
		pname = next_prop_name(obj, propname, sizeof(propname), origprop);
		while (pname && string_prefix(pname, origprop)) {
			ptr = pname + baselen;
			if (*ptr == NUMBER_TOKEN) ptr++;
			if (!*ptr && is_propdir(obj, pname)) {
				char propname2[BUFFER_LEN];
				char *pname2;
				int sublen = strlen(pname);

				pname2 = strcpyn(propname2, sizeof(propname2), pname);
				propname2[sublen++] = PROPDIR_DELIMITER;
				propname2[sublen] = '\0';

				pname2 = next_prop_name(obj, propname2, sizeof(propname2), pname2);
				while (pname2) {
					ptr = pname2 + sublen;
					if (number(ptr)) {
						i = atoi(ptr);
						if (bestval < i && i <= targval) {
							bestval = i;
							bestobj = obj;
							strcpyn(bestname, sizeof(bestname), pname2);
						}
					}
					pname2 = next_prop_name(obj, propname2, sizeof(propname2), pname2);
				}
			}
			ptr = pname + baselen;
			if (number(ptr)) {
				i = atoi(ptr);
				if (bestval < i && i <= targval) {
					bestval = i;
					bestobj = obj;
					strcpyn(bestname, sizeof(bestname), pname);
				}
			}
			pname = next_prop_name(obj, propname, sizeof(propname), pname);
		}
	}
	
	if (*bestname) {
		ptr = safegetprop_strict(player, bestobj, perms, bestname, mesgtyp, &blessed);
		if (!ptr)
			ABORT_MPI("SELECT", "Failed property read.");
	} else {
		ptr = "";
	}
	return ptr;
}
Esempio n. 13
0
const char *
mfn_listprops(MFUNARGS)
{
	dbref obj = what;
	char *ptr, *pname;
	char *endbuf, *pattern;
	char tmpbuf[BUFFER_LEN];
	char patbuf[BUFFER_LEN];
	char pnamebuf[BUFFER_LEN];
	int flag;

	strcpyn(pnamebuf, sizeof(pnamebuf), argv[0]);
	pname = pnamebuf;
	if (argc > 1) {
		obj = mesg_dbref(descr, player, what, perms, argv[1], mesgtyp);
	}
	if (obj == UNKNOWN || obj == AMBIGUOUS || obj == NOTHING || obj == HOME)
		ABORT_MPI("LISTPROPS", "Match failed.");
	if (obj == PERMDENIED)
		ABORT_MPI("LISTPROPS", "Permission denied.");

	if (argc > 2) {
		pattern = argv[2];
	} else {
		pattern = NULL;
	}

	endbuf = pname + strlen(pname);
	if (endbuf != pname) {
		endbuf--;
	}
	if (*endbuf != PROPDIR_DELIMITER && (endbuf - pname) < (BUFFER_LEN - 2)) {
		if (*endbuf != '\0')
			endbuf++;
		*endbuf++ = PROPDIR_DELIMITER;
		*endbuf++ = '\0';
	}

	*buf = '\0';
	endbuf = buf;
	do {
		ptr = next_prop_name(obj, tmpbuf, (int) sizeof(tmpbuf), pname);
		if (ptr && *ptr) {
			flag = 1;
			if (Prop_System(ptr)) {
				flag = 0;
			} else if (!(mesgtyp & MPI_ISBLESSED)) {
				if (Prop_Hidden(ptr)) {
					flag = 0;
				}
				if (Prop_Private(ptr) && OWNER(what) != OWNER(obj)) {
					flag = 0;
				}
				if (obj != player && OWNER(obj) != OWNER(what)) {
					flag = 0;
				}
			}
			if ((flag != 0) && (pattern != NULL)) {
				char *nptr;

				nptr = rindex(ptr, PROPDIR_DELIMITER);
				if (nptr && *nptr) {
					strcpyn(patbuf, sizeof(patbuf), ++nptr);
					if (!equalstr(pattern, patbuf)) {
						flag = 0;
					}
				}
			}
			if (flag) {
				int entrylen = strlen(ptr);
				if ((endbuf - buf) + entrylen + 2 < BUFFER_LEN) {
					if (*buf != '\0') {
						*endbuf++ = '\r';
					}
					strcpyn(endbuf, BUFFER_LEN - (endbuf - buf), ptr);
					endbuf += entrylen;
				}
			}
		}
		pname = ptr;
	} while (ptr && *ptr);

	return buf;
}