dbm/
misc/
old-docs/
/* pdx.c */

#include "copyright.h"
#include "config.h"

#include <stdio.h>
#include <sys/time.h>
#include <ctype.h>

#include "teeny.h"
#include "rwho.h"

static char     buf[BUFFSIZ];

#ifdef PDX

extern int      atoi();
extern int      max_logins;
static int      last_daemon = 0;

#define WEEKDAY_7to5	20	/* 7am to 5pm */
#define WEEKDAY_5to12	25	/* 5pm to midnight */
#define WEEKDAY_12to7	30	/* midnight to 7am */
#define WEEKEND(x)	(x *= 2)

int             current_max()
{
  struct timeval  currenttime;
  struct tm      *ltime;
  int             c_max;

  (void) gettimeofday(&currenttime, (struct timezone *) 0);
  ltime = localtime(&currenttime.tv_sec);

  if (ltime->tm_hour > 6 && ltime->tm_hour < 17) {
    c_max = WEEKDAY_7to5;
  } else if (ltime->tm_hour > 16) {
    c_max = WEEKDAY_5to12;
  } else
    c_max = WEEKDAY_12to7;

  if (ltime->tm_wday == 0 || ltime->tm_wday == 6) {
    WEEKEND(c_max);
  }
  return (c_max);
}

void            max_daemon()
{
  if (max_logins != current_max() && current_max() != last_daemon) {
    max_logins = current_max();
    last_daemon = current_max();
    (void) sprintf(buf, "* Maximum logins has been changed to %d. *\r\n",
		   max_logins);
    notify_wall(buf);

    log_status("STATUS: Daemon reports maximum logins set to %d.\n", max_logins);
  }
}

voidfunc        do_restrict(player, argone)
  int             player;
  char           *argone;
{
  int             new_max;

  if (!iswiz(player)) {
    notify_player(player, "Nice try.\r\n");
    return;
  }
  if (!argone || !*argone || !isdigit(argone[0])) {
    notify_player(player, "You must specifiy a positive number.\r\n");
    return;
  }
  new_max = atoi(argone);
  if (new_max < 0 || (new_max > (current_max() + 10) && !isgod(player))) {
    notify_player(player, "Illegal amount.\r\n");
    return;
  }
  max_logins = new_max;

  (void) sprintf(buf, "* Maximum logins has been changed to %d. *\r\n",
		 max_logins);
  notify_wall(buf);

  log_status("STATUS: %s(#%d) changed maximum logins to %d.\n",
	     getname(player), player, max_logins);
}
#endif				/* PDX */

#ifdef SUPPORT_RWHO
void            rwho_login(player, time)
  int             player;
  long            time;
{
  char           *nm;

  (void) sprintf(buf, "#%d@%s", player, RWHO_NAME);

  if (get_str_elt(player, NAME, &nm) != -1) {
    rwhocli_userlogin(buf, nm, time);
  } else {
    rwhocli_userlogin(buf, "???", time);
  }
}

void            rwho_logout(player)
  int             player;
{
  (void) sprintf(buf, "#%d@%s", player, RWHO_NAME);
  rwhocli_userlogout(buf);
}
#endif				/* SUPPORT_RWHO */