'
' PIRATE.PPE - Written by Dan Shore
' June 5, 1996
'
' Purpose: To allow a user to GAMBLE time or bytes
'
' To install:
'
' 1. Put PIRATE.PPE in it's own subdirectory off of the BANK.PPE
'
' 2. Edit GAMBLE.DAT - This file contains the name of the
' gambling modules (PPE) and a description.
' This file resides in the same directory
' as BANK.PPE
'
' Each gamble ppe that is used with
' BANK.PPE will have two lines entered in
' this configuration file. The first is
' the full path and name of the PPE. The
' second is a brief description of the
' gamble module ppe.
'
' Example:
' C:\PCB\PPE\BANK\PIRATE\PIRATE.PPE
' Brief one line description of game
'
'
' 3. Edit PIRATE.CFG - Consists of two lines w/three fields
' Line #1 = Only allow one play per day
' Line #2 = Time Gamble setup
' Line #3 = Byte Gamble setup
'
' Field #1 = TRUE or FALSE to all that type of gamble
' Field #2 = Maximum amount that can be gambled
' Field #3 = Win percentage
'
' Example: TRUE
' TRUE;30;.5
' TRUE;500000;.5
'
'
' Note about gambling add-ons:
'
' 1. The gambling module PPE *MUST* read & write to a file called
' BANK????.INF (???? = node number). This file contains
' bank balance information about the current user.
'
' The "PATH" to this file is passed at the 1st command
' line parameter (See first line of code).
'
' This information in this file will be as follows:
'
' Line #1 = Current Bank Time
' Line #2 = Current Bank Bytes
'
'──────────────────────────────────────────────────────────────────────────────
'
' Declare our variables
'
STRING hold ' Generic STRING variable
STRING hold2 ' Generic STRING variable
STRING main_prompt ' Generic prompt
STRING user_input ' Generic user input
STRING bank_inf_path ' Path to BANK????.INF file
STRING mod_name ' Name of Gambling Modules
STRING allow_time ' Allow time gamble
STRING time_max ' Max time to bet
STRING time_win_perc ' Amount of time when user wins
STRING allow_byte ' Allow byte gamble
STRING byte_max ' Max bytes to bet
STRING byte_win_perc ' Amount of bytes when user wins
STRING bank_txt ' External Text file
STRING max_dl_bytes ' User Maximum D/L bytes per PASSWORDS
STRING user_cfg_entry ' Entry from Bank.Cfg
INTEGER size ' Generic INTEGER variable
INTEGER bank_bytes ' Current Bank Bytes
INTEGER bank_time ' Current Bank Time
INTEGER gamble_amount ' Amount user gambled
INTEGER max_amount_bytes ' Maximum byte amount in a chest
INTEGER max_bank_bytes ' Max Bank Bytes (.CFG)
INT max_bank_time ' Max Bank Time (.CFG)
INT max_amount_time ' Maximum time amount in a chest
INT x ' Generic INT variable
INT gamble_type ' Time and/or Byte gamble allowed
' 1 = TIME, 2 = BYTE, 3 = BOTH
FLOAT win_percentage ' Show user win percentages
BOOLEAN do_time ' Time or byte gamble
BOOLEAN did_win ' Flag to show user won
BOOLEAN already_gambled ' Flag to show user already gambled today
BOOLEAN allow_once ' Flag to allow player to play more than once
BOOLEAN cannot_use ' Flag to not allow user in - cfg setup
'──────────────────────────────────────────────────────────────────────────────
'
' Declare our Gambling Procedure.
'
DECLARE PROCEDURE DO_GAMBLE (VAR BOOLEAN did_win)
DECLARE PROCEDURE ADD_COMMAS (VAR STRING hold2)
DECLARE PROCEDURE MAX_DLBYTES()
*$USEFUNCS
BEGIN
'
' Retrieve path to bank????.inf file
'
bank_inf_path = GETTOKEN()
'
' Define external text file - Support Language Files
'
bank_txt = PPEPATH() + "GAMBTXT" + LANGEXT()
'
' Open our Log File and log username
'
FAPPEND 7, PPEPATH() + "NODE" + STRING(PCBNODE()) + ".LOG", O_RW, S_DN
FPUTLN 7, "────────────── " + MIXED(U_NAME()) + " ──────────────"
'
' This is the name of the Gambling Module
'
mod_name = "Pirate Chest"
'
' Read configuration file for PIRATE
'
GOSUB READ_CFG
'
' Read the .INF file
'
GOSUB READ_BANK_INF
'
' Configuration error check
'
IF (max_amount_time = 0 && max_amount_bytes = 0) THEN
FPUTLN 7, "Pirate Chest cannot run becuse you have it"
FPUTLN 7, "configured for NO TIME OR BYTES. Check "
FPUTLN 7, "configuration file lines 4 and 5."
NEWLINE
PRINTLN "Module is CONFIGURED WRONG. No TIME or BYTES values or ZERO"
WAIT
GOTO EXIT_PROG
END IF
'
' Configuration lockouts
'
IF (max_amount_time = 0 && max_amount_bytes = 0) cannot_use = TRUE
IF (max_bank_bytes = 0 && max_amount_time = 0) cannot_use = TRUE
IF (max_bank_time = 0 && max_amount_bytes = 0) cannot_use = TRUE
'
' Show file explaining why
'
IF (cannot_use) THEN
DISPFILE PPEPATH() + "NOPLAY", LANG+SEC+GRAPH
WAIT
GOTO EXIT_PROG
END IF
'
' Check to see if user has already gambled today
'
IF (allow_once) GOSUB CHECK_IF_PLAYED
'
' Read the PASSWORDS file to get users maximum d/l byte limit
'
MAX_DLBYTES()
'
' If no TIME in chests, and user has unlimited D/L Bytes,
' then they cannot play the game.
'
IF (max_dl_bytes = "32767" && max_amount_time = 0) THEN
DISPFILE PPEPATH() + "NOTIME", SEC+LANG+GRAPH
NEWLINE
WAIT
GOTO EXIT_PROG
END IF
'
' Display intro file to explain to user what the game is about.
'
' *** Make sure to tell user they can ONLY gamble what is in the BANK
'
'
DISPFILE PPEPATH() + "INTRO", GRAPH+LANG+SEC
NEWLINE
'
' Show user if they are allowed to gamble time and/or bytes
'
GOSUB ALLOWED_BET
'
' Show user percentage when they win
'
GOSUB SHOW_WIN_PERCENTAGE
'
' Ask user if they wish to gamble time or bytes
'
GOSUB ASK_TIME_BYTE
'
' Write username to GAM-USER.DAT - This file keeps track of which
' users have played the gamble game already today.
'
IF (allow_once) THEN
'
FPUTLN 2, U_NAME()
FCLOSE 2
'
END IF
'
' Run the gambling game
'
DO_GAMBLE (did_win)
'
' Write information back to BANK????.INF file
'
GOSUB WRITE_INF
'
' Exit the PPE
'
GOTO EXIT_PROG
END
'────────────────────────────────────────────────────
' Start of Subroutines
'────────────────────────────────────────────────────
'
' Show user if they are allowed to gamble time and/or bytes
'
:ALLOWED_BET
'
' Inform the user if they are allowed to gamble time or bytes
'
IF (allow_time = "TRUE" && bank_time != 0) THEN
PRINTLN READLINE(bank_txt, 1)
FPUTLN 7, READLINE(bank_txt, 2)
gamble_type = 1
END IF
IF (allow_byte = "TRUE" && bank_bytes != 0) THEN
PRINTLN READLINE(bank_txt, 3)
FPUTLN 7, READLINE(bank_txt, 4)
IF (gamble_type) THEN
gamble_type = 3
ELSE
gamble_type = 2
END IF
END IF
IF (bank_time = 0 && bank_bytes = 0) THEN
PRINTLN READLINE(bank_txt, 5)
FPUTLN 7, READLINE(bank_txt, 6)
NEWLINE
WAIT
GOTO EXIT_PROG
END IF
NEWLINE
RETURN
'
' Show user what the winners received for time and byte bets
'
:SHOW_WIN_PERCENTAGE
'
' Show time win percentage
'
IF (gamble_type = 1 || gamble_type = 3) THEN
x = TOFLOAT(time_win_perc) * 100
hold = STRING(x) + "%"
PRINTLN READLINE(bank_txt, 7), hold, READLINE(bank_txt, 8)
FPUTLN 7, READLINE(bank_txt, 9), hold
END IF
'
' Show byte win percentage
'
IF (gamble_type > 1) THEN
x = TOFLOAT(byte_win_perc) * 100
hold = STRING(x) + "%"
PRINTLN READLINE(bank_txt, 10), hold, READLINE(bank_txt, 8)
FPUTLN 7, READLINE(bank_txt, 11), hold
END IF
NEWLINE
RETURN
'
' Write new information to BANK????.INF file
'
:WRITE_INF
'
' Determine amount won. Take the amount gambled and multiply
' by the percentage defined in the .CFG file
'
' If user loses gamble, deduct amount from bank balance
'
IF (did_win) THEN
IF (do_time) THEN
'
' Calculate winning amount
'
gamble_amount = gamble_amount * TOFLOAT(time_win_perc)
FPUTLN 7, READLINE(bank_txt, 12), gamble_amount, READLINE(bank_txt, 13)
bank_time = bank_time + gamble_amount
ELSE
'
' Calculate winning amount
'
gamble_amount = gamble_amount * TOFLOAT(byte_win_perc)
FPUTLN 7, READLINE(bank_txt, 12), gamble_amount, READLINE(bank_txt, 14)
bank_bytes = bank_bytes + gamble_amount
END IF
ELSE
'
' Calculate loss
'
IF (do_time) THEN
bank_time = bank_time - gamble_amount
ELSE
bank_bytes = bank_bytes - gamble_amount
END IF
'
END IF
'
' Delete the INF file and write a new file with the new information.
'
' Bank.PPE will read this file when it reloads
'
DELETE bank_inf_path + "BANK" + STRING(PCBNODE()) + ".INF"
FOPEN 1, bank_inf_path + "BANK" + STRING(PCBNODE()) + ".INF", O_WR, S_DN
FPUTLN 1, STRING(bank_time)
FPUTLN 1, STRING(bank_bytes)
FCLOSE 1
RETURN
'
' Ask user if they wish to gamble time or bytes. Then ask them how much
'
:ASK_TIME_BYTE
WHILE (1) DO
'
' If user can gamble time or bytes, prompt them for which type
' If user can only bet time OR bytes, then pass this section
'
user_input = ""
IF (gamble_type = 3) THEN
main_prompt = READLINE(bank_txt, 15)
INPUTSTR main_prompt, user_input, @X07, 1, "TB", UPCASE+LFAFTER+GUIDE+FIELDLEN
ELSE IF (gamble_type = 1) THEN
user_input = "T"
' FPUTLN 7, READLINE(bank_txt, 16)
ELSE IF (gamble_type = 2) THEN
user_input = "B"
' FPUTLN 7, READLINE(bank_txt, 17)
END IF
'
' Process user request for time or byte bet. Or jump to time
' or byte bet right away due to user only being able to bet
' one type (time or byte) due to bank restrictions.
'
IF (user_input != "") THEN
SELECT CASE (user_input)
'
' Time bet. Build variables based on time (prompt and max amount)
' for next prompt shown to user
'
CASE "T"
FPUTLN 7, READLINE(bank_txt, 16)
hold = READLINE(bank_txt, 18)
IF (TOINTEGER(time_max) > bank_time) THEN
hold2 = STRING(bank_time)
ELSE
hold2 = time_max
END IF
do_time = TRUE
'
' Byte bet. Build variables based on bytes (prompt and max amount)
' for next prompt shown to user
'
CASE "B"
FPUTLN 7, READLINE(bank_txt, 17)
hold = READLINE(bank_txt, 19)
IF (TOINTEGER(byte_max) > bank_bytes) THEN
hold2 = STRING(bank_bytes)
ELSE
hold2 = byte_max
END IF
do_time = FALSE
END SELECT
user_input = ""
'
' Ask user how much they wish to bet
'
WHILE (user_input = "") DO
user_input = ""
main_prompt = READLINE(bank_txt, 20) + hold + READLINE(bank_txt, 21) + hold2 + READLINE(bank_txt, 22)
INPUTSTR main_prompt, user_input, @X07, 9, "0123456789", UPCASE+LFAFTER+GUIDE+FIELDLEN
END WHILE
'
' See if user wishes to quit. If not, log bet amount
'
IF (user_input = "0" || user_input = "") GOTO EXIT_PROG
FPUTLN 7, "Amount of bet = ", user_input
'
' See if user entered too large a value
'
IF (TOINTEGER(user_input) > TOINTEGER(hold2)) THEN
NEWLINE
IF (do_time) THEN
PRINTLN READLINE(bank_txt, 23), hold2
ELSE
PRINTLN READLINE(bank_txt, 24), hold2
END IF
FPUTLN 7, READLINE(bank_txt, 25)
CONTINUE
END IF
'
' Put gamble amount in gamble variable and exit loop
'
gamble_amount = TOINTEGER(user_input)
BREAK
'
ELSE
'
' User hit enter to QUIT gamble
'
GOTO EXIT_PROG
'
END IF
END WHILE
RETURN
'
' Gamble Module code - Add your gambling code here. The only thing
' the gamble code must do is:
'
' 1. Set "did_win = TRUE" for a winner
' 2. Log if user wins or loses (FPUTLN 7)
' 3. Log all gambling activity (easier to track what the program/user did)
'
'
' You can also add your text to GAMBTXT or leave it in the .PPS file
'
PROCEDURE DO_GAMBLE (VAR BOOLEAN did_win)
STRING chest(6) ' Six Treasure Chests
INT type ' Type of value to put in chest
INT count ' Guess Count of user (2 max)
INT time_amount ' Total Time from Chests picked
INTEGER byte_amount ' Total Bytes from Chests picked
'
' Tell user computer is processing Treasure Chests
'
CLS
NEWLINES 5
PRINT READLINE(bank_txt,30)
'
' Process 6 chests
'
FOR x = 1 TO 6
PRINT x, " "
DELAY 6
WHILE (1) DO
DELAY 3
type = RANDOM(2) + 1
IF (type = 1 && (max_amount_time = 0 || max_bank_time = 0)) CONTINUE
IF (type = 2 && (max_amount_bytes = 0 || max_dl_bytes = "32767" || max_bank_bytes = 0)) CONTINUE
BREAK
END WHILE
'
SELECT CASE (type)
CASE 1
chest(x) = "T;" + STRING(RANDOM(max_amount_time) + 1)
CASE 2
chest(x) = "B;" + STRING(RANDOM(max_amount_bytes) + 1)
CASE 3
chest(x) = "0"
END SELECT
'
NEXT
PRINTLN READLINE(bank_txt,31)
'
' Log what is in each chest
'
FOR x = 1 to 6
FPUTLN 7, STRING(x) + " = " + chest(x)
NEXT
'
' Initialize some variables
'
count = 0
did_win = TRUE
'
' Display the 6 chests
'
NEWLINE
PRINTLN READLINE(bank_txt,32)
NEWLINE
PRINTLN " @X02┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐"
PRINTLN " @X02│ @X0F1 @X02│ │ @X0F2 @X02│ │ @X0F3 @X02│ │ @X0F4 @X02│ │ @X0F5 @X02│ │ @X0F6 @X02│"
PRINTLN " @X02└───┘ └───┘ └───┘ └───┘ └───┘ └───┘"
WHILE (count < 2) DO
'
' Ask user to choose a chest
'
NEWLINE
user_input = ""
IF (count = 0) main_prompt = READLINE(bank_txt,33)
IF (count = 1) main_prompt = READLINE(bank_txt,34)
INPUTSTR main_prompt, user_input, @X07, 1, "123456", GUIDE+FIELDLEN
FPUT 7, READLINE(bank_txt,35), " "
'
IF (user_input = "") THEN
FPUTLN 7, READLINE(bank_txt,36)
did_win = FALSE
BREAK
END IF
FPUTLN 7, user_input
'
' Increment out counter (for number of picks)
'
INC count
'
' Tokenize the string of the chest # the user picked
'
TOKENIZE chest(TOINT(user_input))
hold = GETTOKEN()
'
' Process first token to see what type of chest the user picked
'
IF (hold = "0") THEN
PRINTLN READLINE(bank_txt,37)
did_win = FALSE
BREAK
ELSE IF (hold = "T") THEN
hold = GETTOKEN()
time_amount = time_amount + TOINT(hold)
PRINTLN READLINE(bank_txt,38), hold, READLINE(bank_txt,39)
ELSE IF (hold = "B") THEN
hold = GETTOKEN()
size = TOINTEGER(hold)
add_commas(hold2)
byte_amount = byte_amount + size
PRINTLN READLINE(bank_txt,40), hold2, READLINE(bank_txt,41)
END IF
'
END WHILE
'
' See if user picked the Cursed Treasure Chest
'
IF (did_win) THEN
NEWLINE
PRINTLN READLINE(bank_txt,42)
FPUTLN 7, READLINE(bank_txt,43)
'
' Process any Chests picked with Time
'
IF (time_amount != 0) THEN
bank_time = bank_time + time_amount
NEWLINE
PRINTLN "@X0F", time_amount, READLINE(bank_txt,44)
FPUTLN 7, time_amount, READLINE(bank_txt,45)
END IF
'
' Process any Chests picked with Bytes
'
IF (byte_amount != 0) THEN
bank_bytes = bank_bytes + byte_amount
size = byte_amount
add_commas(hold2)
NEWLINE
PRINTLN "@X0F", hold2, READLINE(bank_txt,46)
NEWLINE
FPUTLN 7, byte_amount, READLINE(bank_txt,47)
END IF
WAIT
'
ELSE
'
NEWLINES 2
PRINTLN READLINE(bank_txt,48)
NEWLINE
PRINT READLINE(bank_txt,49)
NEWLINE
PRINTLN READLINE(bank_txt,50)
FPUTLN 7, READLINE(bank_txt,51)
NEWLINE
WAIT
'
END IF
ENDPROC
'
' Read the BANK????.INF file for current user information
'
:READ_BANK_INF
FOPEN 1, bank_inf_path + "BANK" + STRING(PCBNODE()) + ".INF", O_RD, S_DN
FGET 1, hold
bank_time = TOINTEGER(hold)
FGET 1, hold
bank_bytes = TOINTEGER(hold)
'
' Read cfg entry and place in variables
'
FGET 1, user_cfg_entry
TOKENIZE user_cfg_entry
'
' Skip security level
'
hold = GETTOKEN()
max_bank_time = GETTOKEN()
max_bank_bytes = GETTOKEN()
FCLOSE 1
RETURN
'
' Common exit point for program
'
:EXIT_PROG
FPUTLN 7, READLINE(bank_txt, 26)
FPUTLN 7
FCLOSE 7
END
'
' Read gambling configuration file to determine if time or bytes
' are allowed to bet. If so, maximum amounts to bet, and the winning
' percentage are all defined in this file
'
:READ_CFG
'
' Check for existance of .CFG file
'
IF (!EXIST(PPEPATH() + "PIRATE.CFG")) THEN
FAPPEND 6, bank_inf_path + "NODE" + STRING(PCBNODE()) + ".LOG", O_RW, S_DN
FPUTLN 6, "Could not find PIRATE.CFG - Module Aborted"
FCLOSE 6
GOTO EXIT_PROG
END IF
FOPEN 1, PPEPATH() + "PIRATE.CFG", O_RD, S_DN
'
' Continuous Loop
'
WHILE (1) DO
'
' See if player is allowed to play more than once per day
'
FGET 1, hold
'
' See if line is a comment or blank line
'
IF (LEFT(hold,1) = "'" || LEFT(hold,1) = "") CONTINUE
IF (hold = "TRUE") allow_once = TRUE
'
' Process Time information
'
FGET 1, hold
TOKENIZE hold
hold = UPPER(hold)
allow_time = GETTOKEN()
time_max = GETTOKEN()
time_win_perc = GETTOKEN()
'
' Process Byte information
'
FGET 1, hold
TOKENIZE hold
allow_byte = GETTOKEN()
byte_max = GETTOKEN()
byte_win_perc = GETTOKEN()
'
' Maximum time amount in a chest
'
FGET 1, hold
max_amount_time = TOINT(hold)
'
' Maximum byte amount in a chest
'
FGET 1, hold
max_amount_bytes = TOINTEGER(hold)
BREAK
'
END WHILE
FCLOSE 1
RETURN
'
' See if the user has already gambled today
'
:CHECK_IF_PLAYED
'
' Check the date file to see if it is a new day. If it is
' delete the file containing the usernames who have gambled today
'
' If the date file does not exist, we will create it
'
FOPEN 2, PPEPATH() + "CKDATE.DAT", O_RW, S_DN
FGET 2, hold
IF (TODATE(hold) < DATE() || hold = "") THEN
FREWIND 2
FPUT 2, DATE()
DELETE PPEPATH() + "GAM-USER.DAT"
END IF
FCLOSE 2
'
' Check to see if user has already gambled today
'
FOPEN 2, PPEPATH() + "GAM-USER.DAT", O_RW, S_DN
WHILE (1) DO
FGET 2, hold
IF (FERR(2)) BREAK
IF (INSTR(hold, U_NAME())) THEN
NEWLINES 5
PRINTLN READLINE(bank_txt, 27), mod_name, READLINE(bank_txt, 28)
NEWLINE
WAIT
already_gambled = TRUE
END IF
END WHILE
'
' If user already played, exit the program
'
IF (already_gambled) THEN
FPUTLN 7, READLINE(bank_txt, 29)
GOTO EXIT_PROG
END IF
RETURN
'
' Add Commas to display of numeric information
'
PROCEDURE ADD_COMMAS (VAR STRING hold2)
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 MAX_DLBYTES()
STRING temp
GETUSER
'
' 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()
'
' Log max d/l bytes
'
IF (max_dl_bytes != "32767") max_dl_bytes = max_dl_bytes + "000"
size = max_dl_bytes
ADD_COMMAS (hold2)
BREAK
'
END IF
END WHILE
FCLOSE 1
RETURN
END PROC