#include <pragmas/asl_pragmas.h>
#include <pragmas/cia_pragmas.h>
#include <pragmas/console_pragmas.h>
#include <pragmas/diskfont_pragmas.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/exec_pragmas.h>
#include <pragmas/gadtools_pragmas.h>
#include <pragmas/graphics_pragmas.h>
#include <pragmas/icon_pragmas.h>
#include <pragmas/input_pragmas.h>
#include <pragmas/intuition_pragmas.h>
#include <pragmas/rexxsyslib_pragmas.h>
#include <pragmas/timer_pragmas.h>
#include <pragmas/utility_pragmas.h>
#include <pragmas/wb_pragmas.h>

#define SUCCESS 0
#define PRIVATE 10
#define LCFILES 9
#define FAILURE -1
#define NOTALLOWED 1
#define NOTTESTED  2
#define ABORT    -2 
#define HISTORY 999
#define MAXHIST 20

#define NOSCREENS 0
#define BBSSCREENS 1
#define NODESCREENS 2

#define KEYBOARD_TIMEOUT 300L

#ifndef FOREVER
#	define FOREVER for(;;)
#endif

#define FALSE 0
#define TRUE  1

#define AWAIT_LOGON	0
#define SYSOP_LOGON	1
#define LOCAL_LOGON	2
#define REMOTE_LOGON	3
#define GOODBYE_LOGON	4
#define SUSPEND_LOGON	5

#define STANDARD_LOGOFF	1
#define SLEEP_LOGOFF	2
#define OVERTIME_LOGOFF	3
#define CARRIER_LOGOFF	4
#define ILLEGAL_LOGOFF	5

#define ENV_IDLE        0
#define ENV_DOWNLOADING 1
#define ENV_UPLOADING   2
#define ENV_DOORS       3
#define ENV_MAIL        4
#define ENV_STATS       5
#define ENV_ACCOUNT     6
#define ENV_ZOOM        7
#define ENV_FILES       8
#define ENV_BULLETINS   9
#define ENV_VIEWING     10
#define ENV_ACCOUNTSEQ  11
#define ENV_LOGOFF      12
#define ENV_SYSOP       13
#define ENV_SHELL       14
#define ENV_EMACS       15
#define ENV_JOIN        16
#define ENV_CHAT        17
#define ENV_NOTACTIVE   18
#define ENV_REQ_CHAT    19
#define ENV_CONNECT     20
#define ENV_LOGGINGON   21
#define ENV_AWAITCONNECT 22
#define ENV_SCANNING     23
#define ENV_SHUTDOWN     24
#define ENV_MULTICHAT    25
#define ENV_SUSPEND      26
#define ENV_RESERVE      27

#define SV_SYSOPLOG       154
#define SV_LOCALLOG       155
#define SV_ACCOUNTS       156
#define SV_CHAT           157
#define SV_NODEOFFHOOK    158
#define SV_EXITNODE       159
#define SV_INITMODEM      160
#define SV_WHATSUP        161
#define RESERVED_BLOCK10  162
#define SV_INSTANT        170
#define SV_RESERVE        171
#define SV_CHATTOGGLE     172
#define SV_AESHELL        174
#define SV_CLIPBOARD      175
#define SV_START          176
#define SV_NEWMSG         177
#define SV_QUIETNODE      178
#define SV_SETNRAMS       179
#define SV_RESERVENODE    180

#define WAIT     600
#define NOWAIT   FALSE
#define YES      TRUE
#define NO       FALSE
#define ECHO     TRUE
#define NOECHO   FALSE
#define CSI      0x9B
#define RIGHTARROW 2
#define LEFTARROW 3
#define UPARROW 4
#define DOWNARROW 5

#define IOFLAG_FIL_IN	0
#define IOFLAG_KBD_IN	1
#define IOFLAG_SER_IN	2
#define IOFLAG_FIL_OUT	3
#define IOFLAG_PRT_OUT	4
#define IOFLAG_SCR_OUT	5
#define IOFLAG_SER_OUT	6

#define TIMEOUT  -3
#define NO_CARRIER -4
#define GOODBYE  -7
#define EXITCHAT  -8

#define STAT_STARTUP	0
#define STAT_LOGON	1
#define STAT_LOGOFF	2
#define STAT_GUEST_CALL	3
#define STAT_NEW_CALL	4
#define STAT_VALID_CALL	5
#define STAT_MESSAGE	6
#define STAT_LETTER	7
#define STAT_UPLOAD	8
#define STAT_DOWNLOAD	9
#define STAT_NEW_MEMBER	10
#define STAT_SHUTDOWN	11

#define MAX_CONFS 9                  /* Number of conferences */

struct Commands {
 UBYTE   AcLvl[100], SerDevUnit;
 char    SerDev[40], NEW_UserPW[15];
 long    OpeningBaud;
 BYTE    TaskPri;
 char    ConfName[MAX_CONFS][60], ConfLoc[MAX_CONFS][60], BBSName[41], BBSLoc[41], SysopName[41];
 UBYTE   PSAcLvl[6], PSRType[6], PSRatio[6];
 long    PSDBytes[6], PSTime[6];
 char    PSCnfAc[6][10], MInit[101], MReset[31], MRing[31], MAnswer[31], MC300[31],
         MC1200[31], MC2400[31], MC4800[31], MC9600[31], MC19200[31];
 short   NumConf;
 char    SysPass[31], RemotePass[31];
 USHORT  BaudTimes[10];
 char    Pad[18];
};


struct ZModem {
 char    FileName[40], TitleBar[60], ZStat[60];
 long    Filesize, Cps,  Eff, RecPos, ErrorPos, ResumePos;
 ULONG   ApxTime, LastTime;
 char    Pad[2];
};

struct TempSysopInfo {
	UWORD		AccessLevel;
	UWORD		RatioType;
	UWORD		Ratio;
	LONG		TimeTotal;
	UBYTE		ConfAc[10];
	};

 /* Note ConfYM = the last msg you actually read, ConfRead is the same ?? */

struct User
{
	char	Name[31];
	char	Pass[9];
	char	Location[30];
	char	PhoneNumber[13];
	USHORT	Slot_Number;
	USHORT	Sec_Status;
	USHORT	Sec_Board;		/* File or Byte Ratio */
	USHORT	Sec_Library;		/* Ratio              */
	USHORT	Sec_Bulletin;		/* Computer Type      */
	USHORT	Messages_Posted;
	ULONG   NewSinceDate;
	char	PassKey[4];
	ULONG   ConfRead2, ConfRead3, ConfRead4, ConfRead5;
	UWORD   XferProtocol;
	UWORD   Filler2;
	UWORD   Lcfiles;
	UWORD	BadFiles; 
	ULONG   AccountDate;
	UWORD   ScreenType;
	UWORD	EditorType;
	char    Conference_Access[10];
	USHORT  Uploads;
	USHORT	Downloads;
	USHORT	ConfRJoin;
	USHORT	Times_Called;
	long    Time_Last_On;
	long	Time_Used;
	long	Time_Limit;
	long	Time_Total;
	ULONG   Bytes_Download;
	ULONG	Bytes_Upload;
	ULONG	Daily_Bytes_Limit;
	ULONG	Daily_Bytes_Dld;
	char    Expert;
	ULONG   ConfYM1;
	ULONG	ConfYM2;
	ULONG	ConfYM3;
	ULONG	ConfYM4;
	ULONG	ConfYM5;
	ULONG	ConfYM6;
	ULONG	ConfYM7;
	ULONG	ConfYM8;
	ULONG	ConfYM9;
	long    BeginLogCall;
	UBYTE   Protocol;
	UBYTE	UUCPA;
	UBYTE	LineLength;
	UBYTE	New_User;
};


struct RTSUser {
 char pad1[8];
 char    Name[31],Pass[9],Location[30],PhoneNumber[13];
 USHORT  Slot_Number;              /* max 255 should be UBYTE */
 USHORT  Sec_Status,
     Sec_Board,                   /* File or Byte Ratio */
     Sec_Library,                 /* Ratio              */
     Sec_Bulletin,                /* Computer Type      */
     Messages_Posted;
 /* Note ConfYM = the last msg you actually read, ConfRead is the same ?? */
 ULONG   NewSinceDate;
 ULONG   ConfRead[9];
 char    Conference_Access[10];
 USHORT  Uploads, Downloads, ConfRJoin, Times_Called;
 long    Time_Last_On, Time_Used, Time_Limit, Time_Total;
 ULONG   Bytes_Download, Bytes_Upload, Daily_Bytes_Limit, Daily_Bytes_Dld;
 char    Expert;
 ULONG   ConfYM[9];
 long    BeginLogCall;
 UBYTE   Protocol, UUCPA, LineLength, New_User;
 char pad2[16];
 };

struct OLDUserKeys {                 /* changes to UserKeys (RTS) */
 char    UserName[31];
 long    Number;
 UBYTE   New_User;
 UWORD   UPcps;              /* highest upload cps rate */
 UWORD   DNcps;              /* highest dnload cps rate */
 UWORD   Userflags;          /*                         */
 char    Pad[11];            /* ?? should be 15         */
};

struct UserKeys {                 /* changes to UserKeys (RTS) */
 char    UserName[31];
 long    Number;
 UBYTE   New_User;
 UWORD   UPcps;              /* highest upload cps rate */
 UWORD   DNcps;              /* highest dnload cps rate */
 UWORD   Userflags;          /*                         */
 UWORD   baud_rate;          /* last online baud rate   */
 char    Pad[9];             /* ?? should be 15         */
};

struct OldMailHeader {
	char	Status[1];
	long	MsgNumb;
	char	ToName[31],
		FromName[31],
		Subject[31];
	long	MsgDate,
		Recv;
	char Pad;
	};
struct MailHeader {
	char	Status[1];
	long	MsgNumb;
     long ActualMsgNumb;
	char	ToName[31],
		FromName[31],
		Subject[31];
     char ToNet[8],FromNet[8];
	long	MsgDate,
		Recv;
     long threaded;
	char Pad;
	};

struct MailStat {
	long	LowestKey,
		HighMsgNum,
		LowestNotDel;
	char Pad[6];
	};
struct ConfBase
{
  char Handle[31];
  ULONG NewSinceDate, ConfRead,ConfYM;
  ULONG Bytes_Download,Bytes_Upload;
  ULONG Daily_Bytes_Limit,Daily_Bytes_Dld;
  USHORT Upload,Downloads,RatioType,Ratio,Messages_Posted;
  UWORD Access;
  UWORD Active;
};

struct MyData
{
  int Type,Size,misc1,Version;
};

struct MasterData
{
   struct MyData   Code;
   struct ConfBase Conf;
};
/* stupid defines , theres gotta be a better way , will have to 
   consult the Lattice Manual */

#define AbortIO(x) AbortIO((struct IORequest *)x)
#define CheckIO(x) CheckIO((struct IORequest *)x)
#define WaitIO(x) WaitIO((struct IORequest *)x)
#define SendIO(x) SendIO((struct IORequest *)x)
#define DoIO(x) DoIO((struct IORequest *)x)
#define BeginIO(x) BeginIO((struct IORequest *)x)

#define OpenDevice(a, b, c, d) OpenDevice(a, b, (struct IORequest *)c, d)
#define CloseDevice(x) CloseDevice((struct IORequest *)x)

#define DeleteExtIO(x) DeleteExtIO((struct IORequest *)x)

#define Tell(x)  Seek(x,0L,OFFSET_CURRENT)

#undef PutStr

struct StartOption
{
  SHORT LeftEdge;
  SHORT TopEdge;
  SHORT Width;
  SHORT Height;
  int BitPlanes;
  BOOL StatBar;
  BOOL Interlace;
  BOOL DupeCheck;
  BOOL QLogon;
  BOOL TakeCredits;
  BOOL SeenIt;
  BOOL TrapDoor;
  BOOL Iconify;
  BOOL Eall_level;
  BOOL A2232;
  BOOL Toggles[20];
  char Logoff[80];
  char ShutDown[80];
  char CycleLock[80];
  char RamPen[80];
  char BBSConfig[80];
  char FilesNot[80];
  char UserData[80];
  char UserKey[80];
  char OffHook[80];
  char NodeScreen[80];
  APTR t;
  APTR s;
};
#define ACS_ACCOUNT_EDITING      0
#define ACS_BULLETINS            1
#define ACS_COMMENT_TO_SYSOP     2
#define ACS_DOWNLOAD             3
#define ACS_UPLOAD               4
#define ACS_ENTER_MESSAGE        5
#define ACS_FILE_LISTINGS        6
#define ACS_JOIN_CONFERENCE      7
#define ACS_NEW_FILES_SINCE      8
#define ACS_PAGE_SYSOP           9
#define ACS_READ_MSG             10
#define ACS_REMOTE_SHELL         11
#define ACS_DISPLAY_USER_STATS   12
#define ACS_VIEW_A_FILE          13
#define ACS_EDIT_USER_INFO       14
#define ACS_EDIT_USER_NAME       15
#define ACS_EDIT_USER_LOCATION   16
#define ACS_EDIT_PHONE_NUMBER    17
#define ACS_EDIT_PASSWORD        18
#define ACS_ZIPPY_TEXT_SEARCH    19
#define ACS_OVERRIDE_CHAT        20
#define ACS_SYSOP_DOWNLOAD       21
#define ACS_SYSOP_VIEW           22
#define ACS_SYSOP_READ           23
#define ACS_KEEP_UPLOAD_CREDIT   24
#define ACS_OVERRIDE_TIMES       25
#define ACS_CLEAR_SCREEN_MSG     26
#define ACS_ALLOW_FREE_RESUMING  27
#define ACS_ONE_TIME_BULLETINS   28
#define ACS_DO_CALLERSLOG        29
#define ACS_SENTBY_FILES         30
#define ACS_DO_UD_LOG            31
#define ACS_SCREEN_TO_FRONT      32
#define ACS_DEFAULT_CHAT_ON      33
#define ACS_EALL_LEVEL           34
#define ACS_DUPE_FILECHECK       35
#define ACS_MSG_EDIT             36
#define ACS_NODE_LIST            37
#define ACS_MSG_LEVEL            38
#define ACS_MSG_EXPERATION       39
#define ACS_DELETE_MSG           40
#define ACS_ATTACH_FILES         41
#define ACS_CUSTOMCOMMANDS       42
#define ACS_JOIN_SUB_CONFERENCE  43
#define ACS_ZOOM_MAIL            44
#define ACS_MCI_MSG              45
#define ACS_EDIT_DIRS            46
#define ACS_EDIT_ANY             47
#define ACS_BREAK_CHAT           48
#define ACS_QUIET_NODE           49
#define ACS_SYSOP_COMMANDS       50
#define ACS_WHO_IS_ONLINE        51
#define ACS_RELOGON              52
#define ACS_ULSTATS              53
#define ACS_XPR_RECEIVE          54
#define ACS_XPR_SEND             55
#define ACS_WILDCARDS            56
#define ACS_CONFERENCE_ACCOUNTING 57
#define ACS_PRI_MSGFILES         58
#define ACS_PUB_MSGFILES         59
#define ACS_FULLEDIT             60

//#define ADD_BIT(x) newacs[x/16] |= ten[x%16]
//#define REM_BIT(x) newacs[x/16] ^= ten[x%16]
//#define GET_BIT(x) newacs[x/16] |  ten[x%16]

#define LVL_ACCOUNT_EDITING      0
#define LVL_COMMENT_TO_SYSOP     1
#define LVL_DOWNLOAD             2
#define LVL_ENTER_MESSAGE        3
#define LVL_FILE_LISTINGS        4
#define LVL_JOIN_CONFERENCE      5
#define LVL_NEW_FILES_SINCE      6
#define LVL_PAGE_SYSOP           7
#define LVL_READ_MSG             8
#define LVL_DISPLAY_USER_STATS   9
#define LVL_UPLOAD               10
#define LVL_VIEW_A_FILE          11
#define LVL_EDIT_USER_INFO       12
#define LVL_REMOTE_SHELL         13
#define LVL_ZIPPY_TEXT_SEARCH    14
#define LVL_OVERRIDE_CHAT        15
#define LVL_EDIT_USER_NAME       16
#define LVL_EDIT_USER_LOCATION   17
#define LVL_EDIT_PHONE_NUMBER    18
#define LVL_EDIT_PASSWORD        19
#define LVL_SENTBY_FILES         20
#define LVL_DEFAULT_CHAT_ON      21
#define LVL_CLEAR_SCREEN_MSG     22
#define LVL_CAPITOLS_in_FILE     23
#define LVL_CHAT_COLOR_SYSOP     24
#define LVL_CHAT_COLOR_USER      25
#define LVL_VARYING_LINK_RATE    26
#define LVL_KEEP_UPLOAD_CREDIT   27
#define LVL_ALLOW_FREE_RESUMING  28
#define LVL_DO_CALLERSLOG        29
#define LVL_DO_UD_LOG            30
#define LVL_OVERRIDE_TIMES       41
#define LVL_BULLETINS            42
#define LVL_SYSOP_READ           43
#define LVL_NODE_NUMBER          44
#define LVL_SCREEN_TO_FRONT      45
#define LVL_ZOO                  46
#define LVL_PKAX                 47
#define LVL_LHARC                48
#define LVL_WARP                 49
#define LVL_ZIP                  50

#define DEBUG_BEGIN             0
#define DEBUG_DROPDTR           1
#define DEBUG_AWAITING_CONNECT  2
#define DEBUG_RESETING_NODE     3
#define DEBUG_RESETING_MODEM    4
#define DEBUG_MODEM_RESET       5
#define DEBUG_CHECKING_SHUTDOWN 6
#define DEBUG_CONNECT_TIMEOUT   7
#define DEBUG_BAD_CONNECT       8
#define DEBUG_SER_ROUTINES      9
#define DEBUG_CON_ROUTINES     10
#define DEBUG_CONNECT          11
#define DEBUG_SYSOP_LOGON      12
#define DEBUG_REMOTE_LOGON     13
#define DEBUG_SUSPEND_LOGON    14
#define DEBUG_LOCAL_LOGON      15
#define DEBUG_LOGOFF_SCRIPT    16

#define CONSOLE_PORT 1
#define SERIAL_PORT 2
