- /* 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>.";
- 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);
-
- echo "<p class=\"gamenumber\"> Game $gameid </p>\n";
-
-
-
- if(myisset("cancle"))
- echo "<p style=\"background-color:red\";>canceling a game is not implemented at the moment, but will be soon...<br /><br /></p>";
-
- switch($mystatus)
- {
- case 'start':
- check_want_to_play($me);
- DB_set_hand_status_by_hash($me,'init');
- break;
- case 'init':
- if( !myisset("in","update") )
- {
- DB_set_hand_status_by_hash($me,'start');
- echo "you need to answer both question";
- }
- else
- {
- if($_REQUEST["in"] == "no")
- {
- $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,"[DoKo] game cancled",$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<br />";
- echo "TODO: set card pref<br />";
-
- $mycards = DB_get_hand($me);
- sort($mycards);
- echo "<p class=\"mycards\">your cards are: <br />\n";
- foreach($mycards as $card)
- display_card($card);
- echo "</p>\n";
-
- check_for_sickness($me,$mycards);
-
- DB_set_hand_status_by_hash($me,'check');
- }
- }
- break;
-
- case 'check':
- echo "checking if you selected solo or nines...<br />".
- " if you have a wedding, please send an email to the other players. <br />".
- " if you have poverty you need to play a normal game,sorry...<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")
- {
- 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 */
- else
- {
- /* this solo comes first */
- 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 "wedding was chosen<br />\n";
- DB_set_sickness_by_hash($me,"wedding");
- }
- else if($_REQUEST["poverty"] == "yes")
- {
- echo "poverty was chosen<br />\n";
- DB_set_sickness_by_hash($me,"poverty");
- }
- else if($_REQUEST["nines"] == "yes")
- {
- echo "nines was chosen<br />\n";
- DB_set_sickness_by_hash($me,"nines");
- }
- }
-
- DB_set_hand_status_by_hash($me,'poverty');
-
- /* check all players and set game to final result, e.g. solo, wedding, povert, redeal */
-
- 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, delete other ones form Hand table
- * tell people about it.
- */
- echo "<br />checking if someone else selected solo or nines... wedding and poverty not handled at the moment<br />".
- " Please click <a href=\"$host?me=$me\">here</a> to finish the setup.<br />";
-
- /* only set this after all poverty, etc. are handeled*/
- DB_set_hand_status_by_hash($me,'play');
-
- /* check if the game can start */
- $userids = DB_get_all_userid_by_gameid($gameid);
- $ok=1;
- foreach($userids as $user)
- if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='play')
- $ok=0;
-
- if($ok)
- {
- DB_set_game_status_by_gameid($gameid,'play');
-
- /* 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 = 1;
- }
-
- /* gamestatus == normal, => cancel game */
- if($nines && $gamestatus == "normal")
- {
- /* TODO: set game type to nines to be able to keep statistics */
-
- $message = "Hello, \n\n".
- "the game has been cancled becausee someone 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,"[DoKo] game cancled",$message);
- }
-
- /* delete everything from the dB */
- DB_cancel_game($me);
-
- }
-
- /* poverty? */
- $poverty = 0;
-
- /* check players for poverty */
- 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 />";
- }
- }
- /* if gamestatus == normal, set poverty or dpovert (in case two people have poverty) */
-
- /* wedding? */
- $wedding = 0;
- /* check players for wedding */
- foreach($userids as $user)
- {
- if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'wedding')
- {
- $wedding++;
- $name = DB_get_name_by_userid($user);
- echo "$name has a Vorbehalt. <br />" ;
- }
- }
-
- /* if gamestatus == normal, set wedding */
-
- }
-
- 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 $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES
- * 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);
-
- /* get some infos about the game */
- $gamestatus = DB_get_game_status_by_gameid($gameid);
-
- /* display useful things in divs */
-
- /* display local time */
- echo "<div class=\"time\">\n Local times:<table>";
- $users = array();
- $users = DB_get_all_userid_by_gameid($gameid);
- foreach($users as $user)
- {
- $offset = DB_get_user_timezone($user);
- $zone = return_timezone($offset);
- date_default_timezone_set($zone);
- $name = DB_get_name_by_userid($user);
-
- echo "<tr> <td>$name</td> <td>".date("Y-m-d H:i:s")."</td></tr>\n";
- };
- echo "</table>\n</div>\n";
-
- if($gamestatus != 'pre')
- display_status($GT);
-
- /* 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 ".
- "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];
-
- echo " <span class=\"table".($pos-1)."\">$name</span>\n";
- }
- echo "</div>\n";
-
- /* get everything relevant to display the tricks */
- $result = mysql_query("SELECT Hand_Card.card_id as card,".
- " Hand.position as position,".
- " Play.sequence as sequence, ".
- " Trick.id, ".
- " Comment.comment ".
- "FROM Trick ".
- "LEFT JOIN Play ON Trick.id=Play.trick_id ".
- "LEFT JOIN Hand_Card ON Play.hand_card_id=Hand_Card.id ".
- "LEFT JOIN Hand ON Hand_Card.hand_id=Hand.id ".
- "LEFT JOIN Comment ON Play.id=Comment.play_id ".
- "WHERE Trick.game_id='".$gameid."' ".
- "ORDER BY Trick.id,sequence ASC");
- $trickNR = 1;
-
- $lasttrick = DB_get_max_trickid($gameid);
-
- $play = array(); /* needed to calculate winner later */
- $seq = 1;
- $pos = DB_get_startplayer_by_gameid($gameid)-1;
- $firstcard = ""; /* first card in a trick */
-
- echo "\n<ul class=\"tricks\">\n";
- echo " <li> Hello $myname! History: </li>\n";
-
- while($r = mysql_fetch_array($result,MYSQL_NUM))
- {
- $pos = $r[1];
- $seq = $r[2];
- $trick = $r[3];
- $comment = $r[4];
-
- /* save card to be able to find the winner of the trick later */
- $play[$pos] = $r[0];
-
- if($seq==1)
- {
- /* first card in a trick, output some html */
- if($trick!=$lasttrick)
- {
- /* start of an old trick? */
- echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Trick $trickNR</a>\n".
- " <div class=\"trick\" id=\"trick".$trickNR."\">\n".
- " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
- }
- else if($trick==$lasttrick)
- {
- /* start of a last trick? */
- echo " <li onclick=\"hl('$trickNR');\"><a href=\"#\">Current Trick</a>\n".
- " <div class=\"trick\" id=\"trick".$trickNR."\">\n".
- " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
- };
-
- /* remember first card, so that we are able to check, what cards can be played */
- $firstcard = $r[0];
- };
-
- /* display card */
- echo " <div class=\"card".($pos-1)."\">\n";
-
- /* display comments */
- if($comment!="")
- echo " <span class=\"comment\">".$comment."</span>\n";
-
- echo " ";
- display_card($r[0]);
-
- echo " </div>\n"; /* end div card */
-
- /* end of trick? */
- if($seq==4)
- {
- $trickNR++;
- echo " </div>\n </li>\n"; /* end div table, end li table */
- }
- }
-
- if($seq!=4 && $trickNR>1)
- echo " </div>\n </li>\n"; /* end div table, end li table */
-
- echo "</ul>\n";
-
- /* whos turn is it? */
- if($seq==4)
- {
- $winner = get_winner($play,$gametype); /* returns the position */
- $next = $winner;
- $firstcard = ""; /* new trick, no first card */
- }
- else
- {
- $next = $pos+1;
- if($next==5) $next=1;
- }
-
- /* my turn?, display cards as links, ask for comments*/
- if(DB_get_pos_by_hash($me) == $next)
- $myturn = 1;
- else
- $myturn = 0;