#include <exec/types.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "source:aztec/glue.h"
#define FOREVER while(1)
#define KEYBOARD_TIMEOUT 0
#define SUCCESS 1
#define FAILURE 0
#define sm sendmessage
int Edit_Accounts(void);

int GI2;
struct User {
 char    Name[31],Pass[9],Location[30],PhoneNumber[13];
 USHORT  Slot_Number;
 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, ConfRead1, ConfRead2, ConfRead3, ConfRead4,
         ConfRead5;
 UWORD   XferProtocol, Filler2;
 UWORD   Lcfiles,BadFiles; 
 ULONG   AccountDate;
 UWORD   ScreenType, Filler1;
 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   ConfYM1, ConfYM2, ConfYM3, ConfYM4, ConfYM5, ConfYM6, ConfYM7,
         ConfYM8, ConfYM9;
 long    BeginLogCall;
 UBYTE   Protocol, UUCPA, LineLength, New_User;
 };
UBYTE GSTR3[3000],GSTR2[3000],GSTR1[3000];


main(int argc,char *argv[])
{
  if(argc!=2)
  {
    printf("ACNT version 1.0, written by Joseph Hodge\n");
    printf("\n");
    exit(0);
  }
  Register(argv[1][0]-'0');
  Edit_Accounts();
  ShutDown();
  end();
}
struct User *hoozer;
#define AEPutStr(x) sendmessage(x,0)
#define LineInput(x,y,z,t) prompt(x,y,z)
static UBYTE UUCPNumberInput(void)
{
 AEPutStr(" \b");
 prompt("",GSTR1,1);
 return((UBYTE)atol(GSTR1));
}

static int NumberInput(void)
{
 AEPutStr("     \b\b\b\b\b");
 prompt("",GSTR1,5);
 return((int)atol(GSTR1));
}

static ULONG LongNumberInput(void)
{
 AEPutStr("          \b\b\b\b\b\b\b\b\b\b");
 LineInput("",GSTR1,10,KEYBOARD_TIMEOUT);
 return((ULONG)atol(GSTR1));
}

static void Display_Account(int who)
{
 if(hoozer->Slot_Number!=0)	{
	    sprintf(GSTR1,"[0;0H[33m  ACTIVE[0m [%hu]   \r\n",hoozer->Slot_Number);
	    AEPutStr(GSTR1);

	} else {
 	sprintf(GSTR1,"[0;0H[37mINACTIVE[0m [%hu]     \r\n",who);
	    AEPutStr(GSTR1);
	}

 sprintf(GSTR1,"[2;1H[33mA> [32mName[36m:[0m %-32s ",hoozer->Name);
 AEPutStr(GSTR1);
 sprintf(GSTR1,"[2;42H[33mB> [32mLoc.[36m:[0m %-29s\r\n",hoozer->Location);
 AEPutStr(GSTR1);
sprintf(GSTR1,"[33mC> [32mPass ..........[36m:[0m %-8s\r\n",hoozer->Pass);
 AEPutStr(GSTR1);


 sprintf(GSTR1,"[33mD> [32mPhone Number ..[36m:[0m %-13s",hoozer->PhoneNumber);
 AEPutStr(GSTR1);

 sprintf(GSTR1,"[5;1H[33mE> [32mRatio .........[36m:[0m %-7hu\r\n",hoozer->Sec_Library);
 AEPutStr(GSTR1);
 sprintf(GSTR1,"[4;36H[33mF> [32mArea Name......[36m:[0m %s",hoozer->Conference_Access);
 AEPutStr(GSTR1);

 sprintf(GSTR1,"[6;1H[33mG> [32mRatio Type ....[36m:[0m %-5hu",hoozer->Sec_Board);
 AEPutStr(GSTR1);
 if(hoozer->Sec_Board==0) AEPutStr(" [32m<-[33mByte[32m)[0m");
 if(hoozer->Sec_Board==1) AEPutStr(" [32m<-[33mB/F[32m)[0m ");
 if(hoozer->Sec_Board==2) AEPutStr(" [32m<-[33mFile[32m)[0m");

 sprintf(GSTR1,"[5;36H[33mH> [32mSec_Level .....[36m:[0m %-5hu",hoozer->Sec_Status);
 AEPutStr(GSTR1);

 sprintf(GSTR1,"[7;1H[33mI> [32mUploads .......[36m:[0m %-10hu\r\n",hoozer->Uploads);
 AEPutStr(GSTR1);
 sprintf(GSTR1,"[6;36H[33mJ> [32mAutoReJoin ....[36m:[0m %-10hu",hoozer->ConfRJoin);
 AEPutStr(GSTR1);

 sprintf(GSTR1,"[8;1H[33mK> [32mDownloads .....[36m:[0m %-10hu\r\n",hoozer->Downloads);
 AEPutStr(GSTR1);

 sprintf(GSTR1,"[7;36H[33mL> [32mMessages_Posted[36m:[0m %-7hu",hoozer->Messages_Posted);
 AEPutStr(GSTR1);
 sprintf(GSTR1,"[9;1H[33mM> [32mBytes Uled ....[36m:[0m %-10ld\r\n",hoozer->Bytes_Upload);
 AEPutStr(GSTR1);

 sprintf(GSTR1,"[8;36H[33mN> [32mNew_User ......[36m:[0m %s [33m#[32mCalls[36m: [0m%-12ld",(hoozer->New_User?"Yes":"No "),hoozer->Times_Called);
 AEPutStr(GSTR1);
 sprintf(GSTR1,"[10;1H[33mO> [32mBytes Dled ....[36m:[0m %-10ld\r\n",hoozer->Bytes_Download);
 AEPutStr(GSTR1);

 sprintf(GSTR2,"%s",ctime(&hoozer->Time_Last_On));
 GSTR2[24]='\0';
 sprintf(GSTR1,"[9;39H[32mLast Called ...[36m:[0m %s",GSTR2);
 AEPutStr(GSTR1);
 sprintf(GSTR1,"[11;1H[33mQ> [32mByte Limit ....[36m:[0m %-10ld\r\n",hoozer->Daily_Bytes_Limit);
 AEPutStr(GSTR1);

 sprintf(GSTR1,"[10;39H[32mComputer Type .[36m:[0m ");
 AEPutStr(GSTR1);
      AEPutStr("[11;39H[32mScreen Type  ..[36m:[0m ");
 //sprintf(GSTR1,"%sScreenTypes.DEF",Cmds->BBSLoc);
  sprintf(GSTR2,"TITLE.%d",hoozer->ScreenType+1);
  AEPutStr("[11;56H");
  /*if(GetFromIconStr(GSTR1,GSTR2,GSTR2))
  {
    sprintf(GSTR1,"%-16s",GSTR2);
    AEPutStr(GSTR1);
  }*/
//(RTS)

 sprintf(GSTR1,"[13;1H[33mR> [32mTime_Limit[36m:[0m [36m[[0m%-8lu[36m][0m secs    ",hoozer->Time_Limit);
 AEPutStr(GSTR1);
 sprintf(GSTR1," [33mS> [32mTime_Used[36m:[0m [36m[[0m%-8lu[36m][0m secs  [33mT> [32mUUCP[36m: [0m%d\r\n",hoozer->Time_Used,hoozer->UUCPA);
 AEPutStr(GSTR1);
 AEPutStr("\r\n");

 AEPutStr("[33mX[36m=[37mEXIT-NOSAVE [33mTAB[36m=[37mCont  [33m~[36m=[37mSAVE  [33m1-6[36m=[37mPresets  [33m9[36m=[37mRE-ACTIVATE  [33mDEL[36m=[37mDELETE[0m\r\n");
}

static void Display_Account_Info(int who)
{
 if(hoozer->Slot_Number!=0)	{
	    sprintf(GSTR1,"[0;0H[33m  ACTIVE[0m [%hu]   \r\n",hoozer->Slot_Number);
	    AEPutStr(GSTR1);
	} else {
 	sprintf(GSTR1,"[0;0H[37mINACTIVE[0m [%hu]     \r\n",who);
	    AEPutStr(GSTR1);
	}

 sprintf(GSTR1,"[2;10H%-32s",hoozer->Name);
 AEPutStr(GSTR1);
 sprintf(GSTR1,"[2;51H%-29s",hoozer->Location);
 AEPutStr(GSTR1);
sprintf(GSTR1,"[3;21H%-8s",hoozer->Pass);
AEPutStr(GSTR1);

 sprintf(GSTR1,"[4;21H%-13s",hoozer->PhoneNumber);
 AEPutStr(GSTR1);

 sprintf(GSTR1,"[5;21H%-7hu",hoozer->Sec_Library);
 AEPutStr(GSTR1);

 sprintf(GSTR1,"[4;56H%-10s",hoozer->Conference_Access);
 AEPutStr(GSTR1);

 sprintf(GSTR1,"[6;21H%-5hu",hoozer->Sec_Board);
 AEPutStr(GSTR1); 
  if(hoozer->Sec_Board==0) AEPutStr(" [32m<-[33mByte[32m)[0m");
 if(hoozer->Sec_Board==1) AEPutStr(" [32m<-[33mB/F[32m)[0m ");
 if(hoozer->Sec_Board==2) AEPutStr(" [32m<-[33mFile[32m)[0m");

 sprintf(GSTR1,"[5;56H%-5hu",hoozer->Sec_Status);
 AEPutStr(GSTR1);

 sprintf(GSTR1,"[7;21H%-10hu",hoozer->Uploads);
 AEPutStr(GSTR1);
 sprintf(GSTR1,"[6;56H%-7hu",hoozer->ConfRJoin);
 AEPutStr(GSTR1);

 sprintf(GSTR1,"[8;21H%-10hu",hoozer->Downloads);
 AEPutStr(GSTR1);

 sprintf(GSTR1,"[7;56H%-7hu",hoozer->Messages_Posted);
 AEPutStr(GSTR1);
 sprintf(GSTR1,"[9;21H%-10ld",hoozer->Bytes_Upload);
 AEPutStr(GSTR1);

 sprintf(GSTR1,"[8;56H%s [33m#[32mCalls[36m: [0m%-12ld",(hoozer->New_User?"Yes":"No "),hoozer->Times_Called);
 AEPutStr(GSTR1);
 sprintf(GSTR1,"[10;21H%-10ld",hoozer->Bytes_Download);
 AEPutStr(GSTR1);

 sprintf(GSTR2,"%s",ctime(&hoozer->Time_Last_On));
 GSTR2[24]='\0';
 sprintf(GSTR1,"[9;56H%s",GSTR2);
 AEPutStr(GSTR1);
 sprintf(GSTR1,"[11;21H%-10ld",hoozer->Daily_Bytes_Limit);
 AEPutStr(GSTR1);

  //sprintf(GSTR1,"%sScreenTypes.DEF",Cmds->BBSLoc);
  sprintf(GSTR2,"TITLE.%d",hoozer->ScreenType+1);
  AEPutStr("[11;56H");
  /*if(GetFromIconStr(GSTR1,GSTR2,GSTR2))
  {
    sprintf(GSTR1,"%-16s",GSTR2);
    AEPutStr(GSTR1);
  }*/
 
//(RTS)

 sprintf(GSTR1,"[13;17H%-6lu",hoozer->Time_Limit);
 AEPutStr(GSTR1);
 sprintf(GSTR1,"[13;51H%-6lu",hoozer->Time_Used);
 AEPutStr(GSTR1);

 sprintf(GSTR1,"[13;76H%d",hoozer->UUCPA);
 AEPutStr(GSTR1);

}


UWORD EditInfo(int which)
{
int flag; 
int command;
char temp[100];
 //NOFKeys=1;
 Display_Account(which);
 strcpy(GSTR1,hoozer->Name);
 (void)strupr(GSTR1);

	FOREVER	{
		flag=0;
		hotkey("",temp); command=temp[0];
		switch(command)	{
			case 'X':                       /* NO-SAVE */
				AEPutStr("[JNo-Save\r\n");
				flag=1;
				break;
			case '\t':
				flag=2;
				break;
			case '\177':                    /* DELETE */
				AEPutStr("[JDelete\r\n");
				GI2=which;
				hoozer->Slot_Number=0;

             /* changed from ForceSave_Account Thu Jan 30 04:17:48 1992 */
				Save_Account(GI2);
                    //DeleteConfAccess(hoozer->Slot_Number);
				Display_Account_Info(which); 
				flag=0;
				break;
			case ' ':
				Display_Account_Info(which);
				break;
			case '+':
					which=which+1;
					if((hoozer=Load_Account(which))!=NULL)
						Display_Account_Info(which);
					else {
						which=1;
						hoozer=Load_Account(which);
						Display_Account_Info(which);
					}
				break;
			case '-':
					which=which-1;
                         if(which<1) which=1;
					hoozer=Load_Account(which);
					Display_Account_Info(which);
				break;
			case '~': /* SAVE */
				AEPutStr("[JSave\r\n");
                    hoozer->New_User=0;
                    Display_Account_Info(which);
					Save_Account(which);  /* 1 = FORCE SAVE */
				break;
               case '8': case '7':
			case '6': case '5': case '4': case '3':
			case '2': /* VALIDATE */
			case '1':
				break;
             
			case '9':                       /* RE-ACTIVATE */
				AEPutStr("[JRe-Activate\r\n");
				hoozer->Slot_Number=which;
				flag=0;
				break;
			case 'a': case 'A':             /* NAME */
				AEPutStr("[2;10H");
				LineInput(hoozer->Name,hoozer->Name,30,KEYBOARD_TIMEOUT);
				strcpy(GSTR1,hoozer->Name);
				(void)strupr(GSTR1);
				flag=0;
				break;
			case 'b': case 'B':             /* Location */
				AEPutStr("[2;51H");
				LineInput(hoozer->Location,
					hoozer->Location,29,KEYBOARD_TIMEOUT);
				flag=0;
				break;
			case 'c': case 'C': /* PASS */
                        AEPutStr("[3;21H");
				    LineInput(hoozer->Pass,hoozer->Pass,8,KEYBOARD_TIMEOUT);
				flag=0;
				break;
			case 'd': case 'D': /* Phone number */
				AEPutStr("[4;21H");
				LineInput(hoozer->PhoneNumber,
					hoozer->PhoneNumber,12,KEYBOARD_TIMEOUT);
				flag=0;
				break;
			case 'e': case 'E': /* RATIO */
				AEPutStr("[5;21H");
				hoozer->Sec_Library=NumberInput();
				flag=0;
				break;
			case 'f': case 'F': /* conference access */
				AEPutStr("[4;56H");
				LineInput(hoozer->Conference_Access,hoozer->Conference_Access,9,KEYBOARD_TIMEOUT);
                    flag=0;
				break;
			case 'g': case 'G':  /* Ratio Type */
				AEPutStr("[6;21H");
				hoozer->Sec_Board=NumberInput();
                    if(hoozer->Sec_Board<0 || hoozer->Sec_Board > 2) 
                    {
                      AEPutStr("\a"); hoozer->Sec_Board=0; }
 sprintf(GSTR1,"[6;1H[33mG> [32mRatio Type ....[36m:[0m %-5hu",hoozer->Sec_Board);
 AEPutStr(GSTR1);
 if(hoozer->Sec_Board==0) AEPutStr(" [32m<-[33mByte[32m)[0m");
 if(hoozer->Sec_Board==1) AEPutStr(" [32m<-[33mB/F[32m)[0m ");
 if(hoozer->Sec_Board==2) AEPutStr(" [32m<-[33mFile[32m)[0m");

				flag=0;
				break;
			case 'h': case 'H': /* SEC_Level */
  
				    AEPutStr("[5;56H");
				    hoozer->Sec_Status=NumberInput();
				flag=0;
				break;
			case 'i': case 'I':                 /* UPLOADS */
				AEPutStr("[7;21H");
				hoozer->Uploads=NumberInput();
				flag=0;
				break;
			case 'j': case 'J':                 /* conference ReJoin */
				AEPutStr("[6;56H");
				hoozer->ConfRJoin=NumberInput();
             flag=0;
				break;
			case 'k': case 'K': /* DOWNLOADS */
				AEPutStr("[8;21H");
				hoozer->Downloads=NumberInput();
				flag=0;
				break;
			case 'l': case 'L': /* MESSAGES_POSTED */
				AEPutStr("[7;56H");
				hoozer->Messages_Posted=NumberInput();
				flag=0;
				break;
			case 'm': case 'M': /* Bytes Uploaded */
				AEPutStr("[9;21H");
				hoozer->Bytes_Upload=LongNumberInput();
				flag=0;
				break;
               case '#':
                    AEPutStr("[8;68H");
                    hoozer->Times_Called=LongNumberInput();
                    flag=0;
                    break;
			case 'o': case 'O': /* Bytes Downloaded */
				AEPutStr("[10;21H");
				hoozer->Bytes_Download=LongNumberInput();
				flag=0;
				break;
			case 'q': case 'Q': /* Daily Bytes Limit */
				AEPutStr("[11;21H");
				hoozer->Daily_Bytes_Limit=LongNumberInput();
				flag=0;
				break;
			case 'r': case 'R': /* Time_Limit */
				AEPutStr("[13;17H");
				hoozer->Time_Limit=LongNumberInput();
				if(hoozer->Time_Total<hoozer->Time_Limit)
  					hoozer->Time_Total=hoozer->Time_Limit;
				flag=0;
				break;
			case 's': case 'S': /* TIME_USED */

				AEPutStr("[13;51H");
				hoozer->Time_Used=LongNumberInput();
				flag=0;
				break;
			case 't':		case 'T':
				AEPutStr("[13;76H");
				hoozer->UUCPA=UUCPNumberInput();
				flag=0;
				break;

			default:
				flag=0;
				break;
			}
		AEPutStr("[16;1H");
		if(flag) { break; }
		}
//NOFKeys=0;
return((UWORD)flag);
}

WORD CheckNEdit(WORD which)
{
WORD stat;

AEPutStr("\014");
hoozer=Load_Account(which);
if(hoozer==NULL)
	{
	AEPutStr("Warning, error while loading account\r\n");
	return(FAILURE);
	}
AEPutStr("\017\014");
stat=EditInfo(which);
return(stat);
}

int Edit_Accounts(void)
{
WORD stat;
int which;

 FOREVER	{
	    AEPutStr("\r\nEnter Account Number ? ");
	    LineInput("",GSTR3,5,KEYBOARD_TIMEOUT);
	    if(GSTR3[0]=='\0') { goto RETURNF; }


	    which=(int)atol(GSTR3);
	    if(which<=0)  goto RETURNF;
	    CheckNEdit(which);
	}
 RETURNF:
 AEPutStr("\r\n");
 return(SUCCESS);
}

void LastCommand(void)
{
  sm("",1);
  sm("",1);
}

void end(void)
{
  exit(0);
}