/*
                            DSKEL-XS v1.1

                       (Xpress User Stats DOOR)

                       1         2         3
             (123456789012345678901234567890123456789)
Conf Access : XX_X____X___s__sX______X______________X
Caller Num. : 100888
1st Date On : 22 Apr 91
Lst Date On :  7 Mar 92
Security Lv : 255
# Times On  : 1123        Today : 4
Msgs Posted : 1500        Today : 0
File Ratio  : Disabled
Byte Ratio  : Disabled
# Downloads : 71          Today : 0
# Uploads   : 85          Today : 0
Bytes DL'd  : 137936061   Today : 39994
Bytes UL'd  : 8089329     Today : 4433
Online Baud : 14400
Screen Clear: On
Time Bar    : Off
Bytes Avail : 3000000


*/
//**********************
//*****  Includes  *****
//**********************

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

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

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


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


 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;             // Pointers!
   struct SystemData *SystemData;
   struct NodeData   *NodeData;
   struct Today      *Today;
  };

struct MsgPort *MyPort = NULL;
struct MyMessage *msg;
struct MyMessage send;
struct User *User;

char MyName[60],st[60];

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

main(int argc,char *argv[])
{
 char string[200],string1[200];
 char Day[5],Month[5],Year[5];
 register int x=1;
 if(!DoorStart(argv[1])) { PutStr("DSKEL-XS v3.15 [Xpress Stats]\n"); exit(0); }
 strcpy(string,User->MsgBase);
 do
  {
   if(string[x] == 'N') string[x] = '_';
   else if(string[x] == 'S') string[x] = 's';
     else string[x] = 'X';
   x++;
  }
 while(x < 40);
 strmid(string,string1,2,39);
 pl("\f\r\n                       [35m1         2         3\r\n");
 pl("             [36m([35m123456789012345678901234567890123456789[36m)\r\n");
 pl("Conf Access : [0m%s\r\n",string1);
//********************************************************************
 GetStr(string1,95);
 pl("[36mCaller Num. : [0m%s\r\n",string1);
//********************************************************************
 strcpy(string,ctime(&User->Time_First_Called));
 strmid(string,Month,5,3);
 strmid(string,Day,9,2);
 strmid(string,Year,23,2);
 pl("[36m1st Date On : [0m%2s %s %s\r\n",Day,Month,Year);
//********************************************************************
 strcpy(string,ctime(&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);
//********************************************************************
 if(User->UserBitsA & 0x00000400L) strcpy(string1,"On");
 else                             strcpy(string1,"Off");
 pl("[36mScreen Clear: [0m%s\r\n",string1);
//********************************************************************
 if(User->UserBitsA&0x00000008L) strcpy(string1,"On");
 else                           strcpy(string1,"Off");
 pl("[36mTime Bar    : [0m%s\r\n",string1);
//********************************************************************
 pl("[36mBytes Avail : [0m%ld\r\n\r\n",User->Left_DLBytes);
//********************************************************************
 CloseStuff();
}











//********************
//*****  DoorIO  ***** // MUST BE INCLUDED IN ALL DOORS!
//********************

int DOORIO(VOID)
{
 struct MsgPort *HisPort;
 if(send.carrier) return(0);
 HisPort = FindPort(st);
 if(HisPort!=NULL)
  {
   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 *)HisPort,(struct Message *)&send);
   Wait(1 << MyPort->mp_SigBit);
   GetMsg(MyPort);
   if(send.carrier) CloseStuff();
   return(1);
  }
 return(0);
}

//************************
//*****  Door Start  *****
//************************

int DoorStart(TEXT *node)
{
 struct MsgPort *HisPort;
 send.carrier=0;
 sprintf(st,"%s:TEMPEST_DOOR",node);
 HisPort = FindPort(st);
 if(HisPort==NULL) return (FALSE);
 sprintf(MyName,"%s:DOOR_PORT",node);
 MyPort = CreatePort(MyName,0L);
 if(MyPort==NULL)
  {
   PutStr("Cant open port");
   return(int)FALSE;
  }
 DOORIO();
 User=*&send.User;
 return (int)TRUE;
}

//*************************
//*****  Close Stuff  ***** // MUST BE INCLUDED IN ALL DOORS!
//*************************

VOID CloseStuff(VOID)
{
 send.Command=999;
 DOORIO();
 while(msg=(struct MyMessage *)GetMsg(MyPort)) ReplyMsg((struct Message *)msg);
 if(MyPort) DeletePort(MyPort);
 exit(0);
}

//*********************************
//*****  GetStr (Get String)  ***** // Command 33
//*********************************

VOID GetStr(TEXT *s,int opt)
{
 send.Command=33;
 send.Value1=opt;
 strcpy(s,NULL);
 send.text1=s;
 DOORIO();
}

//*****************************
//*****  PL (Print Line)  *****
//*****************************

VOID pl(TEXT *fmt,...)
{
 va_list args;
 char s[255];
 va_start(args,fmt);
 vsprintf(s,fmt,args);
 va_end(args);
 send.Command=1;
 send.text1=&s[0];
 DOORIO();
}
