X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=include%2Fgame.php;h=93ab461415012df85d05094e4f78e5af93a44e1a;hp=564c5c40153df51cd8c338e727c474e0e3741432;hb=f0e93ad1feb9ba47dc1db80354b5f28d29b5ab27;hpb=1ce0838714ea7db3fc3557cb79f1ad82d8bfd708;ds=sidebyside
diff --git a/include/game.php b/include/game.php
index 564c5c4..93ab461 100644
--- a/include/game.php
+++ b/include/game.php
@@ -1,4 +1,23 @@
+ *
+ * This file is part of e-DoKo.
+ *
+ * e-DoKo is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * e-DoKo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with e-DoKo. If not, see .
+ *
+ */
+
/* make sure that we are not called from outside the scripts,
* use a variable defined in config.php to check this
*/
@@ -24,14 +43,11 @@ if(!$myid)
global $GAME,$RULES,$CARDS;
-/* the user has done something, update the timestamp */
-if(isset($_SESSION['id']))
- DB_update_user_timestamp($_SESSION['id']);
-
/* get some information from the DB */
$gameid = DB_get_gameid_by_hash($me);
$myname = DB_get_name('hash',$me);
$mystatus = DB_get_status_by_hash($me);
+$origmystatus = DB_get_status_by_hash($me); /* to show "it's your turn" menu when game has just finished */
$mypos = DB_get_pos_by_hash($me);
$myhand = DB_get_handid('hash',$me);
$myparty = DB_get_party_by_hash($me);
@@ -288,6 +304,16 @@ display_table();
* play: game in progress
* gameover: are we revisiting a game
*/
+
+/* the user has done something, update the timestamp. Use $myid in
+ * active games and check for session-id in old games (myid might be wrong in that case)
+ */
+if($mystatus!='gameover')
+ DB_update_user_timestamp($myid);
+ else
+ if(isset($_SESSION['id']))
+ DB_update_user_timestamp($_SESSION['id']);
+
switch($mystatus)
{
case 'start':
@@ -595,8 +621,8 @@ switch($mystatus)
else if($nines)
{
/* cancel game */
- $message = "the game has been canceled because ".DB_get_name('userid',$nines).
- "has five or more nines and nobody is playing solo.\n\n".
+ $message = "The game has been canceled because ".DB_get_name('userid',$nines).
+ " has five or more nines and nobody is playing solo.\n\n".
"To redeal either start a new game or, in case the game was part of a tournament,\n".
"go to the last game and use the link at the bottom of the page to redeal.\n\n";
@@ -610,9 +636,10 @@ switch($mystatus)
/* update game status */
cancel_game('nines',$gameid);
- echo "The game has been canceled because ".DB_get_name('userid',$nines).
- " has five or more nines and nobody is playing solo.\n";
- return;
+ echo "
The game has been canceled because ".DB_get_name('userid',$nines).
+ " has five or more nines and nobody is playing solo.
\n";
+ echo "\n";
+ break;
}
else if($poverty==1) /* one person has poverty */
{
@@ -957,8 +984,8 @@ switch($mystatus)
/* update game status */
cancel_game('trump',$gameid);
- echo "Game ".DB_format_gameid($gameid)." has been canceled.
";
- return;
+ echo "Game ".DB_format_gameid($gameid)." has been canceled.
";
+ break;
}
else
{
@@ -1419,7 +1446,10 @@ switch($mystatus)
$play = DB_get_cards_by_trick($trickid);
$winner = get_winner($play,$gametype); /* returns the position */
- /* check if someone caught a fox */
+ /*
+ * check if someone caught a fox
+ *******************************/
+
/* first check if we should account for solos at all,
* since it doesn't make sense in some games
*/
@@ -1452,7 +1482,10 @@ switch($mystatus)
}
}
- /* check for karlchen (jack of clubs in the last trick)*/
+ /*
+ * check for karlchen (jack of clubs in the last trick)
+ ******************************************************/
+
/* same as for foxes, karlchen doesn't always make sense
* check what kind of game it is and set karlchen accordingly */
$ok = 1; /* default: karlchen should be accounted for */
@@ -1477,7 +1510,10 @@ switch($mystatus)
DB_query("INSERT INTO Score".
" VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'karlchen')");
}
- /* check for doppelopf (>40 points)*/
+ /*
+ * check for doppelopf (>40 points)
+ ***********************************/
+
$points = 0;
foreach($play as $played)
{
@@ -1492,6 +1528,10 @@ switch($mystatus)
" VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'doko')");
}
+ /*
+ * set winner (for this trick)
+ */
+
if($winner>0)
DB_query("UPDATE Trick SET winner='$winner' WHERE id='$trickid'");
else
@@ -1942,7 +1982,15 @@ switch($mystatus)
{
$oldcards = DB_get_all_hand($me);
$oldcards = mysort($oldcards,$gametype);
- echo "Your cards were:
\n";
+
+ if(isset($_SESSION['id']) && $myid==$_SESSION['id'])
+ echo "Your cards were:
\n";
+ else
+ {
+ $name = DB_get_name('userid',$myid);
+ echo "$name's were:
\n";
+ }
+
foreach($oldcards as $card)
display_card($card,$PREF['cardset']);
@@ -1984,11 +2032,20 @@ switch($mystatus)
/* output other games where it is the users turn
* make sure that the people looking at old games don't see the wrong games here
*/
-if( $mystatus != 'gameover' )
- display_user_menu($myid);
+if( $gamestatus != 'gameover' )
+ {
+ /* game isn't over, only valid user can get here, so show menu */
+ display_user_menu($myid);
+ }
+else if( $origmystatus != 'gameover' )
+ {
+ /* user just played the very last card, game is now over, it's still ok to show the menu though */
+ display_user_menu($myid);
+ }
else if( $mystatus == 'gameover' &&
- isset($_SESSION['id']) )
+ isset($_SESSION['id']) )
{
+ /* user is looking at someone else's game, show the menu for the correct user */
display_user_menu($_SESSION['id']);
}
else