コード例 #1
0
ファイル: eval.c プロジェクト: gtaylor/btmux
char *parse_arglist(dbref player, dbref cause, char *dstr, char delim,
					dbref eval, char *fargs[], dbref nfargs, char *cargs[],
					dbref ncargs)
{
	char *rstr, *tstr, *bp, *str;
	int arg, peval;

	for(arg = 0; arg < nfargs; arg++)
		fargs[arg] = NULL;
	if(dstr == NULL)
		return NULL;
	rstr = parse_to(&dstr, delim, 0);
	arg = 0;

	peval = (eval & ~EV_EVAL);

	while ((arg < nfargs) && rstr) {
		if(arg < (nfargs - 1))
			tstr = parse_to(&rstr, ',', peval);
		else
			tstr = parse_to(&rstr, '\0', peval);
		if(eval & EV_EVAL) {
			bp = fargs[arg] = alloc_lbuf("parse_arglist");
			str = tstr;
			exec(fargs[arg], &bp, 0, player, cause, eval | EV_FCHECK, &str,
				 cargs, ncargs);
			*bp = '\0';
		} else {
			fargs[arg] = alloc_lbuf("parse_arglist");
			StringCopy(fargs[arg], tstr);
		}
		arg++;
	}
	return dstr;
}
コード例 #2
0
ファイル: flags.cpp プロジェクト: sanjayui/tinymux
static UTF8 *AcquireColorLetters(dbref player, dbref target)
{
    int   aflags;
    dbref aowner;

    // Get the value of the object's '@color' attribute (or on a parent).
    //
    UTF8 *color_attr = alloc_lbuf("AcquireColor.1");
    atr_pget_str(color_attr, target, A_COLOR, &aowner, &aflags);

    if ('\0' == color_attr[0])
    {
        free_lbuf(color_attr);
        return NULL;
    }
    else
    {
        UTF8 *AnsiCodes = alloc_lbuf("AcquireColor.2");
        UTF8 *ac = AnsiCodes;
        mux_exec(color_attr, LBUF_SIZE-1, AnsiCodes, &ac, player, target, target,
                AttrTrace(aflags, EV_EVAL|EV_TOP|EV_FCHECK), NULL, 0);
        *ac = '\0';
        free_lbuf(color_attr);
        return AnsiCodes;
    }
}
コード例 #3
0
ファイル: quota.cpp プロジェクト: sanjayui/tinymux
static void show_quota(dbref player, dbref victim)
{
    dbref aowner;
    int aflags;
    UTF8 *buff = alloc_lbuf("show_quota");

    atr_get_str(buff, victim, A_QUOTA, &aowner, &aflags);
    int aq = mux_atol(buff);
    atr_get_str(buff, victim, A_RQUOTA, &aowner, &aflags);
    int rq = aq - mux_atol(buff);

    mux_field fldName = StripTabsAndTruncate(Name(victim), buff, LBUF_SIZE-1, 16);

    if (!Free_Quota(victim))
    {
        mux_sprintf(buff + fldName.m_byte, LBUF_SIZE - fldName.m_byte,
                    T(" Quota: %9d  Used: %9d"), aq, rq);
    }
    else
    {
        mux_sprintf(buff + fldName.m_byte, LBUF_SIZE - fldName.m_byte,
                     T(" Quota: UNLIMITED  Used: %9d"), rq);
    }
    notify_quiet(player, buff);
    free_lbuf(buff);
}
コード例 #4
0
ファイル: nametab.c プロジェクト: chazu/btmux
void interp_nametab(dbref player, NAMETAB * ntab, int flagword, char *prefix,
					char *true_text, char *false_text)
{
	char *buf, *bp, *cp;
	NAMETAB *nt;

	buf = alloc_lbuf("interp_nametab");
	bp = buf;
	for(cp = prefix; *cp; cp++)
		*bp++ = *cp;
	nt = ntab;
	while (nt->name) {
		if(God(player) || check_access(player, nt->perm)) {
			*bp++ = ' ';
			for(cp = nt->name; *cp; cp++)
				*bp++ = *cp;
			*bp++ = '.';
			*bp++ = '.';
			*bp++ = '.';
			if((flagword & nt->flag) != 0)
				cp = true_text;
			else
				cp = false_text;
			while (*cp)
				*bp++ = *cp++;
			if((++nt)->name)
				*bp++ = ';';
		}
	}
	*bp = '\0';
	notify(player, buf);
	free_lbuf(buf);
}
コード例 #5
0
ファイル: create.c プロジェクト: pdbogen/RhostMUSH
static void 
open_exit(dbref player, dbref loc, char *direction, char *linkto, int key)
{
    dbref exit;
    char *tpr_buff, *tprp_buff;

    if (!Good_obj(loc))
	return;

    if (!direction || !*direction) {
	notify_quiet(player, "Open where?");
	return;
    } else if (!controls(player, loc) && !could_doit(player, loc, A_LOPEN, 0, 0)) {
	notify_quiet(player, "Permission denied.");
	return;
    }
    exit = create_obj(player, TYPE_EXIT, direction, 0);
    if (exit == NOTHING)
	return;

    /* Initialize everything and link it in. */

    s_Exits(exit, loc);
    s_Next(exit, Exits(loc));
    s_Exits(loc, exit);

    /* and we're done */

    if ( !(key & SIDEEFFECT ) )
       notify_quiet(player, "Opened.");

    /* See if we should do a link */

    if (!linkto || !*linkto)
	return;

    loc = parse_linkable_room(player, linkto);
    if (loc != NOTHING) {

	/* Make sure the player passes the link lock */

	if ((loc != HOME) && !could_doit(player, loc, A_LLINK, 1, 0)) {
	    notify_quiet(player, "You can't link to there.");
	    return;
	}
	/* Link it if the player can pay for it */

	if (!payfor(player, mudconf.linkcost)) {
            tprp_buff = tpr_buff = alloc_lbuf("open_exit");
	    notify_quiet(player,
			 safe_tprintf(tpr_buff, &tprp_buff, "You don't have enough %s to link.",
				 mudconf.many_coins));
            free_lbuf(tpr_buff);
	} else {
	    s_Location(exit, loc);
	    if ( !(key & SIDEEFFECT ) )
	       notify_quiet(player, "Linked.");
	}
    }
}
コード例 #6
0
ファイル: nametab.c プロジェクト: chazu/btmux
void display_nametab(dbref player, NAMETAB * ntab, char *prefix,
					 int list_if_none)
{
	char *buf, *bp, *cp;
	NAMETAB *nt;
	int got_one;

	buf = alloc_lbuf("display_nametab");
	bp = buf;
	got_one = 0;
	for(cp = prefix; *cp; cp++)
		*bp++ = *cp;
	for(nt = ntab; nt->name; nt++) {
		if(God(player) || check_access(player, nt->perm)) {
			*bp++ = ' ';
			for(cp = nt->name; *cp; cp++)
				*bp++ = *cp;
			got_one = 1;
		}
	}
	*bp = '\0';
	if(got_one || list_if_none)
		notify(player, buf);
	free_lbuf(buf);
}
コード例 #7
0
ファイル: match.cpp プロジェクト: sanjayui/tinymux
// Check for a matching named reference.
//
static dbref absolute_named_reference(UTF8 *name)
{
    if (  NULL == name
       || '\0' == name[0])
    {
        return NOTHING;
    }

    mux_string sRef(name);
    if ('_' != name[0])
    {
        sRef.append(T("."));
        sRef.append(md.player);
    }

    UTF8 *pReferenceName = alloc_lbuf("absolute_named_reference");
    size_t nReferenceName = 0;
    nReferenceName = sRef.export_TextPlain(pReferenceName);

    struct reference_entry *result = (reference_entry *)hashfindLEN(
        pReferenceName, nReferenceName, &mudstate.reference_htab);
    free_lbuf(pReferenceName);

    if (  NULL != result
       && Good_obj(result->target))
    {
        return result->target;
    }
    else
    {
        return NOTHING;
    }
}
コード例 #8
0
ファイル: help.cpp プロジェクト: sanjayui/tinymux
void help_helper(dbref executor, int iHelpfile, UTF8 *topic_arg,
    UTF8 *buff, UTF8 **bufc)
{
    if (!ValidateHelpFileIndex(iHelpfile))
    {
        return;
    }

    size_t nTopic;
    const UTF8 *topic = MakeCanonicalTopicName(topic_arg, nTopic);

    CHashTable *htab = mudstate.aHelpDesc[iHelpfile].ht;
    struct help_entry *htab_entry =
        (struct help_entry *)hashfindLEN(topic, nTopic, htab);

    if (htab_entry)
    {
        UTF8 *result = alloc_lbuf("help_helper");
        if (ReportTopic(executor, htab_entry, iHelpfile, result))
        {
            safe_str(result, buff, bufc);
        }
        else
        {
            safe_str(T("#-1 ERROR"), buff, bufc);
        }
        free_lbuf(result);
    }
    else
    {
        safe_str(T("#-1 TOPIC DOES NOT EXIST"), buff, bufc);
    }
}
コード例 #9
0
ファイル: nametab.c プロジェクト: chazu/btmux
void listset_nametab(dbref player, NAMETAB * ntab, int flagword, char *prefix,
					 int list_if_none)
{
	char *buf, *bp, *cp;
	NAMETAB *nt;
	int got_one;

	buf = bp = alloc_lbuf("listset_nametab");
	for(cp = prefix; *cp; cp++)
		*bp++ = *cp;
	nt = ntab;
	got_one = 0;
	while (nt->name) {
		if(((flagword & nt->flag) != 0) && (God(player) ||
											check_access(player, nt->perm))) {
			*bp++ = ' ';
			for(cp = nt->name; *cp; cp++)
				*bp++ = *cp;
			got_one = 1;
		}
		nt++;
	}
	*bp = '\0';
	if(got_one || list_if_none)
		notify(player, buf);
	free_lbuf(buf);
}
コード例 #10
0
ファイル: flags.cpp プロジェクト: sanjayui/tinymux
void display_flagtab(dbref player)
{
    UTF8 *buf, *bp;
    FLAGNAMEENT *fp;

    bp = buf = alloc_lbuf("display_flagtab");
    safe_str(T("Flags:"), buf, &bp);
    for (fp = gen_flag_names; fp->flagname; fp++)
    {
        FLAGBITENT *fbe = fp->fbe;
        if (  (  (fbe->listperm & CA_WIZARD)
              && !Wizard(player))
           || (  (fbe->listperm & CA_GOD)
              && !God(player)))
        {
            continue;
        }
        safe_chr(' ', buf, &bp);
        safe_str(fp->flagname, buf, &bp);
        if (fbe->flaglett != ' ')
        {
            safe_chr('(', buf, &bp);
            if (!fp->bPositive)
            {
                safe_chr('!', buf, &bp);
            }
            safe_chr(fbe->flaglett, buf, &bp);
            safe_chr(')', buf, &bp);
        }
    }
    *bp = '\0';
    notify(player, buf);
    free_lbuf(buf);
}
コード例 #11
0
ファイル: help.cpp プロジェクト: sanjayui/tinymux
static void help_write(dbref executor, UTF8 *topic_arg, int iHelpfile)
{
    size_t nTopic;
    const UTF8 *topic = MakeCanonicalTopicName(topic_arg, nTopic);

    CHashTable *htab = mudstate.aHelpDesc[iHelpfile].ht;
    struct help_entry *htab_entry =
        (struct help_entry *)hashfindLEN(topic, nTopic, htab);

    if (htab_entry)
    {
        UTF8 *result = alloc_lbuf("help_write");
        if (ReportTopic(executor, htab_entry, iHelpfile, result))
        {
            notify(executor, result);
        }
        else
        {
            notify(executor, T("Sorry, that function is temporarily unavailable."));
        }
        free_lbuf(result);
    }
    else
    {
        ReportMatchedTopics(executor, topic, htab);
        return;
    }
}
コード例 #12
0
ファイル: db_rw.c プロジェクト: chazu/btmux
static int get_list(FILE * f, dbref i, int new_strings)
{
	dbref atr;
	int c;
	char *buff;

	buff = alloc_lbuf("get_list");
	while (1) {
		switch (c = getc(f)) {
		case '>':				/*
								 * read # then string 
								 */
			atr = getref(f);
			if(atr > 0) {
				/*
				 * Store the attr 
				 */

				atr_add_raw(i, atr, (char *) getstring_noalloc(f,
															   new_strings));
			} else {
				/*
				 * Silently discard 
				 */

				getstring_noalloc(f, new_strings);
			}
			break;
		case '\n':				/*
								 * ignore newlines. They're due to v(r). 
								 */
			break;
		case '<':				/*
								 * end of list 
								 */
			free_lbuf(buff);
			c = getc(f);
			if(c != '\n') {
				ungetc(c, f);
				fprintf(stderr, "No line feed on object %d\n", i);
				return 1;
			}
			return 1;
		default:
			fprintf(stderr,
					"Bad character '%c' when getting attributes on object %d\n",
					c, i);
			/*
			 * We've found a bad spot.  I hope things aren't * *
			 * * * * * too bad. 
			 */

			(void) getstring_noalloc(f, new_strings);
		}
	}
}
コード例 #13
0
ファイル: match.c プロジェクト: TinyMUSH/TinyMUSH
dbref absolute_nref(char *str)
{
    char *p, *q, *buf, *bp;
    dbref *np, nref;
    /*
     * Global or local reference? Global references are automatically
     * * prepended with an additional underscore. i.e., #__foo_ is a global
     * * reference, and #_foo_ is a local reference.
     * * Our beginning and end underscores have already been stripped, so
     * * we would see only _foo or foo.
     * *
     * * We are not allowed to nibble our buffer, because we've got a
     * * pointer into the match string. Therefore we must copy it.
     * * If we're matching locally we copy the dbref of the owner first,
     * * which means that we then need to worry about buffer size.
     */
    buf = alloc_lbuf("absolute_nref");

    if (*str == '_') {
	for (p = buf, q = str; *q; p++, q++) {
	    *p = tolower(*q);
	}

	*p = '\0';
    } else {
	bp = buf;
	safe_ltos(buf, &bp, Owner(md.player), LBUF_SIZE);
	safe_chr('.', buf, &bp);

	for (q = str; *q; q++) {
	    safe_chr(tolower(*q), buf, &bp);
	}

	*bp = '\0';
    }

    np = (int *) hashfind(buf, &mudstate.nref_htab);

    if (np && Good_obj(*np)) {
	nref = *np;
    } else {
	nref = NOTHING;
    }

    free_lbuf(buf);
    return nref;
}
コード例 #14
0
ファイル: flags.cpp プロジェクト: sanjayui/tinymux
UTF8 *unparse_object_numonly(dbref target)
{
    UTF8 *buf = alloc_lbuf("unparse_object_numonly");
    if (target < 0)
    {
        mux_strncpy(buf, aszSpecialDBRefNames[-target], LBUF_SIZE-1);
    }
    else if (!Good_obj(target))
    {
        mux_sprintf(buf, LBUF_SIZE, T("*ILLEGAL*(#%d)"), target);
    }
    else
    {
        mux_sprintf(buf, LBUF_SIZE, T("%s(#%d)"), PureName(target), target);
    }
    return buf;
}
コード例 #15
0
ファイル: flags.c プロジェクト: sean-brandt/tinymush
char *unparse_object( dbref player, dbref target, int obey_myopic ) {
    char *buf, *fp, *bp;

    int exam;

    buf = alloc_lbuf( "unparse_object" );
    if( target == NOTHING ) {
        strcpy( buf, "*NOTHING*" );
    } else if( target == HOME ) {
        strcpy( buf, "*HOME*" );
    } else if( target == AMBIGUOUS ) {
        strcpy( buf, "*VARIABLE*" );
    } else if( isGarbage( target ) ) {
        fp = unparse_flags( player, target );
        bp = buf;
        safe_sprintf( buf, &bp, "*GARBAGE*(#%d%s)", target, fp );
        free_sbuf( fp );
    } else if( !Good_obj( target ) ) {
        sprintf( buf, "*ILLEGAL*(#%d)", target );
    } else {
        if( obey_myopic ) {
            exam = MyopicExam( player, target );
        } else {
            exam = Examinable( player, target );
        }
        if( exam ||
                ( Flags( target ) & ( CHOWN_OK | JUMP_OK | LINK_OK |
                                      DESTROY_OK ) ) || ( Flags2( target ) & ABODE ) ) {

            /*
             * show everything
             */
            fp = unparse_flags( player, target );
            bp = buf;
            safe_sprintf( buf, &bp, "%s(#%d%s)", Name( target ), target, fp );
            free_sbuf( fp );
        } else {
            /*
             * show only the name.
             */
            strcpy( buf, Name( target ) );
        }
    }
    return buf;
}
コード例 #16
0
ファイル: flags.c プロジェクト: sean-brandt/tinymush
char *unparse_object_numonly( dbref target ) {
    char *buf, *bp;

    buf = alloc_lbuf( "unparse_object_numonly" );
    if( target == NOTHING ) {
        strcpy( buf, "*NOTHING*" );
    } else if( target == HOME ) {
        strcpy( buf, "*HOME*" );
    } else if( target == AMBIGUOUS ) {
        strcpy( buf, "*VARIABLE*" );
    } else if( !Good_obj( target ) ) {
        sprintf( buf, "*ILLEGAL*(#%d)", target );
    } else {
        bp = buf;
        safe_sprintf( buf, &bp, "%s(#%d)", Name( target ), target );
    }
    return buf;
}
コード例 #17
0
ファイル: mguests.c プロジェクト: chazu/btmux
dbref create_guest(char *name, char *password)
{
	dbref player;
	char *buff;

	if(!Wizard(mudconf.guest_nuker) || !Good_obj(mudconf.guest_nuker))
		mudconf.guest_nuker = 1;

	buff = alloc_lbuf("create_guest");

	/*
	 * Make the player. 
	 */

	player = create_player(name, password, mudconf.guest_nuker, 0, 1);

	if(player == NOTHING) {
		log_text("GUEST: failed in create_player\n");
		return NOTHING;
	}
	/*
	 * Turn the player into a guest. 
	 */

	s_Guest(player);
	move_object(player, mudconf.start_room);
	s_Flags(player, Flags(player) & ~WIZARD);
	s_Pennies(player, Pennies(mudconf.guest_char));
	s_Zone(player, Zone(mudconf.guest_char));
	s_Parent(player, Parent(mudconf.guest_char));

	/*
	 * Make sure the guest is locked. 
	 */
	do_lock(player, player, A_LOCK, tprintf("#%d", player), "me");
	do_lock(player, player, A_LENTER, tprintf("#%d", player), "me");

	/*
	 * Copy all attributes. 
	 */
	atr_cpy(GOD, player, mudconf.guest_char);
	free_lbuf(buff);
	return player;
}
コード例 #18
0
char *trim_spaces(char *string)
{
char	*buffer, *p, *q;

	buffer = alloc_lbuf("trim_spaces");
	p = string;
	q = buffer;
	while (p && *p && isspace((int)*p))		/* remove inital spaces */
		p++;
	while (p && *p) {
		while (*p && !isspace((int)*p))	/* copy nonspace chars */
			*q++ = *p++;
		while (*p && isspace((int)*p))	/* compress spaces */
			p++;
		if (*p) *q++ = ' ';		/* leave one space */
	}
	*q = '\0';				/* terminate string */
	return (buffer);
}
コード例 #19
0
ファイル: door_mush.c プロジェクト: Haunted-Memories/rhost
int mushDoorOpen(DESC *d, int nArgs, char *args[], int id) {
  dbref loc, player = d->player;
  int sock, i_found, retval;
  char *t_buff, *t_bufptr, *s_addy, *s_port, *s_strtok;

  i_found = 1;
  t_bufptr = t_buff = alloc_lbuf("mush_doors");
  s_port = s_strtok = NULL;
  retval = parse_dynhelp(player, player, 0, (char *)"doors", args[0], t_buff, t_bufptr, 1); 
  if ( t_buff && *t_buff && 
       ((strstr(t_buff, (char *)"No entry for") != NULL) ||
        (strstr(t_buff, (char *)"Here are the entries which match") != NULL) ||
        (strstr(t_buff, (char *)"Sorry, that file") != NULL)) ) 
     i_found = 0;
  loc = Location(player);
  if ( i_found && *t_buff && args[0] && *args[0]) {
     s_addy = strtok_r(t_buff, " \t\r\n", &s_strtok);
     if ( s_addy )
        s_port = strtok_r(NULL, " \t\r\n", &s_strtok);
     if ( s_addy && s_port )
        sock = door_tcp_connect(s_addy, s_port, d, id);
     else
        sock = -1;
     if (sock < 0) {
       queue_string(desc_in_use, "Mush connection failed\r\n");
       free_lbuf(t_buff);
       return -1;
     } else {
       queue_string(desc_in_use, "*** CONNECTED ***\r\n");
     }
  } else if ( !i_found || (i_found && args[0] && *args[0]) ) {
     if ( strstr(t_buff, (char *)"Sorry, that file") != NULL )
        queue_string(desc_in_use, "There are currently no mush doors configured.\r\n");
     else
        queue_string(desc_in_use, "Unrecognized mush.  Can not establish connection.\r\n");
     free_lbuf(t_buff);
     return -1;
  } else if ( i_found && (!args[0] || !*args[0]) && t_buff ) {
     queue_string(desc_in_use, t_buff);
  }
  free_lbuf(t_buff);
  return 1;
}
コード例 #20
0
char *munge_space(char *string)
{
char	*buffer, *p, *q;

	buffer = alloc_lbuf("munge_space");
	p = string;
	q = buffer;
	while (p && *p && isspace((int)*p))
		p++;		/* remove inital spaces */
	while (p && *p) {
		while (*p && !isspace((int)*p))
			*q++ = *p++;
		while (*p && isspace((int)*++p)) ;
			if (*p)
				*q++ = ' ';
	}
	*q = '\0';		/* remove terminal spaces and terminate
				 * string */
	return (buffer);
}
コード例 #21
0
ファイル: eval.c プロジェクト: gtaylor/btmux
static void tcache_add(char *orig, char *result)
{
	char *tp;
	TCENT *xp;

	if(strcmp(orig, result)) {
		tcache_count++;
		if(tcache_count <= mudconf.trace_limit) {
			xp = (TCENT *) alloc_sbuf("tcache_add.sbuf");
			tp = alloc_lbuf("tcache_add.lbuf");
			StringCopy(tp, result);
			xp->orig = orig;
			xp->result = tp;
			xp->next = tcache_head;
			tcache_head = xp;
		} else {
			free_lbuf(orig);
		}
	} else {
		free_lbuf(orig);
	}
}
コード例 #22
0
ファイル: help.cpp プロジェクト: sanjayui/tinymux
static void ReportMatchedTopics(dbref executor, const UTF8 *topic, CHashTable *htab)
{
    bool matched = false;
    UTF8 *topic_list = NULL;
    UTF8 *buffp = NULL;
    struct help_entry *htab_entry;
    for (htab_entry = (struct help_entry *)hash_firstentry(htab);
         htab_entry != NULL;
         htab_entry = (struct help_entry *)hash_nextentry(htab))
    {
        mudstate.wild_invk_ctr = 0;
        if (  htab_entry->key
           && quick_wild(topic, htab_entry->key))
        {
            if (!matched)
            {
                matched = true;
                topic_list = alloc_lbuf("help_write");
                buffp = topic_list;
            }
            safe_str(htab_entry->key, topic_list, &buffp);
            safe_chr(' ', topic_list, &buffp);
            safe_chr(' ', topic_list, &buffp);
        }
    }

    if (!matched)
    {
        notify(executor, tprintf(T("No entry for \xE2\x80\x98%s\xE2\x80\x99."), topic));
    }
    else
    {
        notify(executor, tprintf(T("Here are the entries which match \xE2\x80\x98%s\xE2\x80\x99:"), topic));
        *buffp = '\0';
        notify(executor, topic_list);
        free_lbuf(topic_list);
    }
}
コード例 #23
0
ファイル: flags.c プロジェクト: sean-brandt/tinymush
void display_flagtab( dbref player ) {
    char *buf, *bp;

    FLAGENT *fp;

    bp = buf = alloc_lbuf( "display_flagtab" );
    safe_str( ( char * ) "Flags:", buf, &bp );
    for( fp = gen_flags; fp->flagname; fp++ ) {
        if( ( fp->listperm & CA_WIZARD ) && !Wizard( player ) ) {
            continue;
        }
        if( ( fp->listperm & CA_GOD ) && !God( player ) ) {
            continue;
        }
        safe_chr( ' ', buf, &bp );
        safe_str( ( char * ) fp->flagname, buf, &bp );
        safe_chr( '(', buf, &bp );
        safe_chr( fp->flaglett, buf, &bp );
        safe_chr( ')', buf, &bp );
    }
    *bp = '\0';
    notify( player, buf );
    free_lbuf( buf );
}
コード例 #24
0
ファイル: powers.c プロジェクト: TinyMUSH/TinyMUSH
void display_powertab(dbref player)
{
    char *buf, *bp;
    POWERENT *fp;
    bp = buf = alloc_lbuf("display_powertab");
    safe_str((char *) "Powers:", buf, &bp);

    for (fp = gen_powers; fp->powername; fp++) {
	if ((fp->listperm & CA_WIZARD) && !Wizard(player)) {
	    continue;
	}

	if ((fp->listperm & CA_GOD) && !God(player)) {
	    continue;
	}

	safe_chr(' ', buf, &bp);
	safe_str((char *) fp->powername, buf, &bp);
    }

    *bp = '\0';
    notify(player, buf);
    free_lbuf(buf);
}
コード例 #25
0
ファイル: plusemail.cpp プロジェクト: sanjayui/tinymux
void do_plusemail(dbref executor, dbref cause, dbref enactor, int eval, int key,
                 int nargs, UTF8 *arg1, UTF8 *arg2, const UTF8 *cargs[], int ncargs)
{
    UNUSED_PARAMETER(cause);
    UNUSED_PARAMETER(enactor);
    UNUSED_PARAMETER(eval);
    UNUSED_PARAMETER(key);
    UNUSED_PARAMETER(nargs);
    UNUSED_PARAMETER(cargs);
    UNUSED_PARAMETER(ncargs);

    UTF8 inputline[LBUF_SIZE];

    if ('\0' == mudconf.mail_server[0])
    {
        notify(executor, T("@email: Not configured"));
        return;
    }

    if (!arg1 || !*arg1)
    {
        notify(executor, T("@email: I don\xE2\x80\x99t know who you want to e-mail!"));
        return;
    }

    if (!arg2 || !*arg2)
    {
        notify(executor, T("@email: Not sending an empty e-mail!"));
        return;
    }

    UTF8 *addy = alloc_lbuf("mod_email_do_email.headers");
    UTF8 *bp = addy;
    safe_str(arg1, addy, &bp);
    *bp = '\0';

    UTF8 *subject = (UTF8 *)strchr((char *)addy, '/');
    if (subject)
    {
        *subject = '\0';
        subject++;
    }
    else
    {
        subject = mudconf.mail_subject;
    }

    UTF8 *pMailServer = ConvertCRLFtoSpace(mudconf.mail_server);
    SOCKET mailsock = INVALID_SOCKET;
    int result = mod_email_sock_open(pMailServer, 25, &mailsock);

    if (-1 == result)
    {
        notify(executor, tprintf(T("@email: Unable to resolve hostname %s!"),
            pMailServer));
        free_lbuf(addy);
        return;
    }
    else if (-2 == result)
    {
        // Periodically, we get a failed connect, for reasons which elude me.
        // In almost every case, an immediate retry works.  Therefore, we give
        // it one more shot, before we give up.
        //
        result = mod_email_sock_open(pMailServer, 25, &mailsock);
        if (0 != result)
        {
            notify(executor, T("@email: Unable to connect to mailserver, aborting!"));
            free_lbuf(addy);
            return;
        }
    }

    UTF8 *body = alloc_lbuf("mod_email_do_email.body");
    UTF8 *bodyptr = body;
    mux_exec(arg2, LBUF_SIZE-1, body, &bodyptr, executor, executor, executor,
        EV_TOP | EV_STRIP_CURLY | EV_FCHECK | EV_EVAL, NULL, 0);
    *bodyptr = '\0';

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('2' != inputline[0])
    {
        mod_email_sock_close(mailsock);
        notify(executor, tprintf(T("@email: Invalid mailserver greeting (%s)"),
            inputline));
    }

    mod_email_sock_printf(mailsock, T("EHLO %s\r\n"), ConvertCRLFtoSpace(mudconf.mail_ehlo));

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('2' != inputline[0])
    {
        notify(executor, tprintf(T("@email: Error response on EHLO (%s)"),
            inputline));
    }

    mod_email_sock_printf(mailsock, T("MAIL FROM:<%s>\r\n"), ConvertCRLFtoSpace(mudconf.mail_sendaddr));

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('2' != inputline[0])
    {
        notify(executor, tprintf(T("@email: Error response on MAIL FROM (%s)"),
            inputline));
    }

    mod_email_sock_printf(mailsock, T("RCPT TO:<%s>\r\n"), ConvertCRLFtoSpace(addy));

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('2' != inputline[0])
    {
        notify(executor, tprintf(T("@email: Error response on RCPT TO (%s)"),
            inputline));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    mod_email_sock_printf(mailsock, T("DATA\r\n"));

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('3' != inputline[0])
    {
        notify(executor, tprintf(T("@email: Error response on DATA (%s)"),
            inputline));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    UTF8 *pSendName = StringClone(ConvertCRLFtoSpace(mudconf.mail_sendname));
    mod_email_sock_printf(mailsock, T("From: %s <%s>\r\n"),  pSendName, ConvertCRLFtoSpace(mudconf.mail_sendaddr));
    MEMFREE(pSendName);

    mod_email_sock_printf(mailsock, T("To: %s\r\n"), ConvertCRLFtoSpace(addy));
    mod_email_sock_printf(mailsock, T("X-Mailer: TinyMUX %s\r\n"), mudstate.short_ver);
    mod_email_sock_printf(mailsock, T("Subject: %s\r\n\r\n"), ConvertCRLFtoSpace(subject));

    // The body is encoded to include the CRLF.CRLF at the end.
    //
    mod_email_sock_printf(mailsock, T("%s"), EncodeBody(body));

    do
    {
        result = mod_email_sock_readline(mailsock, inputline, LBUF_SIZE - 1);

        // Remove trailing CR and LF characters.
        //
        while (  0 < result
              && (  '\n' == inputline[result-1]
                 || '\r' == inputline[result-1]))
        {
            result--;
            inputline[result] = '\0';
        }
    } while (  0 == result
            || (  3 < result
               && '-' == inputline[3]));

    if (-1 == result)
    {
        mod_email_sock_close(mailsock);
        notify(executor, T("@email: Connection to mailserver lost."));
        free_lbuf(body);
        free_lbuf(addy);
        return;
    }

    if ('2' != inputline[0])
    {
        notify(executor, tprintf(T("@email: Message rejected (%s)"), inputline));
    }
    else
    {
        notify(executor, tprintf(T("@email: Mail sent to %s (%s)"), ConvertCRLFtoSpace(addy), &inputline[4]));
    }

    mod_email_sock_printf(mailsock, T("QUIT\n"));
    mod_email_sock_close(mailsock);

    free_lbuf(body);
    free_lbuf(addy);
}
コード例 #26
0
ファイル: empire.c プロジェクト: RhostMUSH/trunk
int empire_from_empsrv(DESC *d, char *text)
{
  char *pt1, *pt2, *pt3, *tstrtokr;
  int code;

  pt1 = strtok_r(text,"\n", &tstrtokr);
  if (pt1 != NULL) {
    do {
      pt2 = pt1;
      while (*pt2 && !isspace((int)*pt2))
	pt2++;
      *pt2++ = '\0';
      if (isalpha((int)*pt1))
	code = 10 + (*pt1 - 'a');
      else
	code = *pt1 - '0';
      switch (code) {
	case C_PROMPT:
	  if (sscanf(pt2,"%d %d", &(d->door_int2), &(d->door_int3)) != 2)
	    queue_string(d, "empire: bad server prompt.\r\n");
	  d->door_int1 = code;
	  sprintf(d->door_lbuf, "[%d:%d] Command : ", d->door_int2, d->door_int3);
	  empire_prompt(d);
	  break;
	case C_REDIR:
	  queue_string(d,"empire: redirection not supported.\r\n");
	  break;
	case C_PIPE:
	  queue_string(d,"empire: pipe not supported.\r\n");
	  break;
	case C_FLUSH:
	  d->door_int1 = code;
	  strcpy(d->door_lbuf, pt2);
	  empire_prompt(d);
	  break;
	case C_EXECUTE:
	  pt3 = alloc_lbuf("door_exec_temp");
	  if (pt3 == NULL) {
	    queue_string(d,"Door exec failed.\r\n");
	    break;
	  }
	  strcpy(pt3,pt2);
	  do_command(d,pt3);
	  free_lbuf(pt3);
	  if (!(d->flags & DS_HAS_DOOR)) {
	    queue_string(d,"Exec send EOF failed; Empire door was closed.\r\n");
	    return -1;
	  }
	  else if (WRITE(d->door_desc,"ctld\n", 5) < 5) {
	    queue_string(d,"Exec send EOF failed\r\n");
	    return -1;
	  }
	  break;
	case C_INFORM:
	  if (*pt2) {
	    pt2[strlen(pt2)-1] = '\0';
	    sprintf(d->door_mbuf, "(%s)", pt2+1);
	    empire_prompt(d);
	  }
	  else
	    *(d->door_mbuf) = '\0';
	  break;
	default:
	  empire_output(d, code, pt2);
	  break;
      }
    } while ((pt1 = strtok_r(NULL,"\n", &tstrtokr)) != NULL);
  }
  return 1;
}
コード例 #27
0
ファイル: file_c.c プロジェクト: TinyMUSH/TinyMUSH
int fcache_read(FBLOCK ** cp, char *filename)
{
    int n, nmax, tchars, fd;
    char *buff;
    FBLOCK *fp, *tfp;
    /*
     * Free a prior buffer chain
     */
    fp = *cp;

    while (fp != NULL) {
	tfp = fp->hdr.nxt;
	free_mbuf(fp);
	fp = tfp;
    }

    *cp = NULL;

    /*
     * Read the text file into a new chain
     */

    if ((fd = tf_open(filename, O_RDONLY)) == -1) {
	/*
	 * Failure: log the event
	 */
	log_write(LOG_PROBLEMS, "FIL", "OPEN", "Couldn't open file '%s'.", filename);
	tf_close(fd);
	return -1;
    }

    buff = alloc_lbuf("fcache_read.temp");
    /*
     * Set up the initial cache buffer to make things easier
     */
    fp = (FBLOCK *) alloc_mbuf("fcache_read.first");
    fp->hdr.nxt = NULL;
    fp->hdr.nchars = 0;
    *cp = fp;
    tchars = 0;
    /*
     * Process the file, one lbuf at a time
     */
    nmax = read(fd, buff, LBUF_SIZE);

    while (nmax > 0) {
	for (n = 0; n < nmax; n++) {
	    switch (buff[n]) {
	    case '\n':
		fp = fcache_fill(fp, '\r');
		fp = fcache_fill(fp, '\n');
		tchars += 2;

	    case '\0':
	    case '\r':
		break;

	    default:
		fp = fcache_fill(fp, buff[n]);
		tchars++;
	    }
	}

	nmax = read(fd, buff, LBUF_SIZE);
    }

    free_lbuf(buff);
    tf_close(fd);

    /*
     * If we didn't read anything in, toss the initial buffer
     */

    if (fp->hdr.nchars == 0) {
	*cp = NULL;
	free_mbuf(fp);
    }

    return tchars;
}
コード例 #28
0
ファイル: levels.cpp プロジェクト: sanjayui/tinymux
/* ---------------------------------------------------------------------------
 * did_it_rlevel: Have player do something to/with thing, watching the
 * attributes. 'what' is actually ignored, the desclist match being used
 * instead.
 */
void did_it_rlevel
(
    dbref player,
    dbref thing,
    int   what,
    const UTF8 *def,
    int   owhat,
    const UTF8 *odef,
    int   awhat,
    int   ctrl_flags,
    const UTF8 *args[],
    int   nargs
)
{
    if (MuxAlarm.bAlarmed)
    {
        return;
    }

    UTF8 *d, *buff, *act, *charges, *bp;
    dbref aowner;
    int num, aflags;
    int i;
    bool found_a_desc;

    reg_ref **preserve = NULL;
    bool need_pres = false;

    // Message to player.
    //
    if (0 < what)
    {
        // Get description list.
        //
        DESC_INFO *desclist = desclist_match(player, thing);
        found_a_desc = false;
        for (i = 0; i < desclist->n; i++)
        {
            // Ok, if it's A_DESC, we need to check against A_IDESC.
            //
            if (  A_IDESC == what
               && A_DESC == desclist->descs[i])
            {
                d = atr_pget(thing, A_IDESC, &aowner, &aflags);
            }
            else
            {
                d = atr_pget(thing, desclist->descs[i], &aowner, &aflags);
            }

            if ('\0' != d[0])
            {
                // No need for the 'def' message.
                //
                found_a_desc = true;
                if (!need_pres)
                {
                    need_pres = true;
                    preserve = PushRegisters(MAX_GLOBAL_REGS);
                    save_global_regs(preserve);
                }
                buff = bp = alloc_lbuf("did_it.1");
                mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player,
                    AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP),
                    args, nargs);
                *bp = '\0';

                if (  A_HTDESC == desclist->descs[i]
                   && Html(player))
                {
                    safe_str(T("\r\n"), buff, &bp);
                    *bp = '\0';
                    notify_html(player, buff);
                }
                else
                {
                    notify(player, buff);
                }
                free_lbuf(buff);
            }
            free_lbuf(d);
        }

        if (!found_a_desc)
        {
            // No desc found... try the default desc (again).
            // A_DESC or A_HTDESC... the worst case we look for it twice.
            //
            d = atr_pget(thing, what, &aowner, &aflags);
            if ('\0' != d[0])
            {
                // No need for the 'def' message
                //
                found_a_desc = true;
                if (!need_pres)
                {
                    need_pres = true;
                    preserve = PushRegisters(MAX_GLOBAL_REGS);
                    save_global_regs(preserve);
                }
                buff = bp = alloc_lbuf("did_it.1");
                mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player,
                    AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP),
                    args, nargs);
                *bp = '\0';

                if (  A_HTDESC == what
                   && Html(player))
                {
                    safe_str(T("\r\n"), buff, &bp);
                    *bp = '\0';
                    notify_html(player, buff);
                }
                else
                {
                    notify(player, buff);
                }
                free_lbuf(buff);
            }
            else if (def)
            {
                notify(player, def);
            }
            free_lbuf(d);
        }
    }
    else if (  what < 0
            && def)
    {
        notify(player, def);
    }

    if (isPlayer(thing))
    {
       d = atr_pget(mudconf.master_room, get_atr(T("ASSET_DESC")), &aowner, &aflags);
       if (*d)
       {
          if (!need_pres)
          {
             need_pres = true;
             preserve = PushRegisters(MAX_GLOBAL_REGS);
             save_global_regs(preserve);
          }
          buff = bp = alloc_lbuf("did_it.1");
          mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player,
              AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP),
              args, nargs);
          *bp = '\0';
          notify(player, buff);
          free_lbuf(buff);
       }
       free_lbuf(d);
    }

    // Message to neighbors.
    //
    dbref loc;
    if (  0 < owhat
       && Has_location(player)
       && Good_obj(loc = Location(player)))
    {
        d = atr_pget(thing, owhat, &aowner, &aflags);
        if (*d)
        {
            if (!need_pres)
            {
                need_pres = true;
                preserve = PushRegisters(MAX_GLOBAL_REGS);
                save_global_regs(preserve);
            }
            buff = bp = alloc_lbuf("did_it.2");
            mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player,
                AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP),
                args, nargs);
            *bp = '\0';

            if (*buff)
            {
                if (aflags & AF_NONAME)
                {
                    notify_except2_rlevel2(loc, player, player, thing, buff);
                }
                else
                {
                    notify_except2_rlevel2(loc, player, player, thing,
                        tprintf(T("%s %s"), Name(player), buff));
                }
            }
            free_lbuf(buff);
        }
        else if (odef)
        {
            if (ctrl_flags & VERB_NONAME)
            {
                notify_except2_rlevel2(loc, player, player, thing, odef);
            }
            else
            {
                notify_except2_rlevel2(loc, player, player, thing,
                    tprintf(T("%s %s"), Name(player), odef));
            }
        }
        free_lbuf(d);
    }
    else if (  owhat < 0
            && odef
            && Has_location(player)
            && Good_obj(loc = Location(player)))
    {
        if (ctrl_flags & VERB_NONAME)
        {
            notify_except2_rlevel2(loc, player, player, thing, odef);
        }
        else
        {
            notify_except2_rlevel2(loc, player, player, thing,
                tprintf(T("%s %s"), Name(player), odef));
        }
    }

    // If we preserved the state of the global registers, restore them.
    //
    if (need_pres)
    {
        restore_global_regs(preserve);
        PopRegisters(preserve, MAX_GLOBAL_REGS);
    }

    // Do the action attribute.
    //
    if (  awhat > 0
       && IsReal(thing, player))
    {
        act = atr_pget(thing, awhat, &aowner, &aflags);
        if (*act != '\0')
        {
            charges = atr_pget(thing, A_CHARGES, &aowner, &aflags);
            if (*charges)
            {
                num = mux_atol(charges);
                if (num > 0)
                {
                    buff = alloc_sbuf("did_it.charges");
                    mux_ltoa(num-1, buff);
                    atr_add_raw(thing, A_CHARGES, buff);
                    free_sbuf(buff);
                }
                else
                {
                    buff = atr_pget(thing, A_RUNOUT, &aowner, &aflags);
                    if (*buff != '\0')
                    {
                        free_lbuf(act);
                        act = buff;
                    }
                    else
                    {
                        free_lbuf(act);
                        free_lbuf(buff);
                        free_lbuf(charges);
                        return;
                    }
                }
            }
            free_lbuf(charges);

            CLinearTimeAbsolute lta;
            wait_que(thing, player, player, AttrTrace(aflags, 0), false, lta,
                NOTHING, 0,
                act,
                nargs, args,
                mudstate.global_regs);
        }
        free_lbuf(act);
    }
}
コード例 #29
0
ファイル: levels.cpp プロジェクト: sanjayui/tinymux
UTF8 *get_rlevel_desc
(
    dbref player,
    dbref thing,
    int  *piDescUsed
)
{
    dbref aowner;
    int aflags;
    UTF8 *buff = alloc_lbuf("get_rlevel_desc.");
    UTF8 *bp = buff;;
    reg_ref **preserve = NULL;
    bool need_pres = false;
    bool bFirst = true;

    // Get description list.
    //
    DESC_INFO *desclist = desclist_match(player, thing);
    bool found_a_desc = false;
    for (int i = 0; i < desclist->n; i++)
    {
        UTF8 *d = atr_pget(thing, desclist->descs[i], &aowner, &aflags);
        if ('\0' != d[0])
        {
            found_a_desc = true;
            if (!need_pres)
            {
                need_pres = true;
                preserve = PushRegisters(MAX_GLOBAL_REGS);
                save_global_regs(preserve);
            }

            mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player,
                AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP),
                NULL, 0);

            if (!bFirst)
            {
                safe_str(T("\r\n"), buff, &bp);
            }
            else
            {
                bFirst = false;
                *piDescUsed = desclist->descs[i];
            }
        }
        free_lbuf(d);
    }

    if (!found_a_desc)
    {
        UTF8 *d = atr_pget(thing, A_DESC, &aowner, &aflags);
        if ('\0' != d[0])
        {
            found_a_desc = true;
            if (!need_pres)
            {
                need_pres = true;
                preserve = PushRegisters(MAX_GLOBAL_REGS);
                save_global_regs(preserve);
            }

            mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player,
                AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP),
                NULL, 0);
            *bp = '\0';

            *piDescUsed = A_DESC;
        }
        free_lbuf(d);
    }

    // If we preserved the state of the global registers, restore them.
    //
    if (need_pres)
    {
        restore_global_regs(preserve);
        PopRegisters(preserve, MAX_GLOBAL_REGS);
    }

    *bp = '\0';
    return buff;
}
コード例 #30
0
ファイル: levels.cpp プロジェクト: sanjayui/tinymux
void do_txlevel
(
    dbref executor,
    dbref caller,
    dbref enactor,
    int   eval,
    int   key,
    int   nargs,
    UTF8 *object,
    UTF8 *arg,
    const UTF8 *cargs[],
    int   ncargs
)
{
    UNUSED_PARAMETER(caller);
    UNUSED_PARAMETER(enactor);
    UNUSED_PARAMETER(eval);
    UNUSED_PARAMETER(cargs);
    UNUSED_PARAMETER(ncargs);

    if (!arg || !*arg)
    {
        notify_quiet(executor, T("I don\xE2\x80\x99t know what you want to set!"));
        return;
    }

    // Find thing.
    //
    dbref thing = match_controlled(executor, object);
    if (NOTHING == thing)
    {
        return;
    }

    UTF8 lname[9];
    RLEVEL ormask = 0;
    RLEVEL andmask = ~ormask;
    while (*arg)
    {
        int negate = 0;
        while (  *arg
              && mux_isspace(*arg))
        {
            arg++;
        }

        if (*arg == '!')
        {
            negate = 1;
            ++arg;
        }

        int i;
        for (i = 0; *arg && !mux_isspace(*arg); arg++)
        {
            if (i < 8)
            {
                lname[i++] = *arg;
            }
        }

        lname[i] = '\0';
        if (!lname[0])
        {
            if (negate)
            {
                notify(executor, T("You must specify a reality level to clear."));
            }
            else
            {
                notify(executor, T("You must specify a reality level to set."));
            }
            return;
        }

        RLEVEL result = find_rlevel(lname);
        if (!result)
        {
            notify(executor, T("No such reality level."));
            continue;
        }
        if (negate)
        {
            andmask &= ~result;
            notify(executor, T("Cleared."));
        }
        else
        {
            ormask |= result;
            notify(executor, T("Set."));
        }
    }

    // Set the Tx Level.
    //
    UTF8 *buff = alloc_lbuf("do_rxlevel");
    mux_sprintf(buff, LBUF_SIZE, T("%08X %08X"), RxLevel(thing), TxLevel(thing) & andmask | ormask);
    atr_add_raw(thing, A_RLEVEL, buff);
    free_lbuf(buff);
}