示例#1
0
int cf_flag_access( int *vp, char *str, long extra, dbref player, char *cmd ) {
    char *fstr, *permstr, *tokst;

    FLAGENT *fp;

    fstr = strtok_r( str, " \t=,", &tokst );
    permstr = strtok_r( NULL, " \t=,", &tokst );

    if( !fstr || !*fstr || !permstr || !*permstr ) {
        return -1;
    }
    if( ( fp = find_flag( GOD, fstr ) ) == NULL ) {
        cf_log_notfound( player, cmd, "No such flag", fstr );
        return -1;
    }
    /*
     * Don't change the handlers on special things.
     */

    if( ( fp->handler != fh_any ) &&
            ( fp->handler != fh_wizroy ) &&
            ( fp->handler != fh_wiz ) &&
            ( fp->handler != fh_god ) &&
            ( fp->handler != fh_restrict_player ) &&
            ( fp->handler != fh_privileged ) ) {

        log_write( LOG_CONFIGMODS, "CFG", "PERM", "Cannot change access for flag: %s", fp->flagname );
        return -1;
    }
    if( !strcmp( permstr, ( char * ) "any" ) ) {
        fp->handler = fh_any;
    } else if( !strcmp( permstr, ( char * ) "royalty" ) ) {
        fp->handler = fh_wizroy;
    } else if( !strcmp( permstr, ( char * ) "wizard" ) ) {
        fp->handler = fh_wiz;
    } else if( !strcmp( permstr, ( char * ) "god" ) ) {
        fp->handler = fh_god;
    } else if( !strcmp( permstr, ( char * ) "restrict_player" ) ) {
        fp->handler = fh_restrict_player;
    } else if( !strcmp( permstr, ( char * ) "privileged" ) ) {
        fp->handler = fh_privileged;
    } else {
        cf_log_notfound( player, cmd, "Flag access", permstr );
        return -1;
    }
    return 0;
}
示例#2
0
文件: nametab.c 项目: chazu/btmux
int cf_ntab_access(int *vp, char *str, long extra, dbref player, char *cmd)
{
	NAMETAB *np;
	char *ap;

	for(ap = str; *ap && !isspace(*ap); ap++);
	if(*ap)
		*ap++ = '\0';
	while (*ap && isspace(*ap))
		ap++;
	for(np = (NAMETAB *) vp; np->name; np++) {
		if(minmatch(str, np->name, np->minlen)) {
			return cf_modify_bits(&(np->perm), ap, extra, player, cmd);
		}
	}
	cf_log_notfound(player, cmd, "Entry", str);
	return -1;
}
示例#3
0
int cf_flag_name( int *vp, char *str, long extra, dbref player, char *cmd ) {
    char *numstr, *namestr, *tokst;

    FLAGENT *fp;

    int flagnum = -1;

    char *flagstr, *cp;

    numstr = strtok_r( str, " \t=,", &tokst );
    namestr = strtok_r( NULL, " \t=,", &tokst );

    if( numstr && ( strlen( numstr ) == 1 ) ) {
        flagnum = ( int ) strtol( numstr, ( char ** ) NULL, 10 );
    }
    if( ( flagnum < 0 ) || ( flagnum > 9 ) ) {
        cf_log_notfound( player, cmd, "Not a marker flag", numstr );
        return -1;
    }
    if( ( fp = letter_to_flag( *numstr ) ) == NULL ) {
        cf_log_notfound( player, cmd, "Marker flag", numstr );
        return -1;
    }
    /*
     * Our conditions: The flag name MUST start with an underscore. It
     * must not conflict with the name of any existing flag. There is a
     * KNOWN MEMORY LEAK here -- if you name the flag and rename it
     * later, the old bit of memory for the name won't get freed. This
     * should pretty much never happen, since you're not going to run
     * around arbitrarily giving your flags new names all the time.
     */

    flagstr = xstrprintf( "cf_flag_name", "_%s", namestr );
    if( strlen( flagstr ) > 31 ) {
        cf_log_syntax( player, cmd, "Marker flag name too long: %s",
                       namestr );
        XFREE( flagstr, "cf_flag_name" );
    }
    for( cp = flagstr; cp && *cp; cp++ ) {
        if( !isalnum( *cp ) && ( *cp != '_' ) ) {
            cf_log_syntax( player, cmd,
                           "Illegal marker flag name: %s", namestr );
            XFREE( flagstr, "cf_flag_name" );
            return -1;
        }
        *cp = tolower( *cp );
    }

    if( hashfind( flagstr, &mudstate.flags_htab ) ) {
        XFREE( flagstr, "cf_flag_name" );
        cf_log_syntax( player, cmd, "Marker flag name in use: %s",
                       namestr );
        return -1;
    }
    for( cp = flagstr; cp && *cp; cp++ ) {
        *cp = toupper( *cp );
    }

    fp->flagname = ( const char * ) flagstr;
    hashadd( ( char * ) fp->flagname, ( int * ) fp, &mudstate.flags_htab, 0 );

    return 0;
}