2 "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
3 "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
7 <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
8 <link rel="stylesheet" type="text/css" href="standard.css" />
11 <h1> Welcome to E-Doko </h1>
17 $host = "http://doko.nubati.net/index.php";
18 $wiki = "http://wiki.nubati.net/index.php?title=EmailDoko";
27 function mymail($To,$Subject,$message)
33 str_replace("\n","<br />",$message);
34 echo "<br />To: $To<br />Subject: $Subject <br />$message<br />\n";
37 mail($To,$Subject,$message);
41 function parse_status()
43 global $game,$history,$player,$hash,$lines;
46 $game["solo-who"] = -1;
47 $game["solo-what"] = "todo";
48 $game["wedding"] = -1;
49 $game["poverty"] = "";
51 $game["startplayer"] = 0;
55 $tmp = explode( ":",$lines[$i]);
57 $player[$tmp[0]]["number"] = $i;
58 $player[$tmp[0]]["hash"] = $tmp[0];
59 $player[$tmp[0]]["name"] = $tmp[1];
60 $player[$tmp[0]]["email"] = $tmp[2];
61 $player[$tmp[0]]["option"] = $tmp[3];
62 $player[$tmp[0]]["points"] = $tmp[4];
63 $player[$tmp[0]]["cards"] = $tmp[5];
64 if(ereg("s",$tmp[3])) $game["init"]++; /* how many players are ready? */
65 if(ereg("P",$tmp[3])) $game["poverty"].= $i; /* players with poverty, could be two, so use a string */
66 if(ereg("N",$tmp[3])) $game["nines"] = $i; /* the player with too many nines, only one possible */
67 if(ereg("W",$tmp[3])) $game["wedding"] = $i; /* the player with the wedding, also only one possible */
68 if(ereg("([OSQJCAH])",$tmp[3],$match) && ($game["solo-who"]<0) )
70 $game["solo-who"] = $i;
71 $game["startplayer"] = $i;
75 $game["solo-what"] = "No Trump";
77 $game["solo-what"] = "Trump";
79 $game["solo-what"] = "Queen";
81 $game["solo-what"] = "Jack";
83 $game["solo-what"] = "Club";
85 $game["solo-what"] = "Spade";
87 $game["solo-what"] = "Heart";
92 /* save the game history */
93 for($i=4;$i<sizeof($lines);$i++)
95 if(!ereg("^[[:space:]]*$",trim($lines[$i])))
97 $history[] = $lines[$i];
101 if(sizeof($history)==0 || (sizeof($history)==1 && strlen($history[0])==3 ))
102 $history[0] = $game["startplayer"].":";
107 function count_nines($cards)
109 $card = explode(";",$cards);
115 if($c == "25" || $c == "26") $nines++;
116 else if($c == "33" || $c == "34") $nines++;
117 else if($c == "41" || $c == "42") $nines++;
118 else if($c == "47" || $c == "48") $nines++;
124 function check_wedding($cards)
126 $card = explode(";",$cards);
130 if( in_array("3",$card) && in_array("2",$card) )
136 function count_trump($cards)
138 $card = explode(";",$cards);
142 /* count each trump */
145 if( (int)($c) <27) $trump++;
148 /* subtract one, in case player has both foxes */
149 if( in_array("19",$card) && in_array("20",$card) )
157 function card_to_name($card)
163 return "ten of hearts";
166 return "queen of clubs";
169 return "queen of spades";
172 return "queen of hearts";
175 return "queen of diamonds";
178 return "jack of clubs";
181 return "jack of spades";
184 return "jack of hearts";
187 return "jack of diamonds";
190 return "ace of diamonds";
193 return "ten of diamonds";
196 return "king of diamonds";
199 return "nine of diamonds";;
202 return "ace of clubs";
205 return "ten of clubs";
208 return "king of clubs";
211 return "nine of clubs";
214 return "ace of spades";
217 return "ten of spades";
220 return "king of spades";
223 return "nine of spades";
226 return "ace of hearts";
229 return "king of hearts";
232 return "nine of hearts";
234 return "something went wrong, please contact the admin";
238 function card_value($card)
309 echo "something went wrong, please contact the admin <br>";
314 function display_card($card)
316 if( $card/2 - (int)($card/2) == 0.5)
317 echo "<img src=\"cards/".$card.".png\" alt=\"".card_to_name($card)."\" />\n";
319 echo "<img src=\"cards/".($card-1).".png\" alt=\"".card_to_name($card-1)."\" />\n";
323 function display_link_card($card,$me)
325 if( $card/2 - (int)($card/2) == 0.5)
326 echo "<a href=\"index.php?me=$me&card=$card\"><img src=\"cards/".$card.".png\" alt=\"".card_to_name($card)."\" /></a>\n";
328 echo "<a href=\"index.php?me=$me&card=$card\"><img src=\"cards/".($card-1).".png\" alt=\"".card_to_name($card-1)."\" /></a>\n";
332 function save_status()
334 global $player,$game,$hash,$history;
336 $output = fopen("status.txt","w");
339 foreach($hash as $key)
341 /* sorting the options, not sure why I do that actually */
343 if( ereg("i",$player[$key]["option"]) )
345 if( ereg("s",$player[$key]["option"]) )
347 if( ereg("t",$player[$key]["option"]) )
349 if( ereg("c",$player[$key]["option"]) )
351 if( ereg("N",$player[$key]["option"]) )
353 if( ereg("W",$player[$key]["option"]) )
355 if( ereg("P",$player[$key]["option"]) )
357 if( ereg("O",$player[$key]["option"]) )
359 if( ereg("S",$player[$key]["option"]) )
361 if( ereg("Q",$player[$key]["option"]) )
363 if( ereg("J",$player[$key]["option"]) )
365 if( ereg("C",$player[$key]["option"]) )
367 if( ereg("A",$player[$key]["option"]) )
369 if( ereg("H",$player[$key]["option"]) )
371 $player[$key]["option"]=$tmp;
373 /* saving the player stats */
374 fwrite($output,"".$player[$key]["hash"].":" );
375 fwrite($output,"".$player[$key]["name"].":" );
376 fwrite($output,"".$player[$key]["email"].":" );
377 fwrite($output,"".$player[$key]["option"].":" );
378 fwrite($output,"".$player[$key]["points"].":" );
379 fwrite($output,"".$player[$key]["cards"] .":");
380 fwrite($output,"\n");
382 fwrite($output,"\n");
383 foreach($history as $line)
384 fwrite($output,$line);
386 fwrite($output,"\n");
390 echo "can't open file for writing, please inform the admin.";
395 echo "<p>If you find bugs, please list them in the <a href=\"".$wiki."\">wiki</a></p>\n";
397 echo "<p> Cards that have a <span class=\"comment\"> green </span> background have a comment, which you can access by hovering over the card with your mouse ;)</p>\n";
401 /* check for status file and read it, if possible */
403 if(file_exists("status.txt"))
404 $lines = file("status.txt");
408 /* check if we want to start a new game */
409 if( isset($_REQUEST["PlayerA"]) &&
410 isset($_REQUEST["PlayerB"]) &&
411 isset($_REQUEST["PlayerC"]) &&
412 isset($_REQUEST["PlayerD"]) &&
413 isset($_REQUEST["EmailA"]) &&
414 isset($_REQUEST["EmailB"]) &&
415 isset($_REQUEST["EmailC"]) &&
416 isset($_REQUEST["EmailD"]) && sizeof($lines<2))
418 $PlayerA = $_REQUEST["PlayerA"];
419 $PlayerB = $_REQUEST["PlayerB"];
420 $PlayerC = $_REQUEST["PlayerC"];
421 $PlayerD = $_REQUEST["PlayerD"];
422 $EmailA = $_REQUEST["EmailA"] ;
423 $EmailB = $_REQUEST["EmailB"] ;
424 $EmailC = $_REQUEST["EmailC"] ;
425 $EmailD = $_REQUEST["EmailD"] ;
427 $hashA = md5("AGameOfDoko".$PlayerA.$EmailA);
428 $hashB = md5("AGameOfDoko".$PlayerB.$EmailB);
429 $hashC = md5("AGameOfDoko".$PlayerC.$EmailC);
430 $hashD = md5("AGameOfDoko".$PlayerD.$EmailD);
432 /* send out email, check for error with email */
435 "you are invited to play a game of DoKo (that is to debug the program ;).\n".
436 "Place comments and bug reports here:\n".
437 "http://wiki.nubati.net/index.php?title=EmailDoko\n\n".
438 "The whole round would consist of the following players:\n".
443 "If you want to join this game, please follow this link:\n\n".
446 mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
447 mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
448 mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
449 mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
451 /* read in random.txt */
452 if(file_exists("random.txt"))
453 $random = file("random.txt");
455 die("no random file");
457 $randomNR = explode( ":", $random[2] );
459 /* write initial status into file */
460 $output = fopen("status.txt","w");
463 fwrite($output, "$hashA:$PlayerA:$EmailA:::" );
465 fwrite($output,"$randomNR[$i];" );
466 fwrite($output,"$randomNR[11]:" ); $i++;
467 fwrite($output,"\n");
469 fwrite($output, "$hashB:$PlayerB:$EmailB:::" );
471 fwrite($output,"$randomNR[$i];" );
472 fwrite($output,"$randomNR[23]:" ); $i++;
473 fwrite($output,"\n");
475 fwrite($output, "$hashC:$PlayerC:$EmailC:::" );
477 fwrite($output,"$randomNR[$i];" );
478 fwrite($output,"$randomNR[35]:" ); $i++;
479 fwrite($output,"\n");
481 fwrite($output, "$hashD:$PlayerD:$EmailD:::");
483 fwrite($output,"$randomNR[$i];" );
484 fwrite($output,"$randomNR[47]:" );
485 fwrite($output,"\n");
490 echo "can't open file for writing";
493 /* test if a game is running, else output everything for a new game */
497 <p> no game in progress, please input 4 names and email addresses, please make sure that the addresses are correct! </p>
498 <form action="index.php" method="post">
499 Name: <input name="PlayerA" type="text" size="10" maxlength="20" />
500 Email: <input name="EmailA" type="text" size="20" maxlength="30" /> <br />
502 Name: <input name="PlayerB" type="text" size="10" maxlength="20" />
503 Email: <input name="EmailB" type="text" size="20" maxlength="30" /> <br />
505 Name: <input name="PlayerC" type="text" size="10" maxlength="20" />
506 Email: <input name="EmailC" type="text" size="20" maxlength="30" /> <br />
508 Name: <input name="PlayerD" type="text" size="10" maxlength="20" />
509 Email: <input name="EmailD" type="text" size="20" maxlength="30" /> <br />
511 <input type="submit" value="start game" />
516 { /* load game status */
523 * check if a player wants to accept a game
526 if(isset($_REQUEST["a"]))
530 if( ereg("[is]",$player[$a]["option"]) && $game["init"]<4)
532 echo "just wait for the game to start";
534 else if( !ereg("[is]",$player[$a]["option"]) )
538 <form action="index.php" method="post">
539 Do you want to play a game of DoKo?
540 yes<input type="radio" name="in" value="yes" />
541 no<input type="radio" name="in" value="no" /> <br />
543 Do you want to get an email for every card played or only if it your move?
544 every card<input type="radio" name="update" value="card" />
545 only on my turn<input type="radio" name="update" value="turn" /> <br />
547 echo "<input type=\"hidden\" name=\"b\" value=\"$a\" />\n";
549 echo "<input type=\"submit\" value=\"count me in\" />\n";
559 * yes? email him his hand, ask for solo, poverty, email every move or every card?
561 if(isset($_REQUEST["b"]))
565 if( ereg("s",$player[$b]["option"]) && $game["init"]<4)
567 echo "just wait for the game to start";
569 else if( (!isset($_REQUEST["in"])|| !isset($_REQUEST["update"])) && !ereg("i",$player[$b]["option"]))
572 echo "<a href=\"index.php?a=$b\"> here and fill out the form </a> <br />\n";
575 { /* show the hand */
576 if($_REQUEST["in"]=="no")
580 $message = "Hello ".$player[$hash[$i]]["name"].",\n\n".
581 "the game has been canceled due to the request of one of the players.\n";
582 mymail($player[$hash[$i]]["email"],"[DoKo-Debug] the game has been canceled",$message);
584 $output = fopen("status.txt","w");
588 echo "problem opening file";
592 if($_REQUEST["update"]=="card") $player[$b]["option"].="c";
593 if($_REQUEST["update"]=="turn") $player[$b]["option"].="t";
595 $player[$b]["option"].="i";
599 $allcards = $player[$b]["cards"];
600 $mycards = explode(";",$allcards);
603 echo "your cards are <br />\n";
604 foreach($mycards as $card)
610 <p>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 turmp :(...sorry</p>
611 <form action="index.php" method="post">
613 do you want to play solo?
614 <select name="solo" size="1">
616 <option>No trump</option>
617 <option>Normal solo</option>
618 <option>Queen solo</option>
619 <option>Jack solo</option>
620 <option>Club solo</option>
621 <option>Spade solo</option>
622 <option>Heart solo</option>
629 if(check_wedding($player[$b]["cards"]))
631 echo " yes<input type=\"radio\" name=\"wedding\" value=\"yes\" />";
632 echo " no <input type=\"radio\" name=\"wedding\" value=\"no\" /> <br />\n";
636 echo " no <input type=\"hidden\" name=\"wedding\" value=\"no\" /> <br />\n";
639 echo "do you have poverty?";
640 if(count_trump($player[$b]["cards"])<4)
642 echo " yes<input type=\"radio\" name=\"poverty\" value=\"yes\" />";
643 echo " no <input type=\"radio\" name=\"poverty\" value=\"no\" /> <br />\n";
647 echo " no <input type=\"hidden\" name=\"poverty\" value=\"no\" /> <br />\n";
650 echo "do you have too many nines?";
651 if(count_nines($player[$b]["cards"])>4)
653 echo " yes<input type=\"radio\" name=\"nines\" value=\"yes\" />";
654 echo " no <input type=\"radio\" name=\"nines\" value=\"no\" /> <br />\n";
658 echo " no <input type=\"hidden\" name=\"nines\" value=\"no\" /> <br />\n";
661 echo "<input type=\"hidden\" name=\"c\" value=\"$b\" />\n";
662 echo "<input type=\"submit\" value=\"count me in\" />\n";
668 if(isset($_REQUEST["c"]))
672 if(!isset($_REQUEST["solo"])|| !isset($_REQUEST["wedding"])|| !isset($_REQUEST["poverty"]) || !isset($_REQUEST["nines"]) )
675 echo "<a href=\"index.php?b=$c\"> here and fill out the form </a> <br />\n";
677 else if( ereg("s",$player[$c]["option"]) && $game["init"]<4 )
679 echo "just wait for the game to start";
681 else if($game["init"]<4)
683 if( $_REQUEST["solo"]!="No")
685 switch($_REQUEST["solo"])
688 $player[$c]["option"].="O";
691 $player[$c]["option"].="S";
694 $player[$c]["option"].="Q";
697 $player[$c]["option"].="J";
700 $player[$c]["option"].="C";
703 $player[$c]["option"].="A";
706 $player[$c]["option"].="H";
710 else if($_REQUEST["wedding"] == "yes")
712 echo "wedding was chosen<br />\n";
713 $player[$c]["option"].="W";
715 else if($_REQUEST["poverty"] == "yes")
717 echo "poverty was chosen<br />\n";
718 $player[$c]["option"].="P";
720 else if($_REQUEST["nines"] == "yes")
722 echo "nines was chosen<br />\n";
723 $player[$c]["option"].="N";
726 $message = "You're in. Once everyone has filled out the form, ".
727 "the game will start and you'll get an eamil on your turn.\n";
728 mymail($player[$c]["email"],"[DoKo-debug] the game will start soon",$message);
730 $player[$c]["option"].="s";
732 if(file_exists("status.txt"))
733 $lines = file("status.txt");
740 $message = "The game can start now, it's your turn, please use this link to play a card:\n".
741 $host."?me=".$hash[$game["startplayer"]]."\n";
742 mymail($player[$hash[$game["startplayer"]]]["email"],"[DoKo-debug] let's go",$message);
749 /* check for sickness*/
750 /***** someone has 5 nines and no one is playing solo=> cancel game */
751 if($game["nines"]>=0 && $game["solo-who"]<0)
753 $message = $player[$hash[$game["poverty"]]]["nines"]." has more than 4 nines. Game aborted!\n";
756 mymail($player[$hash[$i]]["email"],"[DoKo-debug] the game has been canceled",$message);
759 $output = fopen("status.txt","w");
763 echo "problem opening file";
766 /* who is requesting this*/
767 if(!isset($_REQUEST["me"]))
769 if(!isset($_REQUEST["recovery"]))
771 echo "A game is in progress and kibitzing is not allowed. Sorry!.<br />\n";
772 echo "In case you are playing, but lost your email or can't access the game anymore, please input your email here:<br />\n";
774 <form action="index.php" method="post">
775 recorvery: <input name="recovery" type="text" size="20" maxlength="30" /> <br />
776 <input type="submit" value="get me back into the game" />
782 $recovery=$_REQUEST["recovery"];
785 if(trim($recovery)==trim($player[$hash[$i]]["email"]))
789 $message = "Please try this link: ".$host."?me=".$hash[$ok]."\n".
790 "\n if this doesn't work, contact the admin.\n";
791 mymail($recovery,"[DoKo-Debug] recovery ",$message);
792 echo "email has been sent.";
796 echo "can't find this email address, sorry.";
802 $me = $_REQUEST["me"];
804 /* output if we are playing a solo or a wedding */
805 if($game["solo-who"]>=0)
806 echo $player[$hash[$game["solo-who"]]]["name"]." is playing a ".$game["solo-what"]." solo!<br />\n";
807 else if($game["wedding"]>=0)
808 echo $player[$hash[$game["wedding"]]]["name"]." is playing a wedding!<br />\n";
811 foreach($history as $play)
813 $trick = explode(":",$play);
816 /* found old trick, display it */
817 if(sizeof($trick)==5)
818 echo "<div class=\"oldtrick background".$play[0]."\"><div class=\"table\">\n";
820 echo "<div class=\"trick back".$play[0]."\"><div class=\"table\">\n";
821 for($i=0;$i<sizeof($trick)-1;$i++)
826 $tmp = explode("->",$card);
828 if(strlen($tmp[2])>0)
829 echo "<div class=\"card".$tmp[0]." comment\">";
831 echo "<div class=\"card".$tmp[0]."\">";
832 echo $player[$hash[$tmp[0]]]["name"]." <br />";
833 display_card($tmp[1]);
834 /* check for comment */
835 if(strlen($tmp[2])>0)
836 echo "<div class=\"comment\">".$tmp[2]."</div>\n";
841 echo "</div></div>\n";
844 /* figure out who needs to play next */
850 $next=$history[sizeof($history)-1][0];
853 /* are we trying to play a card? */
854 if(isset($_REQUEST["card"]))
856 if($hash[$next]==$me)
858 $card = $_REQUEST["card"];
859 $mycards = explode(";",$player[$me]["cards"]);
861 /* do we have that card */
862 if(in_array($card,$mycards))
864 /* delete card from array */
866 foreach($mycards as $m)
871 for($i=0;$i<sizeof($tmp)-1;$i++)
876 $player[$me]["cards"]=$tmp2;
878 /* add card to history, special case if this is the first card */
881 $history[sizeof($history)-1]="".$player[$me]["number"]."->".$card.":\n";
885 $tmp = explode(":",$history[sizeof($history)-1]);
886 $tmp[sizeof($tmp)-1] = "".$player[$me]["number"]."->".$card.":";
887 $history[sizeof($history)-1]=join(":",$tmp);
891 echo "<div class=\"card\">";
892 echo " you played <br />";
898 <form action="index.php" method="post">
899 A short comment:<input name="comment" type="text" size="30" maxlength="50" />
900 <input type="hidden" name="me" value="<?php echo $me; ?>" />
901 <input type="submit" value="submit comment" />
904 /* send out email to players who want/need to get informed */
907 $mynext=$next+1; if($mynext>3)$mynext-=4;
908 if((ereg("c",$player[$hash[$i]]["option"]) || $i==$mynext) && $hash[$i]!=$me)
910 $message = " Hello ".$player[$hash[$i]]["name"].",\n\n";
914 $message .= "it's your turn now.\n".
915 "Use this link to play a card: ".$host."?me=".$hash[$i]."\n\n" ;
917 $message .= $player[$me]["name"]." has played the following card ".card_to_name($card)."\n";
919 if($game["solo-who"]>=0)
920 $message.= $player[$hash[$game["solo-who"]]]["name"]." is playing a ".$game["solo-what"]." solo!\n";
922 mymail($player[$hash[$i]]["email"],"[DoKo-debug] a card has been played",$message);
925 echo "<a href=\"index.php?me=".$hash[$mynext]."\"> next player </a> <br />\n";
930 echo "seems like you don't have that card<br />\n";
934 } /* end if card is set */
935 else if(isset($_REQUEST["comment"]))
937 $comment = $_REQUEST["comment"];
938 $tmp = explode(":",$history[sizeof($history)-1]);
939 $tmp2 = explode("->",$tmp[sizeof($tmp)-2]);
941 $comment = str_replace(":","",$comment);
944 $tmp[sizeof($tmp)-2] .= "->".$comment;
945 $history[sizeof($history)-1]=join(":",$tmp);
949 else if(isset($_REQUEST["win"]) && strlen($history[sizeof($history)-1])>3)
951 $win=$_REQUEST["win"];
952 $history[]=$win.":\n";
953 /* count points of the last trick */
956 $tmp = explode(":",$history[sizeof($history)-2]);
959 $tmp2 = explode("->",$tmp[$i]);
961 $points += card_value($c);
963 $player[$hash[$win]]["points"]+=$points;
964 echo "<br />\n ".$player[$hash[$win]]["name"]." won: $points Points <br />\n";
967 }; /* end if win is set */
970 $tmp = explode(":",$history[sizeof($history)-1]);
972 /* check last history entry: end of a trick? ask who won it */
976 <form action="index.php" method="post">
980 echo $player[$hash[$i]]["name"]." <input type=\"radio\" name=\"win\" value=\"$i\" />";
981 echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />";
983 <input type="submit" value="submit" />
988 else if(sizeof($tmp)<5 && 1<sizeof($tmp) && !isset($_REQUEST["card"]))
990 if(sizeof($tmp)==2 && strlen($tmp[0])==1)
995 echo "DEBUG: the next move is for <a href=\"index.php?me=".$hash[$next]."\">the next player</a><br />\n";
997 if(strlen(trim($player[$me]["cards"]))==0)
999 echo "<br /> game over, count points <br />\n";
1002 echo $player[$hash[$i]]["name"]." got ".$player[$hash[$i]]["points"]."<br />\n";
1007 } /* end check for winner */
1009 echo "<br clear=\"both\" />";
1010 /* do we still have cards? display them */
1011 if(strlen(trim($player[$me]["cards"]))>0 )
1013 $allcards = trim($player[$me]["cards"]);
1014 $mycards = explode(";",$allcards);
1018 echo "<p class=\"mycards\">\n";
1019 /* is it our turn? */
1020 if($hash[$next]==$me && !isset($_REQUEST["card"]) && !isset($_REQUEST["win"]))
1022 echo "ITS YOUR TURN <br />\n";
1023 echo "your cards are: <br />\n";
1024 foreach($mycards as $card)
1026 display_link_card($card,$me);
1030 { /* not our turn, just show the hand */
1031 echo "your cards are: <br />\n";
1032 foreach($mycards as $card)
1034 display_card($card);