changed message for new dealer into message for new startplayer
[e-DoKo.git] / include / game.php
index a11e6b6eb48d64c56370b2c497dcfbaeb402e753..a1c02a0b4f90f4929f6c856254bf3b13ca6a7b30 100644 (file)
@@ -1,4 +1,23 @@
 <?php
+/* Copyright 2006, 2007, 2008, 2009, 2010 Arun Persaud <arun@nubati.net>
+ *
+ *   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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
 /* make sure that we are not called from outside the scripts,
  * use a variable defined in config.php to check this
  */
@@ -24,10 +43,6 @@ 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);
@@ -67,7 +82,7 @@ if( $gamestatus == 'pre' )
 else
   {
     /* in a game Schweinchen is not valid in all types of games */
-    if( $gametype == 'normal' || $gametype == 'silent' || $gametype=='trump' || $gametype=='wedding')
+    if( in_array($gametype,array('normal','wedding','trump','silent') ))
       if( in_array($RULES['schweinchen'],array('both','second','secondaftercall')) )
        $ok=1;
   }
@@ -210,16 +225,19 @@ if($session)
     echo "  </div>\n  </div>\n";
 
     /* show score */
+
+    echo "  <div class=\"sessionscore\">";
+
     $score   = generate_score_table($session);
+
+    /* get the last entry to show on the main page */
     $tmpscore= $score;
     $finalscore = array_pop($tmpscore);
     $finalscore = $finalscore['players'];
 
-    echo "  <div class=\"sessionscore\">";
     if($finalscore)
       {
        echo "Score: \n";
-       /* output the final score on the front page */
        foreach($finalscore as $user=>$value)
          {
            $name = DB_get_name('userid',$user);
@@ -232,10 +250,13 @@ if($session)
        echo "&nbsp;";
       }
 
+    /* output all games for the score table */
     echo format_score_table_html($score,$myid);
     echo "  </div>\n";
 
-    /* figure out which game in a session we are in and link to the previous and next game if possible */
+    /* figure out which game in a session we are in and link to the
+     * previous and next game if possible
+     */
     $hashes = DB_get_hashes_by_session($session,$myid);
     $next     = NULL;
     $i = 1;
@@ -282,6 +303,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':
@@ -589,11 +620,10 @@ switch($mystatus)
        else if($nines)
          {
            /* cancel game */
-           $message = "Hello, \n\n".
-             " the game has been canceled because ".DB_get_name('userid',$nines).
+           $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";
+             "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";
 
            $userids = DB_get_all_userid_by_gameid($gameid);
            foreach($userids as $user)
@@ -605,9 +635,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 "<p>The game has been canceled because ".DB_get_name('userid',$nines).
+             " has five or more nines and nobody is playing solo.</p>\n";
+           echo "</div>\n";
+           break;
          }
        else if($poverty==1) /* one person has poverty */
          {
@@ -952,8 +983,8 @@ switch($mystatus)
                /* update game status */
                cancel_game('trump',$gameid);
 
-               echo "<p style=\"background-color:red\";>Game ".DB_format_gameid($gameid)." has been canceled.<br /><br /></p>";
-               return;
+               echo "<p class=\"message\";>Game ".DB_format_gameid($gameid)." has been canceled.<br /><br /></p>";
+               break;
              }
            else
              {
@@ -1414,7 +1445,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
                 */
@@ -1447,7 +1481,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 */
@@ -1472,7 +1509,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)
                  {
@@ -1487,6 +1527,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
@@ -1910,11 +1954,17 @@ switch($mystatus)
             * also check if we have both schweinchen, in that case only display on of them as playable
             */
            if( ($followsuit && !same_type($card,$firstcard)) ||
-               ( (int)($card)==19 && !$GAME['schweinchen-first'] &&
-                 ($RULES['schweinchen']=='second'||
-                  ( $RULES['schweinchen']=='secondaftercall' &&
-                    (DB_get_call_by_hash($GAME['schweinchen-who']) || DB_get_partner_call_by_hash($GAME['schweinchen-who']) )))
-                 && $GAME['schweinchen-who']==$me  )
+               ( (int)($card)==19 &&
+                 !$GAME['schweinchen-first'] &&
+                 ( $RULES['schweinchen']=='second' ||
+                   ( $RULES['schweinchen']=='secondaftercall' &&
+                    (DB_get_call_by_hash($GAME['schweinchen-who']) ||
+                     DB_get_partner_call_by_hash($GAME['schweinchen-who']) )
+                   )
+                 ) &&
+                 $GAME['schweinchen-who']==$me &&
+                 in_array($gametype,array('normal','wedding','trump','silent'))
+                 )
                )
              display_card($card,$PREF['cardset']);
            else
@@ -1931,7 +1981,15 @@ switch($mystatus)
       {
        $oldcards = DB_get_all_hand($me);
        $oldcards = mysort($oldcards,$gametype);
-       echo "Your cards were: <br />\n";
+
+       if(isset($_SESSION['id']) && $myid==$_SESSION['id'])
+         echo "Your cards were: <br />\n";
+       else
+         {
+           $name = DB_get_name('userid',$myid);
+           echo "$name's were: <br />\n";
+         }
+
        foreach($oldcards as $card)
          display_card($card,$PREF['cardset']);