#!/usr/bin/perl #************************************************************************ # TD Keno 1.11 * # Scripted by T.David * # tdkeno.cgi * # Original Creation: 9/26/99 * # Last Modified: 1/12/2000 * # * # Available at http://www.tdscripts.com/ * # * # COPYRIGHT NOTICE * # Copyright 1999-2000 KMR Enterprises All Rights Reserved * # * # By using this script you agree to indemnify us from any liability * # that might arise from its use. This copyright notice MUST * # remain in tact in order to legally use this script. Removal and/or * # modification of the copyright notice voids registration. * # * # You do *NOT* have permission to redistribute or sell the code for * # this program. This script is *NOT* freeware. It can be purchased * # and legally registered by visiting http://www.tdscripts.com/ * # * # VERSION HISTORY # 1.11 - fixed security setting bug * # 1.1 - added ability to change text and background colors, some minor * # formatting for Netscape browsers plus a filewriting fix (12/11) * # 1.0 - orig release (9/26) * # * ########################################################################## ########## Don't modify anything below this line ################# ########################################################################## require "setup.lib"; $match = 0; &parse_form; print "Content-type: text/html\n\n"; if ($security_option eq "yes") { &security; } if ($formdata{'react'} eq "highscore") { &highscore; } if ($formdata{'react'} eq "play") { &play; } if ($formdata{'react'} eq "play2") { &play2; } if ($formdata{'react'} eq "fillform") { &testspots; } if ($formdata{'react'} eq "securitylogin") { &securityloginverify; } else { &securitylogin; } sub security { $comingfrom = $ENV{'HTTP_REFERER'}; unless ($comingfrom =~ m#$mydomain#) { print "

$version can't be run from "; if ($comingfrom eq "") { print "bookmarks or type ins, sorry"; } else { print "$comingfrom, sorry."; } exit; } } sub securitylogin { &header; &table; print "Please enter your valid email address and password to play keno

\n"; &table2; print "
\n"; print "\n"; print "
EMAIL: \n"; print "
PASSWORD:"; print "
\n"; print "
New players create your account from this same form
"; &tableclose; if ($linkback eq "yes") { &td; } exit; } sub default { &header; &identify; print "
\n"; print "\n"; print "\n"; if ($showboard ne "yes") { print "

How many spots do you want to play (1-15)? \n"; print "\n"; } print "

How many games to play the same numbers 1 - $score ( maximum is $maxgames )

\n"; print ""; ## 12/21 Future use only - carryover prior numbers? print "\n"; # print "Replay same numbers?"; # radio yes/no here ## 12/21 Future use only - carryover prior numbers? print " \n"; print "

\n"; exit; } sub identify { $email = $formdata{'email'}; } sub scoreidentify { $games = $formdata{'games'}; delete $formdata{'games'}; } sub securityloginverify { &header; if (-e "$datapath/kenopw.txt") { } else { print "

The Keno database file has not been uploaded yet \n"; exit; } &identify; $password = $formdata{'password'}; if ($email =~ /([\W-.]+\@[\W-.]+)/) { &invalidemail; } if ($password =~ /\!\@\#\$\%\^\&\*\(\)\;\{\}\:\"\'\<\>\,\.\?/) { print "

Sorry, only letters and numbers are valid in the password field."; print "
Please go back and re-enter your password."; exit; } if ($password =~ /^\w{6,10}$/) { } else { print "

Sorry, valid passwords must be a minimum of 6 and maximum of 10 numbers and letters long."; print "
Please go back and re-enter your valid password."; exit; } &readpwdatabase; foreach $pwdata (@pwdb) { if ($pwdata =~ /\b$email\b/) { @checkpw = split(/,/,$pwdata); if ($checkpw[1] =~ /\b$password\b/) { &loginverify; } else { print "

The password entered did not match the password on file"; print "
Go back and enter a valid password."; $ip = $ENV{'REMOTE_ADDR'}; print "
For security purposes your IP address: $ip has been logged."; # optional logging ***could*** be added here... exit; } } } open(PWDATABASE,">>$datapath/kenopw.txt")|| &errorfilewrite; if ($filelocking eq "yes") { flock(PWDATABASE, 2); } print PWDATABASE "$email,$password\n"; if ($filelocking eq "yes") { flock(PWDATABASE, 8); } close(PWDATABASE); print "We could not find you in our player database, so we added you as a new player.\n"; print "
You may want to write down your password for future reference."; print "
Please go back and login to begin the game"; exit; } sub loginverify { if (-e "$datapath/kenodb.txt") { } else { print "

The Keno database file has not been uploaded yet \n"; exit; } &identify; $flag = "no"; if ($email =~ /([\W-.]+\@[\W-.]+)/) { &invalidemail; } &getscore; foreach $data (@emaildb) { if ($data =~ /\b$email\b/) { print "

Found you in our database. Welcome back! \n"; $flag = "yes"; $printscore = "yes"; &loginscore; } } if ($flag eq "no") { print "

You are in the game database. \n"; $score = $resetscore; $newdata = "$email|$score|"; push(@emaildb, $newdata); &writedatabase; } &default; } sub invalidemail { print "

Sorry your email appears to be invalid."; print "
Please go back and re-enter your valid email address."; print "

It must be in the format: myemail\@myisp.com "; exit; } sub readpwdatabase { open(PWDATABASE,"<$datapath/kenopw.txt")|| &errorfilewrite; @pwdb = ; close(PWDATABASE); } sub readdatabase { open(DATABASE,"<$datapath/kenodb.txt")|| &errorfilewrite; @emaildb = ; close(DATABASE); } sub writedatabase { open(DATABASE,">$datapath/kenodb.txt")|| &errorfilewrite; if ($filelocking eq "yes") { flock(DATABASE, 2); } ### added 12/11 td foreach $edata (@emaildb) { chomp($edata); if ($edata) { print DATABASE "$edata\n"; } } ### added 12/11 td if ($filelocking eq "yes") { flock(DATABASE, 8); } close(DATABASE); } sub highscore { &header; &readdatabase; foreach $the_score (@emaildb) { @currentscore = split(/\|/,$the_score); @cutoff = split(/\@/,$currentscore[0]); $namescore = "$currentscore[1] - $cutoff[0]"; push(@highscore, $namescore); } &table; print "$version current High Scores
\n"; @highscore = sort{$b <=> $a}(@highscore); $count = 1; &table2; foreach $highscore (@highscore) { if ($highscore =~ /\d/) { print "
(#$count) $highscore\n"; $count++; } } print "

\n"; &tableclose; print "

Go back with your browser to continue \n"; if ($linkback eq "yes") { &td; } exit; } sub updatescore { &readdatabase; foreach $data (@emaildb) { if ($data =~ /\b$email\b/) { $data = "$email|$score|"; } } &writedatabase; } sub checkscorearray { @checkscore = split(/\|/,$data); $score = $checkscore[1]; } sub loginscore { foreach $data (@emaildb) { if ($data =~ /\b$email\b/) { &checkscorearray; if ($checkscore[1] < 1) { $score = $resetscore; $data = "$email|$score|"; $printscore = "yes"; } } } &printscore; &writedatabase; } sub printscore { if ($printscore eq "yes") { $printscore = "no"; print " Your current score is $score"; } } sub getscore { &readdatabase; foreach $data (@emaildb) { if ($data =~ /\b$email\b/) { &checkscorearray; } } &printscore; } sub checkscore { &readdatabase; foreach $data (@emaildb) { if ($data =~ /\b$email\b/) { &checkscorearray; if ($games > $score) { print "

Playing this number of games ($games) will exceed your score ($score)\n"; print "
Click here to login and play again"; $exitflag = "yes"; } } } if ($exitflag eq "yes") { $exitflag = "no"; exit; } } sub testspots { $spots = $formdata{'spots'}; $games = $formdata{'games'}; $email = $formdata{'email'}; &getscore; if ($showboard ne "yes") { if ($spots <1 || $spots >15) { print "

You chose an invalid number of spots ( $spots ), must be 1-15 \n"; print "
Go back with your browser and re-enter a valid number of spots \n"; exit; } } if ($games > $score || $games > $maxgames || $games == 0 || $games =~ /\!\@\#\$\%\^\&\*\(\)\;\[a-zA-Z]\{\}\:\"\'\<\>\,\.\?/) { print "

Invalid choice ( $games ) for games must be a number between 1 and $score ( maximum $maxgames ) "; print "
Go back with your browser and re-enter a valid number of games \n"; exit; } &fillform; } sub fillform { &header; &identify; &scoreidentify; # uncomment next line to highlight spots played # print "
You chose to play $spots spots. \n"; if ($showboard eq "yes") { &drawkenoboardnew; print "\n"; print "\n"; exit; } else { print " Please choose $spots keno number(s)

"; print "

\n"; print "\n"; print "\n"; print "\n"; print "\n"; if ($spots >1) { print "\n"; } if ($spots >2) { print "\n"; } if ($spots >3) { print "\n"; } if ($spots >4) { print "\n"; } if ($spots >5) { print "\n"; } if ($spots >6) { print "\n"; } if ($spots >7) { print "\n"; } if ($spots >8) { print "\n"; } if ($spots >9) { print "\n"; } if ($spots >10) { print "\n"; } if ($spots >11) { print "\n"; } if ($spots >12) { print "\n"; } if ($spots >13) { print "\n"; } if ($spots >14) { print "\n"; } print "\n"; print "\n"; exit; } } sub header { print ""; print "Play $version"; print ""; } sub footer { print ""; } sub play2 { &identify; &scoreidentify; $checkn = 0; $chosen = $formdata{'chosen'}; @svalid = split(/\,/, $chosen); foreach $valid (@svalid) { $checkn++; if ($checkn > 15) { &errormsg("You chose more than 15 numbers, please go back and choose from 1-15 numbers"); } push (@numbers, $valid); } if ($checkn == 0) { &errormsg("You didn't choose any numbers. Please go back and choose at least 1 number."); } &checkscore; &header; print "
I am playing your card for $games games
\n"; for ($countgames = 0; $countgames < $games; $countgames++) { &pick_numbers; foreach $number (@numbers) { &compare2; } $spots = $#numbers + 1; &play_sub; } &updatescore; if ($score < 1 ) { print "

Thank you for playing. Your score is $score. You must login to play again. "; print "Click here"; exit; } else { print "[Click to QUIT] "; print "[View Current High Scores]\n"; print "

Your current score is $score"; &default; } } sub play_sub { print "

Your total matches are $match out of $spots spots"; &tableclose; if ($showboard eq "yes") { if (@numbers) { &drawkenoboard_graphics; } else { &drawkenoboard; } } if ($spots == 1) { &spots1; } if ($spots == 2) { &spots2; } if ($spots == 3) { &spots3; } if ($spots == 4) { &spots4; } if ($spots == 5) { &spots5; } if ($spots == 6) { &spots6; } if ($spots == 7) { &spots7; } if ($spots == 8) { &spots8; } if ($spots == 9) { &spots9; } if ($spots == 10) { &spots10; } if ($spots == 11) { &spots11; } if ($spots == 12) { &spots12; } if ($spots == 13) { &spots13; } if ($spots == 14) { &spots14; } if ($spots == 15) { &spots15; } $match = 0; @reset = ""; @matched = ""; } sub play { &identify; &scoreidentify; @values = values(%formdata); &checkscore; &header; print "I am playing your card for $games games\n"; for ($countgames = 0; $countgames < $games; $countgames++) { &pick_numbers; foreach $value (@values) { &compare; } $spots = $#values - 1; &play_sub; } &updatescore; if ($score < 1 ) { print "

Thank you for playing. Your score is $score. You must login to play again. "; print "Click here"; exit; } else { print "[Click to QUIT] "; print "[View Current High Scores]\n"; print "

Your current score is $score"; &default; } } sub spots1 { if ($match == 1) { $win = 3; &winner; } $score--; } sub spots2 { if ($match == 2) { $win = 12; &winner; } $score--; } sub spots3 { if ($match == 2) { $win = 1; &winner; } if ($match == 3) { $win = 42; &winner; } $score--; } sub spots4 { if ($match == 2) { $win = 1; &winner; } if ($match == 3) { $win = 3; &winner; } if ($match == 4) { $win = 120; &winner; } $score--; } sub spots5 { if ($match == 3) { $win = 1; &winner; } if ($match == 4) { $win = 10; &winner; } if ($match == 5) { $win = 800; &winner; } $score--; } sub spots6 { if ($match == 3) { $win = 1; &winner; } if ($match == 4) { $win = 3; &winner; } if ($match == 5) { $win = 85; &winner; } if ($match == 6) { $win = 1500; &winner; } $score--; } sub spots7 { if ($match == 4) { $win = 2; &winner; } if ($match == 5) { $win = 20; &winner; } if ($match == 6) { $win = 380; &winner; } if ($match == 7) { $win = 5000; &winner; } $score--; } sub spots8 { if ($match == 4) { $win = 1; &winner; } if ($match == 5) { $win = 5; &winner; } if ($match == 6) { $win = 75; &winner; } if ($match == 7) { $win = 1500; &winner; } if ($match == 8) { $win = 20000; &winner; } $score--; } sub spots9 { if ($match == 5) { $win = 3; &winner; } if ($match == 6) { $win = 40; &winner; } if ($match == 7) { $win = 350; &winner; } if ($match == 8) { $win = 4000; &winner; } if ($match == 9) { $win = 25000; &winner; } $score--; } sub spots10 { if ($match == 5) { $win = 2; &winner; } if ($match == 6) { $win = 15; &winner; } if ($match == 7) { $win = 100; &winner; } if ($match == 8) { $win = 1400; &winner; } if ($match == 9) { $win = 8000; &winner; } if ($match == 10) { $win = 50000; &winner; } $score--; } sub spots11 { if ($match == 5) { $win = 1; &winner; } if ($match == 6) { $win = 5; &winner; } if ($match == 7) { $win = 50; &winner; } if ($match == 8) { $win = 500; &winner; } if ($match == 9) { $win = 4000; &winner; } if ($match == 10) { $win = 10000; &winner; } if ($match == 11) { $win = 60000; &winner; } $score--; } sub spots12 { if ($match == 6) { $win = 4; &winner; } if ($match == 7) { $win = 30; &winner; } if ($match == 8) { $win = 210; &winner; } if ($match == 9) { $win = 1000; &winner; } if ($match == 10) { $win = 5000; &winner; } if ($match == 11) { $win = 25000; &winner; } if ($match == 12) { $win = 75000; &winner; } $score--; } sub spots13 { if ($match == 6) { $win = 3; &winner; } if ($match == 7) { $win = 15; &winner; } if ($match == 8) { $win = 90; &winner; } if ($match == 9) { $win = 500; &winner; } if ($match == 10) { $win = 1000; &winner; } if ($match == 11) { $win = 8000; &winner; } if ($match == 12) { $win = 50000; &winner; } if ($match == 13) { $win = 100000; &winner; } $score--; } sub spots14 { if ($match == 6) { $win = 2; &winner; } if ($match == 7) { $win = 10; &winner; } if ($match == 8) { $win = 50; &winner; } if ($match == 9) { $win = 150; &winner; } if ($match == 10) { $win = 775; &winner; } if ($match == 11) { $win = 2000; &winner; } if ($match == 12) { $win = 8000; &winner; } if ($match == 13) { $win = 50000; &winner; } if ($match == 14) { $win = 100000; &winner; } $score--; } sub spots15 { if ($match == 0) { $win = 10; &winner; } if ($match == 7) { $win = 5; &winner; } if ($match == 8) { $win = 25; &winner; } if ($match == 9) { $win = 100; &winner; } if ($match == 10) { $win = 400; &winner; } if ($match == 11) { $win = 5000; &winner; } if ($match == 12) { $win = 25000; &winner; } if ($match == 13) { $win = 50000; &winner; } if ($match == 14) { $win = 80000; &winner; } if ($match == 15) { $win = 100000; &winner; } $score--; } sub compare2 { foreach $keno(@keno) { if ($keno == $number) { $match++; push(@matched, $keno); # uncomment next line to show matching numbers # print " your $value matched"; } } } sub compare { foreach $keno(@keno) { if ($keno =~ /\b$value\b/ && $value != "" && $value != $duplicatenumber) { $match++; push(@matched, $keno); $duplicatenumber = $value; # uncomment next line to show matching numbers # print " your $value matched"; } } } sub td { print "Copyright 1999-2000 TD Scripts"; print " $cur_version"; } sub parse_form { if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); if ($ENV{'QUERY_STRING'}) { @getpairs =split(/&/, $ENV{'QUERY_STRING'}); push(@pairs,@getpairs); } } else { print "Content-type: text/html\n\n"; print "

Use Post or Get"; } foreach $pair (@pairs) { ($key, $value) = split (/=/, $pair); $key =~ tr/+/ /; $key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~s///g; if ($formdata{$key}) { $formdata{$key} .= ", $value"; } else { $formdata{$key} = $value; } } } sub pick_numbers { &keno_80_numbers; $increment = $countgames + 1; &table; print "20 Random Keno Numbers ... Game # $increment \n"; &table2; # print " \n"; # print ""; } if ($kenoboard == 20) { print ""; } if ($kenoboard == 30) { print ""; } if ($kenoboard == 40) { print ""; } if ($kenoboard == 50) { print ""; } if ($kenoboard == 60) { print ""; } if ($kenoboard == 70) { print ""; } }

20 Random Keno Numbers ... Game # $increment

"; print "
"; for ($new = 0; $new < 20; $new++) { $number = $#reset + 1; srand; $random = int(rand($number)); $next = $random; $keno[$new] = $reset[$next]; if ($reset[$next] = $number) { pop(@reset); } elsif ($next == 0) { shift(@reset); } else { splice(@reset,$reset[$next],1); } print " $keno[$new] \n"; } print "
"; } sub keno_80_numbers { for ($i = 1; $i < 81; $i++) { push(@reset, $i); } } sub errormsg { print "

$_[0]"; print ""; exit; } sub errorfilewrite { print "

The server cannot open the file or the permissions are wrong. \n"; exit; } sub winner { print "

"; print "Congratulations! You Won "; print "$win!"; print "

"; $score = $score + $win; } sub table { print "
\n"; print "

"; } sub table2 { print "

"; } sub tableclose { print "
"; } sub drawkenoboard_graphics { print ""; for ($kenoboard = 1; $kenoboard < 81; $kenoboard++) { print ""; # $rgbcolor = "rgb(231,254,254)"; # this line matches cyan (default) color } else { print "$kenoboard"; } &kenoboardcheck; } print "
"; $rgbcolor = "default"; foreach $keno(@keno) { if ($kenoboard =~ /\b$keno\b/) { # white $rgbcolor = "rgb(255,255,255)"; } } foreach $number(@numbers) { if ($kenoboard == $number) { # yellow $rgbcolor = "rgb(255,255,0)"; } } foreach $matched(@matched) { if ($kenoboard == $matched) { # green $rgbcolor = "rgb(0,255,0)"; } } if ($rgbcolor eq "default") { print "$kenoboard
"; } sub drawkenoboard { print ""; for ($kenoboard = 1; $kenoboard < 81; $kenoboard++) { print ""; # $rgbcolor = "rgb(231,254,254)"; # this line matches cyan (default) color } else { print "$kenoboard"; } &kenoboardcheck; } print "
"; $rgbcolor = "default"; foreach $keno(@keno) { if ($kenoboard =~ /\b$keno\b/) { # white $rgbcolor = "rgb(255,255,255)"; } } foreach $value(@values) { if ($kenoboard =~ /\b$value\b/) { # yellow $rgbcolor = "rgb(255,255,0)"; } } foreach $matched(@matched) { if ($kenoboard =~ /\b$matched\b/) { # green $rgbcolor = "rgb(0,255,0)"; } } if ($rgbcolor eq "default") { print "$kenoboard
"; } sub drawkenoboardnew { ### 12/21 ADD CHECKBOXES FOR PICKING NUMBERS print "
\n"; print "\n"; print "\n"; print "\n"; print "Please choose up to 15 keno numbers

"; print ""; for ($kenoboard = 1; $kenoboard < 81; $kenoboard++) { print ""; &kenoboardcheck; } print "
"; print "$kenoboard
"; ### 12/21 ADD CHECKBOXES FOR PICKING NUMBERS } sub kenoboardcheck { if ($kenoboard == 10) { print "