diff options
-rw-r--r-- | include/cancelgame.php | 8 | ||||
-rw-r--r-- | include/functions.php | 6 | ||||
-rw-r--r-- | include/game.php | 40 | ||||
-rw-r--r-- | include/login.php | 33 | ||||
-rw-r--r-- | include/logout.php | 2 | ||||
-rw-r--r-- | include/newgame.php | 186 | ||||
-rw-r--r-- | include/newgameready.php | 175 | ||||
-rw-r--r-- | include/output.php | 6 | ||||
-rw-r--r-- | include/reminder.php | 10 | ||||
-rw-r--r-- | include/user.php | 10 | ||||
-rw-r--r-- | index.php | 66 |
11 files changed, 288 insertions, 254 deletions
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.<br />\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 " <a href=\"".$INDEX."?me=".$hash."\">$name</a>\n"; + echo " <a href=\"".$INDEX."?action=game&me=".$hash."\">$name</a>\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 "<a href=\"".$INDEX."?me=".$r[0]."\">game ".DB_format_gameid($r[1])." </a><br />\n"; + echo "<a href=\"".$INDEX."?action=game&me=".$r[0]."\">game ".DB_format_gameid($r[1])." </a><br />\n"; } - echo "<hr /> <a href=\"".$INDEX."?new\">Start a new game</a>\n"; + echo "<hr /> <a href=\"".$INDEX."?action=new\">Start a new game</a>\n"; echo "<hr /> <a href=\"".$STATS."\">Statistics</a>\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.<br />\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 "<form action=\"index.php?me=$me\" method=\"post\">\n"; +echo "<form action=\"index.php?action=game&me=$me\" method=\"post\">\n"; /* output game */ @@ -86,7 +94,7 @@ if($session) if($hash == $me) echo "$i \n"; else - echo "<a href=\"".$INDEX."?me=".$hash."\">$i</a> \n"; + echo "<a href=\"".$INDEX."?action=game&me=".$hash."\">$i</a> \n"; $i++; } echo "</div>\n"; @@ -174,7 +182,7 @@ switch($mystatus) DB_set_player_by_gameid($gameid,$who); $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n". - "Use this link to go the game: ".$HOST.$INDEX."?me=".$hash."\n\n" ; + "Use this link to go the game: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ; mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message); */ } @@ -208,7 +216,7 @@ switch($mystatus) * unless a user tries to cheat ;) * can also happen if user reloads the page! */ - echo "<p class=\"message\"> You need to answer the <a href=\"$INDEX?me=$me&in=yes\">questions</a>.</p>"; + echo "<p class=\"message\"> You need to answer the <a href=\"$INDEX?action=game&me=$me&in=yes\">questions</a>.</p>"; DB_set_hand_status_by_hash($me,'init'); } else @@ -223,7 +231,7 @@ switch($mystatus) if($Nvorbehalt>1) { echo "<p class=\"message\"> You selected more than one vorbehalt, please go back ". - "and answer the <a href=\"$INDEX?me=$me&in=yes\">question</a> again.</p>"; + "and answer the <a href=\"$INDEX?action=game&me=$me&in=yes\">question</a> again.</p>"; 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 <a href=\"$INDEX?me=$me\">next step of the setup</a>.</p>"; + echo " Ok, done with checking, please go to the <a href=\"$INDEX?action=game&me=$me\">next step of the setup</a>.</p>"; /* move on to the next stage*/ DB_set_hand_status_by_hash($me,'poverty'); @@ -304,7 +312,7 @@ switch($mystatus) { $message = "Everyone finish the questionary in game ".DB_format_gameid($gameid).", ". "please visit this link now to continue: \n". - " ".$HOST.$INDEX."?me=".$userhash."\n\n" ; + " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ; mymail($To,$EmailName." finished setup in game ".DB_format_gameid($gameid),$message); } }; @@ -513,7 +521,7 @@ switch($mystatus) DB_set_party_by_hash($me,"contra"); echo "Whoever will make the first trick will be on the re team. <br />\n"; - echo " Ok, the game can start now, please finish <a href=\"$INDEX?me=$me\">the setup</a>.<br />"; + echo " Ok, the game can start now, please finish <a href=\"$INDEX?action=game&me=$me\">the setup</a>.<br />"; DB_set_hand_status_by_hash($me,'play'); break; @@ -576,7 +584,7 @@ switch($mystatus) DB_set_player_by_gameid($gameid,$userid); $message = "Someone has poverty, it's your turn to decide, if you want to take the trump. Please visit:". - " ".$HOST.$INDEX."?me=".$userhash."\n\n" ; + " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ; mymail($To,$EmailName." poverty (game ".DB_format_gameid($gameid).")",$message); } @@ -658,7 +666,7 @@ switch($mystatus) $message = "Someone has poverty, it's your turn to decide, ". "if you want to take the trump. Please visit:". - " ".$HOST.$INDEX."?me=".$userhash."\n\n" ; + " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ; mymail($To,$EmailName." poverty (game ".DB_format_gameid($gameid).")",$message); } } @@ -732,10 +740,10 @@ switch($mystatus) /* count trump */ if($nrtrump<4) echo "Player $name has $nrtrump trump. Do you want to take them?". - "<a href=\"index.php?me=$me&trump=$user\">yes</a> <br />\n"; + "<a href=\"index.php?action=game&me=$me&trump=$user\">yes</a> <br />\n"; } } - echo "<a href=\"index.php?me=$me&trump=no\">No,way I take those trump...</a> <br />\n"; + echo "<a href=\"index.php?action=game&me=$me&trump=no\">No,way I take those trump...</a> <br />\n"; echo "</div><div>\n"; echo "Your cards are: <br />\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, <a href=\"$INDEX?me=$me\">start</a> the game.<br />"; + echo " Please, <a href=\"$INDEX?action=game&me=$me\">start</a> the game.<br />"; } else echo "\n <br />"; @@ -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 @@ +<?php +/* make sure that we are not called from outside the scripts, + * use a variable defined in config.php to check this + */ +if(!isset($HOST)) + exit; + +if(!myisset("email","password")) + { + "can't log you in"; + } +else + { + $email = $_REQUEST["email"]; + $password = $_REQUEST["password"]; + + /* verify password and email */ + if(strlen($password)!=32) + $password = md5($password); + + $ok = 1; + $myid = DB_get_userid('email-password',$email,$password); + if(!$myid) + $ok = 0; + + if($ok) + { + /* user information is ok */ + $myname = DB_get_name('email',$email); + $_SESSION["name"] = $myname; + } + } +?>
\ 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 "<div class=\"message\"><span class=\"bigger\">You are now logged out!</span><br />\n". -"(<a href=\"$INDEX\">This will take you back to the home-page</a>)</div>"; ?>
\ 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 "<div class=\"user\">\n"; - output_form_for_new_game($names); - echo "</div>\n"; - display_user_menu(); + echo "<div class=\"message\">Please <a href=\"$INDEX\">log in</a>.</div>"; } - else - { - echo "<div class=\"message\">Please <a href=\"$INDEX\">log in</a>.</div>"; - } -?>
\ 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 "<div class=\"message\">You need to be one of the players to start a <a href=\"$INDEX?action=new\">new game</a>.</div>"; + 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 "<p class=\"message\"> There is already a game going on in session $session, you can't start a new one</p>"; + output_footer(); + DB_close(); + exit(); + } + else if ( DB_is_session_active($session) < 0 ) + { + echo "<p class=\"message\"> ERROR: status of session $session couldn't be determined.</p>"; + 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 "<div class=\"message\">You started a new game. The emails have been sent out!</div>\n"; + } + else + { + $names = DB_get_all_names(); + echo "<div class=\"user\">\n"; + output_form_for_new_game($names); + echo "</div>\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 @@ -<?php -/* make sure that we are not called from outside the scripts, - * use a variable defined in config.php to check this - */ -if(!isset($HOST)) - exit; - -output_status(); -/* user needs to be logged in */ -if( !isset($_SESSION["name"]) ) - { - echo "<div class=\"message\">Please <a href=\"$INDEX\">log in</a>.</div>"; - } - 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 "<div class=\"message\">You need to be one of the players to start a <a href=\"$INDEX?new\">new game</a>.</div>"; - 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 "<p class=\"message\"> There is already a game going on in session $session, you can't start a new one</p>"; - output_footer(); - DB_close(); - exit(); - } - else if ( DB_is_session_active($session) < 0 ) - { - echo "<p class=\"message\"> ERROR: status of session $session couldn't be determined.</p>"; - 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 "<div class=\"message\">You started a new game. The emails have been sent out!</div>\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) <h2> Players </h2> <p>Please select four players (or use the randomly pre-selected names)</p> <p>Remember: you need to be one of the players ;) </p> - <form action="index.php" method="post"> + <form action="index.php?action=new" method="post"> <div class="table"> <img src="pics/table.png" alt="table" /> @@ -278,7 +278,7 @@ function output_home_page($pre,$game,$done,$avgtime) <p> Please <a href="./register.php">register</a>, in case you have not done that yet <br /> or login with you email-address or name and password here: </p> - <form action="index.php" method="post"> + <form action="index.php?action=login" method="post"> <fieldset> <legend>Login</legend> <table> @@ -383,7 +383,7 @@ function output_status() /* logout info */ echo "\n<div class=\"status\">"; echo $name; - echo " <a href=\"index.php?logout=1\">logout</a>"; + echo " <a href=\"index.php?action=logout\">logout</a>"; echo "</div>\n"; /* last logon time */ diff --git a/include/reminder.php b/include/reminder.php index 1e3135c..a269478 100644 --- a/include/reminder.php +++ b/include/reminder.php @@ -7,6 +7,14 @@ if(!isset($HOST)) output_status(); +if(!myisset("me")) + { + echo "Hmm, you really shouldn't mess with the urls.<br />\n"; + output_footer(); + DB_close(); + exit(); + } + $me = $_REQUEST["me"]; /* test for valid ID */ @@ -39,7 +47,7 @@ if( (time()-strtotime($r[0]) > 60*60*24*7) && ($r[2]!='gameover') ) /* = 1 week "It's your turn in game ".DB_format_gameid($gameid)." \n". "Actually everyone else is waiting for you for more than a week now ;)\n\n". "Please visit this link now to continue: \n". - " ".$HOST.$INDEX."?me=".$userhash."\n\n" ; + " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ; /* make sure we don't send too many reminders to one person */ if(DB_get_reminder($r[1],$gameid)>0) diff --git a/include/user.php b/include/user.php index 0f67a68..8feac01 100644 --- a/include/user.php +++ b/include/user.php @@ -212,14 +212,14 @@ if(myisset("forgot")) } if($r[4]=='pre') { - echo "\n <span class=\"gamestatuspre\"><a href=\"".$INDEX."?me=".$r[0]."\">p </a></span> "; + echo "\n <span class=\"gamestatuspre\"><a href=\"".$INDEX."?action=game&me=".$r[0]."\">p </a></span> "; } else if ($r[4]=='gameover') - echo "\n <span class=\"gamestatusover\"><a href=\"".$INDEX."?me=".$r[0]."\">F </a></span> "; + echo "\n <span class=\"gamestatusover\"><a href=\"".$INDEX."?action=game&me=".$r[0]."\">F </a></span> "; else { - echo "\n <span class=\"gamestatusplay\"><a href=\"".$INDEX."?me=".$r[0]."\">P </a></span> "; + echo "\n <span class=\"gamestatusplay\"><a href=\"".$INDEX."?action=game&me=".$r[0]."\">P </a></span> "; } if($r[4] != 'gameover') { @@ -233,12 +233,12 @@ if(myisset("forgot")) if(DB_get_reminder($r[3],$gameid)==0) if(time()-strtotime($r[2]) > 60*60*24*7) echo "". - "<a href=\"$INDEX?remind=1&me=".$r[0]."\">Send a reminder.</a>"; + "<a href=\"$INDEX?action=reminder&me=".$r[0]."\">Send a reminder.</a>"; echo "(it's $name's turn)\n"; }; if(time()-strtotime($r[2]) > 60*60*24*30) echo "". - "<a href=\"$INDEX?cancel=1&me=".$r[0]."\">Cancel?</a>". + "<a href=\"$INDEX?action=cancel&me=".$r[0]."\">Cancel?</a>". " (clicking here is final and can't be restored)"; } @@ -31,51 +31,41 @@ output_header(); /* The rest of the file consists of handling user input. * The user sends information via html GET and POST variables, - * the script checks if these are set via "myisset" - * which can check a list of variables. + * and the action variable tells the prog what the user wants to do */ +if(myisset("action")) + $action=$_REQUEST['action']; +else + $action=""; /* so that we can use a default option below */ -/* does the user want to log out? */ -if(myisset("logout")) - { - require './include/logout.php'; - } -/* check if we want to start a new game */ -else if(myisset("new")) +switch($action) { + case 'new': require './include/newgame.php'; - } -/*check if everything is ready to set up a new game */ -else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","callrule" )) - { - require './include/newgameready.php'; - } -/* cancel a game, if nothing has happend in the last N minutes */ -else if(myisset("cancel","me")) - { + break; + case 'cancel': require './include/cancelgame.php'; - } -/* send out a reminder */ -else if(myisset("remind","me")) - { + break; + case 'reminder': require './include/reminder.php'; - } -/* handle request from one specific player for one game, - * (the hash is set on a per game base) */ -else if(myisset("me")) - { + break; + case 'logout': + require './include/logout.php'; + require './include/welcome.php'; + break; + case 'login': + require './include/login.php'; + require './include/user.php'; + break; + case 'game': require './include/game.php'; - } -/* user status page */ -else if( myisset("email","password") || isset($_SESSION["name"]) ) - { - require './include/user.php'; - } -/* default login page */ - else - { - require './include/welcome.php'; - } + break; + default: + if(isset($_SESSION["name"])) + require './include/user.php'; + else + require './include/welcome.php'; + } output_footer(); |