X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=index.php;h=bae38d4c778adcc6bc72563167053b79cb9a5042;hp=6ab8f2e2fe65e2df05228022039f8a42751c2f5a;hb=6adb80a6c530cc68eabafc64db8cbbb34b3614d6;hpb=2ca8cc3e3c95c7be49ba76054180af2750ce1ba5 diff --git a/index.php b/index.php index 6ab8f2e..bae38d4 100644 --- a/index.php +++ b/index.php @@ -1,519 +1,169 @@ - - -
-Game $gameid has been cancled.
You need to wait longer before you can cancle a game...
\n"; + } +/* handle request from one specific player for one game, + * (the hash is set on a per game base) */ +else if(myisset("me")) { -?> -no game in progress, please input 4 names and email addresses, please make sure that the addresses are correct!
- - - \n"; - } - } -/* *** - * * * - * *** - * * * - * *** - * yes? email him his hand, ask for solo, poverty, email every move or every card? - */ - if(isset($_REQUEST["b"])) - { - $b = $_REQUEST["b"]; - - if( ereg("s",$player[$b]["option"]) && $game["init"]<4) - { /* the player already filled out everything */ - echo "just wait for the game to start"; - } - else if( (!isset($_REQUEST["in"])|| !isset($_REQUEST["update"])) && !ereg("i",$player[$b]["option"])) - { /* the player didn't fill out the form at "a" correctly */ - echo "go back to "; - echo " here and fill out the formyour cards are:
\n";
- foreach($mycards as $card)
- display_card($card);
- echo "
aehm... at the moment poverty is not implented. so I guess you need to play a normal game, even if you have less than 3 trump :(...sorry
- - \n"; - } - } - } + output_check_want_to_play($me); + break; + } + else + { + /* move on to the next stage*/ + DB_set_hand_status_by_hash($me,'init'); + } + case 'init': + /* first check if everything went ok in the last step + * if not, send user back, if yes, check what he did + */ + if( !myisset("in") ) + { + echo "You need to answer the question.
"; + DB_set_hand_status_by_hash($me,'start'); + } + else + { + if($_REQUEST["in"] == "no") + { + /* cancel the game */ + $message = "Hello, \n\n". + "the game has been canceled due to the request of one of the players.\n"; + + $userids = DB_get_all_userid_by_gameid($gameid); + foreach($userids as $user) + { + $To = DB_get_email_by_userid($user); + mymail($To,$EmailName."game $gameid canceled",$message); + } + + /* delete everything from the dB */ + DB_cancel_game($me); + } + else + { + echo "Thanks for joining the game..."; + + $mycards = DB_get_hand($me); + sort($mycards); + echo "your cards are:
\n";
+ foreach($mycards as $card)
+ display_card($card,$PREF["cardset"]);
+ echo "
You need to answer the questions.
"; + DB_set_hand_status_by_hash($me,'init'); + } + else + { + echo "Processing what you selected in the last step...just wait for the game to start
\n"; - } - else if(!isset($_REQUEST["solo"]) || - !isset($_REQUEST["wedding"]) || - !isset($_REQUEST["poverty"]) || - !isset($_REQUEST["nines"]) ) - {/* player still needs to fill out the form */ - echo "go back to "; - echo " here and fill out the formThe game can start now, it's your turn, please use this link to play a card.
\n"; - } - else 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); - echo "The game has started. An email has been sent out to the first player.
\n"; - } - else - { - echo "You're in. Once everyone has filled out the form, ". - "the game will start and you'll get an eamil on your turn.
\n"; - } - } - } - /* END SETUP */ + if($gametype == "solo") + { + /* do nothing */ + } + else if($nines) + { + /* cancel game */ + /* TODO: should we keep statistics of this? */ + $message = "Hello, \n\n". + " the game has been canceled because ".DB_get_name_by_userid($nines). + " has five or more nines and nobody is playing solo.\n\n". + " To redeal either start a new game or, in case the game was part of a tournament, \n". + " go to the last game and use the link at the bottom of the page to redeal."; + + $userids = DB_get_all_userid_by_gameid($gameid); + foreach($userids as $user) + { + $To = DB_get_email_by_userid($user); + mymail($To,$EmailName."game $gameid canceled",$message); + } + + /* delete everything from the dB */ + DB_cancel_game($me); + + echo "The game has been canceled because ".DB_get_name_by_userid($nines). + " has five or more nines and nobody is playing solo.\n"; + output_footer(); + DB_close(); + exit(); + } + else if($poverty==1) /* one person has poverty */ + { + DB_set_gametype_by_gameid($gameid,"poverty"); + $gametype = "poverty"; + $who = DB_get_sickness_by_gameid($gameid); + if(!$who) + { + $firstsick = DB_get_sickness_by_pos_and_gameid(1,$gameid); + if($firstsick == "poverty") + DB_set_sickness_by_gameid($gameid,2); /* who needs to be asked first */ + else + DB_set_sickness_by_gameid($gameid,1); /* who needs to be asked first */ + } + } + else if($poverty==2) /* two people have poverty */ + { + DB_set_gametype_by_gameid($gameid,"dpoverty"); + $gametype = "dpoverty"; + $who = DB_get_sickness_by_gameid($gameid); + if(!$who) + { + $firstsick = DB_get_sickness_by_pos_and_gameid(1,$gameid); + if($firstsick == "poverty") + { + $seconsick = DB_get_sickness_by_pos_and_gameid(1,$gameid); + if($secondsick == "poverty") + DB_set_sickness_by_gameid($gameid,30); /* who needs to be asked first */ + else + DB_set_sickness_by_gameid($gameid,20); /* who needs to be asked first */ + } + else + DB_set_sickness_by_gameid($gameid,10); /* who needs to be asked first */ + } + } + else if($wedding> 0) + { + DB_set_gametype_by_gameid($gameid,"wedding"); + DB_set_sickness_by_gameid($gameid,'-1'); /* wedding not resolved yet */ + $gametype = "wedding"; + }; + + echo "your cards are:
\n";
+ foreach($mycards as $card)
+ display_card($card,$PREF["cardset"]);
+ echo "
Game $gameid has been cancled.
".$r[0]." | (".$r[2].") | ".$r[1]." |
".$r[0]." | ".$r[1]." |
An email with the game information has been sent.
\n"; - } - else - { - echo "can't find this email address, sorry.
\n"; - }; - } /* end recovery */ - } - else - { /* $me is set */ - $me = $_REQUEST["me"]; - - /* show history */ - /* old tricks as list */ - echo "These are your games that haven't started yet:
\n";
+ $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date,Game.player from Hand".
+ " LEFT JOIN Game On Hand.game_id=Game.id".
+ " WHERE Hand.user_id='$uid' AND Game.status='pre'" );
+ while( $r = mysql_fetch_array($result,MYSQL_NUM))
+ {
+ echo "game #".$r[1]." ";
+ if($r[3]==$uid || $r[3]==NULL)
+ echo "(it's your turn)\n";
+ else
+ {
+ $name = DB_get_name_by_userid($r[3]);
+ echo "(it's $name's turn)\n";
+ };
+
+ if(time()-strtotime($r[2]) > 60*60*24*30)
+ echo " The game has been running for over a month.".
+ " Do you want to cancel it? yes".
+ " (clicking here is final and can't be restored)";
+ echo "
";
+ }
+ echo "
These are the games you are playing in:
\n";
+ $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date,Game.player from Hand".
+ " LEFT JOIN Game On Hand.game_id=Game.id".
+ " WHERE Hand.user_id='$uid' AND Game.status='play'" );
+ while( $r = mysql_fetch_array($result,MYSQL_NUM))
+ {
+ echo "game #".$r[1]." ";
+ if($r[3])
+ {
+ if($r[3]==$uid)
+ echo "(it's your turn)\n";
+ else
+ {
+ $name = DB_get_name_by_userid($r[3]);
+ echo "(it's $name's turn)\n";
+ };
+ }
+ if(time()-strtotime($r[2]) > 60*60*24*30)
+ echo " The game has been running for over a month.".
+ " Do you want to cancel it? yes".
+ " (clicking here is final and can't be restored)";
+ echo "
";
+ }
+ echo "
And these are your games that are already done:
Game: \n";
+ $output = array();
+ $result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status='gameover'" );
+ while( $r = mysql_fetch_array($result,MYSQL_NUM))
+ $output[] = "#".$r[1]." ";
+ echo implode(", ",$output)."
Registered players:
\n";
+ echo implode(", ",$names)."\n";
+ echo "
Want to start a new game? Visit this page.
"; + } + } + else + { + echo "Sorry email and password don't match. Please try again.