* * 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 */ if(!isset($HOST)) exit; /* calling game.php only makes sense when we give it a hash for a game */ if(!myisset('me')) { echo "Hmm, you really shouldn't mess with the urls.
\n"; return; } $me = $_REQUEST['me']; /* Ok, got a hash, but is it valid? */ $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."; return; } global $GAME,$RULES,$CARDS; /************************************** * 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(isset($_SESSION['id'])?$_SESSION['id']:$myid); /* 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; } /* do we need to worry about Schweinchen? * check gametype and rules * if yes, figure out if someone actually has Schweinchen * save information in $GAME */ $ok=0; 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( in_array($gametype,array('normal','wedding','trump','silent') )) if( in_array($RULES['schweinchen'],array('both','second','secondaftercall')) ) $ok=1; } /* these are the defaults */ $GAME['schweinchen-who'] = NULL; $GAME['schweinchen-first'] = NULL; $GAME['schweinchen-second'] = NULL; if($ok) { /* need to check for Schweinchen */ for($i=1;$i<5;$i++) { $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) ) $GAME['schweinchen-who']=$hash; }; $GAME['schweinchen-first'] = 0; /* to keep track if they have been played already */ $GAME['schweinchen-second'] = 0; } /* end check for Schweinchen */ /* set the $CARDS variable, needed for sorting the cards * we set it to normal so that the pre-game phase is handled ok * and later set it to the correct game type that is played */ set_gametype('normal'); /* 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 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']) ) { /* 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"; /* 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) $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"; /* 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\n"; /* end div trick, end li trick , end ul tricks */ } /* end output pre-game trick */ break; case 'play': case 'gameover': echo "\n\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_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