/*
	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 <stdio.h>

#include "main.h"


#define SITEMAX 40
#define DESCRIPTIONMAX 22
#define NAMEMAX 15
#define CHANNELMAX 15
#define FORMATMAX 40
#define ACCOUNTMAX (INPUTMAX+12)


/* macros used on flags */
#define is_user(x,y)		x->flags & (y)
#define toggle_user(x,y)	x->flags = x->flags ^ (y)
#define is_user_not(x,y)	!(is_user(x,y))

/* user flags */
#define Ftyping 	0x0001
#define Fgot_cr 	0x0002
#define Fecho_text	0x0004
#define Flinemode	0x0008
#define Fgot_comm	0x0010
#define Fcomm_line	0x0020
#define Fmultiple_comm  0x0040
#define Flogged_in	0x0080

#define Fmess_supp	0x0100
#define Fhush		0x0200
#define Fmonitor	0x0400
#define Fcolour		0x0800
#define Flinewrap	0x1000
#define Fhilite		0x2000


struct user {
  int desc;
  char name[NAMEMAX], 
       site[SITEMAX], 
       description[DESCRIPTIONMAX], 
       account[ACCOUNTMAX];
  int port;
  int sec_level;

  struct user 
    *next;

  unsigned flags;
  int ts_mode;

/* variables used for command processing */
  char which_comm;
  void (*present_comm)();
  int linecharmax;  /* maximum number of characters that will be read in */
	
/* which desc is a user sending a private to */
  struct user *private_to;

/* channel user is on */
  struct channel *channel;

/* user's newline character */
  char newline;

  int colour;
  int line_width;

/* gags and reverse gags */
  unsigned char *gags;
  unsigned char *reverse_gags;

/* times */
  long logintime;	/* time they logged in */
  long idletime;	/* number of seconds since they did something */

/* number of lines user typed in */
  short number_of_lines;

/* queues */	
  struct queue *input,		/* input queue buffers input */
	       *output;		/* output queue buffers output */

/* message, action, and active strings */
  char message_format[FORMATMAX],
       action_format[FORMATMAX];
};	


struct channel {
  char name[CHANNELMAX+1];
  int count;
  struct user *lock;
  struct channel *next;
};


struct queue {
  char *queue, *begin;
  int length;
};


extern struct user *firstuser;
extern struct channel *firstchannel, default_channel;

struct user *set_init_user ();
void clear_queue ();
struct queue *create_queue ();
char *create_text_queue ();
void destroy_queue ();
void destroy_text_queue ();
void initialize_user ();
