X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=include%2Fgame.php;h=ceed8bbba49d25191fe4cf940d9358b8d7d95c3e;hp=0e16292abd5fb4459152e7b507531260ff21d4f6;hb=be7fad04dae48d5fa0c209b84be3e9cf9b763472;hpb=09515348107d9aab7823a12d31b082a2ebb75555 diff --git a/include/game.php b/include/game.php index 0e16292..ceed8bb 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,14 @@ if(!$myid) DB_close(); exit(); } - + +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 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 +43,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); @@ -56,21 +59,53 @@ if($gametype=="solo") $GT = $gametype." ".$GT; } -/* does anyone have both foxes */ -$GAME["schweinchen"]=0; -for($i=1;$i<5;$i++) +/* 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' ) { - $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"]=1; - $GAME["schweinchen-who"]=$hash; - } - }; + /* always need to use Schweinchen to figure out for example who has poverty */ + $ok=1; + } +else + { + /* in a game Schweinchen is not valid in all types of games */ + if( $gametype == 'normal' || $gametype == 'silent' || $gametype=='trump' ) + 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'); /* put everyting in a form */ -echo "
\n"; output_footer(); DB_close(); exit();