fixed typo and added a comment
[e-DoKo.git] / include / game.php
index 79cdfa6fef32aa623ba5fa13399250a5f65255dc..ff96594b4a4ff46df2e64a658c6a33f123ca09b9 100644 (file)
@@ -57,6 +57,9 @@ $playid   = DB_get_current_playid($gameid); /* might be -1 at beginning of the g
 
 /* get prefs and save them in a variable*/
 $PREF = DB_get_PREF(isset($_SESSION['id'])?$_SESSION['id']:$myid);
+/* set language chosen in preferences, will become active on the next reload (see index.php)*/
+$_SESSION['language'] = $PREF['language'];
+
 
 /* get rule set for this game */
 $RULES = DB_get_RULES($gameid);
@@ -323,7 +326,7 @@ if($session)
 
     /* check for solo, add game type to session number */
     echo "    Game $session.$j";
-    if($GT !='normal')
+    if($gamestatus != 'pre' && $GT !='normal' )
       echo " ($GT)";
     if(isset($_SESSION['id']) && $_SESSION['id']==$myid)
       {
@@ -520,8 +523,9 @@ switch($mystatus)
 
 /* Depending on the situation we set
  *   cards_status (see functions.php for possible options)
+ *   most of the times we need to just show the cards, so we make this the default
  */
-$cards_status = CARDS_EMPTY;
+$card_status = CARDS_SHOW;
 
 /* Also collect message that should be displayed to the user, so that we can show
  * them after showing the table. This makes the html flow more consistent and easier
@@ -545,7 +549,10 @@ switch($mystatus)
       {
        /* asks the player, if he wants to join the game */
        output_check_want_to_play($me);
+
+       /* don't show the cards before the user joined the game */
        $card_status = CARDS_EMPTY;
+
        break;
       }
     else
@@ -563,6 +570,8 @@ switch($mystatus)
                mymail($user,$gameid,GAME_CANCELED,$email_message);
              }
 
+           $card_status = CARDS_EMPTY;
+
            /* update game status */
            cancel_game('noplay',$gameid);
            break;
@@ -579,16 +588,16 @@ switch($mystatus)
 
            /* check if everyone has reached this stage, set player in game-table to the next player */
            $userids = DB_get_all_userid_by_gameid($gameid);
-           foreach($userids as $user)
+           foreach($userids as $userid)
              {
-               $userstat = DB_get_hand_status_by_userid_and_gameid($user,$gameid);
+               $userstat = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
                if($userstat!='init')
                  {
                    /* whos turn is it? */
-                   DB_set_player_by_gameid($gameid,$user);
+                   DB_set_player_by_gameid($gameid,$userid);
                    break;
                  }
-             };
+             }
          }
       }
   case 'init':
@@ -600,8 +609,6 @@ switch($mystatus)
        $mycards = DB_get_hand($me);
        output_check_for_sickness($me,$mycards);
 
-       $card_status = CARDS_SHOW;
-
        break;
       }
     else
@@ -619,8 +626,6 @@ switch($mystatus)
            $messages[] = "You selected more than one sickness, please go back ".
              "and answer the <a href=\"$INDEX?action=game&amp;me=$me&amp;in=yes\">question</a> again.";
 
-           $card_status = CARDS_SHOW;
-
            break;
          }
        else
@@ -698,13 +703,13 @@ switch($mystatus)
     /* check if everyone has reached this stage */
     $userids = DB_get_all_userid_by_gameid($gameid);
     $ok = 1;
-    foreach($userids as $user)
+    foreach($userids as $userid)
       {
-       $userstat = DB_get_hand_status_by_userid_and_gameid($user,$gameid);
+       $userstat = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
        if($userstat!='check')
          {
            $ok = 0;
-           DB_set_player_by_gameid($gameid,$user);
+           DB_set_player_by_gameid($gameid,$userid);
            break;
          }
       };
@@ -715,15 +720,6 @@ switch($mystatus)
          'Seems like this is not the case, so you need to wait a bit... '.
          'you will get an email once that is the case, please use the link in '.
          'that email to continue the game.');
-
-       /* display cards, if player was just at the init-phase he will still see the cards from there
-        * we can put this one here, since the last player to finish the init state won't get here and
-        * will still see his card anyway from the init-phase
-        */
-       if($mystatus=='check')
-         {
-           $card_status = CARDS_SHOW;
-         }
       }
     else
       {
@@ -923,8 +919,8 @@ switch($mystatus)
          {
            $startplayer = DB_get_startplayer_by_gameid($gameid);
            $hash        = DB_get_hash_from_game_and_pos($gameid,$startplayer);
-           $who         = DB_get_userid('hash',$hash);
-           DB_set_player_by_gameid($gameid,$who);
+           $userid      = DB_get_userid('hash',$hash);
+           DB_set_player_by_gameid($gameid,$userid);
 
            if($hash!=$me)
              {
@@ -933,7 +929,7 @@ switch($mystatus)
                    /* email startplayer */
                    $email_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" ;
-                   mymail($who,$gameid,GAME_READY,$email_message);
+                   mymail($userid,$gameid,GAME_READY,$email_message);
                  }
              }
            else
@@ -962,7 +958,6 @@ switch($mystatus)
                  }
              }
          }
-       $card_status = CARDS_SHOW;
       }
     break;
 
@@ -1007,9 +1002,6 @@ switch($mystatus)
     /* get hand */
     $mycards = DB_get_hand($me);
 
-    /* default: show cards, will be overwritten, if we need to give back cards */
-    $card_status = CARDS_SHOW;
-
     /* check if user need to give more cards back */
     if( ($myparty=='re' || $myparty=='contra') && count($mycards)>12)
       {
@@ -1023,8 +1015,8 @@ switch($mystatus)
        /* email start player */
        $startplayer = DB_get_startplayer_by_gameid($gameid);
        $hash        = DB_get_hash_from_game_and_pos($gameid,$startplayer);
-       $who         = DB_get_userid('hash',$hash);
-       DB_set_player_by_gameid($gameid,$who);
+       $userid      = DB_get_userid('hash',$hash);
+       DB_set_player_by_gameid($gameid,$userid);
 
        if($hash!=$me)
          {
@@ -1033,7 +1025,7 @@ switch($mystatus)
                /* email startplayer */
                $email_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" ;
-               mymail($who,$gameid,GAME_READY,$email_message);
+               mymail($userid,$gameid,GAME_READY,$email_message);
              }
          }
        else
@@ -1269,13 +1261,13 @@ switch($mystatus)
       {
        $ok = 1;
        $userids = DB_get_all_userid_by_gameid($gameid);
-       foreach($userids as $user)
+       foreach($userids as $userid)
          {
-           $userstatus = DB_get_hand_status_by_userid_and_gameid($user,$gameid);
+           $userstatus = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
            if($userstatus !='play' && $userstatus!='gameover')
              {
                $ok = 0;
-               DB_set_player_by_gameid($gameid,$user);
+               DB_set_player_by_gameid($gameid,$userid);
                break;
              }
          }
@@ -1287,15 +1279,15 @@ switch($mystatus)
            /* email startplayer */
            $startplayer = DB_get_startplayer_by_gameid($gameid);
            $hash        = DB_get_hash_from_game_and_pos($gameid,$startplayer);
-           $who         = DB_get_userid('hash',$hash);
-           DB_set_player_by_gameid($gameid,$who);
+           $userid      = DB_get_userid('hash',$hash);
+           DB_set_player_by_gameid($gameid,$userid);
 
            if($hash!=$me && DB_get_email_pref_by_hash($hash)!='emailaddict')
              {
                /* email startplayer) */
                $email_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" ;
-               mymail($who,$gameid, GAME_READY, $email_message);
+               mymail($userid,$gameid, GAME_READY, $email_message);
              }
          }
       }
@@ -1329,8 +1321,6 @@ switch($mystatus)
        $messages[] = _('You finished the setup, but not everyone else finished it... '.
          'You need to wait for the others. Just wait for an email.');
 
-       $card_status = CARDS_SHOW;
-
        break; /* not sure this works... the idea is that you can
                * only  play a card after everyone is ready to play */
       }
@@ -1744,15 +1734,15 @@ switch($mystatus)
            if(DB_get_game_status_by_gameid($gameid)=='play')
              {
                $next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
-               $who       = DB_get_userid('hash',$next_hash);
-               DB_set_player_by_gameid($gameid,$who);
+               $userid    = DB_get_userid('hash',$next_hash);
+               DB_set_player_by_gameid($gameid,$userid);
 
                $email_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" ;
-               if( DB_get_email_pref_by_uid($who)!='emailaddict' )
+               if( DB_get_email_pref_by_uid($userid)!='emailaddict' )
                  {
-                   mymail($who,$gameid, GAME_YOUR_TURN, $email_message);
+                   mymail($userid,$gameid, GAME_YOUR_TURN, $email_message);
                  }
              }
            else /* send out final email */
@@ -2096,7 +2086,7 @@ switch($mystatus)
     /* check if game is over, display results */
     if(DB_get_game_status_by_gameid($gameid)=='play')
       {
-       echo _('The game is over for you... other people still need to play though');
+       $messages[] = _('The game is over for you... other people still need to play though');
       }
     break;
   default: