
   (********************************************************************

                 What-The-Heckware from the 'Bad Attitude BBS'
                           814-459-2116    2400 Baud

 This is my source code for a upload/download ratio checking program for
 Spitfire BBS.  To configure it to so your BBS's name is in the bulletins
 type LEECH CONFIG... To find out the command line usage type LEECH.  One
 word of caution... you cannot change the name of LEECH or use utilities
 such as PKLITE or DIET until after you configure the program.

 I've tested this and it seems to work fine but You should always make a
 backup of your SFUSERS.DAT before using any program for the first few times.

 Thanks to thank Mike Woltz for his Pascal examples, there are quite a few
 of them in here and I (and others) probably woudn't have even played with TP
 if he didn't put source code out and get us going.
 .
 I know as a programmer I have a long way to go and the more experienced
 will see quite a bit in here that could be better.  This is meant more for
 the people like me who have just started and need source code to follow
 (however poor) and I hope this helps them.

 You may do as you wish with it AS LONG AS YOU DON'T TRY TO MAKE MONEY FROM
 IT!  I'm tired of the greedy or un-feeling SysOp's who want to try to make
 money from other Spitfire SysOp's.  There are some fine utilities and stuff
 out there that you can see the work that went into but the majority are just
 fluff.

 This Program uses:
                       Source from Buffalo Creek Software - Mike Woltz

                       Source & ideas from 'TONS' of Public Domain

                       AutoInst from David Dubois - Zelkop Software
                       for its Auto-Configuration routines.

   ********************************************************************)

Program Sfleech;

Uses
  Crt,dos;

TYPE
        InstallBlockType = record
                               BBS : String;
                        end;
type
          UserDefaults = (Onekey,Reserved,Pause);
          Users         = Record
                            UserName,
                            CallingFrom      : String[30];
                            Password,
                            TimeDate         : String[14];
                            PhoneNumber      : String[12];
                            BirthDate        : String[8];
                            SecurityLevel    : Integer;
                            Uploads,
                            Downloads,
                            TotalUK,
                            TotalDK          : LongInt;
                            TimesOn,
                            TimeLeft,
                            Last_M_Conf,
                            Last_F_Area,
                            TransPro         : Integer;
                            Defaults         : Set Of UserDefaults;
                            FirstLogDate     : String[8];
                            SubscriptionDate : LongInt;
                            ConfQueue        : Array[0..31] Of Byte;
                            ExtraBytes       : Array[1..75] Of Byte;
                            AllowPurge,
                            BadLastOff,
                            ScrollBack,
                            Xpert,
                            LockedOut,
                            Deleted          : Boolean;
                            Linelen,
                            Pagelen,
                            OnToday,
                            Illegal,
                            DLToday,
                            ForeGround       : Byte;
                            ExtraWord        : Word;
                            DLBytes          : LongInt;
                            NewFCheck        : String[8];
                            Extra            : Array[1..25] Of Byte;
                          End;

Const
         InstallBlock : InstallBlockType
                 = ( BBS : 'The Bad Attitude BBS!');



 VAR
    UF          : File Of Users;
    User        : Users;


  (*---------------------------------------*)
    procedure ReInstall;
  (*---------------------------------------*)

  const
    FileName = 'Leech.Exe';
  var
    ExeFile    : file;
    HeaderSize : word;
  begin
    assign    ( ExeFile, FileName );
    reset     ( ExeFile, 1 );

    seek      ( ExeFile, 8 );
    blockread ( ExeFile, HeaderSize, sizeof ( HeaderSize ) );

    seek      ( ExeFile,   longint(16) * (   seg ( InstallBlock )
                                  - PrefixSeg
                                  + HeaderSize          )
                         + ofs ( InstallBlock )
                         - 256                           );

    blockwrite ( ExeFile, InstallBlock, sizeof ( InstallBlock ) );

    close      ( ExeFile );
  end;

  (*---------------------------------------*)
    Procedure Leech_Init;
  (*---------------------------------------*)

var
   yes_no : char;
        P : Byte;

begin
     with InstallBlock do
      begin
      writeln;
      for p := 1 to Length(BBS) do
         BBS[p] := UpCase(BBS[p]);

      writeln('BBS name is now configured to ',BBS);
      writeln('Would you like to personalize leech [y/n] ');
      yes_no := upcase(readkey);
      if yes_no <> 'Y' then
      halt;
      write  ( 'Please enter your BBS''s name - ' );
      readln ( BBS );
    end;  { update .EXE file }

  ReInstall;
  writeln;
  WriteLn ( '  LEECH.EXE is now configured...');
  writeln ( '  Next time run it will contain your BBS''s name.' );
halt;
 end;


  (*---------------------------------------*)
    Function Trim(S : String) : String;
  (*---------------------------------------*)

    Begin;
      While (S[1]=' ') And (Length(S)>0) Do S:=Copy(S,2,Length(S));
      While (S[Length(S)]=' ') And (Length(S)>0) Do S:=Copy(S,1,Length(S)-1);
      Trim:=S;
    End;


  (*---------------------------------------*)
    Procedure MakeLogo;
  (*---------------------------------------*)

    Begin;
        Writeln;
                 Writeln('                   SF-LEECH v1.1');
      TextColor(15);
      TextBackGround(4);
         Writeln('浜様様様様様様様様様様様様様様様様様様様様様様様様様融');
         Writeln('�   What-The-Heckware from -  The Bad Attitude BBS   �');
         Writeln('�                                 814-459-2116       �');
         Writeln('藩様様様様様様様様様様様様様様様様様様様様様様様様様夕');
         Writeln;
      TextBackGround(0);
          Writeln(' Member                  U/L        D/L');
            Writeln(' -------                 ---        ---');
    End;


   (*--------------------------------------*)
     Procedure config;
   (*--------------------------------------*)

 var
   Junk : string;
   i : byte;

    begin
      junk := Paramstr(1);

      for i := 1 to Length(junk) do
              junk[i] := UpCase(junk[i]);
      if junk = 'CONFIG' then
      Leech_init;
   end;

   (*--------------------------------------*)
     Procedure param;
   (*--------------------------------------*)

begin
    If ParamCount < 5 Then
   Begin
  Writeln;
  Writeln('Parameters For SF-Leech Are');
  Writeln;
  Writeln('           LEECH CONFIG - configures leech with your BBS name');
  Writeln;
  Writeln('            (1) = Directory for the bulletin');
  Writeln('            (2) = File name you want the bulletin to be');
  Writeln('            (3) = Security level you want to check ratios for');
  Writeln('            (4) = Security level you want them set at if out-of-line');
  Writeln('            (5) = Upload/Download ratio your system enforces');
  Writeln;
  Writeln('      Event Example:  CD\SF\WORK');
  Writeln('                      LEECH D:\SF\DISPLAY BULLET20 20 15 5');
  Writeln('                      CD\SF              |');
  Writeln('                      SF               Spaces');
  Writeln;
  Writeln('     Hint: Make sure you don''t make the low security level');
  Writeln('           your new user level or you will be upgrading the new');
  Writeln('           users who have uploaded but haven''t been verified.');
  Writeln('           If you don''t want a Bulletin just call it something');
  Writeln('           so you can see what changes were made.');
  Writeln;
   Halt;
    end;
     end;

  VAR
     Done          : Boolean;
     C             : Char;
     Leech,
     LeechClr      : Text;
     name,
     UserName,
     TheirBBS      : String;
     Total_Users,
     RecNo,
     P,
     X,
     Y,
     Z,
     lg,
     BBS_Ratio,
     Security_From,
     Security_To,
     Securitylevel    : Integer;
     Uploads,
     Downloads        : LongInt;
     ups,
     downs,
     linecolor        : string;
     Where_At         : String[40];
     Bullet           : String[12];
     randcolor        : byte;


 begin
   config;
   param;
   Assign(UF,'SFUSERS.DAT');
     {$I-}Reset(UF);{$I+}
      If IOResult<>0 Then
    Begin;
       Writeln('SFUSERS.DAT not found!');
        Writeln('Halting!!!',^G);
     Halt;
  End;

     Clrscr;
     MakeLogo;

       with installblock do
     TheirBBS := BBS;
          for p := 1 to Length(TheirBBS) do
         TheirBBS[p] := UpCase(TheirBBS[p]);


       Where_At  := Paramstr(1);
       Bullet    := Paramstr(2);
  Val(Paramstr(3),Security_From,x);
  Val(Paramstr(4),Security_to,y);
  Val(Paramstr(5),BBS_Ratio,z);

    P := Length(Paramstr(1));
     If Where_At[P] <> '\' Then
      Where_At := Where_At + '\';

    Assign(Leechclr,Where_At+Bullet+'.CLR');
    {$I-}Rewrite(Leechclr);{$I+}
     Append(Leechclr);

   Assign(Leech,Where_At+Bullet+'.BBS');
    {$I-}Rewrite(Leech);{$I+}
     Append(Leech);
      Writeln(Leech,'');
      Writeln(Leechclr,'');
        Writeln(Leech,' --  Over '+TheirBBS+' Ratio  --');
        Writeln(Leechclr,#27+'[0;1;36m --  Over '+TheirBBS+' Ratio  --');
          Writeln(leech,' Member                  U/L        D/L');
          Writeln(leechclr,#27+'[0;1;33m Member                  U/L        D/L');
            Writeln(leech,' -------                 ---        ---');
            Writeln(leechclr,#27+'[0;1;33m -------                 ---        ---');


 Total_Users:=Filesize(UF);
     Done := False;
       Recno := 0;

   Repeat
      Seek(Uf,Recno);
       Read(Uf,User);

  With User Do
    If (SecurityLevel = Security_From) or (SecurityLevel = Security_To) Then
     Begin
            Name := Trim(Username);
            If Length(Name) < 20 then
       for lg := Length(Name) to 20 do
       name := name + '.';

    str(uploads,ups);
    str(downloads,downs);

       ups := trim(ups);
       downs := trim(downs);

        repeat
        downs := '.' + downs;
        until length(downs) = 4;
        repeat
        ups := '.' + ups;
       until length(ups)= 4;

    If Uploads < Downloads Div BBS_Ratio Then

     Begin
        Randcolor := random(6)+1;

        Writeln(Leech,' '+name+'..',ups,'.......',downs);
        Writeln(Leechclr,' '+#27+'[0;1;3',randcolor,'m'+name+'..',ups,'.......',downs,+#27+'[37m');

         Writeln(' '+name+'..',ups,'.......',downs);
          Securitylevel:= Security_To;
   End

     Else
    if uploads > 0 then
    begin
   If SecurityLevel = Security_To Then
     Securitylevel := Security_From;
     end;
    End;

    RecNo:= (FilePos(Uf)-1);
      Seek(Uf,RecNo);
       Write(Uf,User);
        RecNo:=(RecNo + 1);

     If (RecNo=Total_Users -1)
       Then Done := True;
         Until Done;

          Writeln(Leech);
          Writeln(LeechClr);
           Writeln(Leech,'FreeWare From The Bad Attitude BBS!');
           Writeln(Leechclr,#27+'[0;1;36m FreeWare From The Bad Attitude BBS!'+#27+'[37m');

          {$I-}Close(UF);{$I+}
           {$I-}Close(Leech);{$I+}
           {$I-}Close(LeechClr);{$I+}
  End.