untermud/DOC/
untermud/DOC/U/
untermud/DOC/U/U-examples/
untermud/DOC/internals/
untermud/DOC/wizard/
untermud/MISC/
untermud/MISC/dbchk/
untermud/RWHO/
untermud/RWHO/rwhod/
#include    "config.h"
#include    "mud.h"
#include    "vars.h"
#include    "match.h"

/*
Handle wizard and unwizard commands
*/

static int wiz_set(char *who, char *aswho, int on_off);
static int wiz_passwd(char *who, char *aswho, char *new);

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

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



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 (UERR_FATAL);
    }
    say (who, "password removed.\n", (char *) 0);
  } else {
    if (ut_setpass (system_object, new)) {
      say (who, "can't set passwd.\n", (char *) 0);
      return (UERR_FATAL);
    }
    say (who, "password set.\n", (char *) 0);
  }
  return (UERR_NONE);
}




/* figure out what the hell the goober is trying to do - modularize */
/* ARGSUSED */
int cmd__wizard (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 (UERR_BADPARM);
  }

  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 (UERR_PERM);
  }

  /* 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 (UERR_PERM);
    }
  }

  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 (UERR_BADPARM);
}