/*
	Schrodinger's Box Haven  code version -0.1 alpha
        Copyright (C) 1994, Gordon Chan

	You can do whatever ya want with this code as long as you leave this
        copyright & disclaimer intact.  You can hack it up all you want, etc...
        No guarantees.

	Send comments, flames, bug reports, etc ... to
		au233@freenet.carleton.ca  <---- (preferred address for now)
		gjc@achilles.net
		gchan@ccs.carleton.ca
*/


/* Here's the copyrights & disclaimers from the Opium Den and unixCB codes */

/* Opium Den */
/*
  val's haven code v -0.85

        Copyright (C) 1994 Joel Ward

        Warranty:
                Don't blame me for anything.

        You can do whatever the fuck you want with this code as long as you
don't remove this copyright/disclaimer notice.
*/

/* unixCB */
/*
  
  cbd.c
  
  "cbd.c" is the main code for the CB simulator.
  
  Copyright (c) 1992, Gary Grossman.  All rights reserved.
  Send comments and questions to: garyg@soda.berkeley.edu
  
  */

#include <string.h>

#include "linked_lists.h"
#include "security.h"


static char *passwd[NUM_SEC_LEVEL] = {"barney", "the", "cute", "purple", 
	"dinosaur"}, *shut = {"In your fucking dreams"};

void change_security_level (user, password)
	struct user *user;
	char *password;
{
	int i;
	char temp[80];
		
	toggle_user (user, Fcomm_line);

	if (!strcmp(password, shut) )
		do_shutdown ();

	for (i = JOEDUDE; i < NUM_SEC_LEVEL; i++)
		if (!strcmp(password, passwd[i]) ) {
			user->sec_level = i;
			sprintf (temp, ">> Security level changed to %d.\r\n", i);
			write_user (user->desc, temp);		
			return;
		}


	write_user (user->desc, ">> Security level not changed.\r\n");
}


void raise_security(user, person)
  struct user *user;
  char *person;
{
  struct user *u;
  char text[120];

  if (!*person) {
    write_user(user->desc, ">> Nobody's security level was raised.\r\n");
    user->linecharmax = INPUTMAX;
    return;
  }

  person[NAMEMAX-1] = '\0';
  if ((u = (struct user *)find_user(person)) == (struct user *)0) {
    sprintf(text, ">> %s is not logged on.\r\n", person);
    write_user(user->desc, text);
  } else {
    if (u->sec_level == GOD) {
      sprintf(text, ">> %s's security level is already too high.  Security level not changed.\r\n", u->name);
      write_user(user->desc, text);
    } else {
      u->sec_level++;
      sprintf(text, ">> %s's security has been raised to %d.\r\n", u->name, u->sec_level);
      write_user(user->desc, text);
      sprintf(text, ">> Your security has been raised to %d by %s.\r\n", u->sec_level, user->name);
      write_user(u->desc, text);
    }
  }
  toggle_user(user, Fcomm_line);
  user->linecharmax = INPUTMAX;
}


void lower_security(user, person)
  struct user *user;
  char *person;
{
  struct user *u;
  char text[120];

  if (!*person) {
    write_user(user->desc, ">> Nobody's security level was raised.\r\n");
    user->linecharmax = INPUTMAX;
    return;
  }

  person[NAMEMAX-1] = '\0';
  if ((u = (struct user *)find_user(person)) == (struct user *)0) {
    sprintf(text, ">> %s is not logged on.\r\n", person);
    write_user(user->desc, text);
  } else {
    if (u->sec_level == JOEDUDE) {
      sprintf(text, ">> %s's security level is already too low.  Security level not changed.\r\n", u->name);
      write_user(user->desc, text);
    } else {
      u->sec_level--;
      sprintf(text, ">> %s's security has been lowered to %d.\r\n", u->name, u->sec_level);
      write_user(user->desc, text);
      sprintf(text, ">> Your security has been lowered to %d by %s.\r\n", u->sec_level, user->name);
      write_user(u->desc, text);
    }
  }
  toggle_user(user, Fcomm_line);
  user->linecharmax = INPUTMAX;
}

