-
You are now logged out! \n".
+ "(This will take you back to the home-page)";
+ }
+/* check if we want to start a new game */
+else if(myisset("new"))
+ {
+ output_status();
+ /* user need to be logged in to do this */
+ if( isset($_SESSION["name"]) )
{
- echo "couldn't find one of the names, please start a new game";
- exit();
+ $names = DB_get_all_names();
+ echo "
";
+ }
+ }
+/*check if everything is ready to set up a new game */
+else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","call" ))
+ {
+ output_status();
+ /* user needs to be logged in */
+ if( !isset($_SESSION["name"]) )
{
- $followup= $_REQUEST["followup"];
- mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', NULL, NULL,'pre','$followup' ,NULL)");
+ echo "
";
}
else
- mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', NULL, NULL,'pre', NULL ,NULL)");
- $game_id = mysql_insert_id();
-
- /* create hash */
- $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA);
- $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB);
- $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC);
- $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD);
-
- /* 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,'false','false',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,'false','false',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,'false','false',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,'false','false',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."?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);
-
- }
-/* end set up a new game */
+ {
+ /* 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["call"];
+
+ /* get the emails addresses of the players */
+ $EmailA = DB_get_email_by_name($PlayerA);
+ $EmailB = DB_get_email_by_name($PlayerB);
+ $EmailC = DB_get_email_by_name($PlayerC);
+ $EmailD = DB_get_email_by_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_by_name($PlayerA);
+ $useridB = DB_get_userid_by_name($PlayerB);
+ $useridC = DB_get_userid_by_name($PlayerC);
+ $useridD = DB_get_userid_by_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
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')");
-else if(isset($_REQUEST["me"]))
+ /* 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 */
+ }
+/* cancel a game, if nothing has happend in the last N minutes */
+else if(myisset("cancel","me"))
{
- /* handle request from one specifig player,
- * the hash is set on a per game base, so first just handle this game
- * perhaps also show links to other games in a sidebar
- */
-
+ output_status();
+
$me = $_REQUEST["me"];
/* test for valid ID */
@@ -161,540 +239,2154 @@ else if(isset($_REQUEST["me"]))
if(!$myid)
{
echo "Can't find you in the database, please check the url. \n";
- echo "perhaps the game has been cancled.";
+ echo "perhaps the game has been canceled, check by login in here.";
+ output_footer();
+ DB_close();
exit();
}
-
+
DB_update_user_timestamp($myid);
/* get some information from the DB */
$gameid = DB_get_gameid_by_hash($me);
$myname = DB_get_name_by_hash($me);
- $mystatus = DB_get_status_by_hash($me);
-
- switch($mystatus)
+
+ /* check if game really is old enough to be canceled */
+ $result = mysql_query("SELECT mod_date from Game WHERE id='$gameid' " );
+ $r = mysql_fetch_array($result,MYSQL_NUM);
+ if(time()-strtotime($r[0]) > 60*60*24*30) /* = 1 month */
{
- case 'start':
- check_want_to_play($me);
- DB_set_hand_status_by_hash($me,'init');
- break;
- case 'init':
- if( !isset($_REQUEST["in"]) || !isset($_REQUEST["update"]))
+ $message = "Hello, \n\n".
+ "Game ".DB_format_gameid($gameid).
+ " has been canceled since nothing happend for a while and $myname requested it.\n";
+
+ $userids = DB_get_all_userid_by_gameid($gameid);
+ foreach($userids as $user)
{
- DB_set_hand_status_by_hash($me,'start');
- echo "you need to answer both question";
+ $To = DB_get_email_by_userid($user);
+ mymail($To,$EmailName."game ".DB_format_gameid($gameid)." canceled (timed out)",$message);
}
- else
- {
- if($_REQUEST["in"] == "no")
- {
- echo "TODO: email everyone that the game has been canceled. ";
- /*something like need to modify for DB backend
- for($i=0;$i<4;$i++)
- {
- $message = "Hello ".$player[$hash[$i]]["name"].",\n\n".
- "the game has been canceled due to the request of one of the players.\n";
- mymail($player[$hash[$i]]["email"],"[DoKo-Debug] the game has been canceled",$message);
- }
- */
- /* delete everything from the dB */
- DB_cancel_game($me);
- }
- else
- {
- echo "thanks for joining the game... please scroll down";
- echo "TODO: make this page nicer ";
- echo "TODO: set card pref ";
-
- $mycards = DB_get_hand($me);
- sort($mycards);
- echo "
your cards are: \n";
- foreach($mycards as $card)
- display_card($card);
- echo "
\n";
-
- check_for_sickness($me,$mycards);
-
- DB_set_hand_status_by_hash($me,'check');
- }
- }
- break;
-
- case 'check':
- echo "no checking at the moment... you need to play a normal game. At the moment you need to reload this page to finish the setup.";
- if(!isset($_REQUEST["solo"]) ||
- !isset($_REQUEST["wedding"]) ||
- !isset($_REQUEST["poverty"]) ||
- !isset($_REQUEST["nines"]) )
+
+ /* delete everything from the dB */
+ DB_cancel_game($me);
+
+ echo "
Game ".DB_format_gameid($gameid).
+ " has been canceled.
";
+ }
+ else
+ echo "
You need to wait longer before you can cancel a game...
\n";
+ }
+/* send out a reminder */
+else if(myisset("remind","me"))
+ {
+ output_status();
+
+ $me = $_REQUEST["me"];
+
+ /* test for valid ID */
+ $myid = DB_get_userid_by_hash($me);
+ if(!$myid)
+ {
+ echo "Can't find you in the database, please check the url. \n";
+ echo "perhaps the game has been canceled, check by login in here.";
+ output_footer();
+ DB_close();
+ exit();
+ }
+
+ DB_update_user_timestamp($myid);
+
+ /* get some information from the DB */
+ $gameid = DB_get_gameid_by_hash($me);
+ $myname = DB_get_name_by_hash($me);
+
+ /* check if player hasn't done anything in a while */
+ $result = mysql_query("SELECT mod_date,player,status from Game WHERE id='$gameid' " );
+ $r = mysql_fetch_array($result,MYSQL_NUM);
+ if( (time()-strtotime($r[0]) > 60*60*24*7) && ($r[2]!='gameover') ) /* = 1 week */
+ {
+ $name = DB_get_name_by_userid($r[1]);
+ $To = DB_get_email_by_userid($r[1]);
+ $userhash = DB_get_hash_from_gameid_and_userid($gameid,$r[1]);
+
+ $message = "Hello $name, \n\n".
+ "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" ;
+
+ /* make sure we don't send too many reminders to one person */
+ if(DB_get_reminder($r[1],$gameid)>0)
{
- DB_set_hand_status_by_hash($me,'init');
- /* problem: by setting it back to init, variables "in" and "update" are
- * not set, so the player will be send back to the start, after seeing his hand
- */
- echo "you need to fill out the form";
+ echo "
Game ".DB_format_gameid($gameid).
+ ": an email has been sent out.
";
}
- DB_set_hand_status_by_hash($me,'poverty');
-
- /* check all players and set game to final result, e.g. solo, wedding, povert, redeal */
-
- /* reset solo, etc from players who did say something, but it didn't matter? */
- break;
- case 'poverty':
- echo " poverty not handeled at the moment... you need to play a normal game ";
-
- /* only set this after all poverty, etc. are handeled*/
- DB_set_hand_status_by_hash($me,'play');
+ }
+ else
+ echo "
You need to wait longer before you can send out a reminder...
\n";
+ }
+/* handle request from one specific player for one game,
+ * (the hash is set on a per game base) */
+else if(myisset("me"))
+ {
+ $me = $_REQUEST["me"];
- /* check if the game can start */
- $userids = DB_get_all_userid_by_gameid($gameid);
- $done=1;
- foreach($userids as $user)
- if(DB_get_hand_status_by_userid($user)!='play')
- $done=0;
+ /* test for valid ID */
+ $myid = DB_get_userid_by_hash($me);
+ if(!$myid)
+ {
+ echo "Can't find you in the database, please check the url. \n";
+ echo "perhaps the game has been canceled, check by login in here.";
+ output_footer();
+ DB_close();
+ exit();
+ }
+
+ /* user might get here by clicking on the link in an email, so session might not be set */
+ if(isset($_SESSION["name"]))
+ output_status($_SESSION["name"]);
- if($done)
- DB_set_game_status_by_gameid($gameid,'play');
+ /* the user had done something, update the timestamp */
+ DB_update_user_timestamp($myid);
- break;
- case 'play':
- case 'gameover': /*both entries here, so that the tricks are visible for both in case of 'play' there is a break later that skips the last part*/
- /* display local time */
- echo "
\n"; /* end div trick, end li trick */
+ }
+
+ /* output tricks */
+ while($r = mysql_fetch_array($result,MYSQL_NUM))
+ {
+ $pos = $r[1];
+ $seq = $r[2];
+ $trick = $r[3];
+ $comment = $r[4];
+ $user = $r[6];
+
+ /* check if first schweinchen has been played */
+ if( $GAME["schweinchen"] && ($r[0] == 19 || $r[0] == 20) )
+ $GAME["schweinchen"]++;
+
+ /* save card to be able to find the winner of the trick later */
+ $play[$seq] = array("card"=>$r[0],"pos"=>$pos);
+
+ if($seq==1)
+ {
+ /* first card in a trick, output some html */
+ if($trick!=$lasttrick)
+ {
+ /* start of an old trick? */
+ echo "
\n".
+ " \n";
+ };
+
+ /* remember first card, so that we are able to check, what cards can be played */
+ $firstcard = $r[0];
+ };
+
+ /* display card */
+ echo "
\n"; /* end div trick, end li trick */
+
+ /* display points in case game is over */
+ if($mystatus=='gameover' && DB_get_game_status_by_gameid($gameid)=='gameover' )
+ {
+ echo "
\n";
+ /* add pic for re/contra
+ " \n";*/
+
+ $result = mysql_query("SELECT User.fullname, IFNULL(SUM(Card.points),0), Hand.party,Hand.position FROM Hand".
+ " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id".
+ " LEFT JOIN User ON User.id=Hand.user_id".
+ " LEFT JOIN Play ON Trick.id=Play.trick_id".
+ " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id".
+ " LEFT JOIN Card ON Card.id=Hand_Card.card_id".
+ " WHERE Hand.game_id='$gameid'".
+ " GROUP BY User.fullname" );
+ while( $r = mysql_fetch_array($result,MYSQL_NUM))
+ echo "
\n".
+ "
".$r[2]." ".$r[1]."
\n".
+ "
\n";
+
+ echo "
\n
\n"; /* end div trick, end li trick */
+ }
+
+
+ echo "\n"; /* end ul tricks*/
+
+ echo "
\n";
+
+ /* if the game is over do some extra stuff, therefore exit the swtich statement if we are still playing*/
+ if($mystatus=='play')
break;
- default:
- echo "error in testing the status";
- }
- exit();
- }
-/* user status page */
- else if(isset($_REQUEST["email"]) && isset($_REQUEST["password"]))
- {
- /* test id and password, should really be done in one step */
- $email = $_REQUEST["email"];
- $password = $_REQUEST["password"];
- if(strlen($password)!=32)
- $password = md5($password);
+ /* the following happens only when the gamestatus is 'gameover' */
+ /* check if game is over, display results */
+ if(DB_get_game_status_by_gameid($gameid)=='play')
+ {
+ echo "The game is over for you.. other people still need to play though";
+ }
+ else
+ {
+ $result = mysql_query("SELECT Hand.party, IFNULL(SUM(Card.points),0) FROM Hand".
+ " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id".
+ " LEFT JOIN User ON User.id=Hand.user_id".
+ " LEFT JOIN Play ON Trick.id=Play.trick_id".
+ " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id".
+ " LEFT JOIN Card ON Card.id=Hand_Card.card_id".
+ " WHERE Hand.game_id='$gameid'".
+ " GROUP BY Hand.party" );
+ echo "
these are the games you are playing in: \n";
- $result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status<>'gameover'" );
- while( $r = mysql_fetch_array($result,MYSQL_NUM))
- echo "game #".$r[1]." ";
- echo "
Want to start a new game? remember 4 names from the list above and visit ".
- "this page.
";
- }
- else
+ }
+ break;
+ default:
+ myerror("error in testing the status");
+ }
+ /* output left menu */
+ display_user_menu();
+
+ /* output right menu */
+
+ /* display rule set for this game */
+ echo "
\n";
+
+ if($gamestatus != 'pre')
+ echo " Gametype: $GT \n";
+
+ echo "Rules: \n";
+ echo "10ofhearts : ".$RULES["dullen"] ." \n";
+ echo "schweinchen: ".$RULES["schweinchen"] ." \n";
+ echo "call: ".$RULES["call"] ." \n";
+
+ echo "\n";
+ if($gamestatus == 'play' )
+ output_form_calls($me);
+
+ /* get time from the last action of the game */
+ $result = mysql_query("SELECT mod_date from Game WHERE id='$gameid' " );
+ $r = mysql_fetch_array($result,MYSQL_NUM);
+ $gameend = time() - strtotime($r[0]);
+
+ if($gamestatus == 'play' || $gameend < 60*60*24*7)
{
- echo "sorry email and password don't match ";
+ echo " \nA short comment:\n";
+ echo "";
}
- exit();
- }
-/* page for registration */
-else if(isset($_REQUEST["register"]) )
- {
- echo "IMPORTANT: passwords are going over the net as clear text, so pick an easy password. No need to pick anything complicated here ;)
";
- echo "TODO: convert timezone into a menu \n";
- echo "TODO: figure out a way to handle passwrods \n";
-?>
-
-
-
-";
- $ok=0;
- }
- if(DB_get_userid_by_email($_REQUEST["Remail"]))
- {
- echo "this email address is already used ?! ";
- $ok=0;
- }
- if($ok)
+
+ echo "\n";
+
+
+ if($mystatus=='gameover' && DB_get_game_status_by_gameid($gameid)=='gameover' )
+ {
+ echo "\n";
+
+ $session = DB_get_session_by_gameid($gameid);
+ $result = mysql_query("SELECT id,create_date FROM Game".
+ " WHERE session=$session".
+ " ORDER BY create_date DESC".
+ " LIMIT 1");
+ $r = -1;
+ if($result)
+ $r = mysql_fetch_array($result,MYSQL_NUM);
+
+ if(!$session || $gameid==$r[0])
{
- $r=mysql_query("INSERT INTO User VALUES(NULL,".DB_quote_smart($_REQUEST["Rfullname"]).
- ",".DB_quote_smart($_REQUEST["Remail"]).
- ",".DB_quote_smart(md5($_REQUEST["Rpassword"])).
- ",".DB_quote_smart($_REQUEST["Rtimezone"]).",NULL)");
-
- if($r)
- echo " added you to the database";
+ /* suggest a new game with the same people in it, just rotated once (unless last game was solo) */
+ $names = DB_get_all_names_by_gameid($gameid);
+ $type = DB_get_gametype_by_gameid($gameid);
+
+ if($type=="solo")
+ output_ask_for_new_game($names[0],$names[1],$names[2],$names[3],$gameid);
else
- echo " something went wrong";
+ output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);
}
- }
+ }
+
+ $session = DB_get_session_by_gameid($gameid);
+ $score = generate_score_table($session);
+
+ // if(size_of($score)>30)
+ echo $score;
+
+ echo "
\n";
+
+ echo "\n";
+ output_footer();
+ DB_close();
+ exit();
+ }
+/* user status page */
+else if( myisset("email","password") || isset($_SESSION["name"]) )
+ {
+ /* test id and password, should really be done in one step */
+ if(!isset($_SESSION["name"]))
+ {
+ $email = $_REQUEST["email"];
+ $password = $_REQUEST["password"];
+ }
+ else
+ {
+ $name = $_SESSION["name"];
+ $email = DB_get_email_by_name($name);
+ $password = DB_get_passwd_by_name($name);
+ };
+
+ /* user has forgotten his password */
+ if(myisset("forgot"))
+ {
+ /* check if player is in the database */
+ $ok = 1;
+
+ $myid = DB_get_userid_by_email($email);
+ if(!$myid)
+ $ok = 0;
+
+ if($ok)
+ {
+ /* check how many entries in recovery table */
+ $number = DB_get_number_of_passwords_recovery($myid);
+
+ /* if less than N recent ones, add a new one and send out email */
+ if( $number < 5 )
+ {
+ echo "Ok, I send you a new password. ";
+ if($number >1)
+ echo "N.B. You tried this already $number times during the last day and it will only work ".
+ " 5 times during a day. ";
+ echo "The new password will be valid for one day, make sure you reset it to something else. ";
+ echo "Back to the main page.";
+
+ /* create temporary password, use the fist 8 letters of a md5 hash */
+ $TIME = (string) time(); /* to avoid collisions */
+ $hash = md5("Anewpassword".$email.$TIME);
+ $newpw = substr($hash,1,8);
+
+ $message = "Someone (hopefully you) requested a new password. \n".
+ "You can use this email and the following password: \n".
+ " $newpw \n".
+ "to log into the server. The new password is valid for 24h, so make\n".
+ "sure you reset your password to something new. Your old password will\n".
+ " also still be valid until you set a new one\n";
+ mymail($email,$EmailName."recovery ",$message);
+
+ /* we save these in the database */
+ DB_set_recovery_password($myid,md5($newpw));
+ }
+ else
+ {
+ /* make it so that people (or a robot) can request thousands of passwords within a short time
+ * and spam a user this way */
+ echo "Sorry you already tried 5 times during the last 24h. ".
+ "You need to use one of those passwords or wait to get a new one. ";
+ echo "Back to the main page.";
+ }
+ }
+ else
+ {/* can't find user id in the database */
+
+ /* no email given? */
+ if($email=="")
+ echo "You need to give me an email address! ".
+ "Please try again.";
+ else /* default error message */
+ echo "Couldn't find a player with this email! ".
+ "Please contact Arun, if you think this is a mistake ".
+ "or else try again.";
+ }
+ }
+ else
+ { /* normal user page */
+ /* verify password and email */
+ if(strlen($password)!=32)
+ $password = md5($password);
+
+ $ok = 1;
+ $myid = DB_get_userid_by_email_and_password($email,$password);
+ if(!$myid)
+ $ok = 0;
+
+ if($ok)
+ {
+ /* user information is ok */
+ $myname = DB_get_name_by_email($email);
+ $_SESSION["name"] = $myname;
+ output_status();
+
+ DB_get_PREF($myid);
+
+ /* does the user want to change some preferences? */
+ if(myisset("setpref"))
+ {
+ $setpref=$_REQUEST["setpref"];
+ switch($setpref)
+ {
+ case "germancards":
+ case "englishcards":
+ $result = mysql_query("SELECT * from User_Prefs".
+ " WHERE user_id='$myid' AND pref_key='cardset'" );
+ if( mysql_fetch_array($result,MYSQL_NUM))
+ $result = mysql_query("UPDATE User_Prefs SET value=".DB_quote_smart($setpref).
+ " WHERE user_id='$myid' AND pref_key='cardset'" );
+ else
+ $result = mysql_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','cardset',".
+ DB_quote_smart($setpref).")");
+ echo "Ok, changed you preferences for the cards.\n";
+ break;
+ case "emailaddict":
+ case "emailnonaddict":
+ $result = mysql_query("SELECT * from User_Prefs".
+ " WHERE user_id='$myid' AND pref_key='email'" );
+ if( mysql_fetch_array($result,MYSQL_NUM))
+ $result = mysql_query("UPDATE User_Prefs SET value=".DB_quote_smart($setpref).
+ " WHERE user_id='$myid' AND pref_key='email'" );
+ else
+ $result = mysql_query("INSERT INTO User_Prefs VALUES(NULL,'$myid','email',".
+ DB_quote_smart($setpref).")");
+ echo "Ok, changed you preferences for sending out emails.\n";
+ break;
+ }
+ }
+ /* user wants to change his password or request a temporary one */
+ else if(myisset("passwd"))
+ {
+ if( $_REQUEST["passwd"]=="ask" )
+ {
+ /* reset password form*/
+ output_password_recovery($email,$password);
+ }
+ else if($_REQUEST["passwd"]=="set")
+ {
+ /* reset password */
+ $ok = 1;
+
+ /* check if old password matches */
+ $oldpasswd = md5($_REQUEST["password0"]);
+ if(!( ($password == $oldpasswd) || DB_check_recovery_passwords($oldpasswd,$email) ))
+ $ok = -1;
+ /* check if new passwords are types the same twice */
+ if($_REQUEST["password1"] != $_REQUEST["password2"] )
+ $ok = -2;
+
+ switch($ok)
+ {
+ case '-2':
+ echo "The new passwords don't match. ";
+ break;
+ case '-1':
+ echo "The old password is not correct. ";
+ break;
+ case '1':
+ echo "Changed the password. ";
+ mysql_query("UPDATE User SET password='".md5($_REQUEST["password1"]).
+ "' WHERE id=".DB_quote_smart($myid));
+ break;
+ }
+ /* set password */
+ }
+ }
+ else /* output default user page */
+ {
+ /* display links to settings */
+ output_user_settings();
+
+ DB_update_user_timestamp($myid);
+
+ display_user_menu();
+
+ /* display all games the user has played */
+ echo "
";
+ echo "
These are all your games:
\n";
+ echo "
Session: \n";
+ echo " p = pre-game phase ";
+ echo "P = game in progess ";
+ echo "F = game finished ";
+ echo "
\n";
+
+ $output = array();
+ $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date,Game.player,Game.status from Hand".
+ " LEFT JOIN Game ON Game.id=Hand.game_id".
+ " WHERE user_id='$myid'".
+ " ORDER BY Game.session,Game.create_date" );
+ $gamenrold = -1;
+ echo "
Sorry email and password don't match. Please try again.
";
+ }
+ };
+ output_footer();
+ DB_close();
+ exit();
+ }
/* default login page */
-else
- { /* no new game, not in a game */
- home_page();
- }
-?>
-
-
+ else
+ {
+ /* this outputs the default home page with some extra statistics on it */
-