Metropoli BBS
VIEWER: bank3a.pps MODE: TEXT (CP437)
'
'  Bank3a - Written by Dan Shore - SysOp
'                      The Shoreline BBS
'                      September 12, 1996
'
'   Purpose:  When user logs off, prompt them to bank time, bytes or
'             log off the BBS.  The user will only be prompted for
'             depositing time or bytes IF they are able to (.CFG file
'             allows their security level to deposit time/bytes and
'             their bank balance is not max'ed out already).
'
'
'      NOTE:  If you do not use Warning on Logoff follow steps 1A & 1B
'             If you use Warning on Logoff follow steps 1C & 1D
'
'     ┌─────────────────────────────────────────────────────────┐
'     │ USE STEPS 1A and 1B IF YOU DO NOT USE WARNING ON LOGOFF │
'     └─────────────────────────────────────────────────────────┘
'
'       1A. Go into PCBSETUP and edit the log off script file.
'
'           B.  File Locations
'           D.  New User/Logon/off Questionnaires
'               Name/Loc of Logoff Script Quest.
'
'           Edit this field to the following:
'
'               C:\PCB\PPE\BANK\BANK3A.PPE
'
'                       - OR -
'
'               C:\PCB\PPE\BANK\BANK3A.PPE 110
'
'           The value on the command line will exempt any user
'           who's security level is GREATER THAN OR EQUAL to
'           this value (the PPE will not execute).  If no value
'           is entered (like example above) the PPE will execute
'           for all users.
'
'           NOTE:  You have have to change the path to the
'                  PPE to match your system.
'
'       1B. Go into PCBSETUP and edit
'
'           G.  Configuration Options
'           C.  System Control
'
'           Check the following entry
'
'           Warning on Logoff Command       : N
'
'     ┌──────────────────────────────────────────────────┐
'     │ USE STEPS 1C and 1D IF YOU USE WARNING ON LOGOFF │
'     └──────────────────────────────────────────────────┘
'
'       1C. Go into PCBSETUP and edit
'
'           G.  Configuration Options
'           C.  System Control
'
'           Check the following entry
'
'           Warning on Logoff Command       : Y
'
'       1D. Replace PCBText #605 with:
'
'           !c:\pcb\ppe\bank\bank3a.ppe
'
'           You can edit your PCBText file manually or use a
'           command line like the example below.  Modify the
'           paths for your setup.
'
' MKPCBTXT C:\PCB\GEN\PCBTEXT /I:605 "!c:\pcb\ppe\bank\bank3a.ppe"
'
'                       - OR -
'
' MKPCBTXT C:\PCB\GEN\PCBTEXT /I:605 "!c:\pcb\ppe\bank\bank3a.ppe 110"
'
'           The value on the command line will exempt any user
'           who's security level is GREATER THAN OR EQUAL to
'           this value (the PPE will not execute).  If no value
'           is entered (like example above) the PPE will execute
'           for all users.
'
'     ┌──────────────────────────┐
'     │ DO STEP 2 FOR ALL SETUPS │
'     └──────────────────────────┘
'
'       2.  Edit the file BANK3TL for your BBS name.  Try not
'           to change the width of the box as it will not
'           match the box in the PPE.  If you need to change
'           the width of the box, then you will need to
'           modify the PPE and recompile the code.
'
'           USE PCBEDIT ON BANK3TL to help keep the box size!
'
'────────────────────────────────────────────────────────────────────────────
'
'  Initialize variables

STRING pcb_user_name           ' User name
STRING main_prompt             ' Generic input prompt
STRING user_input              ' Generic user input
STRING key                     ' Check for key hit
STRING last_date               ' Last date user used Bank
STRING hold                    ' Generic string variable
STRING cfg_sl                  ' Security level read from .CFG file
STRING hold2                   ' Generic STRING variable
STRING options                 ' Input values allowed by user
STRING bank_txt                ' Text file for all user prompts
STRING pass_parm               ' Security Level to omit from this
                               '   program.  If no parameter is passed
                               '   all users will run this PPE

INT bank_time                  ' Current Bank Time
INT max_time_wd                ' Maximum time that can be withdrawn
INT max_bank_time              ' Maximum Bank Time
INT time_wd                    ' Time withdrawn for the day

INTEGER bank_bytes             ' Current Bank Bytes
INTEGER max_byte_wd            ' Maximum bytes that can be withdrawn
INTEGER max_bank_bytes         ' Maximum Bank Bytes
INTEGER byte_wd                ' Bytes withdrawn for the day
INTEGER max_dl_bytes           ' Users maximum d/l bytes allowed

BOOLEAN use_bank_time          ' Flag to allow user to deposit time
BOOLEAN use_bank_bytes         ' Flag to allow user to deposit bytes
BOOLEAN time                   ' Flag for deposit time or bytes
BOOLEAN user_found             ' Flag used for detecting if user already
                               '   played logoff games
BOOLEAN logoff_warn            ' Logoff Warning from PCBoard.Dat
BOOLEAN no_logoff              ' Flag for user choosing not to logoff
BOOLEAN bank_open              ' Flag to show bank is open
'────────────────────────────────────────────────────────────────────────────

DECLARE PROCEDURE WAIT_FOR_KEY ()
DECLARE PROCEDURE DEPOSIT (BOOLEAN time)
DECLARE PROCEDURE ADD_COMMAS (VAR STRING hold2, INTEGER size)
DECLARE PROCEDURE ASK_MAXIMUM (VAR INTEGER int1, INTEGER int2, INTEGER int3, INTEGER int4, INTEGER int5, VAR STRING user_input, VAR STRING hold, BOOLEAN time)
DECLARE PROCEDURE GET_MAX_DL_BYTES(VAR STRING max_dl_bytes)

*$USEFUNCS

BEGIN

  '
  '  Get user info
  '
  GETUSER
  STARTDISP FNS

  '
  '  Get command line parameter (if any)
  '
  pass_parm = GETTOKEN()

  '
  '  Define external text file - Support Language Files
  '
  bank_txt = PPEPATH() + "BANKTXT" + LANGEXT()

  '
  '  Read the PCBoard.Dat file and see if Warning on Logoff
  '  is enabled (Line 197 = "Y").
  '
  logoff_warn = RTRIM(READLINE(PCBDAT(),197)," ")

  '
  '  If users typed "G Y" or "BYE" exit the PPE
  '
  hold = UPPER(LASTANS())
  IF (INSTR(hold, YESCHAR()) > 0 || (U_SEC >= TOINT(pass_parm) && pass_parm != "")) THEN
    NEWLINE
    GOTO EXIT_PROG
  END IF

  '
  '  Read the BANK?.CFG file for user security level parameters
  '
  GOSUB READ_CFG

  '
  '  If we have a username and do not have the Password Prompt, check
  '  bank database for account and balance
  '
  GOSUB CHECK_DATABASE

  '
  '  Display menu - Time/Byte deposit depends if they have an account
  '                 and if they are allowed to deposit time/bytes
  '
  NEWLINE
  DISPFILE PPEPATH() + "BANK3TL", GRAPH+LANG
  IF (use_bank_time)    PRINTLN READLINE(bank_txt, 200)
  IF (use_bank_bytes)   PRINTLN READLINE(bank_txt, 201)
  IF (logoff_warn)      PRINTLN READLINE(bank_txt, 202)
                        PRINTLN READLINE(bank_txt, 203)
                        PRINTLN READLINE(bank_txt, 204)
                        PRINTLN READLINE(bank_txt, 205)

   '
   '  Set user options based on what the user is allowed to do
   '
   options = YESCHAR()

   '
   '  If warning on logoff enabled, add NOCHAR() as an option
   '
   IF (logoff_warn) options = options + NOCHAR()

   '
   '  Set other options based on what user is able to do
   '  (time and byte banking)
   '
   IF (use_bank_time) options = options + "T"
   IF (use_bank_bytes) options = options + "B"

   '
   '  Set default answer (log off bbs) so user can just hit enter
   '
   user_input = YESCHAR()
   NEWLINE
   main_prompt = READLINE(bank_txt, 206)
   INPUTSTR main_prompt, user_input, @X0E, 1, options, GUIDE+FIELDLEN+UPCASE+AUTO
   NEWLINE

   '
   '  Process user request
   '
   SELECT CASE (user_input)
     CASE "B"
       GOSUB START_LOGGING
       FPUTLN 7, READLINE(bank_txt, 207)
       DEPOSIT (FALSE)
       GOSUB CLOSE_LOG
     CASE "T"
       GOSUB START_LOGGING
       FPUTLN 7, READLINE(bank_txt, 208)
       DEPOSIT (TRUE)
       GOSUB CLOSE_LOG
     CASE "N"
       no_logoff = TRUE
   END SELECT

  '
  '  Let's get outa here!!
  '
  GOTO EXIT_PROG

END

'───────────────────────────
'   SUBROUTINES
'───────────────────────────

'
'  Check bank database for user
'
:CHECK_DATABASE

   '
   '  Open Database and Index
   '
   DOPEN 5, PPEPATH() + "BANK", FALSE
   DNOPEN 5, PPEPATH() + "BANK"

   '
   '  Check index to see if username exists in DB
   '
   pcb_user_name = UPPER(RTRIM(U_NAME(), " "))
   DSEEK 5, pcb_user_name

   '
   '  User name exists in the bank
   '
   IF (DCHKSTAT(5) = 0) THEN

     '
     '  Check to make sure we have an EXACT match of username
     '
     hold = TRIM(DGET (5, "usr_name")," ")
     IF (hold = pcb_user_name) THEN
       bank_time = DGET (5,"banktime")
       bank_bytes = DGET(5, "bankbytes")
       byte_wd = DGET (5, "bytewd")
       time_wd = DGET (5, "timewd")

       '
       '  Read the PASSWORDS file to get users maximum d/l byte limit
       '
       GET_MAX_DL_BYTES (max_dl_bytes)

       '
       '  See if time is available for deposit
       '
       IF (bank_time < max_bank_time && max_bank_time != 0 && MINLEFT() > 0) THEN
         use_bank_time = TRUE
       END IF

       '
       '  See if bytes are available for deposit
       '
       IF (bank_bytes < max_bank_bytes && max_bank_bytes != 0) THEN
         IF (U_BDLDAY() = 0) THEN
           use_bank_bytes = TRUE
         ELSE
           IF (max_dl_bytes * 1000 - U_BDLDAY() > 0) use_bank_bytes = TRUE
         END IF
       END IF
     END IF
   END IF

'
'  Close Log File
'
:CLOSE_LOG

   '
   '  CLose the bank log and the database
   '
   FPUTLN 7, READLINE(bank_txt, 112)
   FPUTLN 7
   FCLOSE 7
   RETURN

'
'  Common exit point
'
:EXIT_PROG

   '
   '  If bank database is open, close it
   '
   IF (bank_open) THEN
     DNCLOSEALL 5
     DCLOSE 5
   END IF

   '
   '  Turn off non-stop mode
   '
   STARTDISP FCL

   '
   '  If using warning on logoff setting and user has used time/byte
   '  banking, automatically logoff user after banking process
   '
   IF (logoff_warn) THEN
     IF (!no_logoff) user_input = YESCHAR()
     KBDSTUFF user_input + CHR(13)
   END IF
   '
   END

'
'  User is in database - ask if they wish to withdraw time
'
:START_LOGGING

    '
    '  Open node specific Log file & log current information
    '
    FAPPEND 7, PPEPATH() + "NODE" + STRING(PCBNODE()) + ".LOG", O_RW, S_DN
    FPUTLN 7, "────────────── " + MIXED(U_NAME()) + " ──────────────"
    FPUTLN 7
    FPUTLN 7, READLINE(bank_txt, 1), DATE()
    FPUTLN 7, READLINE(bank_txt, 2), TIME()
    FPUTLN 7, READLINE(bank_txt, 209)
    FPUTLN 7, READLINE(bank_txt, 169)
    FPUTLN 7, READLINE(bank_txt, 18), bank_time
    FPUTLN 7, READLINE(bank_txt, 17), bank_bytes
    RETURN

'
'  Deposit time or bytes here
'
PROCEDURE DEPOSIT (BOOLEAN time)

   INTEGER int1, int2, int3, int4, int5, size
   STRING str1
   BOOLEAN do_it

   '
   '  Get withdraw amouts for bytes and time.  These will be adjusted
   '  if the user deposits time/bytes
   '
   byte_wd = DGET (5, "bytewd")
   time_wd = DGET (5, "timewd")

   '
   '  Update last date used
   '
   DPUT 5, "last_d_acc", STRING(DATE())

   '
   '  Set variables based on time or byte deposit
   '
   IF (time) THEN
     int4 = bank_time
     int5 = max_bank_time
     str1 = "Time"
   ELSE
     int4 = bank_bytes
     int5 = max_bank_bytes
     str1 = "Bytes"
   END IF

   '
   '  Prompt for how many bytes/minutes to deposit
   '
   NEWLINE
   user_input = ""
   IF (!time) THEN
     NEWLINE
     size = bank_bytes
     ADD_COMMAS (hold2, size)
     PRINTLN READLINE(bank_txt, 210), hold2

     IF (max_dl_bytes * 1000 - U_BDLDAY() < (int5 - int4)) THEN
       size = max_dl_bytes * 1000 - U_BDLDAY()
     ELSE
       size = int5 - int4
     END IF
     ADD_COMMAS (hold2, size)
     PRINTLN READLINE(bank_txt, 211), hold2

     NEWLINE
     main_prompt = READLINE(bank_txt, 212)
     INPUTSTR main_prompt, user_input, @X0A, 9, "0123456789", GUIDE+FIELDLEN+ERASELINE
   ELSE
     NEWLINE
     PRINTLN READLINE(bank_txt, 210), bank_time
     IF (MINLEFT() > (int5 - int4)) THEN
       PRINTLN READLINE(bank_txt, 213), int5 - int4
     ELSE
       PRINTLN READLINE(bank_txt, 213), MINLEFT()
     END IF
     NEWLINE
     main_prompt = READLINE(bank_txt, 214)
     INPUTSTR main_prompt, user_input, @X0A, 3, "0123456789", GUIDE+FIELDLEN+ERASELINE
   END IF

   '
   '  User hit enter
   '
   IF (user_input = "") THEN
     NEWLINE
     RETURN
   END IF

   '
   '  Set variables according to time or bytes
   '
   IF (time) THEN
     int1 = TOINTEGER(user_input)
     int2 = time_wd
     int3 = max_time_wd
   ELSE
     int1 = TOINTEGER(user_input)
     int2 = byte_wd
     int3 = max_byte_wd
   END IF

   '
   '  check to see if the amount is more that what is avilable
   '  online for the user (DL Bytes for the day, and time remaining)
   '
   IF (!time) THEN
     IF (int1 > max_dl_bytes * 1000 - U_BDLDAY()) do_it = TRUE
   ELSE
     IF (int1 > MINLEFT ()) do_it = TRUE
   END IF

   '
   '  If trying to deposit more than what they have available
   '
   IF (do_it) THEN
     NEWLINE
     PRINTLN READLINE(bank_txt, 133), " ", str1, READLINE(bank_txt, 134)
     FPUTLN 7, READLINE(bank_txt, 135), " ", str1, ": ", int1, READLINE(bank_txt, 136), " ", str1

     '
     '  Show user what maximum amount is
     '
     IF (!time && (max_dl_bytes * 1000 - U_BDLDAY()) != 0) THEN
       ASK_MAXIMUM (int1, int2, int3, int4, int5, user_input, hold, time)
     ELSE IF (time && MINLEFT() > 0) THEN
       ASK_MAXIMUM (int1, int2, int3, int4, int5, user_input, hold, time)
     END IF

     '
     '  User did not want to use maximum amount
     '
     IF (hold = NOCHAR()) RETURN
     '
   END IF

   '
   ' test to see if input + current bank balance would be
   ' allowed in bank
   '
   IF (int4 + int1 > int5) THEN
     NEWLINE
     PRINTLN READLINE(bank_txt, 137)
     FPUTLN 7, READLINE(bank_txt, 135), " ", str1, ": ", int1, READLINE(bank_txt, 121), " ", str1

     '
     '  Ask the user to act on mamximum amount
     '
     IF (int5 - int4 > 0) THEN
       ASK_MAXIMUM (int1, int2, int3, int4, int5, user_input, hold, time)
     ELSE
       hold = NOCHAR()
     END IF

     '
     '  If user decided not to deposit max amount, exit out of routine
     '
     IF (hold = NOCHAR()) RETURN

   END IF

   '
   '  Write the new time information to the users file and database
   '
   IF (int1 != 0) THEN
     '
     '  Process Byte request
     '
     IF (!time) THEN
       '
       '  Adjust user byte info
       '
       ADJDBYTES int1
       '
       '  calculate and add info to database
       '
       bank_bytes = bank_bytes + int1
       DPUT 5, "bankbytes", bank_bytes
       '
     ELSE
       '
       '  Time Processing
       '
       ADJTIME -int1
       '
       '  Database information
       '
       bank_time = bank_time + int1
       DPUT 5, "banktime", bank_time
       '
     END IF

     '
     '  Display results of deposit request
     '
     NEWLINE
     size = int1
     ADD_COMMAS (hold2, size)
     IF (!time) THEN
       PRINT "         @X0F", hold2, READLINE(bank_txt, 216)
       FPUTLN 7, READLINE(bank_txt, 139), int1
     ELSE
       PRINT "         @X0F", hold2, READLINE(bank_txt, 217)
       FPUTLN 7, READLINE(bank_txt, 141), int1
     END IF

     '
     '  Adjust withdraw/day amount based on deposit type
     '
     IF (!time) THEN
       '
       '  Add more information to database
       '
       IF (byte_wd != 0) DPUT 5, "bytewd", byte_wd - int1
       '
     ELSE
       '
       '  Add more information to database
       '
       IF (time_wd != 0) DPUT 5, "timewd", time_wd - int1
       '
     END IF

     NEWLINES 2
     DELAY 36
     RETURN
     '
   END IF

END PROC

'
'  Read configuration file
'
:READ_CFG

   '
   ' Check for node specific configuration file.  If not exist,
   ' use generic BANK.CFG configuration file.
   '
   hold2 = PPEPATH() + "bank" + STRING(PCBNODE()) + ".cfg"
   IF (EXIST(hold2)) THEN
     FOPEN 1, hold2, O_RD, S_DN
   ELSE
     FOPEN 1, PPEPATH() + "bank.cfg", O_RD, S_DN
   END IF

   '
   '  Read configuration file until users security level is found
   '
   WHILE (1) DO
     '
     '  Retrieve a line from configuration file
     '
     FGET 1, hold

     '
     '  If we reach end of file, then we have not found a match to
     '  the users security level.  Log error and exit the BBS.
     '
     '  If you do not wish to have this information logged, comment
     '  out the 4 lines after the IF statement. (start logging to close
     '  log)
     '
     IF (FERR(1)) THEN
       GOSUB START_LOGGING
       LOG READLINE(bank_txt, 143), FALSE
       FPUTLN 7, READLINE(bank_txt, 144), STRING(U_SEC), READLINE(bank_txt, 145)
       GOSUB CLOSE_LOG
       '
       '  Exit PPE back to BBS
       '
       GOTO EXIT_PROG
       '
     END IF

     '
     '  See if line is a comment
     '
     IF (LEFT(hold,"'")) CONTINUE

     '
     '  Get all the parameter from the line just read in
     '
     TOKENIZE hold
     cfg_sl = GETTOKEN()

     '
     '  If users security level is matched, get first four values and exit
     '  else read the next entry (continue)
     '
     IF (TOINTEGER(cfg_sl) != U_SEC) THEN
       CONTINUE
     ELSE
       max_bank_time = GETTOKEN()
       max_bank_bytes = GETTOKEN()
       max_time_wd = GETTOKEN()
       max_byte_wd = GETTOKEN()
       BREAK
     END IF
     '
   END WHILE
   FCLOSE 1
   RETURN

'
'  Wait for user to hit any key
'
PROCEDURE WAIT_FOR_KEY()

   WHILE (key = "") DO
     key = INKEY()
     DELAY 3
   END WHILE
   key = ""

ENDPROC

'
'  Depending on trans_type, calculate the maximum withdraw amount,
'  then prompt user for confirmation
'
PROCEDURE ASK_MAXIMUM (VAR INTEGER int1, INTEGER int2, INTEGER int3, INTEGER int4, INTEGER int5, VAR STRING user_input, VAR STRING hold, BOOLEAN time)

   INTEGER size

   '
   '  Check for Time or Bytes and determine MAX amount
   '
   IF (time) THEN
     IF (MINLEFT() < (int5 - int4)) THEN
       size = MINLEFT()
     ELSE
       size = int5 - int4
     END IF
   ELSE
     IF (max_dl_bytes * 1000 - U_BDLDAY() < (int5 - int4)) THEN
       size = max_dl_bytes * 1000 - U_BDLDAY()
     ELSE
       size = int5 - int4
     END IF
   END IF

   '
   '  Add commas to maximum amount display if needed
   '
   ADD_COMMAS (hold2, size)

   '
   '  Prompt the user to deposit max amount
   '
   hold = YESCHAR()
   main_prompt = READLINE(bank_txt, 215) + hold2 + READLINE(bank_txt, 129)
   INPUTSTR main_prompt, hold, @X0E, 1, "YN", ERASELINE+UPCASE+GUIDE+FIELDLEN

   '
   '  Set user input equal to maximum value if answer was YES
   '
   IF (hold = YESCHAR()) int1 = size

ENDPROC

'
'  Add Commas to display of numeric information
'
PROCEDURE ADD_COMMAS (VAR STRING hold2, INTEGER size)

   INT x
   STRING temp

   temp = TRIM(STRING(size)," ")
   x = LEN(temp)
   '
   '  If the number is less than 4 characters in length, no need to add
   '  any commas to it.
   '
   IF (x < 4) THEN
     hold2 = temp
     RETURN
   END IF
   '
   '  Left pad the string with spaces (easy to add commas this way)
   '
   temp = SPACE(9-x) + temp

   IF (INSTR(temp,"-")) THEN
     '
     '  String has a negative symbol in it...Do not put a comma after it
     '
     IF (INSTR(MID(temp,1,3),"-")) THEN
       hold2 = MID(temp,1,3) + MID(temp,4,3) + "," + MID(temp,7,3)
     ELSE IF (INSTR(MID(temp,4,3),"-")) THEN
       hold2 = MID(temp,4,3) + MID(temp,7,3)
     END IF
   ELSE
     '
     '  Rebuild string with comma(s) in proper places
     '
     IF (MID(temp,1,3) != "   ") THEN
       hold2 = MID(temp,1,3) + "," + MID(temp,4,3) + "," + MID(temp,7,3)
     ELSE IF (MID(temp,4,3) != "   ") THEN
       hold2 = MID(temp,4,3) + "," + MID(temp,7,3)
     END IF
   END IF
   '
   '  Remove the left padded spaces we added above
   '
   hold2 = LTRIM(hold2," ")
   RETURN

ENDPROC

'
'  Find out maximum download bytes available for user
'
PROCEDURE GET_MAX_DL_BYTES(VAR STRING max_dl_bytes)

INT x
STRING temp

   '
   '  Find password file in PCBOARD.DAT and find matching
   '  security level.  Once found, get the total d/l bytes
   '  available to the user.
   '
   '  Security level is the 2nd parameter and daily d/l byte limit
   '  is the 4th parameter.
   '
   '
   hold = RTRIM(READLINE(PCBDAT(),32)," ")
   FOPEN 1, hold, O_RD, S_DN
   WHILE (1) DO
     '
     '  Read a line from the passwrd file
     '
     FGET 1, hold2
     '
     '  Check for EOF
     '
     IF (FERR(1)) BREAK
     '
     '  Replace any commas with semi-colons so we can tokenize string
     '
     hold2 = REPLACESTR (hold2, ",", ";")
     TOKENIZE hold2
     '
     '  2nd parm is security level
     '
     temp = GETTOKEN()
     x = GETTOKEN()
     '
     '  See if we match the users security level
     '
     IF (U_SEC() = x) THEN
       '
       '  4th parm is daily d/l byte limit
       '
       temp = GETTOKEN()
       max_dl_bytes = GETTOKEN()
       BREAK
       '
     END IF
   END WHILE
   FCLOSE 1

END PROC

[ RETURN TO DIRECTORY ]