X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=include%2Fgame.php;h=35b94cd70c1cc6862ad285b949fb98fe7525ddb3;hp=0e16292abd5fb4459152e7b507531260ff21d4f6;hb=9239ba22c382383cd258ad3f36b2bc0dc99664b2;hpb=09515348107d9aab7823a12d31b082a2ebb75555 diff --git a/include/game.php b/include/game.php index 0e16292..35b94cd 100644 --- a/include/game.php +++ b/include/game.php @@ -1,13 +1,21 @@ \n"; + output_footer(); + DB_close(); + exit(); + } $me = $_REQUEST["me"]; -/* test for valid ID */ +/* Ok, got a hash, but is it valid? */ $myid = DB_get_userid('hash',$me); if(!$myid) { @@ -17,12 +25,12 @@ if(!$myid) DB_close(); exit(); } - + /* 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 had done something, update the timestamp */ +/* the user has done something, update the timestamp */ DB_update_user_timestamp($myid); /* get some information from the DB */ @@ -33,18 +41,11 @@ $mypos = DB_get_pos_by_hash($me); $myhand = DB_get_handid('hash',$me); $session = DB_get_session_by_gameid($gameid); -/* get prefs and save them */ -DB_get_PREF($myid); +/* get prefs and save them in a variable*/ +$PREF = DB_get_PREF($myid); /* get rule set for this game */ -$result = mysql_query("SELECT * FROM Rulesets". - " LEFT JOIN Game ON Game.ruleset=Rulesets.id ". - " WHERE Game.id='$gameid'" ); -$r = mysql_fetch_array($result,MYSQL_NUM); - -$RULES["dullen"] = $r[2]; -$RULES["schweinchen"] = $r[3]; -$RULES["call"] = $r[4]; +$RULES = DB_get_RULES($gameid); /* get some infos about the game */ $gametype = DB_get_gametype_by_gameid($gameid); @@ -70,7 +71,7 @@ for($i=1;$i<5;$i++) }; /* put everyting in a form */ -echo "
\n"; +echo "\n"; /* output game */ @@ -86,7 +87,7 @@ if($session) if($hash == $me) echo "$i \n"; else - echo "$i \n"; + echo "$i \n"; $i++; } echo "\n"; @@ -174,7 +175,7 @@ switch($mystatus) DB_set_player_by_gameid($gameid,$who); $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n". - "Use this link to go the game: ".$HOST.$INDEX."?me=".$hash."\n\n" ; + "Use this link to go the game: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ; mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message); */ } @@ -182,59 +183,52 @@ switch($mystatus) } } case 'init': - + /* here we ask the player if he is sick */ $mycards = DB_get_hand($me); sort($mycards); - - output_check_for_sickness($me,$mycards); - - echo "

Your cards are:
\n"; - foreach($mycards as $card) - display_card($card,$PREF["cardset"]); - echo "

\n"; - - /* move on to the next stage*/ - DB_set_hand_status_by_hash($me,'check'); - break; - - case 'check': - /* ok, user is in the game, saw his cards and selected his vorbehalt - * so first we check what he selected - */ + if(!myisset("solo","wedding","poverty","nines") ) { - /* all these variables have a pre-selected default, - * so we should never get here, - * unless a user tries to cheat ;) - * can also happen if user reloads the page! - */ - echo "

You need to answer the questions.

"; - DB_set_hand_status_by_hash($me,'init'); + output_check_for_sickness($me,$mycards); + + echo "

Your cards are:
\n"; + foreach($mycards as $card) + display_card($card,$PREF["cardset"]); + echo "

\n"; + + break; } else { - /* check if someone selected more than one vorbehalt */ - $Nvorbehalt = 0; - if($_REQUEST["solo"]!="No") $Nvorbehalt++; - if($_REQUEST["wedding"] == "yes") $Nvorbehalt++; - if($_REQUEST["poverty"] == "yes") $Nvorbehalt++; - if($_REQUEST["nines"] == "yes") $Nvorbehalt++; - - if($Nvorbehalt>1) + /* check if someone selected more than one sickness */ + $Nsickness = 0; + if($_REQUEST["solo"]!="No") $Nsickness++; + if($_REQUEST["wedding"] == "yes") $Nsickness++; + if($_REQUEST["poverty"] == "yes") $Nsickness++; + if($_REQUEST["nines"] == "yes") $Nsickness++; + + if($Nsickness>1) { - echo "

You selected more than one vorbehalt, please go back ". - "and answer the question again.

"; - DB_set_hand_status_by_hash($me,'init'); + echo "

You selected more than one sickness, please go back ". + "and answer the question again.

"; + + echo "

Your cards are:
\n"; + foreach($mycards as $card) + display_card($card,$PREF["cardset"]); + echo "

\n"; + + break; } else { + /* everything is ok, save what user said and proceed */ echo "

Processing what you selected in the last step..."; /* check if this sickness needs to be handled first */ $gametype = DB_get_gametype_by_gameid($gameid); - $startplayer = DB_get_startplayer_by_gameid($gameid); + $startplayer = DB_get_startplayer_by_gameid($gameid); /* need this to check which solo goes first */ - if( $_REQUEST["solo"]!="No") + if( $_REQUEST["solo"]!="No" ) { /* user wants to play a solo */ @@ -273,45 +267,18 @@ switch($mystatus) " is playing solo, this game will be canceled.
\n"; DB_set_sickness_by_hash($me,"nines"); } - - echo " Ok, done with checking, please go to the next step of the setup.

"; - + + echo "

\n"; + /* move on to the next stage*/ DB_set_hand_status_by_hash($me,'poverty'); - - /* check if everyone has reached this stage, send out email */ - $userids = DB_get_all_userid_by_gameid($gameid); - $ok = 1; - foreach($userids as $user) - { - $userstat = DB_get_hand_status_by_userid_and_gameid($user,$gameid); - if($userstat!='poverty' && $userstat!='play') - { - $ok = 0; - DB_set_player_by_gameid($gameid,$user); - } - }; - if($ok) - { - /* reset player = everyone has to do something now */ - DB_set_player_by_gameid($gameid,NULL); - - foreach($userids as $user) - { - $To = DB_get_email('userid',$user); - $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user); - if($userhash != $me) - { - $message = "Everyone finish the questionary in game ".DB_format_gameid($gameid).", ". - "please visit this link now to continue: \n". - " ".$HOST.$INDEX."?me=".$userhash."\n\n" ; - mymail($To,$EmailName." finished setup in game ".DB_format_gameid($gameid),$message); - } - }; - }; }; }; - break; + + case 'check': + /* hmm, by reorganizing things a bit, this stage is empty at the moment */ + /* move on to the next stage, but user shouldn't get here anymore anyway */ + DB_set_hand_status_by_hash($me,'poverty'); case 'poverty': /* here we need to check if there is a solo or some other form of sickness. @@ -513,7 +480,7 @@ switch($mystatus) DB_set_party_by_hash($me,"contra"); echo "Whoever will make the first trick will be on the re team.
\n"; - echo " Ok, the game can start now, please finish the setup.
"; + echo " Ok, the game can start now, please finish the setup.
"; DB_set_hand_status_by_hash($me,'play'); break; @@ -576,7 +543,7 @@ switch($mystatus) DB_set_player_by_gameid($gameid,$userid); $message = "Someone has poverty, it's your turn to decide, if you want to take the trump. Please visit:". - " ".$HOST.$INDEX."?me=".$userhash."\n\n" ; + " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ; mymail($To,$EmailName." poverty (game ".DB_format_gameid($gameid).")",$message); } @@ -592,7 +559,7 @@ switch($mystatus) /* get hand id for user $trump */ $userhand = DB_get_handid('gameid-userid',$gameid,$trump); /* copy trump from player A to B */ - $result = mysql_query("UPDATE Hand_Card SET hand_id='$myhand' WHERE hand_id='$userhand' AND card_id<'27'" ); + $result = DB_query("UPDATE Hand_Card SET hand_id='$myhand' WHERE hand_id='$userhand' AND card_id<'27'" ); /* add hidden button with trump in it to get to the next point */ echo "
\n"; @@ -610,13 +577,12 @@ switch($mystatus) /* if exchange is set to a value>0, exchange that card back to user $trump */ if($exchange >0) { - $result = mysql_query("UPDATE Hand_Card SET hand_id='$userhand'". - " WHERE hand_id='$myhand' AND card_id='$exchange'" ); + $result = DB_query("UPDATE Hand_Card SET hand_id='$userhand'". + " WHERE hand_id='$myhand' AND card_id='$exchange'" ); }; /* if number of cards == 12, set status to play for both users */ - $result = mysql_query("SELECT COUNT(*) FROM Hand_Card WHERE hand_id='$myhand'" ); - $r = mysql_fetch_array($result,MYSQL_NUM); + $r = DB_query_array("SELECT COUNT(*) FROM Hand_Card WHERE hand_id='$myhand'" ); if(!$r) { myerror("error in poverty"); @@ -658,7 +624,7 @@ switch($mystatus) $message = "Someone has poverty, it's your turn to decide, ". "if you want to take the trump. Please visit:". - " ".$HOST.$INDEX."?me=".$userhash."\n\n" ; + " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ; mymail($To,$EmailName." poverty (game ".DB_format_gameid($gameid).")",$message); } } @@ -732,10 +698,10 @@ switch($mystatus) /* count trump */ if($nrtrump<4) echo "Player $name has $nrtrump trump. Do you want to take them?". - "yes
\n"; + "yes
\n"; } } - echo "No,way I take those trump...
\n"; + echo "No,way I take those trump...
\n"; echo "
\n"; echo "Your cards are:
\n"; @@ -803,11 +769,11 @@ switch($mystatus) { /* email startplayer) */ $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n". - "Use this link to play a card: ".$HOST.$INDEX."?me=".$hash."\n\n" ; + "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ; mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message); } else - echo " Please, start the game.
"; + echo " Please, start the game.
"; } else echo "\n
"; @@ -851,8 +817,7 @@ switch($mystatus) } /* get time from the last action of the game */ - $result = mysql_query("SELECT mod_date from Game WHERE id='$gameid' " ); - $r = mysql_fetch_array($result,MYSQL_NUM); + $r = DB_query_array("SELECT mod_date from Game WHERE id='$gameid' " ); $gameend = time() - strtotime($r[0]); /* handel comments in case player didn't play a card, allow comments a week after the end of the game */ @@ -877,23 +842,23 @@ switch($mystatus) }; /* get everything relevant to display the tricks */ - $result = mysql_query("SELECT Hand_Card.card_id as card,". - " Hand.position as position,". - " Play.sequence as sequence, ". - " Trick.id, ". - " GROUP_CONCAT(CONCAT('',User.fullname,': ',Comment.comment,'')". - " SEPARATOR '\n' ), ". - " Play.create_date, ". - " Hand.user_id ". - "FROM Trick ". - "LEFT JOIN Play ON Trick.id=Play.trick_id ". - "LEFT JOIN Hand_Card ON Play.hand_card_id=Hand_Card.id ". - "LEFT JOIN Hand ON Hand_Card.hand_id=Hand.id ". - "LEFT JOIN Comment ON Play.id=Comment.play_id ". - "LEFT JOIN User On User.id=Comment.user_id ". - "WHERE Trick.game_id='".$gameid."' ". - "GROUP BY Trick.id, sequence ". - "ORDER BY Trick.id, sequence ASC"); + $result = DB_query("SELECT Hand_Card.card_id as card,". + " Hand.position as position,". + " Play.sequence as sequence, ". + " Trick.id, ". + " GROUP_CONCAT(CONCAT('',User.fullname,': ',Comment.comment,'')". + " SEPARATOR '\n' ), ". + " Play.create_date, ". + " Hand.user_id ". + "FROM Trick ". + "LEFT JOIN Play ON Trick.id=Play.trick_id ". + "LEFT JOIN Hand_Card ON Play.hand_card_id=Hand_Card.id ". + "LEFT JOIN Hand ON Hand_Card.hand_id=Hand.id ". + "LEFT JOIN Comment ON Play.id=Comment.play_id ". + "LEFT JOIN User On User.id=Comment.user_id ". + "WHERE Trick.game_id='".$gameid."' ". + "GROUP BY Trick.id, sequence ". + "ORDER BY Trick.id, sequence ASC"); $trickNR = 1; $lasttrick = DB_get_max_trickid($gameid); @@ -930,7 +895,7 @@ switch($mystatus) } /* output tricks */ - while($r = mysql_fetch_array($result,MYSQL_NUM)) + while($r = DB_fetch_array($result)) { $pos = $r[1]; $seq = $r[2]; @@ -1014,9 +979,8 @@ switch($mystatus) /* check if we have card and that we haven't played it yet*/ /* set played in hand_card to true where hand_id and card_id*/ - $result = mysql_query("SELECT id FROM Hand_Card WHERE played='false' and ". + $r = DB_query_array("SELECT id FROM Hand_Card WHERE played='false' and ". "hand_id='$handid' AND card_id=".DB_quote_smart($card)); - $r = mysql_fetch_array($result,MYSQL_NUM); $handcardid = $r[0]; if($handcardid) /* everything ok, play card */ @@ -1026,19 +990,19 @@ switch($mystatus) /* check if a call was made, must do this before we set the card status to played */ if(myisset("call") && $_REQUEST["call"] == "120" && can_call(120,$me)) - $result = mysql_query("UPDATE Hand SET point_call='120' WHERE hash='$me' "); + $result = DB_query("UPDATE Hand SET point_call='120' WHERE hash='$me' "); if(myisset("call") && $_REQUEST["call"] == "90" && can_call(90,$me)) - $result = mysql_query("UPDATE Hand SET point_call='90' WHERE hash='$me' "); + $result = DB_query("UPDATE Hand SET point_call='90' WHERE hash='$me' "); if(myisset("call") && $_REQUEST["call"] == "60" && can_call(60,$me)) - $result = mysql_query("UPDATE Hand SET point_call='60' WHERE hash='$me' "); + $result = DB_query("UPDATE Hand SET point_call='60' WHERE hash='$me' "); if(myisset("call") && $_REQUEST["call"] == "30" && can_call(30,$me)) - $result = mysql_query("UPDATE Hand SET point_call='30' WHERE hash='$me' "); + $result = DB_query("UPDATE Hand SET point_call='30' WHERE hash='$me' "); if(myisset("call") && $_REQUEST["call"] == "0" && can_call(0,$me)) - $result = mysql_query("UPDATE Hand SET point_call='0' WHERE hash='$me' "); + $result = DB_query("UPDATE Hand SET point_call='0' WHERE hash='$me' "); /* mark card as played */ - mysql_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=". - DB_quote_smart($card)); + DB_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=". + DB_quote_smart($card)); /* get trick id or start new trick */ $a = DB_get_current_trickid($gameid); @@ -1048,11 +1012,11 @@ switch($mystatus) $playid = DB_play_card($trickid,$handcardid,$sequence); - /* check special output for schweinchen in case: + /* check special output for schweinchen in case: * schweinchen is in the rules, a fox has been played and the gametype is correct */ - if( $GAME["schweinchen"] && - ($card == 19 || $card == 20) && + if( $GAME["schweinchen"] && + ($card == 19 || $card == 20) && ($gametype == "normal" || $gametype == "silent"|| $gametype=="trump")) { $GAME["schweinchen"]++; // count how many have been played including this one @@ -1107,7 +1071,7 @@ switch($mystatus) $winner = get_winner($play,$gametype); /* returns the position */ /* check if someone caught a fox */ - /* first check if we should account for solos at all, + /* first check if we should account for solos at all, * since it doesn't make sense in some games */ $ok = 0; /* fox shouldn't be counted */ @@ -1119,7 +1083,7 @@ switch($mystatus) } else $ok = 1; /* for all other games (not solos) foxes are ok too */ - + if($ok==1) foreach($play as $played) { @@ -1134,11 +1098,11 @@ switch($mystatus) $party2 = DB_get_party_by_gameid_and_userid($gameid,$uid2); if($party1 != $party2) - mysql_query("INSERT INTO Score". - " VALUES( NULL,NULL,$gameid,'$party1',$uid1,$uid2,'fox')"); + DB_query("INSERT INTO Score". + " VALUES( NULL,NULL,$gameid,'$party1',$uid1,$uid2,'fox')"); } } - + /* 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 */ @@ -1151,7 +1115,7 @@ switch($mystatus) if($solo == "trumpless" || $solo == "jack" || $solo == "queen" ) $ok = 0; /* no Karlchen in these solos */ } - + if($ok) foreach($play as $played) if ( $played['card']==11 || $played['card']==12 ) @@ -1161,8 +1125,8 @@ switch($mystatus) $uid1 = DB_get_userid('gameid-position',$gameid,$winner); $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1); - mysql_query("INSERT INTO Score". - " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'karlchen')"); + DB_query("INSERT INTO Score". + " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'karlchen')"); } /* check for doppelopf (>40 points)*/ $points = 0; @@ -1175,12 +1139,12 @@ switch($mystatus) $uid1 = DB_get_userid('gameid-position',$gameid,$winner); $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1); - mysql_query("INSERT INTO Score". - " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'doko')"); + DB_query("INSERT INTO Score". + " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'doko')"); } if($winner>0) - mysql_query("UPDATE Trick SET winner='$winner' WHERE id='$trickid'"); + DB_query("UPDATE Trick SET winner='$winner' WHERE id='$trickid'"); else echo "ERROR during scoring"; @@ -1260,38 +1224,38 @@ switch($mystatus) $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."?me=".$next_hash."\n\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" ) mymail($email,$EmailName."a card has been played in game ".DB_format_gameid($gameid),$message); } else /* send out final email */ { /* individual score */ - $result = mysql_query("SELECT User.fullname, IFNULL(SUM(Card.points),0), Hand.party FROM Hand". - " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id". - " LEFT JOIN User ON User.id=Hand.user_id". - " LEFT JOIN Play ON Trick.id=Play.trick_id". - " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id". - " LEFT JOIN Card ON Card.id=Hand_Card.card_id". - " WHERE Hand.game_id='$gameid'". - " GROUP BY User.fullname" ); + $result = DB_query("SELECT User.fullname, IFNULL(SUM(Card.points),0), Hand.party FROM Hand". + " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id". + " LEFT JOIN User ON User.id=Hand.user_id". + " LEFT JOIN Play ON Trick.id=Play.trick_id". + " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id". + " LEFT JOIN Card ON Card.id=Hand_Card.card_id". + " WHERE Hand.game_id='$gameid'". + " GROUP BY User.fullname" ); $message = "The game is over. Thanks for playing :)\n"; $message .= "Final score:\n"; - while( $r = mysql_fetch_array($result,MYSQL_NUM)) + while( $r = DB_fetch_array($result) ) $message .= " ".$r[0]."(".$r[2].") ".$r[1]."\n"; - $result = mysql_query("SELECT Hand.party, IFNULL(SUM(Card.points),0) FROM Hand". - " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id". - " LEFT JOIN User ON User.id=Hand.user_id". - " LEFT JOIN Play ON Trick.id=Play.trick_id". - " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id". - " LEFT JOIN Card ON Card.id=Hand_Card.card_id". - " WHERE Hand.game_id='$gameid'". - " GROUP BY Hand.party" ); + $result = DB_query("SELECT Hand.party, IFNULL(SUM(Card.points),0) FROM Hand". + " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id". + " LEFT JOIN User ON User.id=Hand.user_id". + " LEFT JOIN Play ON Trick.id=Play.trick_id". + " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id". + " LEFT JOIN Card ON Card.id=Hand_Card.card_id". + " WHERE Hand.game_id='$gameid'". + " GROUP BY Hand.party" ); $message .= "\nTotals:\n"; $re = 0; $contra = 0; - while( $r = mysql_fetch_array($result,MYSQL_NUM)) + while( $r = DB_fetch_array($result) ) { $message .= " ".$r[0]." ".$r[1]."\n"; if($r[0] == "re") @@ -1339,12 +1303,19 @@ switch($mystatus) $winning_party = NULL; if($call_re == NULL && $call_contra==NULL) - if($re>120) - $winning_party="re"; - else - $winning_party="contra"; + { + /* nobody made a call, so it's easy to figure out who won */ + if($re>120) + $winning_party="re"; + else + $winning_party="contra"; + } else { + /* if one party makes a call, they only win, iff they make enough points + * if only one party made a call, the other one wins, + * if the first one didn't make it + */ if($call_re) { $offset = 120 - $call_re; @@ -1353,7 +1324,7 @@ switch($mystatus) if($re > 120+$offset) $winning_party="re"; - else if ( $call_contra == NULL ) + else if ($call_contra == NULL ) $winning_party="contra"; } @@ -1365,7 +1336,7 @@ switch($mystatus) if($contra > 120+$offset) $winning_party="contra"; - else if ( $call_contra == NULL ) + else if ($call_re == NULL ) $winning_party="re"; } } @@ -1377,38 +1348,38 @@ switch($mystatus) { for( $p=$call_contra;$p<=120; $p+=30 ) { - mysql_query("INSERT INTO Score". - " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'against$p')"); + DB_query("INSERT INTO Score". + " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'against$p')"); } for( $p=$call_contra; $p<120; $p+=30) { if( $re >= $p ) - mysql_query("INSERT INTO Score". - " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'made$p')"); + DB_query("INSERT INTO Score". + " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'made$p')"); } } if($winning_party!="re" and $call_re!=NULL) { for( $p=$call_re;$p<=120; $p+=30 ) { - mysql_query("INSERT INTO Score". - " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'against$p')"); + DB_query("INSERT INTO Score". + " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'against$p')"); } for( $p=$call_re; $p<120; $p+=30) { if( $contra>=$p ) - mysql_query("INSERT INTO Score". - " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'made$p')"); + DB_query("INSERT INTO Score". + " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'made$p')"); } } /* point in case contra won */ if($winning_party=="contra") { - mysql_query("INSERT INTO Score". - " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'againstqueens')"); + DB_query("INSERT INTO Score". + " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'againstqueens')"); } /* one point each for winning and each 30 points + calls */ @@ -1421,15 +1392,15 @@ switch($mystatus) $offset = 1; if($re>$p-$offset) - mysql_query("INSERT INTO Score". - " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'".(240-$p)."')"); + DB_query("INSERT INTO Score". + " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'".(240-$p)."')"); } /* re called something and won */ foreach(array(0,30,60,90,120) as $p) { if($call_re!=NULL && $call_re<$p+1) - mysql_query("INSERT INTO Score". - " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'call$p')"); + DB_query("INSERT INTO Score". + " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'call$p')"); } } else if( $winning_party=="contra") @@ -1441,15 +1412,15 @@ switch($mystatus) $offset = 1; if($contra>$p-$offset) - mysql_query("INSERT INTO Score". - " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'".(240-$p)."')"); + DB_query("INSERT INTO Score". + " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'".(240-$p)."')"); } /* re called something and won */ foreach(array(0,30,60,90,120) as $p) { if($call_contra!=NULL && $call_contra<$p+1) - mysql_query("INSERT INTO Score". - " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'call$p')"); + DB_query("INSERT INTO Score". + " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'call$p')"); } } @@ -1458,19 +1429,19 @@ switch($mystatus) $message .= "\n"; $Tpoint = 0; $message .= " Points Re: \n"; - $queryresult = mysql_query("SELECT score FROM Score ". - " WHERE game_id=$gameid AND party='re'". - " "); - while($r = mysql_fetch_array($queryresult,MYSQL_NUM) ) + $queryresult = DB_query("SELECT score FROM Score ". + " WHERE game_id=$gameid AND party='re'". + " "); + while($r = DB_fetch_array($queryresult) ) { $message .= " ".$r[0]."\n"; $Tpoint ++; } $message .= " Points Contra: \n"; - $queryresult = mysql_query("SELECT score FROM Score ". - " WHERE game_id=$gameid AND party='contra'". - " "); - while($r = mysql_fetch_array($queryresult,MYSQL_NUM) ) + $queryresult = DB_query("SELECT score FROM Score ". + " WHERE game_id=$gameid AND party='contra'". + " "); + while($r = DB_fetch_array($queryresult) ) { $message .= " ".$r[0]."\n"; $Tpoint --; @@ -1506,7 +1477,7 @@ switch($mystatus) $score = implode("\n",$score); $score = $header.$score; - + $message .= "Score Table:\n"; $message .= $score; @@ -1526,7 +1497,7 @@ switch($mystatus) $hash = DB_get_hash_from_gameid_and_userid($gameid,$user); $link = "Use this link to have a look at game ".DB_format_gameid($gameid).": ". - $HOST.$INDEX."?me=".$hash."\n\n" ; + $HOST.$INDEX."?action=game&me=".$hash."\n\n" ; if( DB_get_email_pref_by_uid($user) != "emailaddict" ) mymail($To,$EmailName."game over (game ".DB_format_gameid($gameid).") part 2(2)",$link); } @@ -1553,15 +1524,15 @@ switch($mystatus) /* add pic for re/contra " \"table\"\n";*/ - $result = mysql_query("SELECT User.fullname, IFNULL(SUM(Card.points),0), Hand.party,Hand.position FROM Hand". - " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id". - " LEFT JOIN User ON User.id=Hand.user_id". - " LEFT JOIN Play ON Trick.id=Play.trick_id". - " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id". - " LEFT JOIN Card ON Card.id=Hand_Card.card_id". - " WHERE Hand.game_id='$gameid'". - " GROUP BY User.fullname" ); - while( $r = mysql_fetch_array($result,MYSQL_NUM)) + $result = DB_query("SELECT User.fullname, IFNULL(SUM(Card.points),0), Hand.party,Hand.position FROM Hand". + " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id". + " LEFT JOIN User ON User.id=Hand.user_id". + " LEFT JOIN Play ON Trick.id=Play.trick_id". + " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id". + " LEFT JOIN Card ON Card.id=Hand_Card.card_id". + " WHERE Hand.game_id='$gameid'". + " GROUP BY User.fullname" ); + while( $r = DB_fetch_array($result)) echo "
\n". "
".$r[2]."
".$r[1]."
\n". "
\n"; @@ -1578,7 +1549,7 @@ switch($mystatus) echo "$note
\n"; echo "Insert note:\n"; echo "
\n"; - + $mycards = DB_get_hand($me); $mycards = mysort($mycards,$gametype); echo "
\n"; @@ -1647,36 +1618,36 @@ switch($mystatus) } else { - $result = mysql_query("SELECT Hand.party, IFNULL(SUM(Card.points),0) FROM Hand". - " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id". - " LEFT JOIN User ON User.id=Hand.user_id". - " LEFT JOIN Play ON Trick.id=Play.trick_id". - " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id". - " LEFT JOIN Card ON Card.id=Hand_Card.card_id". - " WHERE Hand.game_id='$gameid'". - " GROUP BY Hand.party" ); + $result = DB_query("SELECT Hand.party, IFNULL(SUM(Card.points),0) FROM Hand". + " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id". + " LEFT JOIN User ON User.id=Hand.user_id". + " LEFT JOIN Play ON Trick.id=Play.trick_id". + " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id". + " LEFT JOIN Card ON Card.id=Hand_Card.card_id". + " WHERE Hand.game_id='$gameid'". + " GROUP BY Hand.party" ); echo "
Totals:
\n"; - while( $r = mysql_fetch_array($result,MYSQL_NUM)) + while( $r = DB_fetch_array($result)) echo " ".$r[0]." ".$r[1]."
\n"; - $queryresult = mysql_query("SELECT timediff(mod_date,create_date) ". - " FROM Game WHERE id='$gameid'"); - $r = mysql_fetch_array($queryresult,MYSQL_NUM); + $queryresult = DB_query("SELECT timediff(mod_date,create_date) ". + " FROM Game WHERE id='$gameid'"); + $r = DB_fetch_array($queryresult); echo "

This game took ".$r[0]." hours.

"; echo "
\n Points Re:
\n"; - $queryresult = mysql_query("SELECT score FROM Score ". - " WHERE game_id=$gameid AND party='re'". - " "); - while($r = mysql_fetch_array($queryresult,MYSQL_NUM) ) + $queryresult = DB_query("SELECT score FROM Score ". + " WHERE game_id=$gameid AND party='re'". + " "); + while($r = DB_fetch_array($queryresult) ) echo " ".$r[0]."
\n"; echo "
\n"; echo "
\n Points Contra:
\n"; - $queryresult = mysql_query("SELECT score FROM Score ". - " WHERE game_id=$gameid AND party='contra'". - " "); - while($r = mysql_fetch_array($queryresult,MYSQL_NUM) ) + $queryresult = DB_query("SELECT score FROM Score ". + " WHERE game_id=$gameid AND party='contra'". + " "); + while($r = DB_fetch_array($queryresult) ) echo " ".$r[0]."
\n"; echo "
\n"; @@ -1709,8 +1680,7 @@ switch($mystatus) output_form_calls($me); /* get time from the last action of the game */ - $result = mysql_query("SELECT mod_date from Game WHERE id='$gameid' " ); - $r = mysql_fetch_array($result,MYSQL_NUM); + $r = DB_query_array("SELECT mod_date from Game WHERE id='$gameid' " ); $gameend = time() - strtotime($r[0]); if($gamestatus == 'play' || $gameend < 60*60*24*7) @@ -1719,21 +1689,28 @@ switch($mystatus) echo "
"; } - echo "\n"; + echo "\n
\n"; + + $session = DB_get_session_by_gameid($gameid); + $score = generate_score_table($session); + echo $score; + + echo "
\n"; + + echo "\n"; if($mystatus=='gameover' && DB_get_game_status_by_gameid($gameid)=='gameover' ) { - echo "
\n"; $session = DB_get_session_by_gameid($gameid); - $result = mysql_query("SELECT id,create_date FROM Game". - " WHERE session=$session". - " ORDER BY create_date DESC". - " LIMIT 1"); + $result = DB_query("SELECT id,create_date FROM Game". + " WHERE session=$session". + " ORDER BY create_date DESC". + " LIMIT 1"); $r = -1; if($result) - $r = mysql_fetch_array($result,MYSQL_NUM); + $r = DB_fetch_array($result); if(!$session || $gameid==$r[0]) { @@ -1748,15 +1725,7 @@ switch($mystatus) } } - $session = DB_get_session_by_gameid($gameid); - $score = generate_score_table($session); - - // if(size_of($score)>30) - echo $score; - - echo "
\n"; - echo "\n"; output_footer(); DB_close(); exit();