X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=index.php;h=98420418669f997e73418c4c9d13d7cd8ad07202;hp=64068373728db048265eaecee9d2ec4ee4cb5a40;hb=87619b20d23599acf4132d2f36555ffeda35f775;hpb=d5233803bcd19376ea074e27205a77a0148880ac diff --git a/index.php b/index.php index 6406837..9842041 100644 --- a/index.php +++ b/index.php @@ -1,415 +1,99 @@ - - -
-
",$message);
- echo " canceling a game is not implemented at the moment, but will be soon... your cards are: no game in progress, please input 4 names and email addresses, please make sure that the addresses are correct! aehm... at the moment please just answer everything with no, still need to implement this
To: $To
Subject: $Subject
$message
";
- }
- else
- mail($To,$Subject,$message);
- return;
-}
-
-function parse_status()
-{
- global $game,$history,$player,$hash,$lines;
-
- $game["init"] = 0;
- $game["solo-who"] = -1;
- $game["solo-what"] = "todo";
- $game["wedding"] = -1;
- $game["poverty"] = -1;
- $game["nines"] = -1;
- $game["startplayer"] = 0;
-
- for($i=0;$i<4;$i++)
- {
- $tmp = explode( ":",$lines[$i]);
- $hash[$i] = $tmp[0];
- $player[$tmp[0]]["number"] = $i;
- $player[$tmp[0]]["hash"] = $tmp[0];
- $player[$tmp[0]]["name"] = $tmp[1];
- $player[$tmp[0]]["email"] = $tmp[2];
- $player[$tmp[0]]["option"] = $tmp[3];
- $player[$tmp[0]]["points"] = $tmp[4];
- $player[$tmp[0]]["cards"] = $tmp[5];
- if(ereg("s",$tmp[3])) $game["init"]++;
- if(ereg("P",$tmp[3])) $game["poverty"] = $i;
- if(ereg("N",$tmp[3])) $game["nines"] = $i;
- if(ereg("W",$tmp[3])) $game["wedding"] = $i;
- if(ereg("[OSQJCAH]",$tmp[3]) && ($game["solo-who"]<0) )
- {
- $game["solo-who"] = $i;
- $game["startplayer"] = $i;
- }
-
- }
- /* save the game history */
- for($i=4;$i
\n";
+ echo "perhaps the game has been cancled, check by login in here.";
+ exit();
+ }
+
+ DB_update_user_timestamp($myid);
+
+ /* get some information from the DB */
+ $gameid = DB_get_gameid_by_hash($me);
+ $myname = DB_get_name_by_hash($me);
+ $mystatus = DB_get_status_by_hash($me);
+ $mypos = DB_get_pos_by_hash($me);
+
+ echo " \n";
+
+
+
+ if(myisset("cancle"))
+ echo "
";
+ echo "TODO: set card pref
";
+
+ $mycards = DB_get_hand($me);
+ sort($mycards);
+ echo "
\n";
+ foreach($mycards as $card)
+ display_card($card);
+ echo "
".
+ " if you have a wedding, please send an email to the other players.
".
+ " if you have poverty you need to play a normal game,sorry...
".
+ " Please click here to finish the setup.
";
+ 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 ;) */
+ echo "something went wrong...please contact the admin.";
+ }
+ else
+ {
+ /* check if this sickness needs to be handled first */
+ $gametype = DB_get_gametype_by_gameid($gameid);
+ $startplayer = DB_get_startplayer_by_gameid($gameid);
+
+ if( $_REQUEST["solo"]!="No")
+ {
+ DB_set_solo_by_hash($me,$_REQUEST["solo"]);
+ DB_set_sickness_by_hash($me,"solo");
+ echo "
Seems like you want to play a ".$_REQUEST["solo"]." solo. Got it.
\n";
+
+ if($gametype == "solo" && $startplayer<$mypos)
+ {}/* do nothing */
+ else
+ {
+ /* this solo comes first */
+ DB_set_gametype_by_gameid($gameid,"solo");
+ DB_set_startplayer_by_gameid($gameid,$mypos);
+ DB_set_solo_by_gameid($gameid,$_REQUEST["solo"]);
+ };
+ }
+ else if($_REQUEST["wedding"] == "yes")
+ {
+ /* TODO: add silent solo somewhere*/
+ echo "wedding was chosen
\n";
+ DB_set_sickness_by_hash($me,"wedding");
+ }
+ else if($_REQUEST["poverty"] == "yes")
+ {
+ echo "poverty was chosen
\n";
+ DB_set_sickness_by_hash($me,"poverty");
+ }
+ else if($_REQUEST["nines"] == "yes")
+ {
+ echo "nines was chosen
\n";
+ DB_set_sickness_by_hash($me,"nines");
+ }
+ }
+
+ DB_set_hand_status_by_hash($me,'poverty');
+
+ /* check all players and set game to final result, e.g. solo, wedding, povert, redeal */
+
+ break;
+ case 'poverty':
+ /* here we need to check if there is a solo or some other form of sickness.
+ * If so, which one counts
+ * set that one in the Game table, delete other ones form Hand table
+ * tell people about it.
+ */
+ echo "
checking if someone else selected solo or nines... wedding and poverty not handled at the moment
".
+ " Please click here to finish the setup.
";
- fwrite($output, "$hashC:$PlayerC:$EmailC:::" );
- for(;$i<35;$i++)
- fwrite($output,"$randomNR[$i];" );
- fwrite($output,"$randomNR[35]:" ); $i++;
- fwrite($output,"\n");
+ /* only set this after all poverty, etc. are handeled*/
+ DB_set_hand_status_by_hash($me,'play');
+
+ /* check if the game can start */
+ $userids = DB_get_all_userid_by_gameid($gameid);
+ $ok=1;
+ foreach($userids as $user)
+ if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='play')
+ $ok=0;
+
+ if($ok)
+ {
+ DB_set_game_status_by_gameid($gameid,'play');
+
+ /* check what kind of game we are playing */
+ $gametype = DB_get_gametype_by_gameid($gameid);
+ $startplayer = DB_get_startplayer_by_gameid($gameid);
+
+ /* nines? */
+ $nines = 0;
+ /* check for nines */
+ foreach($userids as $user)
+ {
+ if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'nines')
+ $nines = 1;
+ }
+
+ /* gamestatus == normal, => cancel game */
+ if($nines && $gamestatus == "normal")
+ {
+ /* TODO: set game type to nines to be able to keep statistics */
+
+ $message = "Hello, \n\n".
+ "the game has been cancled becausee someone has five or more nines.\n";
+
+ $userids = DB_get_all_userid_by_gameid($gameid);
+ foreach($userids as $user)
+ {
+ $To = DB_get_email_by_userid($user);
+ mymail($To,"[DoKo] game cancled",$message);
+ }
+
+ /* delete everything from the dB */
+ DB_cancel_game($me);
+
+ }
+
+ /* poverty? */
+ $poverty = 0;
+
+ /* check players for poverty */
+ foreach($userids as $user)
+ {
+ if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'poverty')
+ {
+ $poverty++;
+ $name = DB_get_name_by_userid($user);
+ echo "$name has a Vorbehalt.
";
+ }
+ }
+ /* if gamestatus == normal, set poverty or dpovert (in case two people have poverty) */
+
+ /* wedding? */
+ $wedding = 0;
+ /* check players for wedding */
+ foreach($userids as $user)
+ {
+ if(DB_get_sickness_by_userid_and_gameid($user,$gameid) == 'wedding')
+ {
+ $wedding++;
+ $name = DB_get_name_by_userid($user);
+ echo "$name has a Vorbehalt.
" ;
+ }
+ }
+
+ /* if gamestatus == normal, set wedding */
+
+ }
- fwrite($output, "$hashD:$PlayerD:$EmailD:::");
- for(;$i<47;$i++)
- fwrite($output,"$randomNR[$i];" );
- fwrite($output,"$randomNR[47]:" );
- fwrite($output,"\n");
+ break;
+ case 'play':
+ case 'gameover':
+ /* both entries here, so that the tricks are visible for both.
+ * in case of 'play' there is a break later that skips the last part
+ */
+
+ /* figure out what kind of game we are playing,
+ * set the global variables $TRUMP,$DIAMONDS,$HEARTS,$CLUBS,$SPADES
+ * accordingly
+ */
- fclose($output);
- }
- else
- echo "can't open file for writing";
- };
+ $gametype = DB_get_gametype_by_gameid($gameid);
+ $GT = $gametype;
+ if($gametype=="solo")
+ {
+ $gametype = DB_get_solo_by_gameid($gameid);
+ $GT = $gametype." ".$GT;
+ }
+ else
+ $gametype="normal";
+
+ set_gametype($gametype);
-/* test if a game is running, else output everything for a new game */
-if(sizeof($lines)<2)
+ /* get some infos about the game */
+ $gamestatus = DB_get_game_status_by_gameid($gameid);
+
+ /* display useful things in divs */
+
+ /* display local time */
+ echo "";
+ $users = array();
+ $users = DB_get_all_userid_by_gameid($gameid);
+ foreach($users as $user)
+ {
+ $offset = DB_get_user_timezone($user);
+ $zone = return_timezone($offset);
+ date_default_timezone_set($zone);
+ $name = DB_get_name_by_userid($user);
+
+ echo "
\n \n";
+ };
+ echo "$name ".date("Y-m-d H:i:s")."
";
+ break; /* not sure this works... the idea is that you can
+ * only play a card after everyone is ready to play */
+ }
+
+ /* display the table and the names */
+ $result = mysql_query("SELECT User.fullname as name,".
+ " Hand.position as position ".
+ "FROM Hand ".
+ "LEFT JOIN User ON User.id=Hand.user_id ".
+ "WHERE Hand.game_id='".$gameid."' ".
+ "ORDER BY position ASC");
+
+ echo "\n";
+ echo "
\n";
+
+ /* whos turn is it? */
+ if($seq==4)
+ {
+ $winner = get_winner($play,$gametype); /* returns the position */
+ $next = $winner;
+ $firstcard = ""; /* new trick, no first card */
+ }
+ else
+ {
+ $next = $pos+1;
+ if($next==5) $next=1;
+ }
+
+ /* my turn?, display cards as links, ask for comments*/
+ if(DB_get_pos_by_hash($me) == $next)
+ $myturn = 1;
+ else
+ $myturn = 0;
+
+ /* do we want to play a card? */
+ if(myisset("card") && $myturn)
+ {
+ $card = $_REQUEST["card"];
+ $handid = DB_get_handid_by_hash($me);
+
+ /* 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 ".
+ "hand_id='$handid' AND card_id=".DB_quote_smart($card));
+ $r = mysql_fetch_array($result,MYSQL_NUM);
+ $handcardid = $r[0];
+
+ if($handcardid)
+ {
+ /* mark card as played */
+ mysql_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);
+ $trickid = $a[0];
+ $sequence = $a[1];
+
+ $playid = DB_play_card($trickid,$handcardid,$sequence);
+
+ /* check for coment */
+ if(myisset("comment"))
+ {
+ DB_insert_comment($_REQUEST["comment"],$playid,$myid);
+ };
+
+ /* display played card */
+ echo "
";
+ display_card($card);
+ echo "
";
+
+ /* who is the next player? */
+ $next = $winner;
+ }
+ else
+ {
+ $next = DB_get_pos_by_hash($me)+1;
+ }
+ if($next==5) $next=1;
+
+ /* email next player */
+ $next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
+ $email = DB_get_email_by_hash($next_hash);
+
+ $message = "It's your turn now.\n".
+ "Use this link to play a card: ".$host."?me=".$next_hash."\n\n" ;
+ mymail($email,"[DoKo-debug] a card has been played",$message);
+
+ if($debug)
+ echo "DEBUG: next player
\n";
+
+ }
+ }
+ else
+ {
+ echo "can't find that card?!
\n";
+ }
+ }
+ else if(myisset("card") && !$myturn )
+ {
+ echo "please wait until it's your turn!
\n";
+ }
+
+ $mycards = DB_get_hand($me);
+ $mycards = mysort($mycards,$gametype);
+ echo "
\n";
+ echo "Your cards are:
\n";
+ echo "\n";
+ }
+ else if($mystatus=='play')
+ {
+ echo "Your cards are:
\n";
+ foreach($mycards as $card)
+ display_card($card);
+ }
+ echo "
\n";
+
+ $result = mysql_query("SELECT fullname, SUM(score) FROM Score".
+ " LEFT JOIN Hand ON Hand.id=hand_id".
+ " LEFT JOIN User ON Hand.user_id=User.id".
+ " WHERE Hand.game_id=$gameid".
+ " GROUP BY fullname" );
+ while( $r = mysql_fetch_array($result,MYSQL_NUM))
+ echo " FINAL SCORE: ".$r[0]." ".$r[1]."
";
+
+ /* suggest a new game with the same people in it, just rotated once */
+ $names = DB_get_all_names_by_gameid($gameid);
+ output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);
+ }
+ break;
+ default:
+ echo "error in testing the status";
+ }
+ exit();
+ }
+/* user status page */
+ else if(myisset("email","password"))
{
-?>
-
";
- }
- else
- { /* show the hand */
- if($_REQUEST["in"]=="no")
- {
- for($i=0;$i<4;$i++)
- {
- $message = "Hello ".$player[$hash[$i]]["name"].",\n\n".
- "the game has been canceled due to the request of one of the players.\n";
- mymail($player[$hash[$i]]["email"],"[DoKo-Debug] the game has been canceled",$message);
- }
- $output = fopen("status.txt","w");
- if($output)
- fclose($output);
- else
- echo "problem opening file";
- }
- else
- {
- if($_REQUEST["update"]=="card") $player[$b]["option"].="c";
- if($_REQUEST["update"]=="turn") $player[$b]["option"].="t";
-
- $player[$b]["option"].="i";
-
- save_status();
-
- $allcards = $player[$b]["cards"];
- $mycards = explode(";",$allcards);
-
- sort($mycards);
- echo "your cards are
";
- foreach($mycards as $card)
- {
- display_card($card);
- }
- echo "
\n";
- ?>
-
";
- }
- else if( ereg("s",$player[$c]["option"]) && $game["init"]<4 )
- {
- echo "just wait for the game to start";
- }
- else if($game["init"]<4)
- {
- if( $_REQUEST["solo"]!="No")
- {
- switch($_REQUEST["solo"])
- {
- case "No trump":
- $player[$c]["option"].="O";
- break;
- case "Normal solo":
- $player[$c]["option"].="S";
- break;
- case "Queen solo":
- $player[$c]["option"].="Q";
- break;
- case "Jack solo":
- $player[$c]["option"].="J";
- break;
- case "Club solo":
- $player[$c]["option"].="C";
- break;
- case "Spade solo":
- $player[$c]["option"].="A";
- break;
- case "Hear solo":
- $player[$c]["option"].="H";
- break;
- }
- }
- else if($_REQUEST["wedding"] == "yes")
- {
- echo "wedding was chosen
";
- $player[$c]["option"].="W";
- }
- else if($_REQUEST["poverty"] == "yes")
- {
- echo "poverty was chosen
";
- $player[$c]["option"].="P";
- }
- else if($_REQUEST["nines"] == "yes")
- {
- echo "nines was chosen
";
- $player[$c]["option"].="N";
- }
-
- $message = "you're in. once everyone has filled out the form,".
- "the game will start and you'll get an eamil on your turn\n";
- mymail($player[$c]["email"],"[DoKo-debug] the game will start soon",$message);
-
- $player[$c]["option"].="s";
- save_status();
- if(file_exists("status.txt"))
- $lines = file("status.txt");
- else
- die("no file");
- parse_status();
-
- if($game["init"]==4)
- {
- $message = "The game can start now, it's your turn, please use this link to play a card:\n".
- $host."?me=".$hash[$game["startplayer"]]."\n";
- mymail($player[$hash[$game["startplayer"]]]["email"],"[DoKo-debug] let's go",$message);
- }
-
- }
- }
- if($game["init"]==4)
- {
- /* check for sickness*/
- /***** someone has 5 nines and no one is playing solo=> cance5Al game */
- if($game["nines"]>=0 && $game["solo-who"]<0)
- {
- $message = $player[$hash[$game["poverty"]]]["nines"]." has more than 4 nines. Game aborted!\n";
- for($i=0;$i<4;$i++)
- {
- mymail($player[$hash[$i]]["email"],"[DoKo-debug] the game has been canceled",$message);
- }
- $output = fopen("status.txt","w");
- if($output)
- fclose($output);
- else
- echo "problem opening file";
- }
+ echo "last login: ".date("r",$unixtime)."
";
- /* who is requesting this*/
- if(!isset($_REQUEST["me"]))
- {
- if(!isset($_REQUEST["recovery"]))
- {
- echo "a game is in progress, but you are not playing.
";
- echo "In case you are playing, but lost your email or can't access the game anymore, please input your email here:
";
-?>
-
-these are the games you are playing in:
\n";
+ $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date from Hand".
+ " LEFT JOIN Game On Hand.game_id=Game.id".
+ " WHERE Hand.user_id='$uid' AND Game.status<>'gameover'" );
+ while( $r = mysql_fetch_array($result,MYSQL_NUM))
{
- $recovery=$_REQUEST["recovery"];
- $ok=-1;
- for($i=0;$i<4;$i++)
- if(trim($recovery)==trim($player[$hash[$i]]["email"]))
- $ok=$i;
- if($ok>=0)
- {
- $message = "Please try this link: ".$host."?me=".$hash[$ok]."\n".
- "\n if this doesn't work, contact the admin.\n";
- mymail($recovery,"[DoKo-Debug] recovery ",$message);
- echo "email has been sent.";
- }
- else
- {
- echo "can't find this email address, sorry.";
- };
- }
- }
- else
- {
- $me = $_REQUEST["me"];
-
- echo "game in progress and you are in it
";
- if($game["solo-who"]>=0)
- echo $player[$hash[$game["solo-who"]]]["name"]." is playing a ".$game["solo-what"]." solo!
";
- else if($game["wedding"]>=0)
- echo $player[$hash[$game["wedding"]]]["name"]." is playing a wedding!
";
-
- foreach($history as $play)
- {
- echo "
";
-
- $trick = explode(":",$play);
-
- $last=-2;
- /* found old trick, display it */
- for($i=0;$i
";
- }
- }
- }
- else
- echo "seems like you don't have that card
";
-
- }
-
- }
- else if(isset($_REQUEST["win"]) && strlen($history[sizeof($history)-1])>3)
- {
- $win=$_REQUEST["win"];
- $history[]=$win.":\n";
- /* count points of the last trick */
- $points=0;
-
- $tmp = explode(":",$history[sizeof($history)-2]);
- for($i=0;$i<4;$i++)
- {
- $tmp2 = explode("->",$tmp[$i]);
- $c = $tmp2[1];
- $points += card_value($c);
- }
- $player[$hash[$win]]["points"]+=$points;
- echo "
".$player[$hash[$win]]["name"]." won: $points Points
";
-
- save_status();
- }
- echo "
";
-
- $tmp = explode(":",$history[sizeof($history)-1]);
-
- if(sizeof($tmp)==5)
- {
- ?>
-
and these are your games that are already done:
\n";
+ $result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status='gameover'" );
+ while( $r = mysql_fetch_array($result,MYSQL_NUM))
+ echo "game #".$r[1]."
";
+ echo "
registered players:
\n";
+ foreach ($names as $name)
+ echo "$name
\n";
+ echo "
Want to start a new game? remember 4 names from the list above and visit ". + "this page.
"; + } + else + { + echo "sorry email and password don't match