-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 />";
- }
- }
-
- /* check players for wedding */
- $wedding = 0;
- foreach($userids as $user)
- {
- if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'wedding')
- {
- $wedding=$user;
- $name = DB_get_name_by_userid($user);
- echo "$name has a Vorbehalt. <br />" ;
- }
- };
-
- /* check for solo, output vorbehalt */
- $solo = 0;
- foreach($userids as $user)
- {
- if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'solo')
- {
- $solo++;
- $name = DB_get_name_by_userid($user);
- echo "$name has a Vorbehalt. <br />" ;
- }
- }
-
- /* now check which sickness comes first and set the gametype to it */
-
- /* if gamestatus == normal, set poverty or dpovert (in case two people have poverty) */
- if($poverty>0 && $gametype == "normal")
- {
- if($poverty==1)
- {
- DB_set_gametype_by_gameid($gameid,"poverty");
- $gametype = "poverty";
- }
- else if($poverty==2)
- {
- DB_set_gametype_by_gameid($gameid,"dpoverty");
- $gametype = "dpoverty";
- };
- };
- /* if gamestatus == normal, set wedding */
- if($wedding> 0 && $gametype == "normal")
- {
- DB_set_gametype_by_gameid($gameid,"wedding");
- $gametype = "wedding";
- };
-
- /* now the gametype is set correctly (shouldn't matter that this is calculated for every user)
- * output what kind of game we have */
-
- echo "<br />\n";
-
- $poverty=0;
- foreach($userids as $user)
- {
- $name = DB_get_name_by_userid($user);
- $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
- if($usersick=="poverty")
- $poverty++;
- if($usersick)
- echo "$name has $usersick <br />";
- if($usersick == "wedding" && $gametype =="wedding")
- break;
- if($usersick == "poverty" && $gametype =="poverty")
- break;
- if($usersick == "poverty" && $gametype =="dpoverty" && $poverty==2)
- break;
- if($usersick == "solo" && $gametype =="solo")
- break;
-
- };
-
- if( $gametype != "solo")
- if($GAME["schweinchen"] && $RULES["schweinchen"]=="both" )
- echo DB_get_name_by_hash($GAME["schweinchen-who"])." has Schweinchen. <br />";
-
- echo "<br />\n";
-
- /* finished the setup, set re/contra parties if possible, go to next stage unless there is a case of poverty*/
- switch($gametype)
- {
- case "solo":
- /* are we the solo player? set us to re, else set us to contra */
- $pos = DB_get_pos_by_hash($me);
- if($pos == $startplayer)
- DB_set_party_by_hash($me,"re");
- else
- DB_set_party_by_hash($me,"contra");
- DB_set_hand_status_by_hash($me,'play');
- break;
- case "wedding":
- echo "Don't know who will be Re and Contra, you need to ".
- "figure that out at the end of the game yourself <br />\n";
- DB_set_hand_status_by_hash($me,'play');
- break;
- case "normal":
- $hand = DB_get_all_hand($me);
-
- if(in_array('3',$hand)||in_array('4',$hand))
- DB_set_party_by_hash($me,"re");
- else
- DB_set_party_by_hash($me,"contra");
- DB_set_hand_status_by_hash($me,'play');
- break;
- case "poverty":
- /* figure out who has poverty */
- /* check who was asked already
- * everyone or trump was taken?
- * trump was taken, start game
- * trump was not taken, cancle game
- *
- * not everyone, figure out who is next in the list
- * is the next person this one?
- * no, display wait message, e.g. player X is asked at the moment
- * yes, display trump, ask if he wants to take it
- * no, set player asked to true, email next player
- * yes, display all cards, ask for N return cards
- * set re/contra
- *
- */
- case "dpoverty":
- echo "TODO: handle double poverty here";
- DB_set_hand_status_by_hash($me,'play');
- };
- }
- else
- {
- echo "You need to wait for the others, the game can only start after everyone finished checking their cards.<br />";
- };
-
- /* check if all players are ready to play */
- $ok=1;
- foreach($userids as $user)
- if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='play')
- $ok=0;
-
- if($ok)
- {
- /* only set this after all poverty, etc. are handled*/
- DB_set_game_status_by_gameid($gameid,'play');
- }
-
- 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
- */
-
- /* figure out what kind of game we are playing,
- * set the global variables $CARDS["trump"],$CARDS["diamonds"],$CARDS["hearts"],
- * $CARDS["clubs"],$CARDS["spades"],$CARDS["foxes"]
- * accordingly
- */
-
- $gametype = DB_get_gametype_by_gameid($gameid);
- $GT = $gametype;
- if($gametype=="solo")
- {
- $gametype = DB_get_solo_by_gameid($gameid);
- $GT = $gametype." ".$GT;
- }
- else
- $gametype="normal";
-
- set_gametype($gametype); /* this sets the $CARDS variable */
-
- /* get some infos about the game */
- $gamestatus = DB_get_game_status_by_gameid($gameid);
-
- /* display useful things in divs */
-
- /* display links to the users status page */
- $result = mysql_query("SELECT email,password from User WHERE id='$myid'" );
- $r = mysql_fetch_array($result,MYSQL_NUM);
- output_link_to_user_page($r[0],$r[1]);
-
- display_news();
-
- /* end display useful things*/
-
- /* has the game started? No, then just wait here...*/
- if($gamestatus == 'pre')
- {
- echo "you need to wait for the others... <br />";
- break; /* not sure this works... the idea is that you can
- * only play a card after everyone is ready to play */
- }
-
- /* display the table and the names */
- $result = mysql_query("SELECT User.fullname as name,".
- " Hand.position as position, ".
- " User.id ".
- "FROM Hand ".
- "LEFT JOIN User ON User.id=Hand.user_id ".
- "WHERE Hand.game_id='".$gameid."' ".
- "ORDER BY position ASC");
-
- echo "<div class=\"table\">\n".
- " <img src=\"pics/table.png\" alt=\"table\" />\n";
- while($r = mysql_fetch_array($result,MYSQL_NUM))
- {
- $name = $r[0];
- $pos = $r[1];
- $user = $r[2];
-
- $offset = DB_get_user_timezone($user);
- $zone = return_timezone($offset);
- date_default_timezone_set($zone);
-
- echo " <span class=\"table".($pos-1)."\">\n";
- echo " $name <br />\n";
- echo " local time: ".date("Y-m-d H:i:s")."\n";
- echo " </span>\n";
-
- }
- echo "</div>\n";