".$card.":\n";
- }
- else
- {
- $tmp = explode(":",$history[sizeof($history)-1]);
- $tmp[sizeof($tmp)-1] = "".$player[$me]["number"]."->".$card.":";
- $history[sizeof($history)-1]=join(":",$tmp);
- }
- save_status();
+ /* 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"))
+ {
+ $comment.=$_REQUEST["comment"];
+ };
+ if($comment != "")
+ DB_insert_comment($comment,$playid,$myid);
- echo " you played ";
- display_card($card);
- /* send out email to players who want/need to get informed */
- for($i=0;$i<4;$i++)
- {
- $mynext=$next+1; if($mynext>3)$mynext-=4;
- if((ereg("c",$player[$hash[$i]]["option"]) || $i==$mynext) && $hash[$i]!=$me)
- {
- $message = " Hello ".$player[$hash[$i]]["name"].",\n\n";
-
- if($i==$mynext)
- $message .= "it's your turn now.\n";
- $message .= $player[$me]["name"]. "has played the following card ".card_to_name($card)."\n";
-
- if($game["solo-who"]<=0)
- $message.= $player[$hash[$game["solo-who"]]]." is playing a ".$game["solo-what"]." solo!\n";
+ /* display played card */
+ echo "";
+ echo " you played
";
+ display_card($card);
+ echo "
\n";
+
+ /*check if we still have cards left, else set status to gameover */
+ if(sizeof(DB_get_hand($me))==0)
+ {
+ DB_set_hand_status_by_hash($me,'gameover');
+ $mystatus='gameover';
+ }
+
+ /* if all players are done, set game status to game over,
+ * get the points of the last trick and send out an email
+ * to all players
+ */
+ $userids = DB_get_all_userid_by_gameid($gameid);
+
+ $done=1;
+ foreach($userids as $user)
+ if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='gameover')
+ $done=0;
+
+ if($done)
+ {
+ DB_set_game_status_by_gameid($gameid,"gameover");
+ /* get score for last trick
+ * all other tricks are handled a few lines further down*/
+ $play = DB_get_cards_by_trick($trickid);
+ $winner = get_winner($play,$gametype); /* returns the position */
+ /* get points of last trick and save it */
+ $points = 0;
+ foreach($play as $card)
+ $points = $points + card_value($card["card"]);
+ $winnerid = DB_get_handid_by_gameid_and_position($gameid,$winner);
+ if($winnerid>0)
+ mysql_query("INSERT INTO Score VALUES (NULL, '$gameid', '$winnerid', '$points')");
+ else
+ echo "ERROR during scoring";
+
+ /* email all players */
+ /* individual score */
+ $result = mysql_query("SELECT fullname, SUM(score), Hand.party 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" );
+ $message = "The game is over. Thanks for playing :)\n";
+ while( $r = mysql_fetch_array($result,MYSQL_NUM))
+ $message .= " FINAL SCORE: ".$r[0]."(".$r[2].") ".$r[1]."\n";
+ $message .= "\nIf your not in the list above your score is zero...\n\n";
- mymail($player[$hash[$i]]["email"],"[DoKo] a card has been played",$message);
- echo " next player
";
- }
- }
- }
- 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;
+ $result = mysql_query("SELECT Hand.party, 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 Hand.party" );
+ $message .= "\n";
+ while( $r = mysql_fetch_array($result,MYSQL_NUM))
+ $message .= " FINAL SCORE: ".$r[0]." ".$r[1]."\n";
- $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
";
+ foreach($userids as $user)
+ {
+ $To = DB_get_email_by_userid($user);
+ mymail($To,$EmailName."game over",$message);
+ }
+ }
+
+
+ /* email next player */
+ if(DB_get_game_status_by_gameid($gameid)=='play')
+ {
+ if($sequence==4)
+ {
+ $play = DB_get_cards_by_trick($trickid);
+ $winner = get_winner($play,$gametype); /* returns the position */
+
+ /* get points of last trick and save it, last trick is handled
+ * a few lines further up */
+ $points = 0;
+ foreach($play as $card)
+ $points = $points + card_value($card["card"]);
+
+ $winnerid = DB_get_handid_by_gameid_and_position($gameid,$winner);
+ if($winnerid>0)
+ mysql_query("INSERT INTO Score VALUES (NULL, '$gameid', '$winnerid', '$points')");
+ else
+ echo "ERROR during scoring";
+
+ if($debug)
+ echo "DEBUG: $winner got $points
";
+
+ /* 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,$EmailName."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";
+
+ if($myturn && !myisset("card"))
+ {
+ echo "Hello ".$myname.", it's your turn!
\n";
+ echo "Your cards are:
\n";
+ echo "\n";
+ }
+ else if($mystatus=='play')
+ {
+ echo "Your cards are:
\n";
+ foreach($mycards as $card)
+ display_card($card);
+ }
+ else if($mystatus=='gameover')
+ {
+ $oldcards = DB_get_all_hand($me);
+ $oldcards = mysort($oldcards,$gametype);
+ echo "Your cards were:
\n";
+ foreach($oldcards as $card)
+ display_card($card);
+ }
+ echo "
\n";
+
+ /* check if we need to set status to 'gameover' is done during playing of the card */
+ if($mystatus=='play')
+ break;
+ /* the following happens only when the gamestatus is 'gameover' */
+ /* check if game is over, display results */
+ if(DB_get_game_status_by_gameid($gameid)=='play')
+ {
+ echo "the game is over for you.. other people still need to play though";
+ }
+ else
+ {
+ echo "the game is over now...
\n";
+
+ $result = mysql_query("SELECT fullname, SUM(score), Hand.party 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[2].") ".$r[1]."
";
+
+ $result = mysql_query("SELECT Hand.party, 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 Hand.party" );
+ while( $r = mysql_fetch_array($result,MYSQL_NUM))
+ echo " FINAL SCORE: ".$r[0]." ".$r[1]."
\n";
- save_status();
- }
+
+ $session = DB_get_session_by_gameid($gameid);
+ $result = mysql_query("SELECT id,create_date FROM Game".
+ " WHERE session=$session".
+ " ORDER BY create_date DESC".
+ " LIMIT 1");
+ $r=-1;
+ if($result)
+ $r = mysql_fetch_array($result,MYSQL_NUM);
+
+ if(!$session || $gameid==$r[0])
+ {
+ /* 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";
+ }
+ output_footer();
+ exit();
+ }
+/* user status page */
+ else if(myisset("email","password"))
+ {
+ /* test id and password, should really be done in one step */
+ $email = $_REQUEST["email"];
+ $password = $_REQUEST["password"];
+
+ if(strlen($password)!=32)
+ $password = md5($password);
+
+ $ok=1;
+ $uid = DB_get_userid_by_email_and_password($email,$password);
+ if(!$uid)
+ $ok=0;
+
+ if($ok)
+ {
+ $time = DB_get_user_timestamp($uid);
+ $unixtime =strtotime($time);
+
+ $offset = DB_get_user_timezone($uid);
+ $zone = return_timezone($offset);
+ date_default_timezone_set($zone);
+
+ echo "last login: ".date("r",$unixtime)."
";
+
+ DB_update_user_timestamp($uid);
+
+ echo "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))
+ {
+ echo "game #".$r[1]." ";
+ 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 "
";
-
- $tmp = explode(":",$history[sizeof($history)-1]);
-
- if(sizeof($tmp)==5)
- {
- ?>
-
-the next player
";
-
- if(strlen(trim($player[$me]["cards"]))==0)
- {
- echo "
game over, count points
";
- for($i=0;$i<4;$i++)
- {
- echo $player[$hash[$i]]["name"]." got ".$player[$hash[$i]]["points"]."
";
- }
- }
- }
- if($hash[$next]==$me && strlen(trim($player[$me]["cards"]))>0 )
- {
-
- echo "ITS YOUR TURN
";
- $allcards = trim($player[$me]["cards"]);
- $mycards = explode(";",$allcards);
-
- sort($mycards);
- echo "your cards are
";
- foreach($mycards as $card)
- {
- display_link_card($card,$me);
- }
- echo "
\n";
- }
- echo "
";
-
- }
}
+ echo "\n";
+
+
+ echo "and these are your games that are already done:
Game: \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 "#".$r[1]." , ";
+ echo "
\n";
+
+ $names = DB_get_all_names();
+ echo "registered players:
\n";
+ foreach ($names as $name)
+ echo "$name, \n";
+ echo "
\n";
+
+ echo "Want to start a new game? Visit this page.
";
}
+ else
+ {
+ echo "sorry email and password don't match
";
+ }
+ output_footer();
+ exit();
+ }
+/* page for registration */
+ else if(myisset("register") )
+ {
+ output_register();
+ }
+/* new user wants to register */
+ else if(myisset("Rfullname","Remail","Rpassword","Rtimezone") )
+ {
+ $ok=1;
+ if(DB_get_userid_by_name($_REQUEST["Rfullname"]))
+ {
+ echo "please chose another name
";
+ $ok=0;
+ }
+ if(DB_get_userid_by_email($_REQUEST["Remail"]))
+ {
+ echo "this email address is already used ?!
";
+ $ok=0;
+ }
+ if($ok)
+ {
+ $r=mysql_query("INSERT INTO User VALUES(NULL,".DB_quote_smart($_REQUEST["Rfullname"]).
+ ",".DB_quote_smart($_REQUEST["Remail"]).
+ ",".DB_quote_smart(md5($_REQUEST["Rpassword"])).
+ ",".DB_quote_smart($_REQUEST["Rtimezone"]).",NULL)");
+
+ if($r)
+ echo " added you to the database";
+ else
+ echo " something went wrong";
+ }
+ }
+/* default login page */
+ else
+ {
+ output_home_page();
+ }
- }
+output_footer();
+
+DB_close();
+/*
+ *Local Variables:
+ *mode: php
+ *mode: hs-minor
+ *End:
+ */
?>
-
-
+