home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
bbs_door
/
ebank10.arj
/
EARNBANK.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1992-04-08
|
7KB
|
258 lines
(*
* Copyright 1987, 1992 Samuel H. Smith; All rights reserved
*
* This is a component of the ProDoor System.
* Do not distribute modified versions without my permission.
* Do not remove or alter this notice or any other copyright notice.
* If you use this in your own program you must distribute source code.
* Do not use any of this in a commercial product.
*
*)
{!!!IMPORTANT!!! F5 WON'T WORK WITHOUT THE FOLLOWING LINE}
{$M 9000,18000,18000} {Stack, minheap, maxheap}
{$S-,R-}
{$L+,D+}
{$V-}
Program earnings_bank_door;
Uses
Dos,
MiniCrt, {BIOS-only crt functions}
OpenShare, {Shared text files}
MdosIO, {Dos-level random access files}
BufIO, {Buffered record i/o}
qRead, {Quick string qReadLn procedure}
Tools, {Various utilities}
ProBye,
ProData, {ProDoor/pcboard data}
ProRoot, {ProKit main support library}
ProSysf, {ProKit Status display, function keys, system functions}
ProScan, {File display and colorization}
ProUtil, {ProKit utility library #1}
ProUtil2, {proKit utility library #2}
KitInit; {ProKit initialization/deinit}
const
door_version = 'Earned K Bytes Banking Door 1.0 (04-07-92)';
type
bank_rec = record
name1: char25;
balance: longint;
spare: char35;
end;
var
bankfd: file of bank_rec;
bankrec: bank_rec;
bankrn: longint;
const
bankfile = 'EARNBANK.DAT';
(* ---------------------------------------------------------------- *)
procedure locate_record;
begin
pdisp('$YELLOW$Searching for '+username+' in EARNBANK file ...');
seek(bankfd,0);
while not eof(bankfd) do
begin
read(bankfd,bankrec);
if bankrec.name1 = pcbsys.name then
begin
displn(' Found!');
exit;
end;
end;
displn(' Not found!');
displn('A new EARNBANK record will now be created...');
fillchar(bankrec,sizeof(bankrec),0);
bankrec.name1 := pcbsys.name;
write(bankfd,bankrec);
end;
(* ---------------------------------------------------------------- *)
procedure update_record;
begin
seek(bankfd,filepos(bankfd)-1);
write(bankfd,bankrec);
end;
(* ---------------------------------------------------------------- *)
procedure load_config;
var
fd: text;
begin
assignText(fd,config_file);
reset(fd);
readln(fd);
close(fd);
end;
(* ---------------------------------------------------------------- *)
procedure do_deposit;
var
max_amt: longint;
amt: longint;
i: integer;
begin
max_amt := user.earned_k;
if max_amt = 0 then
begin
displn('No K Bytes available to deposit!');
exit;
end;
if length(cmdline) = 0 then
get_def('K Bytes to deposit, up to '+ltoa(max_amt)+': ',enter_eq_none);
get_nextpar;
if (par <> '') and (par[1] >= '0') and (par[1] <= '9') then
begin
val(par,amt,i);
if amt > max_amt then
amt := max_amt;
if (i = 0) and (amt > 0) then
begin
bankrec.balance := bankrec.balance + amt;
user.earned_k := user.earned_k - amt;
make_log_entry('EarnBank Deposit: '+ltoa(amt)+', Balance: '+ltoa(bankrec.balance),true);
end;
end;
end;
(* ---------------------------------------------------------------- *)
procedure do_withdrawal;
var
max_amt: longint;
amt: longint;
i: integer;
begin
max_amt := $FFFF - user.earned_k;
if max_amt > bankrec.balance then
max_amt := bankrec.balance;
if (max_amt = 0) then
begin
displn('No K bytes available to withdraw!');
exit;
end;
if (max_amt = $FFFF) then
begin
displn('You are already at the K byte limit!');
exit;
end;
if length(cmdline) = 0 then
get_def('K Bytes to withdraw, up to '+ltoa(max_amt)+': ',enter_eq_none);
get_nextpar;
if (par <> '') and (par[1] >= '0') and (par[1] <= '9') then
begin
val(par,amt,i);
if amt > max_amt then
amt := max_amt;
if (i = 0) and (amt > 0) then
begin
bankrec.balance := bankrec.balance - amt;
user.earned_k := user.earned_k + amt;
make_log_entry('EarnBank Withdrawal: '+ltoa(amt)+', Balance: '+ltoa(bankrec.balance),true);
end;
end;
end;
(* ---------------------------------------------------------------- *)
procedure command_menu;
begin
repeat
{prompt for input only if there is not a stacked command pending}
if length(cmdline) = 0 then
begin
newline;
pdispln( '$YELLOW$Welcome to EarnBank, the Earned-K Banking Door!');
newline;
pdispln( '$GREEN$ Current K bytes available = $WHITE$'+ltoa(user.earned_k));
pdispln( '$GREEN$ Current K bytes in bank = $WHITE$'+ltoa(bankrec.balance));
newline;
pdispln( '$YELLOW$Banking Commands: ');
pdispln( '$WHITE$ (D) $GREEN$Deposit K bytes for later use');
pdispln( '$WHITE$ (W) $GREEN$Withdraw K bytes to use now');
pdispln( '$WHITE$ (Q) $GREEN$Return to BBS');
newline;
repeat
display_time_left;
pdisp('$YELLOW$Command? ');
get_cmdline; {get cmdline, map to upper case}
newline;
until dump_user or (length(cmdline) > 0);
end;
if dump_user then exit; {leave menu if carrier lost}
get_nextpar; {scan next parameter from cmdline into par}
if par<> '' then
case par[1] of
'D': do_deposit;
'W': do_withdrawal;
'Q': ;
else displn('What? Please re-enter command!');
end;
until (par[1] = 'Q');
end;
(* ---------------------------------------------------------------- *)
procedure main;
begin
load_config;
cmdline := getenv('PCBDOOR');
assign(bankfd,bankfile);
{$i-} reset(bankfd); {$i+}
if ioresult <> 0 then
begin
rewrite(bankfd);
close(bankfd);
reset(bankfd);
end;
locate_record;
command_menu;
if not dump_user then
update_record;
close(bankfd);
end;
(* ---------------------------------------------------------------- *)
begin {main block}
init; {must be first - opens com port, loads setup and user data}
progname := 'EarnBank'; {program name on status line}
newline;
displn(door_version);
displn('Copyright 1992 Samuel H. Smith');
newline;
main;
uninit; {must be last - closes com port and updates database}
end.