From 924f395a39eeccbcd54d540613e440cbedd6ba3d Mon Sep 17 00:00:00 2001
From: Arun Persaud
Date: Sat, 26 Apr 2008 13:01:41 -0700
Subject: CLEANUP: cleaned up index.php a bit more by introducing an 'action'
variable
no more if, but one nice switch statement in index.php
Signed-off-by: Arun Persaud
---
include/cancelgame.php | 8 ++
include/functions.php | 6 +-
include/game.php | 40 ++++++----
include/login.php | 33 +++++++++
include/logout.php | 2 -
include/newgame.php | 186 ++++++++++++++++++++++++++++++++++++++++++++---
include/newgameready.php | 175 --------------------------------------------
include/output.php | 6 +-
include/reminder.php | 10 ++-
include/user.php | 10 +--
index.php | 66 +++++++----------
11 files changed, 288 insertions(+), 254 deletions(-)
create mode 100644 include/login.php
delete mode 100644 include/newgameready.php
diff --git a/include/cancelgame.php b/include/cancelgame.php
index 9f86142..fba950e 100644
--- a/include/cancelgame.php
+++ b/include/cancelgame.php
@@ -7,6 +7,14 @@ if(!isset($HOST))
output_status();
+if(!myisset("me"))
+ {
+ echo "Hmm, you really shouldn't mess with the urls.
\n";
+ output_footer();
+ DB_close();
+ exit();
+ }
+
$me = $_REQUEST["me"];
/* test for valid ID */
diff --git a/include/functions.php b/include/functions.php
index 991d53d..28e5937 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -700,7 +700,7 @@ function display_table ()
if(!$debug)
echo " $name \n";
else
- echo " $name\n";
+ echo " $name\n";
/* add hints for poverty, wedding, solo, etc */
if($GT=="poverty" && $party=="re")
@@ -823,10 +823,10 @@ function display_user_menu()
while( $r = mysql_fetch_array($result,MYSQL_NUM))
{
- echo "game ".DB_format_gameid($r[1])."
\n";
+ echo "game ".DB_format_gameid($r[1])."
\n";
}
- echo "
Start a new game\n";
+ echo "
Start a new game\n";
echo "
Statistics\n";
diff --git a/include/game.php b/include/game.php
index 0e16292..51d4320 100644
--- a/include/game.php
+++ b/include/game.php
@@ -5,6 +5,14 @@
if(!isset($HOST))
exit;
+if(!myisset("me"))
+ {
+ echo "Hmm, you really shouldn't mess with the urls.
\n";
+ output_footer();
+ DB_close();
+ exit();
+ }
+
$me = $_REQUEST["me"];
/* test for valid ID */
@@ -70,7 +78,7 @@ for($i=1;$i<5;$i++)
};
/* put everyting in a form */
-echo "
";
DB_set_hand_status_by_hash($me,'init');
}
else
@@ -274,7 +282,7 @@ switch($mystatus)
DB_set_sickness_by_hash($me,"nines");
}
- echo " Ok, done with checking, please go to the \n";
echo "Your cards are:
\n";
@@ -803,11 +811,11 @@ switch($mystatus)
{
/* email startplayer) */
$message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
- "Use this link to play a card: ".$HOST.$INDEX."?me=".$hash."\n\n" ;
+ "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
}
else
- echo " Please,
start the game.
";
+ echo " Please,
start the game.
";
}
else
echo "\n
";
@@ -1260,7 +1268,7 @@ switch($mystatus)
$message = "A card has been played in game ".DB_format_gameid($gameid).".\n\n".
"It's your turn now.\n".
- "Use this link to play a card: ".$HOST.$INDEX."?me=".$next_hash."\n\n" ;
+ "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$next_hash."\n\n" ;
if( DB_get_email_pref_by_uid($who)!="emailaddict" )
mymail($email,$EmailName."a card has been played in game ".DB_format_gameid($gameid),$message);
}
@@ -1526,7 +1534,7 @@ switch($mystatus)
$hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
$link = "Use this link to have a look at game ".DB_format_gameid($gameid).": ".
- $HOST.$INDEX."?me=".$hash."\n\n" ;
+ $HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
if( DB_get_email_pref_by_uid($user) != "emailaddict" )
mymail($To,$EmailName."game over (game ".DB_format_gameid($gameid).") part 2(2)",$link);
}
diff --git a/include/login.php b/include/login.php
new file mode 100644
index 0000000..346c71e
--- /dev/null
+++ b/include/login.php
@@ -0,0 +1,33 @@
+
\ No newline at end of file
diff --git a/include/logout.php b/include/logout.php
index d74f091..f2ebbaf 100644
--- a/include/logout.php
+++ b/include/logout.php
@@ -10,6 +10,4 @@ session_unset();
session_destroy();
$_SESSION = array();
-echo "
";
?>
\ No newline at end of file
diff --git a/include/newgame.php b/include/newgame.php
index 5764568..5db0f28 100644
--- a/include/newgame.php
+++ b/include/newgame.php
@@ -7,16 +7,180 @@ if(!isset($HOST))
output_status();
/* user needs to be logged in to do this */
-if( isset($_SESSION["name"]) )
+if(! isset($_SESSION["name"]) )
{
- $names = DB_get_all_names();
- echo "
\n";
- output_form_for_new_game($names);
- echo "
\n";
- display_user_menu();
+ echo "
";
}
- else
- {
- echo "
";
- }
-?>
\ No newline at end of file
+else
+ {
+ if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","callrule" ))
+ {
+ /* get my name */
+ $name = $_SESSION["name"];
+
+ /* the names of the four players */
+ $PlayerA = $_REQUEST["PlayerA"];
+ $PlayerB = $_REQUEST["PlayerB"];
+ $PlayerC = $_REQUEST["PlayerC"];
+ $PlayerD = $_REQUEST["PlayerD"];
+
+ /* the person who sets up the game has to be one of the players */
+ if(!in_array($name,array($PlayerA,$PlayerB,$PlayerC,$PlayerD)))
+ {
+ echo "
You need to be one of the players to start a
new game.
";
+ output_footer();
+ DB_close();
+ exit();
+ }
+
+ /* what rules were selected */
+ $dullen = $_REQUEST["dullen"];
+ $schweinchen = $_REQUEST["schweinchen"];
+ $call = $_REQUEST["callrule"];
+
+ /* get the emails addresses of the players */
+ $EmailA = DB_get_email('name',$PlayerA);
+ $EmailB = DB_get_email('name',$PlayerB);
+ $EmailC = DB_get_email('name',$PlayerC);
+ $EmailD = DB_get_email('name',$PlayerD);
+
+ /* this is used to check if the player names are all ok */
+ if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="")
+ {
+ echo "couldn't find one of the names, please start a new game";
+ output_footer();
+ DB_close();
+ exit();
+ }
+
+ /* get user ids */
+ $useridA = DB_get_userid('name',$PlayerA);
+ $useridB = DB_get_userid('name',$PlayerB);
+ $useridC = DB_get_userid('name',$PlayerC);
+ $useridD = DB_get_userid('name',$PlayerD);
+
+ /* create random numbers */
+ $randomNR = create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD);
+ $randomNRstring = join(":",$randomNR);
+
+ /* create game */
+ $followup = NULL;
+ /* is this game a follow up in an already started session? */
+ if(myisset("followup") )
+ {
+ $followup= $_REQUEST["followup"];
+ $session = DB_get_session_by_gameid($followup);
+ $ruleset = DB_get_ruleset_by_gameid($followup); /* just copy ruleset from old game,
+ this way no manipulation is possible */
+
+ /* check if there is a game in pre or play mode, in that case do nothing */
+ if( DB_is_session_active($session) > 0 )
+ {
+ echo "
There is already a game going on in session $session, you can't start a new one
";
+ output_footer();
+ DB_close();
+ exit();
+ }
+ else if ( DB_is_session_active($session) < 0 )
+ {
+ echo "
ERROR: status of session $session couldn't be determined.
";
+ output_footer();
+ DB_close();
+ exit();
+ }
+
+ if($session)
+ mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',".
+ "'$ruleset','$session' ,NULL)");
+ else
+ {
+ /* get max session and start a new one */
+ $max = DB_get_max_session();
+ $max++;
+ mysql_query("UPDATE Game SET session='".$max."' WHERE id=".DB_quote_smart($followup));
+ mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',".
+ "'$ruleset','$max' ,NULL)");
+ }
+ }
+ else /* no follow up, start a new session */
+ {
+ /* get ruleset information or create new one */
+ $ruleset = DB_get_ruleset($dullen,$schweinchen,$call);
+ if($ruleset <0)
+ {
+ myerror("Error defining ruleset: $ruleset");
+ output_footer();
+ DB_close();
+ exit();
+ };
+ /* get max session */
+ $max = DB_get_max_session();
+ $max++;
+
+ mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre', ".
+ "'$ruleset','$max' ,NULL)");
+ }
+ $game_id = mysql_insert_id();
+
+ /* create hash */
+ $TIME = (string) time(); /* to avoid collisions */
+ $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA.$TIME);
+ $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB.$TIME);
+ $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC.$TIME);
+ $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD.$TIME);
+
+ /* create hands */
+ mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridA).
+ ", ".DB_quote_smart($hashA).", 'start','1',NULL,NULL,NULL,NULL)");
+ $hand_idA = mysql_insert_id();
+ mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridB).
+ ", ".DB_quote_smart($hashB).", 'start','2',NULL,NULL,NULL,NULL)");
+ $hand_idB = mysql_insert_id();
+ mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridC).
+ ", ".DB_quote_smart($hashC).", 'start','3',NULL,NULL,NULL,NULL)");
+ $hand_idC = mysql_insert_id();
+ mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridD).
+ ", ".DB_quote_smart($hashD).", 'start','4',NULL,NULL,NULL,NULL)");
+ $hand_idD = mysql_insert_id();
+
+ /* save cards */
+ for($i=0;$i<12;$i++)
+ mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idA', '".$randomNR[$i]."', 'false')");
+ for($i=12;$i<24;$i++)
+ mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idB', '".$randomNR[$i]."', 'false')");
+ for($i=24;$i<36;$i++)
+ mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idC', '".$randomNR[$i]."', 'false')");
+ for($i=36;$i<48;$i++)
+ mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idD', '".$randomNR[$i]."', 'false')");
+
+ /* send out email, TODO: check for error with email */
+ $message = "\n".
+ "you are invited to play a game of DoKo (that is to debug the program ;).\n".
+ "Place comments and bug reports here:\n".
+ "http://wiki.nubati.net/index.php?title=EmailDoko\n\n".
+ "The whole round would consist of the following players:\n".
+ "$PlayerA\n".
+ "$PlayerB\n".
+ "$PlayerC\n".
+ "$PlayerD\n\n".
+ "If you want to join this game, please follow this link:\n\n".
+ "".$HOST.$INDEX."?action=game&me=";
+
+ mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
+ mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
+ mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
+ mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
+
+ echo "
You started a new game. The emails have been sent out!
\n";
+ }
+ else
+ {
+ $names = DB_get_all_names();
+ echo "
\n";
+ output_form_for_new_game($names);
+ echo "
\n";
+ display_user_menu();
+ }
+ }
+
+?>
diff --git a/include/newgameready.php b/include/newgameready.php
deleted file mode 100644
index 6d74af0..0000000
--- a/include/newgameready.php
+++ /dev/null
@@ -1,175 +0,0 @@
-Please
log in.
";
- }
- else
- {
- /* get my name */
- $name = $_SESSION["name"];
-
- /* the names of the four players */
- $PlayerA = $_REQUEST["PlayerA"];
- $PlayerB = $_REQUEST["PlayerB"];
- $PlayerC = $_REQUEST["PlayerC"];
- $PlayerD = $_REQUEST["PlayerD"];
-
- /* the person who sets up the game has to be one of the players */
- if(!in_array($name,array($PlayerA,$PlayerB,$PlayerC,$PlayerD)))
- {
- echo " ERROR: status of session $session couldn't be determined.
";
- output_footer();
- DB_close();
- exit();
- }
-
- if($session)
- mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',".
- "'$ruleset','$session' ,NULL)");
- else
- {
- /* get max session and start a new one */
- $max = DB_get_max_session();
- $max++;
- mysql_query("UPDATE Game SET session='".$max."' WHERE id=".DB_quote_smart($followup));
- mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',".
- "'$ruleset','$max' ,NULL)");
- }
- }
- else /* no follow up, start a new session */
- {
- /* get ruleset information or create new one */
- $ruleset = DB_get_ruleset($dullen,$schweinchen,$call);
- if($ruleset <0)
- {
- myerror("Error defining ruleset: $ruleset");
- output_footer();
- DB_close();
- exit();
- };
- /* get max session */
- $max = DB_get_max_session();
- $max++;
-
- mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre', ".
- "'$ruleset','$max' ,NULL)");
- }
- $game_id = mysql_insert_id();
-
- /* create hash */
- $TIME = (string) time(); /* to avoid collisions */
- $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA.$TIME);
- $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB.$TIME);
- $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC.$TIME);
- $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD.$TIME);
-
- /* create hands */
- mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridA).
- ", ".DB_quote_smart($hashA).", 'start','1',NULL,NULL,NULL,NULL)");
- $hand_idA = mysql_insert_id();
- mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridB).
- ", ".DB_quote_smart($hashB).", 'start','2',NULL,NULL,NULL,NULL)");
- $hand_idB = mysql_insert_id();
- mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridC).
- ", ".DB_quote_smart($hashC).", 'start','3',NULL,NULL,NULL,NULL)");
- $hand_idC = mysql_insert_id();
- mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridD).
- ", ".DB_quote_smart($hashD).", 'start','4',NULL,NULL,NULL,NULL)");
- $hand_idD = mysql_insert_id();
-
- /* save cards */
- for($i=0;$i<12;$i++)
- mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idA', '".$randomNR[$i]."', 'false')");
- for($i=12;$i<24;$i++)
- mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idB', '".$randomNR[$i]."', 'false')");
- for($i=24;$i<36;$i++)
- mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idC', '".$randomNR[$i]."', 'false')");
- for($i=36;$i<48;$i++)
- mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idD', '".$randomNR[$i]."', 'false')");
-
- /* send out email, TODO: check for error with email */
- $message = "\n".
- "you are invited to play a game of DoKo (that is to debug the program ;).\n".
- "Place comments and bug reports here:\n".
- "http://wiki.nubati.net/index.php?title=EmailDoko\n\n".
- "The whole round would consist of the following players:\n".
- "$PlayerA\n".
- "$PlayerB\n".
- "$PlayerC\n".
- "$PlayerD\n\n".
- "If you want to join this game, please follow this link:\n\n".
- "".$HOST.$INDEX."?me=";
-
- mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
- mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
- mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
- mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
-
- echo "You started a new game. The emails have been sent out!
\n";
- }
-/* end set up a new game */
-?>
\ No newline at end of file
diff --git a/include/output.php b/include/output.php
index 1637603..b22b6ef 100644
--- a/include/output.php
+++ b/include/output.php
@@ -56,7 +56,7 @@ function output_form_for_new_game($names)