/
umud/DOC/
umud/DOC/examples/
umud/DOC/internals/
umud/DOC/wizard/
umud/MISC/
umud/MISC/dbchk/
umud/RWHO/rwhod/
#ifndef	lint
static	char	RCSid[] = "$Header: /usr/users/mjr/hacks/umud/CMD/RCS/wizard.c,v 1.1 91/07/04 17:33:29 mjr Rel $";
#endif

#include	"config.h"

#include	"mud.h"
#include	"vars.h"
#include	"match.h"

/*
Handle wizard and unwizard commands
*/

static	int
wiz_set(who,aswho,on_off)
char	*who;
char	*aswho;
int	on_off;
{
	if(ut_flagged(who,var_isplay) == 0) {
		say(who,"not a player.\n",(char *)0);
		return(1);
	}

	if(on_off) {
		if(ut_set(who,who,typ_flag,var_wiz,"")) {
			say(who,"can't set wizard.\n",(char *)0);
			return(1);
		}
		say(who,"set.\n",(char *)0);
	} else {
		if(ut_unset(who,who,var_wiz)) {
			say(who,"can't unset wizard.\n",(char *)0);
			return(1);
		}
		say(who,"unset.\n",(char *)0);
	}	
	return(0);
}



static	int
wiz_passwd(who,aswho,new)
char	*who;
char	*aswho;
char	*new;
{
	if(new == (char *)0) {
		if(ut_unset(who,system_object,var_pass)) {
			say(who,"can't unset passwd.\n",(char *)0);
			return(1);
		}
		say(who,"password removed.\n",(char *)0);
	} else {
		if(ut_setpass(system_object, new)) {
			say(who,"can't set passwd.\n",(char *)0);
			return(1);
		}
		say(who,"password set.\n",(char *)0);
	}
	return(0);
}




/* figure out what the hell the goober is trying to do - modularize */
/* ARGSUSED */
cmd__wizard(ac,av,who,aswho)
int	ac;
char	*av[];
char	*who;
char	*aswho;
{
	char	pbuf[MAXOID];
	char 	*pw;
	char	*wizs;
	char	*passwd = (char *)0;

	if(ac < 3 || !strcmp(av[1],"help")) {
		say(who,av[0]," on [password]\n",(char *)0);
		say(who,av[0]," off [password]\n",(char *)0);
		say(who,av[0]," password [old-password] [new-password]\n",(char *)0);
		return((ac < 2) ? 1 : 0);
	}

	passwd = av[2];
	
	/* get the system wizard list */
	wizs = ut_getatt(system_object,0,typ_list,var_wizs,(char *)0);

	/* if there is a wizard list and they're not on it... */
	if(wizs != (char *)0 && !lstlook(wizs,who)) {
		say(who,"permission denied.\n",(char *)0);
		return(1);
	}		

	/* get the system wizard password */
	pw = ut_getatt(system_object,0,typ_str,var_pass,(char *)0);

	/* compare it against the one they gave */

	/* if there is no password set, farg it */
	if(pw != (char *)0 && *pw != '\0') {
		rot_init(system_object);
		rot_decode(pw,pbuf);
		if(strcmp(passwd,pbuf)) {
			say(who,"permission denied.\n",(char *)0);
			return(1);
		}
	}
	
	if(!strncmp(av[1],"on",strlen(av[1]))) {
		return(wiz_set(who,aswho,1));
	}

	if(!strncmp(av[1],"off",strlen(av[1]))) {
		return(wiz_set(who,aswho,0));
	}

	if(!strncmp(av[1],"password",strlen(av[1]))) {
		char	*new = (char *)0;

		if(ac > 3) new = av[3];
		else if(pw ==(char *)0 || *pw == '\0') new = passwd;
		return(wiz_passwd(who,aswho,new));
	}

	say(who,"I don't understand what you want to ",av[0],"\n",(char *)0);
	return(1);
}