
/*


   this util converts A15 user.data files to V1.0 user.data files


*/

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

#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/alib_protos.h>

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>

#include <HBBS/ANSI_Codes.h>
#include <HBBS/Defines.h>
#include <HBBS/types.h>
#include <HBBS/Access.h>
#include <HBBS/structures.h>
#include <HBBS/hbbscommon_protos.h>
#include <HBBS/hbbscommon_pragmas.h>
#include <HBBS/Hbbsnode_protos.h>
#include <HBBS/Hbbsnode_pragmas.h>

#include <HBBS/release.h>
char *versionstr="$VER: CVT_A15_V1.0 "RELEASE_STR;

/* **** Variables ********************************************************** */


struct Library *HBBSCommonBase  = NULL;
struct Library *HBBSNodeBase    = NULL;

struct BBSGlobalData *BBSGlobal = NULL;
struct NodeData *N_ND           = NULL;
int    N_NodeNum                = -1;

long __stack=16*1024; // increse this in 4k incrments if you suffer from
                      // random/suprious crashings after or during the running
                      // of your door.

int    gargc;         // these are just copies of main()'s argc and argv..
char   **gargv;

char tmpstr[BIG_STR];

/* **** Functions ********************************************************** */


#ifdef __SASC
int CXBRK(void) { return(0); }
int _CXBRK(void) { return(0); }
void chkabort(void) {}
#endif

static VOID cleanup(ULONG num)
{
  if (HBBSCommonBase)
  {
    HBBS_CleanUpCommon();
    CloseLibrary (HBBSCommonBase);
  }

  if (num) printf("Door Error = %d\n",num);

  exit(0);
}

static VOID init( void )
{
  if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  {
    cleanup(1);
  }

  if (!(HBBS_InitCommon()))
  {
    cleanup(2);
  }
}

struct OldUserData
  {
    // note: users DON'T have any form of ID based upon position in the file
    // but they do have ID, which is thier unique number that will always
    // be the same even if the userdata file is tieded.



    V_BIGNUM   UserID;   // When a user joins the system they are given
                         // a number, this number is BBSGlobal->LastUserNum+1
                         // this number is garunteed to be unique
                         // as this number goes up one everytime a new user
                         // is added to the user data file, but never goes down
                         // when users are removed.
                         // The lastusernum itself is stored in
                         // HBBS:System/Data/Private

    // see the flags USER_#? defined in <hbbs/defines.h>

    V_CHAR     Status;   // 'N' for new user      - the user is a new user..
                         // 'V' for validated     - the sysop has validated the user
                         // 'D' for deleted       - the sysop deleted the account
                         // 'I' for inactive      - the account became inactive
                         // 'L' for logins denied - user is not allowed to login.
                         // 'O' for overwritable  - set if you want this account to
                         //                         be erased by new accounts

    V_SMALLNUM Access;   // defines the users access level..

    // all arrays of V_CHAR are +1 for null terminator and should be allocated
    // with a MEMF_CLEAR flag...

    V_CHAR     Handle[LEN_HANDLE+1];          // all obvious definitions..
    V_CHAR     RealName[LEN_REALNAME+1];
    V_CHAR     Group[LEN_GROUP+1];
    V_CHAR     GeoLocation[LEN_GEOLOCATION+1];
    V_CHAR     Country[LEN_COUNTRY+1];
    V_CHAR     PhoneNumber[LEN_PHONENUMBER+1];
    V_CHAR     Password[LEN_PASSWORD+1];    // not encrypted.. as if i did
                                // encrypt it some bugger would write a
                                // password hacker anyway!
    V_CHAR     ComputerType[LEN_COMPUTERTYPE+1];  // note: this is a string, not a number!

    V_CHAR     SentBy[LEN_SENTBY+1]; // sentby string!  New, for Alpha A9

    V_CHAR     ConfAcsDataFile[LEN_CONFACCESSFILE+1];  // filename pointer to data for the access to
                                                       // conferences, e.g. "NewUser"
               // we look in HBBS:System/Data/ConfAcs for the above filename

               // note: this might be blank, if so the confjoiner program must check the access
               // level of the conference the user wants to join.

               // this file is normally only used to disable/enable access to conferences
               // without changing their access levels (which would enable more ACS_ commands)


    V_CHAR     LeechAccDataFile[LEN_LEECHACCESSFILE+1];
               // we look in HBBS:System/Data/LeechAcs for the above filename

    // below are the values the nukers should play with and all the doors
    // should actually use to figure out stuff like weektops/conf tops/charts...

    // these are also used to work out the ratios and wether the user is over the
    // limit or not..

    V_BIGNUM   UploadBytes;
    V_BIGNUM   UploadFiles;
    V_BIGNUM   DownloadBytes;
    V_BIGNUM   DownloadFiles;

    // these numbers below are the ACTUAL ammount of bytes the user has transferred
    // (via file transfer protocols like Zmodem) no doors should EVER change the
    // values in these variables, treat them as is they were readonly..

    // they should be used for programs that work out the amount of bytes that
    // have been uploaded to the system in a year, how many bytes have been nuked
    // etc etc...

    V_BIGNUM   ActualUploadBytes;
    V_BIGNUM   ActualUploadFiles;
    V_BIGNUM   ActualDownloadBytes;
    V_BIGNUM   ActualDownloadFiles;

    // dates for last upload and when the user last called.. great for spotting
    // users who have uploaded loads and then turned into a leech!
    // also so that doors can work out how many days since user last uploaded
    // great for creating lists of lamers..

    // you could write a door that tells the user their account will expire in N
    // days if they do not upload! cooool!

    LONG       LastUploadDate;
    LONG       LastCalledDate; // use time() and localtime() on these..

    // some vars for bulletin/top chart makers! :-) hope this helps!

    V_BIGNUM   BestCPSUp;
    V_BIGNUM   BestCPSDown;
    V_BIGNUM   CallsMade;
    V_BIGNUM   PagesMade;
    V_BIGNUM   MessagesWritten;


    V_SMALLNUM BytesRatio;   // as in N:1...
    V_SMALLNUM FilesRatio;

    V_BIGNUM   LastConf;  // last conf user was in when they logged off..
    V_BIGNUM   PreferredConf; // users prefrered conference, if this is not set to 0
                             // then join this conference instead of the conference
                             // the user was last in...
                             // conference joiner must check that this is a valid conf
                             // numer and that the user has access to it before
                             // joining it upon login.

    V_SMALLNUM LinesPerScreen; // obvious!

    V_SMALLNUM Protocol;    // number of protocol to use, if set to 0 then
                            // the the bbs will ask the user what
                            // protocol the user wishes to use for EVERY transfer

    V_SMALLNUM Editor;      // same as above except for editing text files...

    V_SMALLNUM ScreenType;  // use for enabling/disabling ansi colour..

    V_CHAR     TimeAccessFile[LEN_TIMEACCESS+1];
                            // number of TimeAccess to use.. (defines when a user
                            // can and can't login..
                            // looks in HBBS:System/Data/TimeAcs for this file..

                            // note: match THIS name to the name in the BBSGlobal->TimeAcsList
                            // nodes's ln_Name field rahter than loading each time as all access
                            // data is loaded at control startup time.

    V_BIGNUM   ExtraTimeLimit;
                            // if this is set then this number will be added to the
                            // amount of time a user is allowed on-line
                            // which is defined for each access level.. *I*mplement

    V_BIGNUM   ExtraBytesLimit;
                            // this number is added to the amount of bytes the user
                            // is allowed to download in one day which is defined
                            // for each access level...

    V_BIGNUM   ExtraCallsLimit;
                            // same as above except for calls a user is allowed to
                            // make in one day
    V_BIGNUM   ExtraChatLimit;
                            // same as above except for chat time user allowed to
                            // have per day

    V_BIGNUM   BytesAllowed;
                            // amount of bytes user is allowed to download in one day.
                            // if set to 0 then the user has unlimited
                            // see TimeAllowed for some rules..
    V_BIGNUM   TimeAllowed;
                            // amount of time user is allowed in one day.
                            // see

    V_BIGNUM   ChatAllowed;
                            // amount of chat time user is allowed in one day.

    V_BIGNUM   CallsAllowed;
                            // amount of calls a user is allowed to make in one day.


    V_BIGNUM   TimeUsed;
                            // total amount of time used today..
                            // (so, to determine when to log off a user get the amount
                            // of time a user is allowed per day from the access settings
                            // for that level, then add the ExtraTimeLimit to that, then
                            // take off the TimeUsed value and if it's <= 0 then log em off!

                            // The BBS Resets this value at 00:00am to 0 when the user is
                            // online, the frontend must check the last called date with
                            // todays date to determine wether or not to reset this
                            // at logon time..

    V_BIGNUM   BytesUsed;
                            // amount of bytes downloaded today. see timeused also.

    V_BIGNUM   CallsUsed;
                            // amount of calls made today. see timeused also.

    V_BIGNUM   ChatUsed;
                            // amount of chat time used today. see timeused also.

    V_CHAR     UserType;    // currently set to either
                            // USERTYPE_NORMAL or USERTYPE_EXPERT
                            // this is used by the CmdPrompt door to
                            // decide wether or not to display the menu options
                            // availiable to the user.  can also be used by
                            // other programs

    V_BIGNUM   Language;    // Number of LanguageName/Extn to be used. (index starts at 1)

  }; // don't forget to update HBBSCommon.c/HBBS_InitUserData()

int main(int argc,char **argv)
{
  BPTR INFH,OUTFH;

  struct UserData nu;
  struct OldUserData ou;
  LONG br;

  init();

  if (argc==3)
  {

    if (INFH=Open(argv[1],MODE_OLDFILE))
    {
      if (OUTFH=Open(argv[2],MODE_NEWFILE))
      {
        do
        {
          br=Read(INFH,&ou,sizeof(struct OldUserData));
          if (br>0)
          {
            nu.UserID=ou.UserID;
            nu.Status=ou.Status;
            nu.Access=ou.Access;

            strcpy(nu.Handle,ou.Handle);
            strcpy(nu.RealName,ou.RealName);
            strcpy(nu.Group,ou.Group);
            strcpy(nu.GeoLocation,ou.GeoLocation);
            strcpy(nu.Country,ou.Country);
            strcpy(nu.PhoneNumber,ou.PhoneNumber);
            strcpy(nu.Password,ou.Password);
            strcpy(nu.ComputerType,ou.ComputerType);
            strcpy(nu.SentBy,ou.SentBy);
            strcpy(nu.ConfAcsDataFile,ou.ConfAcsDataFile);
            strcpy(nu.LeechAccDataFile,ou.LeechAccDataFile);

            nu.UploadBytes=ou.UploadBytes;
            nu.UploadFiles=ou.UploadFiles;
            nu.DownloadBytes=ou.DownloadBytes;
            nu.DownloadFiles=ou.DownloadFiles;
            nu.ActualUploadBytes=ou.ActualUploadBytes;
            nu.ActualUploadFiles=ou.ActualUploadFiles;
            nu.ActualDownloadBytes=ou.ActualDownloadBytes;
            nu.ActualDownloadFiles=ou.ActualDownloadFiles;
            nu.LastUploadDate=0;
            nu.LastCalledDate=0;
            nu.BestCPSUp=ou.BestCPSUp;
            nu.BestCPSDown=ou.BestCPSDown;
            nu.CallsMade=ou.CallsMade;
            nu.PagesMade=ou.PagesMade;
            nu.MessagesWritten=ou.MessagesWritten;
            nu.BytesRatio=ou.BytesRatio;
            nu.FilesRatio=ou.FilesRatio;
            nu.LastConf=ou.LastConf;
            nu.PreferredConf=ou.PreferredConf;
            nu.LinesPerScreen=ou.LinesPerScreen;
            nu.Protocol=ou.Protocol;
            nu.Editor=ou.Editor;
            nu.ScreenType=ou.ScreenType;

            strcpy(nu.TimeAccessFile,ou.TimeAccessFile);

            nu.ExtraTimeLimit=ou.ExtraTimeLimit;
            nu.ExtraBytesLimit=ou.ExtraBytesLimit;
            nu.ExtraCallsLimit=ou.ExtraCallsLimit;
            nu.ExtraChatLimit=ou.ExtraChatLimit;

            nu.BytesAllowed=ou.BytesAllowed;
            nu.TimeAllowed=ou.TimeAllowed;
            nu.ChatAllowed=ou.ChatAllowed;
            nu.CallsAllowed=ou.CallsAllowed;
            nu.TimeUsed=ou.TimeUsed;
            nu.BytesUsed=ou.BytesUsed;
            nu.CallsUsed=ou.CallsUsed;
            nu.ChatUsed=ou.ChatUsed;

            nu.UserType=ou.UserType;
            nu.Language=ou.Language;

            Write(OUTFH,&nu,sizeof(struct UserData));
          }
        } while (br>0);

        Close(OUTFH);
      }
      else puts("Can't open output file");
      Close(INFH);
    }

    else puts("Can't open input file");
  }
  else
  {
    puts("usage: CVTData <in> <out>\n"
         "Converts HBBS A15 release 1 format user data to A16 release 1 format");
  }
  cleanup(0);
}

/* **** End Of File ******************************************************** */
