#!/usr/bin/perl
# NOTE: the above line must be changed to show the path to the
# Perl interpreter on your system! Leave the #! as is, but
# the path may have to be changed if yours is different.
#########################################################################
# SFEPoker v1.0.6 #
# Simple online video poker game for a website. #
# Copyright 2003, Kristina L. Pfaff-Harris #
# All rights reserved. #
# #
#########################################################################
##### License for SFEPoker 1.0.6
#####
##### This program may be used free of charge under the following
##### conditions:
#####
##### 1. All instructions and Copyright lines must remain unchanged.
#####
##### 2. All pages generated by the program must contain one of the
##### following pieces of HTML code:
#####
##### Powered by SFEPoker:
#####
##### http://www.tesol.net/scripts
##### OR:
#####
#####
#####
##### You may not remove the information described above from the script
##### without express written permission from the author.
#####
##### 3. You may not sell or distribute this program. You may charge
##### a reasonable fee for installing it for a client as long as
##### you make it clear that you are not the author, and you are
##### not selling the program to them: only charging for installing
##### it.
#####
##### 4. You agree that this program is offered without warranty of
##### any kind, including warranty of fitness for a particular
##### purpose. You further agree that the author and all sites
##### associated in any way with this program are not liable for
##### any damage or loss incurred as a result of using this program.
#####
##### 5. You may modify the program for your own use but you may not
##### distribute modified copies under any circumstances without
##### express written permission from the author.
#####
##### 6. Use of this program requires agreement to all the terms and
##### conditions of this license. If you do not agree to one or
##### more of these terms, you may not use the program.
#####
#########################################################################
##### #
##### IMPORTANT INSTRUCTIONS: #
##### #
##### In this program, I have put **CHANGE** in all the places where #
##### you will need to modify the program to run on your server, so #
##### that you can easily find all the places where changes are #
##### necessary. This program must be chmod 755 or 775 in order to #
##### work, and the directory where you want SFEPoker to put its #
##### files must be chmod 777. #
##### #
#########################################################################
# #
# IMPORTANT: If you FTPed this program to your server in "binary" mode, #
# it will NOT work! If you're not sure, please go back and FTP it #
# to your server again and make sure you use "ascii" mode. If you get #
# "500 Server Error", this is almost always the cause. :) #
# #
# Using the program: #
# This program requires the file "sfepoker.cgi" at a minimum in #
# order to work. Please read the README.sfepoker file for more #
# information. #
# #
# Please check the Scripts for Educators FAQ first #
# (http://tesol.net/scripts/FAQ/) if you have problems. If none of that #
# helps, email me and I'll at least try to help. :-) #
# #
# I hope this program proves useful to you! Please contact me #
# (http://tesol.net/scriptmail.html) for any bugs or feedback. #
#########################################################################
##### #
##### BEGIN SECTION WHERE YOU WILL NEED TO CHANGE THINGS: #
##### #
##### In this section, there are several places where you'll need #
##### to make changes. Please read all instructions carefully #
##### before you make the changes. #
##### #
#########################################################################
# $basedir: This is the base directory on your server where you
# want the program to store the files that keep track of
# the players' credits and their cards for their games.
# *CHANGE* this to the full base system path
# to where you want these files to be created and stored.
# Please see the README.sfepoker file for more
# information about $basedir, and how to set it up.
# Please note that this is NOT a URL, and should NOT
# contain "http://"
#
# If your web server is a Unix-type system, then this
# probably MUST begin a /, and the folder must be writeable
# by the web server. For example:
# $basedir = "/path/to/your/files";
#
# If your web server is a Windows-type system, then this
# probably MUST begin a "c:" or "d:" or "e:". For example:
# $basedir = "c:/path/to/your/files";
#
# One slight exception to the above is this: if you make a directory
# called "poker" in the same directory where this script is, then
# what I have below may work. If nothing else, it's worth a shot. :-)
$basedir = "./poker_files/";
# $keep_cookies_time: Information about each player and their
# "credits," cards, and so forth, is stored in a cookie in their browser,
# but also in files on the server. (This is because it's easy to get
# around anything in a browser, but not so easy to get around something
# on the server.) $keep_cookies_time is how long, in seconds, you want
# to keep these files lying around if the person isn't playing. Note
# that if a person closes their browser, they'll probably lose the cookie
# and have to create new files anyway. The default timeout is 15 minutes,
# meaning that if someone doesn't play for 15 minutes, their session will
# time out and they'll start over. If you do not want to ever delete these
# files, set $keep_cookies_time = "forever"; (This is not advisable because
# eventually this could take up all your disk space.) One hour is
# 3600. 24 hours is 86400. One week is 604800. One month is 2592000.
$keep_cookies_time = 900;
# $cgi_url is the web address of where you've set up this script.
# You'll need to change this to the URL of where you've set it up on
# your site. If you get a "File not found" error, it usually means
# that this isn't set up correctly. **CHANGE** this to the web
# address of this script on your web server.
$cgi_url = "http://yourdomain.com/sfepoker.cgi";
# $image_url is the web address of where you've put the gif images
# that came with this program. These images are needed in order to draw the
# cards. If the corners of the cards look strange, or show broken images,
# it probably means that this setting is not correct. **CHANGE** this
# to the URL of where you've put the gif image files that came with this
# program. This MUST begin with "http://" and it MUST end with a "/" as
# in the example below.
$image_url = "http://www.yourdomain.com/poker_images/";
# As you'll notice from the demo, there's a title across the top
# of the game page that shows a link.
# $game_title_text is the text of that link, or, in other words,
# the part of the link you see.
# $game_title_url is the site you want this to link to. You can have
# it say "Back to My Site" and have the link go to http://yoursite.com,
# or **CHANGE** it to whatever you like.
# IMPORTANT: DO NOT USE any " or @ signs or the script will break.
# ONLY change in between the "" that are already there.
$game_title_text = "SFE Presents: Online Video Poker";
$game_link_url = "http://tesol.net/scripts/SFEPoker/";
# $page_title_text is just the text for the title of the pages
# generated by the program.
# IMPORTANT: DO NOT USE any " or @ signs or the script will break.
# ONLY change in between the "" that are already there.
$page_title_text = "Welcome to Online Video Poker!";
# Now, the rest of this is just to make it easier to change the titles
# and words that are shown for various things. If you want to translate
# this game into another language, just translate the words below.
# IMPORTANT: DO NOT USE any " or @ signs or the script will break.
# ONLY change in between the "" that are already there.
# Names for winning hands
$royal_flush_text = "Royal Flush";
$straight_flush_text = "Straight Flush";
$four_of_a_kind_text = "Four of a Kind";
$straight_text = "Straight";
$flush_text = "Flush";
$full_house_text = "Full House";
$three_of_a_kind_text = "Three of a Kind";
$two_pair_text = "Two Pair";
$jacks_or_better_text = "Jacks or Better";
# What to say to the loser.
$loser_text = "LOSER!!!!";
$loser_amount_text = "ZIP!!!";
# Miscellaneous text
$new_game_text = "New Game.";
$reload_detected_text = "Reload Detected.";
$hold_text = "HOLD";
$held_text = "HELD";
$your_cards_text = "Your Cards";
$click_on_a_card_text = "Click on a card to select or unselect it.";
$draw_text = "Draw";
$you_have_won_text = "You have won %WINNINGS%";
$you_have_text = "You have %WINNINGS% in the bank.";
$betting_text = "Betting 5.";
$payouts_text = "Payouts";
$balance_text = "Balance: ";
$credits_text = "Credits";
$rules_text = "Rules";
$play_again_text = "Play Again?";
$entertainment_only_text = "
This game is for ENTERTAINMENT ONLY.
Credits are NOT-NEGOTIABLE.
No actual money or currency of any kind is involved in this game.
";
#########################################################################
##### #
##### END SECTION WHERE YOU WILL NEED TO CHANGE THINGS: #
##### #
##### You should not need to change anything beyond this point. In #
##### fact, anything you change beyond this point may completely #
##### break the program and cause it not to function. However, feel #
##### free to browse through the code if you like that sort of thing. #
##### :-) #
##### #
#########################################################################
my %data = &get_data();
# If $basedir doesn't exist, or we can't create files there, then the script
# won't run. So, we'll run a check or two to make sure we can, and if not,
# we'll print an informative error message.
&no_basedir_error();
# First, let's clear out old cookie files. Otherwise, they build up
# until there are millions of them.
if($keep_cookies_time && $keep_cookies_time !~ /^forever$/ && $keep_cookies_time =~ /^\d+$/){
opendir(DIR, "$basedir");
@cookiefiles = readdir(DIR);
closedir(DIR);
foreach $ckf (@cookiefiles){
if(-f "$basedir/$ckf" && $ckf =~ /^\d\d\d\d\d\d\d\d\d/){
if(time - (stat("$basedir/$ckf"))[9] > $keep_cookies_time){
unlink("$basedir/$ckf");
}
}
}
}
# We keep track of the user's cards and money and so forth by setting
# a cookie which we use to find the file where we saved their stuff
# on the server.
$cookie = $ENV{'HTTP_COOKIE'};
# I was kind of sloppy in setting the cookie when I was writing this and I
# set two different cookies, which ruined my whole day. This is just for
# those beta testers who were using it.
$cookie =~ s/Student=;//;
if($ENV{'SERVER_NAME'} =~ /linguistic-funland.com$/i ||
$ENV{'SERVER_NAME'} =~ /tesol.net$/i){
$entertainment_only_text .= " **DEMO VERSION** All credits will be reset to zero
periodically in this demo. ";
}
($stuff,$cookie) = split(/=/, $cookie);
if($cookie !~ /^\d+/){
$cookieyear = (CORE::localtime(time))[5] + 1900 + 25;
$cookie = time . $$ . $ENV{'REMOTE_ADDR'};
print "Content-type: text/html\n";
print "Set-Cookie: RCV=$cookie; expires=Fri, 26-Dec-$cookieyear 15:45:40 GMT;\n\n";
}
else {
print "Content-type: text/html\n\n";
}
$cookie =~ s/;//;
$moneyfile = "$basedir/$cookie";
$cardfile = "$basedir/$cookie.cards";
$screenfile = "$basedir/$cookie.screentracker";
# No longer needed
if(-f $screenfile){ unlink($screenfile); }
# If the money file based on their cookie doesn't exist, then we'll
# create it and give them 100 to start off with.
unless(-f $moneyfile){
open(F, ">>$moneyfile"); print F "100"; close(F);
}
# This is just a shortcut so I didn't have to keep typing it. :-)
$bg = " bgcolor=\"#FFFFFF\"";
$pagetop = <$page_title_text
EOF
$topmsg = <