X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=include%2Fgame.php;h=30abe7d53687d8600f0c0ef51a6cc57c988e5f66;hp=0d4f0a9856606465caabe651390a197e333b170b;hb=522e61d6c5c04dac9c3254ddd2fd7ebb82a1a104;hpb=086ed1db2ec28817b3370481455c84ceaf6448c2
diff --git a/include/game.php b/include/game.php
index 0d4f0a9..30abe7d 100644
--- a/include/game.php
+++ b/include/game.php
@@ -5,33 +5,28 @@
if(!isset($HOST))
exit;
-if(!myisset("me"))
+/* 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";
- output_footer();
- DB_close();
- exit();
+ return;
}
+$me = $_REQUEST['me'];
-$me = $_REQUEST["me"];
-
-/* test for valid ID */
+/* 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.";
- output_footer();
- DB_close();
- exit();
+ return;
}
-/* 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"]);
+global $GAME,$RULES,$CARDS;
-/* the user had done something, update the timestamp */
-DB_update_user_timestamp($myid);
+/* the user has done something, update the timestamp */
+if(isset($_SESSION['id']))
+ DB_update_user_timestamp($_SESSION['id']);
/* get some information from the DB */
$gameid = DB_get_gameid_by_hash($me);
@@ -39,64 +34,246 @@ $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 */
-DB_get_PREF($myid);
+/* get prefs and save them in a variable*/
+$PREF = DB_get_PREF(isset($_SESSION['id'])?$_SESSION['id']:$myid);
/* get rule set for this game */
-$r = DB_query_array("SELECT * FROM Rulesets".
- " LEFT JOIN Game ON Game.ruleset=Rulesets.id ".
- " WHERE Game.id='$gameid'" );
-
-$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);
$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;
}
-/* 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( 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');
/* put everyting in a form */
-echo "