/*                          UserStatus.mod

.----------------------------------------.------------------------------------.
| Handle:                                |   Slot Number: 1,222               |
|   From: 123456789012345678901234567890 | Computer Type:                     |
|  Phone:                                |     Last Call: 06/06/93 @ 22:22:22 |
|-------------------------.--------------^----------.-------------------------|
| Security Level: 233     | Daily Time: 1,000       | Bulletins Access: Yes   |
|     Byte Ratio:         |  Time Left: 1,000       |      Door Access:       |
|     File Ratio: Off     |  Time Bank: 1,000       |      File Access:       |
`-------------------------^-------------------------^-------------------------'

         Totals                   Today's Stats               Limits
.-------------------------.-------------------------.-------------------------.
|    Calls: 11,000        |    Calls: 11,000        |    Calls: 11,000        |
| Messages: 11,000        | Messages: 11,000        | Messages: 22,099        |
|-------------------------|-------------------------|-------------------------|
| UL Files: 1,000         | UL Files: 1,000         |                         |
| UL Bytes: 1,000,000,000 | UL Bytes: 1,000,000,000 |                         |
|-------------------------|-------------------------|-------------------------|
| DL Files: 1,000         | DL Files: 1,000         | DL Files: 1,000         |
| DL Bytes: 1,000,000,000 | DL Bytes: 1,000,000,000 | DL Bytes: 1,000,000,000 |
`-------------------------^-------------------------^-------------------------'
*/
//**********************
//*****  Includes  *****
//**********************

#include <proto/all.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include <stdarg.h>
#include <string.h>
#include <tempest/headers.h>
#include <Skeleton/Commas.h>

//********************************
//*****  Structures/Defines  *****
//********************************

 struct MyMessage
  {
   struct Message Msg; // for Exec message routines
   ULONG  Command;     // Command to be executed.

   char   *text1,
          *text2,
          *text3;
   int    Value1,
          Value2;
   ULONG  LongValue;
   LONGBITS Flags;
   int    carrier;
   struct User       *User;
   struct SystemData *SystemData;
   struct NodeData   *NodeData;
   struct Today      *Today;
  };

struct MyMessage send;

struct User *User;
struct SystemData *SystemData;
struct NodeData *NodeData;
struct Today *Today;
struct MsgPort *MyPort = NULL;
struct MyMessage *msg;

int  DoorStart(TEXT *);
int  DOORIO(WORD);
VOID CloseStuff(VOID);
VOID pl(TEXT *,...);
VOID GetStr(TEXT *,int);

struct MsgPort *TempestPort;

//******************
//*****  Main  *****
//******************

int main(int argc,char *argv[])
{
 char string[200],string1[200];
 char Day[5],Month[5],Year[5];
 int x=1;
 if(!DoorStart(argv[1])) { PutStr("TempesT Door\n"); exit(0); }
//********************************************************************


 pl("\f[34m.----------------------------------------.------------------------------------.\r\n");
 pl("| [36mHandle[0m: [33m%-30s [34m|   [36mSlot Number[0m: %-5s               [34m|\r\n",
     User->Name,commas(User->Slot_Number,buff));
 pl("|   [36mFrom[0m: %-30s [34m| [36mComputer Type[0m: %-19.19s [34m|\r\n",
     User->City,User->ComputerType);
 pl("|  [36mPhone[0m: %-12s                   [34m|     [36mLast Call[0m:                     [34m|\r\n",
     User->VoicePhone);
 pl("|-------------------------.--------------^----------.-------------------------|\r\n");
 pl("| [36mSecurity Level[0m: %3d     [34m| [36mDaily Time[0m: %-5s       [34m| [36mBulletins Access[0m:       [34m|\r\n",
     User->Security,commas((User->Limit_Time),buff));
 pl("|     [36mByte Ratio[0m: %-2d      [34m|  [36mTime Left[0m: %-5s       [34m|      [36mDoor Access[0m:       [34m|\r\n",
     User->B_Ratio,commas(User->Left_Time,buff));

 pl("|     [36mFile Ratio[0m: %-2d      [34m|  [36mTime Bank[0m: %-5s       [34m|      [36mFile Access[0m:       [34m|\r\n",
     User->F_Ratio,commas((User->Total_TimeBank),buff));
 pl("`-------------------------^-------------------------^-------------------------'\r\n\r\n");

 pl("         [35mTotals                   Today's Stats               Limits[34m\r\n");
 pl(".-------------------------.-------------------------.-------------------------.\r\n");
 pl("|    [36mCalls[0m: %-6s        [34m|    [36mCalls[0m: ",
     commas(User->Total_Calls,buff));
 pl("%-6s        [34m|    [36mCalls[0m: ",
     commas(User->Period_Calls,buff));
 pl("%-6s        [34m|\r\n",commas(User->Limit_Calls,buff));


 pl("| [36mMessages[0m: %-6s        [34m| [36mMessages[0m: ",
     commas(User->Total_Posts,buff));
 pl("%-6s        [34m| [36mMessages[0m: ",
     commas(User->Period_Posts,buff));
 pl("%-6s        [34m|\r\n",commas(User->Limit_Posts,buff));

 pl("|-------------------------|-------------------------|-------------------------|\r\n");
 pl("| [36mUL Files[0m: %-6s        [34m| [36mUL Files[0m: ",
     commas(User->Total_ULFiles,buff));
 pl("%-6s        [34m|                         |\r\n",commas(User->Period_ULFiles,buff));


 pl("| [36mUL Bytes[0m: %-13s [34m| [36mUL Bytes[0m: ",
     commas(User->Total_ULBytes,buff));
 pl("%-13s [34m|                         |\r\n",commas(User->Period_ULBytes,buff));

 pl("|-------------------------|-------------------------|-------------------------|\r\n");
 pl("| [36mDL Files[0m: %-6s        [34m| [36mDL Files[0m: ",
     commas(User->Total_DLFiles,buff));
 pl("%-5s         [34m| [36mDL Files[0m: ",
     commas(User->Period_DLFiles,buff));
 pl("%-5s         [34m|\r\n",commas(User->Limit_DLFiles,buff));

 pl("| [36mDL Bytes[0m: %-13s [34m| [36mDL Bytes[0m: ",
     commas(User->Total_DLBytes,buff));
 pl("%-13s [34m| [36mDL Bytes[0m: ",
     commas(User->Period_DLBytes,buff));
 pl("%-13s [34m|\r\n",commas(User->Limit_DLBytes,buff));
 pl("`-------------------------^-------------------------^-------------------------'[0m\r\n");


// strcpy(string,Myctime(&User->Time_Last_Logoff));
// strmid(string,Month,5,3);
// strmid(string,Day,9,2);
// strmid(string,Year,23,2);
// pl("[36mLst Date On : [0m%2s %s %s\r\n",Day,Month,Year);
//********************************************************************
// pl("[36mSecurity Lv : [0m%d\r\n",User->Security);
//********************************************************************
// pl("[36m# Times On  : [0m%-5d       [36mToday : [0m%d\r\n",User->Total_Calls,User->Period_Calls);
//********************************************************************
// pl("[36mMsgs Posted : [0m%-5d       [36mToday : [0m%d\r\n",User->Total_Posts,User->Period_Posts);
//********************************************************************
// if(User->F_Ratio==0) strcpy(string1,"Disabled");
// else                sprintf(string1,"%d/1",User->B_Ratio);
// pl("[36mFile Ratio  : [0m%s\r\n",string1);
//********************************************************************
// if(User->B_Ratio==0) strcpy(string1,"Disabled");
// else                sprintf(string1,"%d/1",User->B_Ratio);
// pl("[36mByte Ratio  : [0m%s\r\n",string1);
//********************************************************************
// pl("[36m# Downloads : [0m%-4d        [36mToday : [0m%d\r\n",User->Total_DLFiles,User->Period_DLFiles);
//********************************************************************
// pl("[36m# Uploads   : [0m%-4d        [36mToday : [0m%d\r\n",User->Total_ULFiles,User->Period_ULFiles);
//********************************************************************
// pl("[36mBytes DL'd  : [0m%-10ld  [36mToday : [0m%ld \r\n",User->Total_DLBytes,User->Period_DLBytes);
//********************************************************************
// pl("[36mBytes UL'd  : [0m%-10ld  [36mToday : [0m%ld\r\n",User->Total_ULBytes,User->Period_ULBytes);
//********************************************************************
// GetStr(string1,19);
// pl("[36mOnline Baud : [0m%s\r\n",string1);
//********************************************************************
// pl("[36mBytes Avail : [0m%ld\r\n\r\n",User->Limit_DLBytes);
//********************************************************************

//*************************
//*****  Close Stuff  *****
//*************************
 CloseStuff();
}



//===========================* Beginning of Module *===========================
char *Myctime(long *secs)
{
 struct tm *tm;
 tm=gmtime(secs);
 return(asctime(tm));
}



//************************
//*****  Door Start  ***** // MUST BE INCLUDED IN ALL DOORS!
//************************
int DoorStart(TEXT *node)
{
 char string[60];
 send.carrier=0;
 sprintf(string,"%s:TEMPEST_DOOR",node);
 TempestPort=FindPort(string);
 if(TempestPort==NULL) return(int)FALSE;
 MyPort=CreateMsgPort();
 if(MyPort==NULL) return(int)FALSE;
 DOORIO(0);
 User=*&send.User;
 SystemData=*&send.SystemData;
 NodeData=*&send.NodeData;
 Today=*&send.Today;
 return(int)TRUE;
}
//********************
//*****  DoorIO  ***** // MUST BE INCLUDED IN ALL DOORS!
//********************
int DOORIO(WORD Command)
{
 if(send.carrier) return(0);
 send.Command=Command;
 send.Msg.mn_Node.ln_Type = NT_MESSAGE;
 send.Msg.mn_Length = sizeof(send);
 send.Msg.mn_ReplyPort = MyPort;
 send.carrier=0;
 PutMsg((struct MsgPort *)TempestPort,(struct Message *)&send);
 Wait(1 << MyPort->mp_SigBit);
 GetMsg(MyPort);
 if((send.carrier)&&(send.Command!=999)) CloseStuff();
 return(1);
}
//*************************
//*****  Close Stuff  ***** // MUST BE INCLUDED IN ALL DOORS!
//*************************
VOID CloseStuff(VOID)
{
 DOORIO(999);
 while(msg=(struct MyMessage *)GetMsg(MyPort)) ReplyMsg((struct Message *)msg);
 if(MyPort) DeleteMsgPort(MyPort);
 exit(0);
}
//*********************************
//*****  GetStr (Get String)  ***** // Command 33
//*********************************
VOID GetStr(TEXT *s,int opt)
{
 send.Value1=opt;
 strcpy(s,"");
 send.text1=s;
 DOORIO(33);
}
//*****************************
//*****  PL (Print Line)  ***** // Command 1 with "%s %d",xxx,xxx) paramter support
//*****************************
VOID pl(TEXT *fmt,...)
{
 va_list args;
 TEXT s[255];
 va_start(args,fmt);
 vsprintf(s,fmt,args);
 va_end(args);
 send.text1=&s[0];
 DOORIO(1);
}
