
#ifndef CNET_CONTROL
#define CNET_CONTROL

#include "ports.h"
#include "config.h"

struct	PortConfig {
	UBYTE	online;           // port loaded or not
	UBYTE	open;             // 1==perm, 2==call only

	UBYTE	check;            // menu:  BITS 0=DoorsClosed, 1=FilesClosed, 2=MsgsClosed
                           //             3=NoNewUsers,  4=SysopIsIn
                           // see also: MainPort->check_latch

	UBYTE	idle;             // clock, SAG, SAM ?

	UBYTE	offline;          // port loaded, but modem offline
	UBYTE	not_used;

	UBYTE	bplanes;
	UBYTE	lace;             // 0=none, 1=24 line, 2=49 line

	USHORT	sizes[8];      // workbench window & zoom size
};

struct MainPortExtension
	{
	struct SignalSemaphore sem[20]; // sem[0] = lock reload_text variable..
					// sem[1] = lock idd (identd data) before insertion/removal
	                                // sem[2..19] not yet assigned/used.

	UBYTE reload_text;	// set to 1 to cause control to reload text/menu.
	                     // you MUST ObtainSemphore(&myp->MPE->sem[0]) before accessing!

	UBYTE newsman_up;			// 1 if cnet news server (news-task) is running.
	struct Task	*newstask;	// pointer to news-task Task structure if running.
	struct IdentdData *idd;		// linked list of identd info for in-use clients
	};


struct MainPort {          // common, public to all ports
                           // the same msgport that Findport("cnetport")
                           // returns a pointer to..

   struct  MsgPort mp;		// 0  - standard EXEC message port
   char    portName[22];   // 34

   char    LastOn[32];     // 56

	long	Nums[5];          //  88 [0] # of physical user accounts
                           //     [1] # of in-use user accounts
                           //     [2] last assigned unique ID Number
                           //     [3] # of calls to system TOTAL
                           //     [4] # of calls now logged

	ULONG	SAG[2][72];             // 108 activity graph
	long	SAM[5][15];		         // activity monitor
	struct	IsDate SAMDate[6];

	long	um[10];           // for C programmer use.  You can
                           // (typecast) them as you need to.
                           // Initially at bootup == 0

	struct	Window		*PWindow;		// pointer to control window if open; otherwise 0
	struct	TransType	*FirstTT;
	struct	SubboardType4 *Subboard;
	struct	LinkPort	*link;				// all-linked port users!
	struct	KeyElement4	*Key;				// alpha order, etc.
	short		*IName;							// Indexes into KeyElement4 array
	short		*IPhone;							// Indexes into KeyElement4 array
	char		*SubTitle;
	struct	MailLock	*mlock;
	struct	ChargeSet	*FirstCharge;

	long	ns;				// number of subs in memory (allocated)

	UBYTE	toss_up;			// TRUE if toss running..
	UBYTE	yank_up;			// TRUE if yank-task running..
	UBYTE	serv_exit;		// internally set as TRUE to tell mail-task, yank-task and any other "server" programs to quit - control is closing down/quitting
	UBYTE	item_up;			// not used
	UBYTE	mail_up;			// TRUE if mail-task running..
	UBYTE	fileman_up;		// TRUE if test/transform server up and running - added as of v4.21 (06-Aug-96)

	UBYTE expansion1[6];	// future expansion

	long	OpenPfiles;    // number of currently open doors

	struct	NoiseType	*FirstNT;

	long	ClickMaint;		// can we use local mouse maint?
	long	Verbose;		   // do not redirect to NIL: for debug

	long	s1;			// version of CONTROL
	long	s2;
	long	s3;			// serial number of owner 0==DEMO

	struct	BitMap  ClockBrush;	// 40 bytes - for the large port clock on idle ports
	struct	SignalSemaphore SEM[19];

					// for critical structure/file/variable locking..
               // Don't hold these in LOCKED state for long
               // as DEADLOCKS will occur!

					// ObtainSemaphore(SEM[x]) to lock, ReleaseSemaphore(SEM[x]) to unlock
					// SEM[0]  = for locking myp (MainPort) itself!
					// SEM[1]  = User myp->Key[], myp->IName, myp->PName, myp->Phone locking
					// SEM[2]  = z.Upload/z.nuploads/z.NoUploaded locking
					// SEM[3]  = for locking serial device
					// SEM[4]  = myp->NUMS[1] locking (NUMS[1] = number of user account currently active
					// SEM[5]  = net/echomail import/export,  subbards3/4 data file and COMPLETE allocated subboard locking - lock before altering/ordering subboard structures
					// SEM[7]  = conference (join) chat locking
					// SEM[8]  = joinlink/conference (join) ROOM locking
					// SEM[10] = Pfile locking
					// SEM[11] = bbs.udata, bbs.cuser & userlist locking
					// SEM[12] = sysdata:log/%s locking
					// SEM[13] = semaphore for locking LIST items - ie. items in a type "LIST" subboard
					// SEM[14] = vote list locking while reading/editing vote items/results
					// SEM[16] = lock before accessing the CopyCDRom() function
					// SEM[18] = semaphore for locking SAM
													

	struct	AccessGroup     AGC[32];	// BBS.ADATA / Access Group stuff

	struct	NewConfig1 gc;	            // global configuration defaults

	char	SysPassword[6][21];
	ULONG	IDQ;

	short	root;                         // first area#
	struct	PortConfig  pc   [101];    // For CONTROL, remembers things about each port's window menus, etc,..
	struct	PortData   *PortZ[100];    // pointers to each port's PortData struct
	struct	Room       *CRoom[100];    // pointers to ROOM structures..

	struct	ULock *FirstULock;         // Account Locking ... list of dynamically locked accounts!
	short	LastTickHour;                 // control is ticking ...
	short	LastTickMinute;

	short	HiPort; // highest port loaded
	short	nPorts;

	char	regto[32], regco[32];

	struct	SignalSemaphore ysem;      // the 3.1 Yank-Task
	struct	YankType *yfirst;

	struct	SignalSemaphore isem;      // WAS the 3.1 Item-Task = not used
	struct	ItemServerType *ifirst;		// not used!

	struct	SignalSemaphore csem;      // the 3.1 Charge-Server
	struct	ChargeType *cfirst;

	struct	SignalSemaphore sem;

	struct	PortData *z0;              // control's PortData structure - copied to other ports as default, when opened..

	/* new for v4.12 */
	UBYTE		cron_up;							/* non-zero if events are being externally edited - Control WILL NOT exit as long as this is >0 */
	struct	JobType4 *Events;			   /* configured events */
	struct	SignalSemaphore eventsem;	/* lock this using ObtainSemaphore() before altering myp->Events! */
                                       /* make sure to release using ReleaseSemaphore() after changing events list */

	struct	SignalSemaphore cesem;		/* control event semaphore locking  - internal use only! */
	struct	JobType4	*cEvents;			/* list of events to be executed by Control */

	struct	SignalSemaphore flsem;		/* semaphore for locking the LIST of file locks */

	struct	Library *NodelistBase;		/* traplist.library - nodelist base */

	UBYTE check_latch;		// 3rd party coders - SET this (1=SET) if ANY of the PortConfig "check" bits are altered via doors
                           //                    changes will not take effect unless this is latched!!

	// task pointers Added in v4.21/v4.22 - used to send signals to CNet servers
	// ie. use Signal(myp->mailtask, SIGBREAKF_CTRL_C) to tell mail-task to quit
	//     note: server will set it's myp->#?task pointer to ZERO when it exits
	//           You cannot be sure the task has exited until it's Task pointer
	//           is 0.  Also, if a server is processing a packet (ie. mail item,
	//           test/transform, NNTPGet etc, the task/server will not exit
	//           until the current operation is complete.
	struct Task	*mailtask;					// pointer to mail-task task structure
	struct Task	*filetask;					// pointer to file-task task structure
	struct Task	*nntptask;					// pointer to nntpget task structure
	struct Task	*yanktask;					// pointer to yank-task task structure

	struct MainPortExtension *MPE;		// MainPort data extensions - see struct MainPortExtension above.
};

#endif
