X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=include%2Fgame.php;h=cef2c6537c2a11141a38ac387f546943f8624b1b;hp=7905acd63a00a9d1e5ae7619711e5a0d520e85a7;hb=f5d068d8b0c003324c075489a4894be2b66eb051;hpb=853c2a611637ab3abf65feb86b4b5f96c1749cb9 diff --git a/include/game.php b/include/game.php index 7905acd..cef2c65 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 */ @@ -6,14 +25,12 @@ if(!isset($HOST)) exit; /* calling game.php only makes sense when we give it a hash for a game */ -if(!myisset("me")) +if(!myisset('me')) { echo "Hmm, you really shouldn't mess with the urls.
\n"; - output_footer(); - DB_close(); - exit(); + return; } -$me = $_REQUEST["me"]; +$me = $_REQUEST['me']; /* Ok, got a hash, but is it valid? */ $myid = DB_get_userid('hash',$me); @@ -21,30 +38,24 @@ 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."; - 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); - -/* get some information from the DB */ +/************************************** + * 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); $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); /* get prefs and save them in a variable*/ -$PREF = DB_get_PREF($myid); +$PREF = DB_get_PREF(isset($_SESSION['id'])?$_SESSION['id']:$myid); /* get rule set for this game */ $RULES = DB_get_RULES($gameid); @@ -53,10 +64,10 @@ $RULES = DB_get_RULES($gameid); $gametype = DB_get_gametype_by_gameid($gameid); $gamestatus = DB_get_game_status_by_gameid($gameid); $GT = $gametype; -if($gametype=="solo") +if($gametype=='solo') { $gametype = DB_get_solo_by_gameid($gameid); - $GT = $gametype." ".$GT; + $GT = $gametype.' '.$GT; } /* do we need to worry about Schweinchen? @@ -69,11 +80,14 @@ if( $gamestatus == 'pre' ) { /* always need to use Schweinchen to figure out for example who has poverty */ $ok=1; + /* unless the gametype is set and we know that we are in poverty were schweinchen is not valid */ + if( in_array( $gametype,array('poverty','dpoverty') )) + $ok=0; } else { /* in a game Schweinchen is not valid in all types of games */ - if( $gametype == 'normal' || $gametype == 'silent' || $gametype=='trump' ) + if( in_array($gametype,array('normal','wedding','trump','silent') )) if( in_array($RULES['schweinchen'],array('both','second','secondaftercall')) ) $ok=1; } @@ -90,7 +104,7 @@ if($ok) { $hash = DB_get_hash_from_game_and_pos($gameid,$i); $cards = DB_get_all_hand($hash); - if( in_array("19",$cards) && in_array("20",$cards) ) + if( in_array('19',$cards) && in_array('20',$cards) ) $GAME['schweinchen-who']=$hash; }; $GAME['schweinchen-first'] = 0; /* to keep track if they have been played already */ @@ -104,31 +118,366 @@ if($ok) */ set_gametype('normal'); -/* put everyting in a form */ -echo "
\n"; +/* 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); + }; + +/* 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 */ + + +/* check for calls, set comment */ +if(myisset('call') && $_REQUEST['call'] == '120' && can_call(120,$me)) + { + $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(myisset('call') && $_REQUEST['call'] == '60' && can_call(60,$me)) + { + $result = DB_query("UPDATE Hand SET point_call='60' WHERE hash='$me' "); + $comment .= "No 60"; + } +if(myisset('call') && $_REQUEST['call'] == '30' && can_call(30,$me)) + { + $result = DB_query("UPDATE Hand SET point_call='30' WHERE hash='$me' "); + $comment .= "No 30"; + } +if(myisset('call') && $_REQUEST['call'] == '0' && can_call(0,$me)) + { + $result = DB_query("UPDATE Hand SET point_call='0' WHERE hash='$me' "); + $comment .= "Zero"; + } + + -/* output game */ +/***************************************************************** + * 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 + *****************************************************************/ -/* output extra division in case this game is part of a session */ +if( $gamestatus != 'gameover' && isset($_SESSION['id']) ) + { + /* game isn't over, only valid user can get here, so show menu */ + display_user_menu($myid, $me); + } +else if( $mystatus == 'gameover' && isset($_SESSION['id']) ) + { + /* user is looking at someone else's game, show the menu for the correct user */ + display_user_menu($_SESSION['id'],$me); + } +else + { + echo "
\n"; + echo "It's your turn in these games: \n"; + echo "Please log in to see this information.\n"; + echo "
\n\n"; + } + +/***************************************************************** + * output extra division in case this game is part of a session + *****************************************************************/ if($session) { - echo "
\n". - "This game is part of session $session: \n"; + echo "
\n"; + + /* output rule set */ + echo "
\n "._('Rules').":\n"; + switch($RULES['dullen']) + { + case 'none': + echo " \""._('no\n"; break; + case 'firstwins': + echo " \""._('ten\n"; break; + case 'secondwins': + echo " \""._('second\n"; break; + } + switch($RULES['schweinchen']) + { + case 'none': + echo " \""._('no\n"; break; + case 'both': + echo " \""._('two\n"; break; + case 'second': + echo " \"".('second\n"; break; + case 'secondaftercall': + echo " \""._('second\n"; break; + } + switch($RULES['call']) + { + case '1st-own-card': + echo " \""._('1st-own-card')."\"\n"; break; + case '5th-card': + echo " \""._('5th-card')."\"\n"; break; + case '9-cards': + echo " \""._('9-cards')."\"\n"; break; + } + echo "
\n"; + echo ' '._('10ofhearts').": {$RULES['dullen']}
\n"; + echo ' '._('schweinchen').": {$RULES['schweinchen']}
\n"; + echo ' '._('call').": {$RULES['call']}
\n"; + echo ' '._('lowtrump').": {$RULES['lowtrump']}
\n"; + echo "
\n
\n"; + + /* show score */ + + echo "
"; + + $score = generate_score_table($session); + + /* get the last entry to show on the main page */ + $tmpscore= $score; + $finalscore = array_pop($tmpscore); + $finalscore = $finalscore['players']; + + if($finalscore) + { + echo _('Score').": \n"; + foreach($finalscore as $user=>$value) + { + $name = DB_get_name('userid',$user); + echo " ".substr($name,0,2).": $value "; + } + } + else + { + /* first game, no score yet */ + echo " "; + } + + /* output all games for the score table */ + echo format_score_table_html($score,$myid); + echo "
\n"; + + /* 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; foreach($hashes as $hash) { - if($hash == $me) - echo "$i \n"; - else - echo "$i \n"; - $i++; + if($hash == $me) + $j=$i; + $i++; + $lasthash=$hash; + } + $i--; + + if($j>1) + $previous = $hashes[$j-2]; + else + $previous = NULL; + if($j<$i) + $next = $hashes[$j]; + else + $next = NULL; + + /* check for solo, add game type to session number */ + echo " Game $session.$j"; + if($GT !='normal') + 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"; + + echo "\n
\n"; + } + +/* 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']); + + +/****************************************************************************** + * Output menu for selecting tricks + ******************************************************************************/ + +switch($mystatus) + { + case 'start': + break; + case 'init': + case 'check': + /* output sickness of other playes, in case they already selected and are sitting in front of the current player */ + echo "\n
    \n"; + echo "
  • Pre\n"; + + echo "
  • \n
\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"; + + $mygametype = DB_get_gametype_by_gameid($gameid); + + echo "
  • Pre\n"; + echo "
  • \n
\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 */ + $mygametype = DB_get_gametype_by_gameid($gameid); + $mygamesolo = DB_get_solo_by_gameid($gameid); + if($mygametype != 'normal') /* only show when needed */ + if(!( $mygametype == 'solo' && $mygamesolo == 'silent') ) + echo "
  • Pre
  • \n"; + + $result = DB_query("SELECT Trick.id ". + "FROM Trick ". + "WHERE Trick.game_id='".$gameid."' ". + "GROUP BY Trick.id ". + "ORDER BY Trick.id ASC"); + $trickNR = 1; + $lasttrick = DB_get_max_trickid($gameid); + + /* output tricks */ + while($r = DB_fetch_array($result)) + { + $trick=$r[0]; + if($trick!=$lasttrick) + echo "
  • "._('Trick')." $trickNR
  • \n"; + else if($trick==$lasttrick) + echo "
  • "._('Trick')." $trickNR
  • \n"; + $trickNR++; } - echo "
\n"; + + /* if game is over, also output link to Score tab */ + if($mystatus=='gameover' && DB_get_game_status_by_gameid($gameid)=='gameover' ) + echo "
  • "._('Score')."
  • \n"; + + /* output previous/next buttons */ + echo "
  • \n"; + echo "
  • \n"; + + echo "\n\n"; + + break; + default: } + +/****************************************************************************** + * Output tricks played, table, messages, and cards (depending on game status) + ******************************************************************************/ + +/* put everyting in a form */ +echo "\n"; + /* display the table and the names */ -display_table(); +display_table_begin(); + + +/****************************** + * Output pre-trick if needed * + ******************************/ + +switch($mystatus) + { + case 'start': + break; + case 'init': + case 'check': + /* output sickness of other playes, in case they already selected and are sitting in front of the current player */ + echo "\n
    \n"; + echo "
    \n"; + + for($pos=1;$pos<5;$pos++) + { + $usersick = DB_get_sickness_by_pos_and_gameid($pos,$gameid); + $userid = DB_get_userid('gameid-position',$gameid,$pos); + $userstatus = DB_get_hand_status_by_userid_and_gameid($userid,$gameid); + + if($userstatus=='start' || $userstatus=='init') + echo "
    still needs
    to decide
    \n"; /* show this to everyone */ + else + if($usersick!=NULL) /* in the init-phase we only showed players with $pos<$mypos, now we can show all */ + echo "
    sick
    \n"; + else + echo "
    healthy
    \n"; + } + echo "
    \n
    \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