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>";
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"] = -1;
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"]++;
65 if(ereg("P",$tmp[3])) $game["poverty"] = $i;
66 if(ereg("N",$tmp[3])) $game["nines"] = $i;
67 if(ereg("W",$tmp[3])) $game["wedding"] = $i;
68 if(ereg("[OSQJCAH]",$tmp[3]) && ($game["solo-who"]<0) )
70 $game["solo-who"] = $i;
71 $game["startplayer"] = $i;
75 /* save the game history */
76 for($i=4;$i<sizeof($lines);$i++)
78 if(!ereg("^[[:space:]]*$",trim($lines[$i])))
80 $history[] = $lines[$i];
84 if(sizeof($history)==0 || (sizeof($history)==1 && strlen($history[0])==3 ))
85 $history[0] = $game["startplayer"].":";
90 function count_nines($cards)
92 $card = explode(";",$cards);
98 if($c == "25" || $c == "26") $nines++;
99 else if($c == "33" || $c == "34") $nines++;
100 else if($c == "41" || $c == "42") $nines++;
101 else if($c == "47" || $c == "48") $nines++;
107 function check_wedding($cards)
109 $card = explode(";",$cards);
113 if( in_array("3",$card) && in_array("2",$card) )
119 function count_trump($cards)
121 $card = explode(";",$cards);
125 /* count each trump */
128 if( (int)($c) <27) $trump++;
131 /* subtract one, in case player has both foxes */
132 if( in_array("19",$card) && in_array("20",$card) )
140 function card_to_name($card)
146 return "ten of hearts";
149 return "queen of clubs";
152 return "queen of spades";
155 return "queen of hearts";
158 return "queen of diamonds";
161 return "jack of clubs";
164 return "jack of spades";
167 return "jack of hearts";
170 return "jack of diamonds";
173 return "ace of diamonds";
176 return "ten of diamonds";
179 return "king of diamonds";
182 return "nine of diamonds";;
185 return "ace of clubs";
188 return "ten of clubs";
191 return "king of clubs";
194 return "nine of clubs";
197 return "ace of spades";
200 return "ten of spades";
203 return "king of spades";
206 return "nine of spades";
209 return "ace of hearts";
212 return "king of hearts";
215 return "nine of hearts";
217 return "something went wrong, please contact the admin";
221 function card_value($card)
292 echo "something went wrong, please contact the admin <br>";
297 function display_card($card)
299 if( $card/2 - (int)($card/2) == 0.5)
300 echo "<img src=\"cards/".$card.".png\" height=\"100\" alt=\"".card_to_name($card)."\" />\n";
302 echo "<img src=\"cards/".($card-1).".png\" height=\"100\" alt=\"".card_to_name($card-1)."\" />\n";
306 function display_link_card($card,$me)
308 if( $card/2 - (int)($card/2) == 0.5)
309 echo "<a href=\"index.php?me=$me&card=$card\"><img src=\"cards/".$card.".png\" height=\"100\" alt=\"".card_to_name($card)."\" /></a>\n";
311 echo "<a href=\"index.php?me=$me&card=$card\"><img src=\"cards/".($card-1).".png\" height=\"100\" alt=\"".card_to_name($card-1)."\" /></a>\n";
315 function save_status()
317 global $player,$game,$hash,$history;
319 $output = fopen("status.txt","w");
322 foreach($hash as $key)
324 /* sorting the options, not sure why I do that actually */
326 if( ereg("i",$player[$key]["option"]) )
328 if( ereg("s",$player[$key]["option"]) )
330 if( ereg("t",$player[$key]["option"]) )
332 if( ereg("c",$player[$key]["option"]) )
334 if( ereg("N",$player[$key]["option"]) )
336 if( ereg("W",$player[$key]["option"]) )
338 if( ereg("P",$player[$key]["option"]) )
340 if( ereg("O",$player[$key]["option"]) )
342 if( ereg("S",$player[$key]["option"]) )
344 if( ereg("Q",$player[$key]["option"]) )
346 if( ereg("J",$player[$key]["option"]) )
348 if( ereg("C",$player[$key]["option"]) )
350 if( ereg("A",$player[$key]["option"]) )
352 if( ereg("H",$player[$key]["option"]) )
354 $player[$key]["option"]=$tmp;
356 /* saving the player stats */
357 fwrite($output,"".$player[$key]["hash"].":" );
358 fwrite($output,"".$player[$key]["name"].":" );
359 fwrite($output,"".$player[$key]["email"].":" );
360 fwrite($output,"".$player[$key]["option"].":" );
361 fwrite($output,"".$player[$key]["points"].":" );
362 fwrite($output,"".$player[$key]["cards"] .":");
363 fwrite($output,"\n");
365 fwrite($output,"\n");
366 foreach($history as $line)
367 fwrite($output,$line);
369 fwrite($output,"\n");
373 echo "can't open file for writing, please inform the admin.";
378 echo "<p>If you find bugs, please list them in the <a href=\"".$wiki."\">wiki</a></p>\n";
382 /* check for status file and read it, if possible */
384 if(file_exists("status.txt"))
385 $lines = file("status.txt");
389 /* check if we want to start a new game */
390 if( isset($_REQUEST["PlayerA"]) &&
391 isset($_REQUEST["PlayerB"]) &&
392 isset($_REQUEST["PlayerC"]) &&
393 isset($_REQUEST["PlayerD"]) &&
394 isset($_REQUEST["EmailA"]) &&
395 isset($_REQUEST["EmailB"]) &&
396 isset($_REQUEST["EmailC"]) &&
397 isset($_REQUEST["EmailD"]) && sizeof($lines<2))
399 $PlayerA = $_REQUEST["PlayerA"];
400 $PlayerB = $_REQUEST["PlayerB"];
401 $PlayerC = $_REQUEST["PlayerC"];
402 $PlayerD = $_REQUEST["PlayerD"];
403 $EmailA = $_REQUEST["EmailA"] ;
404 $EmailB = $_REQUEST["EmailB"] ;
405 $EmailC = $_REQUEST["EmailC"] ;
406 $EmailD = $_REQUEST["EmailD"] ;
408 $hashA = md5("AGameOfDoko".$PlayerA.$EmailA);
409 $hashB = md5("AGameOfDoko".$PlayerB.$EmailB);
410 $hashC = md5("AGameOfDoko".$PlayerC.$EmailC);
411 $hashD = md5("AGameOfDoko".$PlayerD.$EmailD);
413 /* send out email, check for error with email */
416 "you are invited to play a game of DoKo (that is to debug the program ;).\n".
417 "Place comments and bug reports here:\n".
418 "http://wiki.nubati.net/index.php?title=EmailDoko\n\n".
419 "The whole round would consist of the following players:\n".
424 "If you want to join this game, please follow this link:\n\n".
427 mymail($EmailA,"Invite for a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
428 mymail($EmailB,"Invite for a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
429 mymail($EmailC,"Invite for a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
430 mymail($EmailD,"Invite for a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
432 /* read in random.txt */
433 if(file_exists("random.txt"))
434 $random = file("random.txt");
436 die("no random file");
438 $randomNR = explode( ":", $random[1] );
440 /* write initial status into file */
441 $output = fopen("status.txt","w");
444 fwrite($output, "$hashA:$PlayerA:$EmailA:::" );
446 fwrite($output,"$randomNR[$i];" );
447 fwrite($output,"$randomNR[11]:" ); $i++;
448 fwrite($output,"\n");
450 fwrite($output, "$hashB:$PlayerB:$EmailB:::" );
452 fwrite($output,"$randomNR[$i];" );
453 fwrite($output,"$randomNR[23]:" ); $i++;
454 fwrite($output,"\n");
456 fwrite($output, "$hashC:$PlayerC:$EmailC:::" );
458 fwrite($output,"$randomNR[$i];" );
459 fwrite($output,"$randomNR[35]:" ); $i++;
460 fwrite($output,"\n");
462 fwrite($output, "$hashD:$PlayerD:$EmailD:::");
464 fwrite($output,"$randomNR[$i];" );
465 fwrite($output,"$randomNR[47]:" );
466 fwrite($output,"\n");
471 echo "can't open file for writing";
474 /* test if a game is running, else output everything for a new game */
478 <p> no game in progress, please input 4 names and email addresses, please make sure that the addresses are correct! </p>
479 <form action="index.php" method="post">
480 Name: <input name="PlayerA" type="text" size="10" maxlength="20" />
481 Email: <input name="EmailA" type="text" size="20" maxlength="30" /> <br />
483 Name: <input name="PlayerB" type="text" size="10" maxlength="20" />
484 Email: <input name="EmailB" type="text" size="20" maxlength="30" /> <br />
486 Name: <input name="PlayerC" type="text" size="10" maxlength="20" />
487 Email: <input name="EmailC" type="text" size="20" maxlength="30" /> <br />
489 Name: <input name="PlayerD" type="text" size="10" maxlength="20" />
490 Email: <input name="EmailD" type="text" size="20" maxlength="30" /> <br />
492 <input type="submit" value="start game" />
497 { /* load game status */
504 * check if a player wants to accept a game
507 if(isset($_REQUEST["a"]))
511 if( ereg("[is]",$player[$a]["option"]) && $game["init"]<4)
513 echo "just wait for the game to start";
515 else if( !ereg("[is]",$player[$a]["option"]) )
519 <form action="index.php" method="post">
520 Do you want to play a game of DoKo?
521 yes<input type="radio" name="in" value="yes" />
522 no<input type="radio" name="in" value="no" /> <br />
524 Do you want to get an email for every card played or only if it your move?
525 every card<input type="radio" name="update" value="card" />
526 only on my turn<input type="radio" name="update" value="turn" /> <br />
528 echo "<input type=\"hidden\" name=\"b\" value=\"$a\" />\n";
530 echo "<input type=\"submit\" value=\"count me in\" />\n";
540 * yes? email him his hand, ask for solo, poverty, email every move or every card?
542 if(isset($_REQUEST["b"]))
546 if( ereg("s",$player[$b]["option"]) && $game["init"]<4)
548 echo "just wait for the game to start";
550 else if( (!isset($_REQUEST["in"])|| !isset($_REQUEST["update"])) && !ereg("i",$player[$b]["option"]))
553 echo "<a href=\"index.php?a=$b\"> here and fill out the form </a> <br />\n";
556 { /* show the hand */
557 if($_REQUEST["in"]=="no")
561 $message = "Hello ".$player[$hash[$i]]["name"].",\n\n".
562 "the game has been canceled due to the request of one of the players.\n";
563 mymail($player[$hash[$i]]["email"],"[DoKo-Debug] the game has been canceled",$message);
565 $output = fopen("status.txt","w");
569 echo "problem opening file";
573 if($_REQUEST["update"]=="card") $player[$b]["option"].="c";
574 if($_REQUEST["update"]=="turn") $player[$b]["option"].="t";
576 $player[$b]["option"].="i";
580 $allcards = $player[$b]["cards"];
581 $mycards = explode(";",$allcards);
584 echo "your cards are <br>\n";
585 foreach($mycards as $card)
591 <p>aehm... at the moment please just answer everything with no, still need to implement this</p>
592 <form action="index.php" method="post">
594 do you want to play solo?
595 <select name="solo" size="1">
597 <option>No trump</option>
598 <option>Normal solo</option>
599 <option>Queen solo</option>
600 <option>Jack solo</option>
601 <option>Club solo</option>
602 <option>Spade solo</option>
603 <option>Heart solo</option>
610 if(check_wedding($player[$b]["cards"]))
612 echo " yes<input type=\"radio\" name=\"wedding\" value=\"yes\" />";
613 echo " no <input type=\"radio\" name=\"wedding\" value=\"no\" /> <br />\n";
617 echo " no <input type=\"hidden\" name=\"wedding\" value=\"no\" /> <br />\n";
620 echo "do you have poverty?";
621 if(count_trump($player[$b]["cards"])<4)
623 echo " yes<input type=\"radio\" name=\"poverty\" value=\"yes\" />";
624 echo " no <input type=\"radio\" name=\"poverty\" value=\"no\" /> <br />\n";
628 echo " no <input type=\"hidden\" name=\"poverty\" value=\"no\" /> <br />\n";
631 echo "do you have too many nines?";
632 if(count_nines($player[$b]["cards"])>4)
634 echo " yes<input type=\"radio\" name=\"nines\" value=\"yes\" />";
635 echo " no <input type=\"radio\" name=\"nines\" value=\"no\" /> <br />\n";
639 echo " no <input type=\"hidden\" name=\"nines\" value=\"no\" /> <br />\n";
642 echo "<input type=\"hidden\" name=\"c\" value=\"$b\" />\n";
643 echo "<input type=\"submit\" value=\"count me in\" />\n";
649 if(isset($_REQUEST["c"]))
653 if(!isset($_REQUEST["solo"])|| !isset($_REQUEST["wedding"])|| !isset($_REQUEST["poverty"]) || !isset($_REQUEST["nines"]) )
656 echo "<a href=\"index.php?b=$c\"> here and fill out the form </a> <br />\n";
658 else if( ereg("s",$player[$c]["option"]) && $game["init"]<4 )
660 echo "just wait for the game to start";
662 else if($game["init"]<4)
664 if( $_REQUEST["solo"]!="No")
666 switch($_REQUEST["solo"])
669 $player[$c]["option"].="O";
672 $player[$c]["option"].="S";
675 $player[$c]["option"].="Q";
678 $player[$c]["option"].="J";
681 $player[$c]["option"].="C";
684 $player[$c]["option"].="A";
687 $player[$c]["option"].="H";
691 else if($_REQUEST["wedding"] == "yes")
693 echo "wedding was chosen<br />\n";
694 $player[$c]["option"].="W";
696 else if($_REQUEST["poverty"] == "yes")
698 echo "poverty was chosen<br />\n";
699 $player[$c]["option"].="P";
701 else if($_REQUEST["nines"] == "yes")
703 echo "nines was chosen<br />\n";
704 $player[$c]["option"].="N";
707 $message = "you're in. once everyone has filled out the form,".
708 "the game will start and you'll get an eamil on your turn\n";
709 mymail($player[$c]["email"],"[DoKo-debug] the game will start soon",$message);
711 $player[$c]["option"].="s";
713 if(file_exists("status.txt"))
714 $lines = file("status.txt");
721 $message = "The game can start now, it's your turn, please use this link to play a card:\n".
722 $host."?me=".$hash[$game["startplayer"]]."\n";
723 mymail($player[$hash[$game["startplayer"]]]["email"],"[DoKo-debug] let's go",$message);
730 /* check for sickness*/
731 /***** someone has 5 nines and no one is playing solo=> cance5Al game */
732 if($game["nines"]>=0 && $game["solo-who"]<0)
734 $message = $player[$hash[$game["poverty"]]]["nines"]." has more than 4 nines. Game aborted!\n";
737 mymail($player[$hash[$i]]["email"],"[DoKo-debug] the game has been canceled",$message);
739 $output = fopen("status.txt","w");
743 echo "problem opening file";
746 /* who is requesting this*/
747 if(!isset($_REQUEST["me"]))
749 if(!isset($_REQUEST["recovery"]))
751 echo "a game is in progress, but you are not playing.<br />\n";
752 echo "In case you are playing, but lost your email or can't access the game anymore, please input your email here:<br />\n";
754 <form action="index.php" method="post">
755 recorvery: <input name="recovery" type="text" size="20" maxlength="30" /> <br />
756 <input type="submit" value="get me back into the game" />
762 $recovery=$_REQUEST["recovery"];
765 if(trim($recovery)==trim($player[$hash[$i]]["email"]))
769 $message = "Please try this link: ".$host."?me=".$hash[$ok]."\n".
770 "\n if this doesn't work, contact the admin.\n";
771 mymail($recovery,"[DoKo-Debug] recovery ",$message);
772 echo "email has been sent.";
776 echo "can't find this email address, sorry.";
782 $me = $_REQUEST["me"];
784 echo "game in progress and you are in it<br />\n";
785 if($game["solo-who"]>=0)
786 echo $player[$hash[$game["solo-who"]]]["name"]." is playing a ".$game["solo-what"]." solo!<br />\n";
787 else if($game["wedding"]>=0)
788 echo $player[$hash[$game["wedding"]]]["name"]." is playing a wedding!<br />\n";
791 foreach($history as $play)
795 $trick = explode(":",$play);
798 /* found old trick, display it */
799 for($i=0;$i<sizeof($trick)-1;$i++)
804 $tmp = explode("->",$card);
805 echo $player[$hash[$tmp[0]]]["name"]." played ";
806 display_card($tmp[1]);
812 /* figure out who needs to play next */
818 $next=$history[sizeof($history)-1][0];
821 /* are we trying to play a card? */
822 if(isset($_REQUEST["card"]))
824 if($hash[$next]==$me)
826 $card = $_REQUEST["card"];
827 $mycards = explode(";",$player[$me]["cards"]);
829 /* do we have that card */
830 if(in_array($card,$mycards))
832 /* delete card from array */
834 foreach($mycards as $m)
839 for($i=0;$i<sizeof($tmp)-1;$i++)
844 $player[$me]["cards"]=$tmp2;
846 /* add card to history, special case if this is the first card */
849 $history[sizeof($history)-1]="".$player[$me]["number"]."->".$card.":\n";
853 $tmp = explode(":",$history[sizeof($history)-1]);
854 $tmp[sizeof($tmp)-1] = "".$player[$me]["number"]."->".$card.":";
855 $history[sizeof($history)-1]=join(":",$tmp);
862 /* send out email to players who want/need to get informed */
865 $mynext=$next+1; if($mynext>3)$mynext-=4;
866 if((ereg("c",$player[$hash[$i]]["option"]) || $i==$mynext) && $hash[$i]!=$me)
868 $message = " Hello ".$player[$hash[$i]]["name"].",\n\n";
872 $message .= "it's your turn now.\n".
873 "Use this link to play a card: ".$host."?me=".$hash[$i]."\n\n" ;
875 $message .= $player[$me]["name"]. "has played the following card ".card_to_name($card)."\n";
877 if($game["solo-who"]>=0)
878 $message.= $player[$hash[$game["solo-who"]]]." is playing a ".$game["solo-what"]." solo!\n";
880 mymail($player[$hash[$i]]["email"],"[DoKo-debug] a card has been played",$message);
883 echo "<a href=\"index.php?me=".$hash[$mynext]."\"> next player </a> <br />\n";
888 echo "seems like you don't have that card<br />\n";
892 } /* end if card is set */
893 else if(isset($_REQUEST["win"]) && strlen($history[sizeof($history)-1])>3)
895 $win=$_REQUEST["win"];
896 $history[]=$win.":\n";
897 /* count points of the last trick */
900 $tmp = explode(":",$history[sizeof($history)-2]);
903 $tmp2 = explode("->",$tmp[$i]);
905 $points += card_value($c);
907 $player[$hash[$win]]["points"]+=$points;
908 echo "<br />\n ".$player[$hash[$win]]["name"]." won: $points Points <br />\n";
911 }; /* end if win is set */
914 $tmp = explode(":",$history[sizeof($history)-1]);
916 /* check last history entry: end of a trick? ask who won it */
920 <form action="index.php" method="post">
924 echo $player[$hash[$i]]["name"]." <input type=\"radio\" name=\"win\" value=\"$i\" />";
925 echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />";
927 <input type="submit" value="submit" />
932 else if(sizeof($tmp)<5 && 1<sizeof($tmp) && !isset($_REQUEST["card"]))
934 if(sizeof($tmp)==2 && strlen($tmp[0])==1)
939 echo "DEBUG: the next move is for <a href=\"index.php?me=".$hash[$next]."\">the next player</a><br />\n";
941 if(strlen(trim($player[$me]["cards"]))==0)
943 echo "<br /> game over, count points <br />\n";
946 echo $player[$hash[$i]]["name"]." got ".$player[$hash[$i]]["points"]."<br />\n";
951 } /* end check for winner */
953 /* do we still have cards? display them */
954 if(strlen(trim($player[$me]["cards"]))>0 )
956 $allcards = trim($player[$me]["cards"]);
957 $mycards = explode(";",$allcards);
961 echo "<p class=\"mycards\">\n";
962 /* is it our turn? */
963 if($hash[$next]==$me)
965 echo "ITS YOUR TURN <br />\n";
966 echo "your cards are: <br />\n";
967 foreach($mycards as $card)
969 display_link_card($card,$me);
973 { /* not our turn, just show the hand */
974 echo "your cards are: <br />\n";
975 foreach($mycards as $card)