if(!myisset("me"))
{
echo "Hmm, you really shouldn't mess with the urls.<br />\n";
- output_footer();
- DB_close();
- exit();
+ return;
}
$me = $_REQUEST["me"];
{
echo "Can't find you in the database, please check the url.<br />\n";
echo "perhaps the game has been canceled, check by login in <a href=\"$INDEX\">here</a>.";
- output_footer();
- DB_close();
- exit();
+ return;
}
global $GAME,$RULES,$CARDS;
-/* 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"]);
-
/* the user has done something, update the timestamp */
DB_update_user_timestamp($myid);
/* put everyting in a form */
echo "<form action=\"index.php?action=game&me=$me\" method=\"post\">\n";
-/* output game */
+/* handle user notes (only possible while game is running)*/
+if( $mystatus!='gameover' )
+ if(myisset("note"))
+{
+ $note = $_REQUEST['note'];
+
+ if($note != "")
+ DB_insert_note($note,$gameid,$myid);
+};
+output_user_notes($myid,$gameid,$mystatus);
+
+/* handle calls */
+if(myisset("call") && $_REQUEST["call"] == "120" && can_call(120,$me))
+ $result = DB_query("UPDATE Hand SET point_call='120' WHERE hash='$me' ");
+if(myisset("call") && $_REQUEST["call"] == "90" && can_call(90,$me))
+ $result = DB_query("UPDATE Hand SET point_call='90' WHERE hash='$me' ");
+if(myisset("call") && $_REQUEST["call"] == "60" && can_call(60,$me))
+ $result = DB_query("UPDATE Hand SET point_call='60' WHERE hash='$me' ");
+if(myisset("call") && $_REQUEST["call"] == "30" && can_call(30,$me))
+ $result = DB_query("UPDATE Hand SET point_call='30' WHERE hash='$me' ");
+if(myisset("call") && $_REQUEST["call"] == "0" && can_call(0,$me))
+ $result = DB_query("UPDATE Hand SET point_call='0' WHERE hash='$me' ");
/* output extra division in case this game is part of a session */
if($session)
{
- echo "<div class=\"session\">\n".
- "This game is part of session $session: \n";
+ echo "<div class=\"session\">\n";
+ echo " <div class=\"sessionrules\">Rules (+icons fur rules) \n";
+ echo " <div>\n";
+ echo " 10ofhearts : ".$RULES["dullen"] ."<br />\n";
+ echo " schweinchen: ".$RULES["schweinchen"] ."<br />\n";
+ echo " call: ".$RULES["call"] ."<br />\n";
+ echo " </div>\n </div>\n";
+ echo " <div class=\"sessionscore\">Score \n";
+ $score = generate_score_table($session);
+ echo format_score_table_html($score,$myid);
+ echo " </div>\n";
$hashes = DB_get_hashes_by_session($session,$myid);
$i = 1;
foreach($hashes as $hash)
{
- if($hash == $me)
- echo "$i \n";
- else
- echo "<a href=\"".$INDEX."?action=game&me=".$hash."\">$i</a> \n";
- $i++;
+ if($hash == $me)
+ $j=$i;
+ $i++;
+ $lasthash=$hash;
}
+ $i--;
+ echo "This is game number $j of <a href=\"".$INDEX."?action=game&me=$lasthash\">$i</a> in session $session.";
echo "</div>\n";
}
echo "The game has been canceled because ".DB_get_name('userid',$nines).
" has five or more nines and nobody is playing solo.\n";
- output_footer();
- DB_close();
- exit();
+ return;
}
else if($poverty==1) /* one person has poverty */
{
{
/* email startplayer */
$message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
- "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
+ "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
}
}
{
/* email player for poverty */
$message = "Poverty: It's your turn now in game ".DB_format_gameid($gameid).".\n".
- "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$whohash."\n\n" ;
+ "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$whohash."\n\n" ;
mymail($email,$EmailName."Poverty (game ".DB_format_gameid($gameid).") ",$message);
}
}
{
/* email startplayer */
$message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
- "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
+ "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
}
}
DB_cancel_game($me);
echo "<p style=\"background-color:red\";>Game ".DB_format_gameid($gameid)." has been canceled.<br /><br /></p>";
- output_footer();
- DB_close();
- exit();
+ return;
}
else
{
DB_set_hand_status_by_hash($userhash,'poverty');
$message = "Two people have poverty, it's your turn to decide, if you want to take the trump. Please visit:".
- " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
+ " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
mymail($To,$EmailName." double poverty (game ".DB_format_gameid($gameid).")",$message);
{
/* email startplayer) */
$message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
- "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
+ "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
}
}
DB_insert_comment($comment,$playid,$myid);
};
- /* handle notes in case player didn't play a card, allow notes only during a game */
- if( (!myisset("card") && $mystatus=='play') )
- if(myisset("note"))
- {
- $note = $_REQUEST["note"];
-
- if($note != "")
- DB_insert_note($note,$gameid,$myid);
- };
-
/* get everything relevant to display the tricks */
$result = DB_query("SELECT Hand_Card.card_id as card,".
" Hand.position as position,".
"WHERE Trick.game_id='".$gameid."' ".
"GROUP BY Trick.id, sequence ".
"ORDER BY Trick.id, sequence ASC");
- $trickNR = 1;
+ $trickNR = 0;
$lasttrick = DB_get_max_trickid($gameid);
$play = array(); /* needed to calculate winner later */
if($mygametype != 'normal' && $mygametype != 'silent') /* only show when needed */
{
echo " <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n".
- " <div class=\"trick\" id=\"trick0\">\n";
+ " <div class=\"trick\" id=\"trick0\">\n";
$show = 1;
for($mypos=1;$mypos<5;$mypos++)
{
$comment = $r[4];
$user = $r[6];
+ /* count number of tricks */
+ if($seq==1)
+ $trickNR++;
+
/* check if first schweinchen has been played */
if( $GAME['schweinchen-who'] && ($r[0] == 19 || $r[0] == 20) )
if(!$GAME['schweinchen-first'])
/* end of trick? */
if($seq==4)
{
- $trickNR++;
echo " </div>\n </li>\n"; /* end div trick, end li trick */
}
}
/* 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("call") && $_REQUEST["call"] == "120" && can_call(120,$me))
- $result = DB_query("UPDATE Hand SET point_call='120' WHERE hash='$me' ");
- if(myisset("call") && $_REQUEST["call"] == "90" && can_call(90,$me))
- $result = DB_query("UPDATE Hand SET point_call='90' WHERE hash='$me' ");
- if(myisset("call") && $_REQUEST["call"] == "60" && can_call(60,$me))
- $result = DB_query("UPDATE Hand SET point_call='60' WHERE hash='$me' ");
- if(myisset("call") && $_REQUEST["call"] == "30" && can_call(30,$me))
- $result = DB_query("UPDATE Hand SET point_call='30' WHERE hash='$me' ");
- if(myisset("call") && $_REQUEST["call"] == "0" && can_call(0,$me))
- $result = DB_query("UPDATE Hand SET point_call='0' WHERE hash='$me' ");
-
/* mark card as played */
DB_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".
DB_quote_smart($card));
$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.$INDEX."?action=game&me=".$next_hash."\n\n" ;
+ "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$next_hash."\n\n" ;
if( DB_get_email_pref_by_uid($who)!="emailaddict" )
mymail($email,$EmailName."a card has been played in game ".DB_format_gameid($gameid),$message);
}
$session = DB_get_session_by_gameid($gameid);
$score = generate_score_table($session);
- /* convert html to ascii */
- $score = str_replace("<div class=\"scoretable\">\n<table class=\"score\">\n <tr>\n","",$score);
- $score = str_replace("</table></div>\n","",$score);
- $score = str_replace("\n","",$score);
- $score = str_replace(array("<tr>","</tr>","<td>","</td>"),array("","\n","","|"),$score);
- $score = explode("\n",$score);
-
- $header = array_slice($score,0,1);
- $header = explode("|",$header[0]);
- for($i=0;$i<sizeof($header);$i++)
- $header[$i]=str_pad($header[$i],6," ",STR_PAD_BOTH);
- $header = implode("|",$header);
- $header.= "\n------+------+------+------+------+\n";
- if(sizeof($score)>5) $header.= " ... \n";
-
- if(sizeof($score)>5) $score = array_slice($score,-5,5);
- for($i=0;$i<sizeof($score);$i++)
- {
- $line = explode("|",$score[$i]);
- for($j=0;$j<sizeof($line);$j++)
- $line[$j]=str_pad($line[$j],6," ",STR_PAD_LEFT);
- $score[$i] = implode("|",$line);
- }
-
- $score = implode("\n",$score);
- $score = $header.$score;
$message .= "Score Table:\n";
- $message .= $score;
+ $message .= format_score_table_ascii($score);
/* send out final email */
$all = array();
$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.$INDEX."?action=game&me=".$hash."\n\n" ;
+ $HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
if( DB_get_email_pref_by_uid($user) != "emailaddict" )
mymail($To,$EmailName."game over (game ".DB_format_gameid($gameid).") part 2(2)",$link);
}
}
echo " <li onclick=\"hl_prev();\" class=\"old\"><a href=\"#\">prev</a></li>\n";
- echo " <li onclick=\"hl_next();\" class=\"old\"><a href=\"#\">next</a></li>\n</ul>\n"; /* end ul tricks*/
-
- echo "<div class=\"notes\"> Personal notes: <br />\n";
- $notes = DB_get_notes_by_userid_and_gameid($myid,$gameid);
- foreach($notes as $note)
- echo "$note <hr />\n";
- echo "Insert note:<input name=\"note\" type=\"text\" size=\"15\" maxlength=\"100\" />\n";
- echo "</div> \n";
+ echo " <li onclick=\"hl_next();\" class=\"old\"><a href=\"#\">next</a></li>\n";
+ echo "</ul>\n"; /* end ul tricks*/
$mycards = DB_get_hand($me);
$mycards = mysort($mycards,$gametype);
/* display rule set for this game */
echo "<div class=\"gameinfo\">\n";
- if($gamestatus != 'pre')
- echo " Gametype: $GT <br />\n";
-
- echo "Rules: <br />\n";
- echo "10ofhearts : ".$RULES["dullen"] ."<br />\n";
- echo "schweinchen: ".$RULES["schweinchen"] ."<br />\n";
- echo "call: ".$RULES["call"] ."<br />\n";
-
- echo "<hr />\n";
if($gamestatus == 'play' )
output_form_calls($me);
if($gamestatus == 'play' || $gameend < 60*60*24*7)
{
echo "<br />\nA short comment:<input name=\"comment\" type=\"text\" size=\"15\" maxlength=\"100\" />\n";
- echo "<hr />";
}
- echo "<input type=\"submit\" value=\"submit\" />\n<hr />\n";
-
- $session = DB_get_session_by_gameid($gameid);
- $score = generate_score_table($session);
-
- echo $score;
+ echo "<input type=\"submit\" value=\"submit\" />\n";
echo "</div>\n";
output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);
}
}
-
-
- output_footer();
- DB_close();
- exit();
?>
\ No newline at end of file