X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=include%2Fgame.php;h=1dbd1e95d0e2afc58b55a5830f6896331bdb78cb;hp=0e16292abd5fb4459152e7b507531260ff21d4f6;hb=HEAD;hpb=09515348107d9aab7823a12d31b082a2ebb75555
diff --git a/include/game.php b/include/game.php
index 0e16292..1dbd1e9 100644
--- a/include/game.php
+++ b/include/game.php
@@ -1,99 +1,447 @@
+ *
+ * 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
\n";
+ return;
+ }
+$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();
+ echo _('Cannot find you in the database, please check the url.')."
\n";
+ printf(_('Perhaps the game has been canceled, check by login in here.'),$INDEX);
+ 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"]);
-/* the user had done something, update the timestamp */
-DB_update_user_timestamp($myid);
+global $GAME,$RULES,$CARDS;
-/* get some information from the DB */
+/**************************************
+ * get some information from the DB
+ **************************************/
+start:
$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);
+$playid = DB_get_current_playid($gameid); /* might be -1 at beginning of the game */
-/* 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);
+/* set language chosen in preferences */
+$_SESSION['language'] = $PREF['language'];
+set_language($PREF['language']);
/* 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);
-$gamestatus = DB_get_game_status_by_gameid($gameid);
-$GT = $gametype;
-if($gametype=="solo")
+$gametype_raw = DB_get_gametype_by_gameid($gameid);
+$gametype_solo = DB_get_solo_by_gameid($gameid);
+
+/* replace solo with the type of solo */
+$gametype = $gametype_raw;
+if($gametype_raw=='solo')
+ $gametype = $gametype_solo;
+
+/* gametype for displaying it (hides hidden solo)*/
+$GT = get_display_gametype($gameid);
+
+$gamestatus = DB_get_game_status_by_gameid($gameid);
+
+
+
+/* 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' )
{
- $gametype = DB_get_solo_by_gameid($gameid);
- $GT = $gametype." ".$GT;
+ /* 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 part1: check what was called, set everything up
+ * we only can submit it to the database at the end, since the playid
+ * might change if a player plays a card
+ *****************************************************************/
+
+/* initialize comments */
+$commentCall = '';
-/* does anyone have both foxes */
-$GAME["schweinchen"]=0;
-for($i=1;$i<5;$i++)
+/* check for calls, set comment */
+if( myisset('call') )
{
- $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($_REQUEST['call'] == '120' && can_call(120,$me))
{
- $GAME["schweinchen"]=1;
- $GAME["schweinchen-who"]=$hash;
+ $result = DB_query("UPDATE Hand SET point_call='120' WHERE hash='$me' ");
+ if($myparty=='re')
+ $commentCall = 'Re';
+ else if($myparty=='contra')
+ $commentCall = 'Contra';
}
- };
+ else if($_REQUEST['call'] == '90' && can_call(90,$me))
+ {
+ $result = DB_query("UPDATE Hand SET point_call='90' WHERE hash='$me' ");
+ $commentCall = 'No 90';
+ }
+ else if($_REQUEST['call'] == '60' && can_call(60,$me))
+ {
+ $result = DB_query("UPDATE Hand SET point_call='60' WHERE hash='$me' ");
+ $commentCall = 'No 60';
+ }
+ else if($_REQUEST['call'] == '30' && can_call(30,$me))
+ {
+ $result = DB_query("UPDATE Hand SET point_call='30' WHERE hash='$me' ");
+ $commentCall = 'No 30';
+ }
+ else if($_REQUEST['call'] == '0' && can_call(0,$me))
+ {
+ $result = DB_query("UPDATE Hand SET point_call='0' WHERE hash='$me' ");
+ $commentCall = 'Zero';
+ }
+ }
+
+/**********************************************************
+ * handle comments unless we play a card at the same time *
+ * (if we play a card, we need to update playid) *
+ **********************************************************/
-/* put everyting in a form */
-echo "