\n".
"
\n";
}
else if($trick==$lasttrick)
{
/* start of a last trick? */
echo "
Trick $trickNR\n".
" \n".
"
\n";
};
/* remember first card, so that we are able to check, what cards can be played */
$firstcard = $r[0];
};
/* display card */
echo "
\n";
/* display comments */
if($comment!="")
echo " \n";
echo " ";
display_card($r[0],$PREF["cardset"]);
echo "
\n"; /* end div card */
/* end of trick? */
if($seq==4)
{
$trickNR++;
echo "
\n \n"; /* end div trick, end li trick */
}
}
/* 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;
/* do we want to play a card? */
if(myisset("card") && $myturn)
{
$card = $_REQUEST["card"];
$handid = DB_get_handid_by_hash($me);
/* check if we have card and that we haven't played it yet*/
/* set played in hand_card to true where hand_id and card_id*/
$result = mysql_query("SELECT id FROM Hand_Card WHERE played='false' and ".
"hand_id='$handid' AND card_id=".DB_quote_smart($card));
$r = mysql_fetch_array($result,MYSQL_NUM);
$handcardid = $r[0];
if($handcardid) /* everything ok, play card */
{
/* update Game timestamp */
DB_update_game_timestamp($gameid);
/* check if a call was made, must do this before we set the card status to played */
if(myisset("call120") && $_REQUEST["call120"] == "yes" && can_call(120,$me))
$result = mysql_query("UPDATE Hand SET point_call='120' WHERE hash='$me' ");
if(myisset("call90") && $_REQUEST["call90"] == "yes" && can_call(90,$me))
$result = mysql_query("UPDATE Hand SET point_call='90' WHERE hash='$me' ");
if(myisset("call60") && $_REQUEST["call60"] == "yes" && can_call(60,$me))
$result = mysql_query("UPDATE Hand SET point_call='60' WHERE hash='$me' ");
if(myisset("call30") && $_REQUEST["call30"] == "yes" && can_call(30,$me))
$result = mysql_query("UPDATE Hand SET point_call='30' WHERE hash='$me' ");
if(myisset("call0") && $_REQUEST["call0"] == "yes" && can_call(0,$me))
$result = mysql_query("UPDATE Hand SET point_call='0' WHERE hash='$me' ");
/* mark card as played */
mysql_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".
DB_quote_smart($card));
/* get trick id or start new trick */
$a = DB_get_current_trickid($gameid);
$trickid = $a[0];
$sequence = $a[1];
$tricknr = $a[2];
$playid = DB_play_card($trickid,$handcardid,$sequence);
/* check for schweinchen */
if($card == 19 || $card == 20 )
{
$GAME["schweinchen"]++;
if($GAME["schweinchen"]==3 && $RULES["schweinchen"]=="second" )
DB_insert_comment("Schweinchen! ",$playid,$myid);
if($RULES["schweinchen"]=="both" )
DB_insert_comment("Schweinchen! ",$playid,$myid);
if ($debug)
echo "schweinchen = ".$GAME["schweinchen"]." ---
";
}
/* if sequence == 4 check who one in case of wedding */
if($sequence == 4 && $GT == "wedding")
{
/* is wedding resolve */
$resolved = DB_get_sickness_by_gameid($gameid);
if($resolved<0)
{
/* who has wedding */
$userids = DB_get_all_userid_by_gameid($gameid);
foreach($userids as $user)
{
$usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
if($usersick == "wedding")
$whosick = $user;
}
/* who won the trick */
$play = DB_get_cards_by_trick($trickid);
$winner = get_winner($play,$gametype); /* returns the position */
$winnerid = DB_get_userid_by_gameid_and_position($gameid,$winner);
/* is tricknr <=3 */
if($tricknr <=3 && $winnerid!=$whosick)
{
/* set resolved at tricknr*/
$resolved = DB_set_sickness_by_gameid($gameid,$tricknr);
/* set partner */
$whash = DB_get_hash_from_gameid_and_userid($gameid,$winnerid);
DB_set_party_by_hash($whash,"re");
}
if($tricknr == 3 && $winnerid==$whosick)
{
/* set resolved at tricknr*/
$resolved = DB_set_sickness_by_gameid($gameid,'3');
}
}
}
/* if sequence == 4, set winner of the trick, count points and set the next player */
if($sequence==4)
{
$play = DB_get_cards_by_trick($trickid);
$winner = get_winner($play,$gametype); /* returns the position */
if($winner>0)
mysql_query("UPDATE Trick SET winner='$winner' WHERE id='$trickid'");
else
echo "ERROR during scoring";
if($debug)
echo "DEBUG: position $winner won the trick
";
/* who is the next player? */
$next = $winner;
}
else
{
$next = DB_get_pos_by_hash($me)+1;
}
if($next==5) $next=1;
/* check for coment */
if(myisset("comment"))
{
$comment = $_REQUEST["comment"];
if($comment != "")
DB_insert_comment($comment,$playid,$myid);
};
/* display played card */
$pos = DB_get_pos_by_hash($me);
if($sequence==1)
{
echo "
Trick ".($tricknr)."\n".
" \n".
"
\n";
}
echo "
";
/* display comments */
display_card($card,$PREF["cardset"]);
if($comment!="")
echo " \n";
echo "
\n";
/*check if we still have cards left, else set status to gameover */
if(sizeof(DB_get_hand($me))==0)
{
DB_set_hand_status_by_hash($me,'gameover');
$mystatus='gameover';
}
/* if all players are done, set game status to game over,
* get the points of the last trick and send out an email
* to all players
*/
$userids = DB_get_all_userid_by_gameid($gameid);
$done=1;
foreach($userids as $user)
if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='gameover')
$done=0;
if($done)
DB_set_game_status_by_gameid($gameid,"gameover");
/* email next player, if game is still running */
if(DB_get_game_status_by_gameid($gameid)=='play')
{
$next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
$email = DB_get_email_by_hash($next_hash);
$who = DB_get_userid_by_email($email);
DB_set_player_by_gameid($gameid,$who);
$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."?me=".$next_hash."\n\n" ;
mymail($email,$EmailName."a card has been played in game ".DB_format_gameid($gameid),$message);
}
else /* send out final email */
{
/* individual score */
$result = mysql_query("SELECT User.fullname, IFNULL(SUM(Card.points),0), Hand.party 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" );
$message = "The game is over. Thanks for playing :)\n";
$message .= "Final score:\n";
while( $r = mysql_fetch_array($result,MYSQL_NUM))
$message .= " ".$r[0]."(".$r[2].") ".$r[1]."\n";
$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" );
$message .= "\nTotals:\n";
while( $r = mysql_fetch_array($result,MYSQL_NUM))
$message .= " ".$r[0]." ".$r[1]."\n";
/* send out final email */
$all = array();
foreach($userids as $user)
$all[] = DB_get_email_by_userid($user);
$To = implode(",",$all);
$help = "\n\n (you can use reply all on this email to reach all the players.)\n";
mymail($To,$EmailName."game over (game ".DB_format_gameid($gameid).") part 1(2)",$message.$help);
foreach($userids as $user)
{
$To = DB_get_email_by_userid($user);
$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."?me=".$hash."\n\n" ;
mymail($To,$EmailName."game over (game ".DB_format_gameid($gameid).") part 2(2)",$link);
}
}
}
else
{
echo "can't find that card?!
\n";
}
}
else if(myisset("card") && !$myturn )
{
echo "please wait until it's your turn!
\n";
}
if($seq!=4 && $trickNR>1)
echo "
\n