X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=include%2Fgame.php;h=a50b247d0adc76e90fdc0b363940950f5393b2a0;hp=3564d9cc382efbdbff0b705a8be1e33cb1505cba;hb=692b2c53acc3d0f8a0205b7aba84938580540df7;hpb=2bd1c94dd7e712bb2cc8e2c16fb317bd0169c59c
diff --git a/include/game.php b/include/game.php
index 3564d9c..a50b247 100644
--- a/include/game.php
+++ b/include/game.php
@@ -1,5 +1,5 @@
+/* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Arun Persaud '._('Got it').' :)
\n";
+ echo _("Hmm, you really shouldn't mess with the urls.")."
\n";
return;
}
$me = $_REQUEST['me'];
@@ -36,8 +36,8 @@ $me = $_REQUEST['me'];
$myid = DB_get_userid('hash',$me);
if(!$myid)
{
- echo "Can't find you in the database, please check the url.
\n";
- echo "perhaps the game has been canceled, check by login in here.";
+ echo _('Cannot find you in the database, please check the url.')."
\n";
+ printf(_('Perhaps the game has been canceled, check by login in here.'),$INDEX);
return;
}
@@ -49,27 +49,36 @@ global $GAME,$RULES,$CARDS;
$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);
$session = DB_get_session_by_gameid($gameid);
+$playid = DB_get_current_playid($gameid); /* might be -1 at beginning of the game */
/* get prefs and save them in a variable*/
$PREF = DB_get_PREF(isset($_SESSION['id'])?$_SESSION['id']:$myid);
+/* set language chosen in preferences */
+$_SESSION['language'] = $PREF['language'];
+set_language($PREF['language']);
/* get rule set for this game */
$RULES = DB_get_RULES($gameid);
/* get some infos about the game */
-$gametype = DB_get_gametype_by_gameid($gameid);
-$gamestatus = DB_get_game_status_by_gameid($gameid);
-$GT = $gametype;
-if($gametype=='solo')
- {
- $gametype = DB_get_solo_by_gameid($gameid);
- $GT = $gametype.' '.$GT;
- }
+$gametype_raw = DB_get_gametype_by_gameid($gameid);
+$gametype_solo = DB_get_solo_by_gameid($gameid);
+
+/* replace solo with the type of solo */
+$gametype = $gametype_raw;
+if($gametype_raw=='solo')
+ $gametype = $gametype_solo;
+
+/* gametype for displaying it (hides hidden solo)*/
+$GT = get_display_gametype($gameid);
+
+$gamestatus = DB_get_game_status_by_gameid($gameid);
+
+
/* do we need to worry about Schweinchen?
* check gametype and rules
@@ -129,96 +138,135 @@ if( $mystatus!='gameover' )
DB_insert_note($note,$gameid,$myid);
};
-/* handle calls, output a comment to show when the call was made */
-/* initialize comments */
-$comment = '';
-
-/* get information needed to submit comment */
-$playid = DB_get_current_playid($gameid);
-
-/* set comment */
-if($comment != '')
- DB_insert_comment($comment,$playid,$myid);
-/* clear up */
-unset($comment);
-/* end check for calls */
+/*****************************************************************
+ * handle calls part1: check what was called, set everything up
+ * we only can submit it to the database at the end, since the playid
+ * might change if a player plays a card
+ *****************************************************************/
+/* initialize comments */
+$commentCall = '';
/* check for calls, set comment */
-if(myisset('call') && $_REQUEST['call'] == '120' && can_call(120,$me))
+if( myisset('call') )
{
- $result = DB_query("UPDATE Hand SET point_call='120' WHERE hash='$me' ");
- if($myparty=='re')
- $comment .= "Re";
- else if($myparty=='contra')
- $comment .= "Contra";
- }
-if(myisset('call') && $_REQUEST['call'] == '90' && can_call(90,$me))
- {
- $result = DB_query("UPDATE Hand SET point_call='90' WHERE hash='$me' ");
- $comment .= "No 90";
+ if($_REQUEST['call'] == '120' && can_call(120,$me))
+ {
+ $result = DB_query("UPDATE Hand SET point_call='120' WHERE hash='$me' ");
+ if($myparty=='re')
+ $commentCall = 'Re';
+ else if($myparty=='contra')
+ $commentCall = 'Contra';
+ }
+ else if($_REQUEST['call'] == '90' && can_call(90,$me))
+ {
+ $result = DB_query("UPDATE Hand SET point_call='90' WHERE hash='$me' ");
+ $commentCall = 'No 90';
+ }
+ else if($_REQUEST['call'] == '60' && can_call(60,$me))
+ {
+ $result = DB_query("UPDATE Hand SET point_call='60' WHERE hash='$me' ");
+ $commentCall = 'No 60';
+ }
+ else if($_REQUEST['call'] == '30' && can_call(30,$me))
+ {
+ $result = DB_query("UPDATE Hand SET point_call='30' WHERE hash='$me' ");
+ $commentCall = 'No 30';
+ }
+ else if($_REQUEST['call'] == '0' && can_call(0,$me))
+ {
+ $result = DB_query("UPDATE Hand SET point_call='0' WHERE hash='$me' ");
+ $commentCall = 'Zero';
+ }
}
-if(myisset('call') && $_REQUEST['call'] == '60' && can_call(60,$me))
+
+/**********************************************************
+ * handle comments unless we play a card at the same time *
+ * (if we play a card, we need to update playid) *
+ **********************************************************/
+
+
+/* get time from the last action of the game */
+$r = DB_query_array("SELECT mod_date from Game WHERE id=".DB_quote_smart($gameid));
+$gameend = time() - strtotime($r[0]);
+
+/* handle comments in case player didn't play a card, allow comments a week after the end of the game */
+if( (!myisset('card') && $mystatus!='gameover') || ($mystatus=='gameover' && ($gameend < 60*60*24*7)) )
+ if(myisset('comment'))
+ {
+ $comment = $_REQUEST['comment'];
+
+ if($comment != '')
+ DB_insert_comment($comment,$playid,$gameid,$myid);
+ };
+
+
+/*****************************************************************
+ * 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( $gamestatus != 'gameover' && isset($_SESSION['id']) )
{
- $result = DB_query("UPDATE Hand SET point_call='60' WHERE hash='$me' ");
- $comment .= "No 60";
+ /* game isn't over, only valid user can get here, so show menu */
+ display_user_menu($myid, $me);
}
-if(myisset('call') && $_REQUEST['call'] == '30' && can_call(30,$me))
+else if( $mystatus == 'gameover' && isset($_SESSION['id']) )
{
- $result = DB_query("UPDATE Hand SET point_call='30' WHERE hash='$me' ");
- $comment .= "No 30";
+ /* user is looking at someone else's game, show the menu for the correct user */
+ display_user_menu($_SESSION['id'],$me);
}
-if(myisset('call') && $_REQUEST['call'] == '0' && can_call(0,$me))
+else
{
- $result = DB_query("UPDATE Hand SET point_call='0' WHERE hash='$me' ");
- $comment .= "Zero";
+ echo ' \n\n";
}
-
/*****************************************************************
* output extra division in case this game is part of a session
*****************************************************************/
if($session)
{
- echo "
\n";
@@ -234,7 +282,7 @@ if($session)
$score = generate_score_table($session);
/* get the last entry to show on the main page */
- $tmpscore= $score;
+ $tmpscore = $score;
$finalscore = array_pop($tmpscore);
$finalscore = $finalscore['players'];
@@ -244,13 +292,13 @@ if($session)
foreach($finalscore as $user=>$value)
{
$name = DB_get_name('userid',$user);
- echo " ".substr($name,0,2).": $value ";
+ echo ' '.substr($name,0,2).": $value ";
}
}
else
{
/* first game, no score yet */
- echo " ";
+ echo ' ';
}
/* output all games for the score table */
@@ -261,7 +309,7 @@ if($session)
* previous and next game if possible
*/
$hashes = DB_get_hashes_by_session($session,$myid);
- $next = NULL;
+ $next = NULL;
$i = 1;
foreach($hashes as $hash)
{
@@ -282,18 +330,22 @@ if($session)
$next = NULL;
/* check for solo, add game type to session number */
- echo " Game $session.$j";
- if($GT !='normal')
- echo " ($GT)";
+ echo ' '._('Game')." $session.$j";
+ if($gamestatus != 'pre')
+ if($gametype_raw != 'normal') /* only show when needed */
+ if(!($gametype_raw == 'solo' && $gametyep_solo == 'silent') )
+ echo " ($GT)";
+
if(isset($_SESSION['id']) && $_SESSION['id']==$myid)
{
if($previous)
echo " "._('previous')." \n";
if($next)
echo " "._('next')." \n";
+
+ if($j != $i )
+ echo " "._('last')." \n";
}
- if($j != $i )
- echo " last \n";
echo "\n\n";
+ echo "
\n"; /* end div trick, end li trick , end tricks*/
+ /* end displaying sickness */
+ break;
+ case 'poverty':
+ /* output pre-game trick in case user reloads,
+ * only needs to be done when a team has been formed */
+ if($myparty=='re' || $myparty=='contra')
+ {
+ echo "\n\n";
+ echo "
\n\n"; /* end div trick, end li trick , end ul tricks */
+ }
+ /* end output pre-game trick */
+ break;
+ case 'play':
+ case 'gameover':
+
+ echo "\n\n";
+
+ /* output vorbehalte */
+ if($gametype_raw != 'normal') /* only show when needed */
+ if(!($gametype_raw == 'solo' && $gametyep_solo == 'silent') )
+ echo "
\n\n";
+
+ break;
+ default:
+ }
+
+
/******************************************************************************
* Output tricks played, table, messages, and cards (depending on game status)
******************************************************************************/
@@ -316,7 +440,7 @@ if($mystatus!='gameover')
echo "
\n";
+ {
+ $messages[] = sprintf(_('Please, start the game.'),$INDEX."?action=game&me=$me").
+ "
\n";
+ $nobreak=1;
+ }
}
else
{
@@ -798,7 +908,11 @@ switch($mystatus)
$whoid = DB_get_userid('gameid-position',$gameid,$who);
if($whoid==$myid)
- echo "Please, start the game.
start the game.'),$INDEX."?action=game&me=$me").
+ "
\n";
- $card_status = CARDS_SHOW;
}
- break;
+ if(!$nobreak)
+ break;
case 'poverty':
/* user only gets here in a poverty game, several things have to be handled here:
@@ -835,6 +950,11 @@ switch($mystatus)
* it is easier to check B) first
*/
+ /* in case the user can go do the next stage, we want to skip the break statement at the
+ * end. We keep track of these cases using this variable
+ */
+ $nobreak=0;
+
set_gametype($gametype); /* this sets the $CARDS variable */
$myparty = DB_get_party_by_hash($me);
@@ -851,35 +971,14 @@ switch($mystatus)
if($exchange >0)
{
$result = DB_query("UPDATE Hand_Card SET hand_id='$partnerhand'".
- " WHERE hand_id='$myhand' AND card_id=".DB_quote_smart($exchange));
+ " WHERE hand_id=".DB_quote_smart($myhand)." AND card_id=".DB_quote_smart($exchange));
DB_add_exchanged_card(DB_quote_smart($exchange),$myhand,$partnerhand);
};
}
- /* output pre-game trick in case user reloads,
- * only needs to be done when a team has been formed */
- if($myparty=='re' || $myparty=='contra')
- {
- echo "\n\n";
-
- $mygametype = DB_get_gametype_by_gameid($gameid);
-
- echo "
\n\n"; /* end div trick, end li trick , end ul tricks */
- }
- /* end output pre-game trick */
-
/* 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)
{
@@ -893,21 +992,23 @@ 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)
{
if(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);
+ set_language($userid,'uid');
+ $email_message = sprintf(_("It's your turn now in game %s.\n".
+ 'Use this link to play a card: '),DB_format_gameid($gameid)).$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
+ mymail($userid,$gameid,GAME_READY,$email_message);
+ set_language($myid,'uid');
}
}
else
- echo " \n";
+ $messages[]= sprintf(_('Please, start the game.'),$INDEX."?action=game&me=$me");
}
/* the following is part A) of what needs to be done */
@@ -934,13 +1035,16 @@ switch($mystatus)
if($card<27) $nrtrump++;
$low='';
if($usersick=='lowtrump')
- $low='low';
- echo "Player $name has $nrtrump $low trump. Do you want to take them?".
- "Yes
\n";
+ $low=_('low');
+ /// TRANSLATORS: first %s=name, %d=number of trump, second %s= '' or 'low' for trumpfarmut
+ printf(_('Player %s has %d %s trump. Do you want to take them?'.
+ 'Yes')."
\n",
+ $name,$nrtrump,$low,"index.php?action=game&me=$me&trump=$user");
}
}
- echo "No way
\n";
- echo "
\n";
+ echo "
If this was a mistake all 4 players need to send an Email to $ADMIN_NAME at $ADMIN_EMAIL requesting that the game should be restarted."); break; case 'cancel-timedout': - echo "
"; + $messages[] = _("The game has been canceled because one player wasn't responding.This game took ".$r[0]." hours.
\n"; + echo ''; + printf(_('This game took %d hours.'), $r[0]); + echo "
\n"; - echo "See how other played the same hand: \n"; + echo '
'._('See how other played the same hand:')." \n"; foreach($other_game_ids as $id) { $otherhash = DB_get_hash_from_game_and_pos($id,$mypos); @@ -2168,7 +2364,7 @@ if(sizeof($other_game_ids)>0 && $mystatus=='gameover') echo "
\n"; } -echo "