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

#include <proto/all.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <exec/memory.h>

#include <time.h>
#include <string.h>
#include <Tempest/headers.h>
#include <tempest/defines.h>
#include <skeleton/commas.h>

int Loadnody(int node);
char *Myctime(long *);
void PRINTF(char *fmt,...);
VOID GetBBSPath(char *Path);

 struct node_info nody;
 struct SystemData SystemData;
 char string[200],string2[100];
 char BBSPATH[100];
 char Handle[40],Location[40],Activity[30],Time[15],ULFilename[15],DLFilename[15],
      ULFilesize[15],DLFileSize[15];
 int stat,NODES;
 int i,fd;
 int online=0;

//************************
//*****  Structures  *****
//************************

int main(int argc,char *argv[])
{
 sprintf(string,"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"");
 if(argc != 1)
  {
   PRINTF("\n[m[1m    _______ _________\n");
   PRINTF("   / ___/ [4m/[m[1m/ / ___/ /    [[32mSKEL-Who v3.51[m[1m] - [3mCLI Who[m\n");
   PRINTF("[1m  [4m/[m[1m__  /   _/ ___/ [4m/[m[1m__\n");
   PRINTF("[1m [4m/[m[1m____[4m/[m[1m_/\\_[4m)[m[1m____[4m/[m[1m____/   For Tempest BBS - [Programmer: Michael Bockert]\n");
   PRINTF(string);
   exit(0);
  }
 GetBBSPath(BBSPATH);
//********************************
//*****  Load Internal.Data  *****
//********************************

 sprintf(string,"%ssetup/SystemData.data",BBSPATH);
 fd=Open(string,MODE_OLDFILE);
 if(fd==0) exit(0);
 stat=Read(fd,(char *)&SystemData,sizeof(struct SystemData));
 Close(fd);
 if(stat!=sizeof(struct SystemData)) { PRINTF("Error-SystemData\n"); exit(0); }

 NODES = SystemData.NumberOfLines;

 PRINTF("\f    .-------.-------------------------.---------------------------------------.\n");
 PRINTF("    | LoGoN | HanDLe / LoCATioN       |  ACTiViTY CPS FiLENAME POSiTiON SiZE  |\n");

 i=0;
 do
  {
   stat=Loadnody(i);
   if(stat==0) goto EXIT;

   if(nody.UserInfo->Name[0]==NULL) goto EXIT;

   strcpy(Handle,nody.UserInfo->Name);
   strcpy(Location,nody.UserInfo->City);
   strcpy(ULFilename,nody.GLOB->ULFileName);
   strcpy(DLFilename,nody.GLOB->DLFileName);
   if(i!=0) online++;
   sprintf(string,"%s",Myctime(&nody.UserInfo->Time_Last_Connect));
   strmid(string,Time,12,5);
   strcpy(Activity,nody.GLOB->activity);
   if(nody.NodeDataInfo->LocalMode==0) sprintf(string2,"%2d",i);
   else                                strcpy(string2," L");

   PRINTF(".---|-------|-------------------------|---------------------------------------|\n");
   PRINTF("|%2s | %5s | %-23.23s | ",string2,Time,Handle);

   switch(nody.GLOB->AN)
    {
     case 35: PRINTF("UL:%5d %-12.12s %7d/%7d |\n",nody.GLOB->ULCPS,ULFilename,nody.GLOB->ULPosition,nody.GLOB->ULFileSize);
              break;
     default: PRINTF("%-38.38s|\n",Activity);
    }
   PRINTF("`---| %5.5d | %-23.23s | ",nody.GLOB->CurrentBaudRate,Location);
   switch(nody.GLOB->AN)
    {
     case 29: PRINTF("UL:%5d %-12.12s %7d/%7d |\n",nody.GLOB->ULCPS,ULFilename,nody.GLOB->ULPosition,nody.GLOB->ULFileSize);
              break;
     case 35: PRINTF("DL:%5d %-12.12s %7d/%7d |\n",nody.GLOB->DLCPS,DLFilename,nody.GLOB->DLPosition,nody.GLOB->DLFileSize);
              break;
     case 58: PRINTF("UL:%5d %-12.12s %7d/%7d |\n",nody.GLOB->ULCPS,ULFilename,nody.GLOB->ULPosition,nody.GLOB->ULFileSize);
              break;
     case 18: PRINTF("DL:%5d %-12.12s %7d/%7d |\n",nody.GLOB->DLCPS,DLFilename,nody.GLOB->DLPosition,nody.GLOB->DLFileSize);
              break;
     default: PRINTF("                                      |\n");
    }
   EXIT:
   i++;
  }
 while(i<=NODES);
 PRINTF("    |-------^-------------------------^---------------------------------------|\n");
 PRINTF("    |------------------.------------------.-----------------.-----------------|\n");
 PRINTF("    | Active Lines: %2d | Users Online: %2d | Free Lines: %2d  | SKEL-WHO  v3.50 |\n",
         NODES,online,(NODES-online));
 PRINTF("    `------------------^------------------^-----------------^-----------------'\n");
 exit(0);
}
//************************
//*****  Load Nody  ******
//************************

int Loadnody(int node)
{
 char string[50];
 register int y;
 int file;
 sprintf(string,"Node:NodeInfo_%d",node);
 for(y=1;y<3;y++)
  {
   file=Open(string,MODE_OLDFILE);
   if(file!=0)
    {
     Read(file,(char *)&nody,sizeof(struct node_info));
     Close(file);
     return(1);
    }
  }
 return(0);
}
//===========================* Beginning of Module *===========================
char *Myctime(long *secs)
{
 struct tm *tm;
 tm=gmtime(secs);
 return(asctime(tm));
}
//===========================* Beginning of Module *===========================
void PRINTF(char *fmt,...)
{
 va_list args;
 char string[200];
 va_start(args, fmt);
 vsprintf(string, fmt, args);
 va_end(args);
 Write(Output(),string,strlen(string));
}
//===========================* Beginning of Module *===========================
VOID GetBBSPath(char *Path)
{
 FILE *fp;
 fp=fopen("S:TempestPath","r");
 if(fp==NULL)
  {
   strcpy(Path,"");
   return;
  }
 fgets(Path,100,fp);
 fclose(fp);
}
