- /* cancle a game, if it is older than N minutes */
-
- $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.<br />\n";
- echo "perhaps the game has been cancled, check by login in <a href=\"$host\">here</a>.";
- output_footer();
- 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 game really is old enough */
- $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)
- {
- $message = "Hello, \n\n".
- "Game $gameid has been cancled since nothing happend for a while and $myname requested it.\n";
-
- $userids = DB_get_all_userid_by_gameid($gameid);
- foreach($userids as $user)
- {
- $To = DB_get_email_by_userid($user);
- mymail($To,$EmailName."game cancled (timed out)",$message);
- }
-
- /* delete everything from the dB */
- DB_cancel_game($me);
-
- echo "<p style=\"background-color:red\";>Game $gameid has been cancled.<br /><br /></p>";
- }
- else
- echo "<p>You need to wait longer before you can cancle a game...</p>\n";
- }
-else if(myisset("me"))
- {
- /* handle request from one specific player,
- * the hash is set on a per game base
- */
-
- $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.<br />\n";
- echo "perhaps the game has been cancled, check by login in <a href=\"$host\">here</a>.";
- output_footer();
- 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);
- $mypos = DB_get_pos_by_hash($me);
-
-
- /* display rule set */
- echo "<div class=\"ruleset\">\n";
- $result = mysql_query("SELECT * FROM Rulesets LEFT JOIN Game ON Game.ruleset=Rulesets.id WHERE Game.id='$gameid'" );
- $r = mysql_fetch_array($result,MYSQL_NUM);
-
- $RULES["dullen"]=$r[2];
- $RULES["schweinchen"]=$r[3];
-
- /* get some infos about the game */
- $gametype = DB_get_gametype_by_gameid($gameid);
- $gamestatus = DB_get_game_status_by_gameid($gameid);
- $GT = $gametype;
- if($gametype=="solo")
- {
- $gametype = DB_get_solo_by_gameid($gameid);
- $GT = $gametype." ".$GT;
- }
- else
- $gametype="normal";
-
- if($gamestatus != 'pre')
- echo " Gametype: $GT <br />\n";
-
- echo "Rules: <br />\n";
- echo "10ofhearts : ".$r[2]."<br />\n";
- echo "schweinchen: ".$r[3]."<br />\n";
- echo "</div>\n";
-
- /* does anyone have both foxes */
- $GAME["schweinchen"]=0;
- for($i=1;$i<5;$i++)
- {
- $hash = DB_get_hash_from_game_and_pos($gameid,$i);
- $cards = DB_get_all_hand($hash);
- if( in_array("19",$cards) && in_array("20",$cards) )
- {
- $GAME["schweinchen"]=1;
- $GAME["schweinchen-who"]=$hash;
- }
- };
-
- /* mystatus gets the player through the different stages of a game.
- * start: yes/no
- * init: check values from start,
- * check for sickness
- * check: check for return values from init
- * poverty: handle poverty, wait here until all player have reached this state
- * display sickness and move on to game
- * play: game in progress
- * gameover: are we revisiting a game
- */
- switch($mystatus)
- {
- case 'start':
- check_want_to_play($me);
- /* move on to the next stage*/
- DB_set_hand_status_by_hash($me,'init');
- break;
- case 'init':
- if( !myisset("in") )
- {
- echo "you need to answer the question";
- DB_set_hand_status_by_hash($me,'start');
- }
- else
- {
- if($_REQUEST["in"] == "no")
- {
- /* cancle the game */
- $message = "Hello, \n\n".
- "the game has been canceled due to the request of one of the players.\n";
-
- $userids = DB_get_all_userid_by_gameid($gameid);
- foreach($userids as $user)
- {
- $To = DB_get_email_by_userid($user);
- mymail($To,$EmailName."game canceled",$message);
- }
-
- /* delete everything from the dB */
- DB_cancel_game($me);
- }
- else
- {
- echo "thanks for joining the game...";
-
- $mycards = DB_get_hand($me);
- sort($mycards);
- echo "<p class=\"mycards\" style=\"margin-top:8em;\">your cards are: <br />\n";
- foreach($mycards as $card)
- display_card($card);
- echo "</p>\n";
-
- check_for_sickness($me,$mycards);
-
- /* move on to the next stage*/
- DB_set_hand_status_by_hash($me,'check');
- }
- }
- break;
-
- case 'check':
- echo "checking if you selected solo or nines...<br />".
- " Please click <a href=\"$host?me=$me\">here</a> to finish the setup.<br />";
- if(!myisset("solo","wedding","poverty","nines") )
- {
- /* all these variables have a pre-selected default,
- * so we should never get here,
- * unless a user tries to cheat ;) */
- echo "something went wrong...please contact the admin.";
- }
- else
- {
- /* check if this sickness needs to be handled first */
- $gametype = DB_get_gametype_by_gameid($gameid);
- $startplayer = DB_get_startplayer_by_gameid($gameid);
-
- if( $_REQUEST["solo"]!="No")
- {
- /* store the info in the user's hand info */
- DB_set_solo_by_hash($me,$_REQUEST["solo"]);
- DB_set_sickness_by_hash($me,"solo");
- echo "<br />Seems like you want to play a ".$_REQUEST["solo"]." solo. Got it.<br />\n";
-
- if($gametype == "solo" && $startplayer<$mypos)
- {}/* do nothing, since someone else already is playing solo */
- else
- {
- /* this solo comes first
- * store info in game table
- */
- DB_set_gametype_by_gameid($gameid,"solo");
- DB_set_startplayer_by_gameid($gameid,$mypos);
- DB_set_solo_by_gameid($gameid,$_REQUEST["solo"]);
- };
- }
- else if($_REQUEST["wedding"] == "yes")
- {
- /* TODO: add silent solo somewhere*/
- echo "Ok, you don't want to play a silent solo...wedding was chosen.<br />\n";
- DB_set_sickness_by_hash($me,"wedding");
- }
- else if($_REQUEST["poverty"] == "yes")
- {
- echo "So you got poverty. You might as well have said nothing, since this is not implemented yet,".
- " so you need to play a normal game...to make it a bit harder, I'll tell the other people that".
- " you only have a few trump... should make the game more interesting (although perhaps not for you:))<br />\n";
- DB_set_sickness_by_hash($me,"poverty");
- }
- else if($_REQUEST["nines"] == "yes")
- {
- echo "What you just don't want to play a game because you have a few nines? Well, if no one".
- " is playing solo, this game will be canceled.<br />\n";
- DB_set_sickness_by_hash($me,"nines");
- }
- }
-
- /* move on to the next stage*/
- DB_set_hand_status_by_hash($me,'poverty');
-
-
- break;
- case 'poverty':
- /* here we need to check if there is a solo or some other form of sickness.
- * If so, which one counts
- * set that one in the Game table
- * tell people about it.
- */
- echo "<br />checking if someone else selected solo or nines... poverty not handled at the moment<br />".
- " Please click <a href=\"$host?me=$me\">here</a> to finish the setup.<br />";
-
- /* check if everyone has reached this stage */
- $userids = DB_get_all_userid_by_gameid($gameid);
- $ok=1;
- foreach($userids as $user)
- {
- $userstat = DB_get_hand_status_by_userid_and_gameid($user,$gameid);
- if($userstat!='poverty' && $userstat!='play')
- $ok=0;
- };
-
- if($ok)
- {
- echo "Everyone has finished checking their cards, let's see what they said...<br />";
- /* check what kind of game we are playing */
- $gametype = DB_get_gametype_by_gameid($gameid);
- $startplayer = DB_get_startplayer_by_gameid($gameid);
-
- /* nines? */
- $nines = 0;
- /* check for nines */
- foreach($userids as $user)
- if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'nines')
- $nines = $user;
-
- /* gamestatus == normal, => cancel game */
- if($nines && $gametype != "solo")
- {
- /* TODO: should we keep statistics of this? */
- $message = "Hello, \n\n".
- "the game has been canceled because ".DB_get_name_by_userid($nines)." has five or more nines.\n";
-
- $userids = DB_get_all_userid_by_gameid($gameid);
- foreach($userids as $user)
- {
- $To = DB_get_email_by_userid($user);
- mymail($To,$EmailName."game canceled",$message);
- }
-
- /* delete everything from the dB */
- DB_cancel_game($me);
- output_footer();
- exit();
- }
-
- /* check for different sickness and just output a general info */
-
- /* check players for poverty */
- $poverty = 0;
- foreach($userids as $user)
- {
- if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'poverty')
- {
- $poverty++;
- $name = DB_get_name_by_userid($user);
- echo "$name has a Vorbehalt. <br />";
- }
- }