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>
18 $host = "http://doko.nubati.net/index.php";
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)."\" />";
302 echo "<img src=\"cards/".($card-1).".png\" height=\"100\" alt=\"".card_to_name($card-1)."\" />";
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>";
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>";
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.";
380 /* check for status file and read it, if possible */
382 if(file_exists("status.txt"))
383 $lines = file("status.txt");
387 /* check if we want to start a new game */
388 if( isset($_REQUEST["PlayerA"]) &&
389 isset($_REQUEST["PlayerB"]) &&
390 isset($_REQUEST["PlayerC"]) &&
391 isset($_REQUEST["PlayerD"]) &&
392 isset($_REQUEST["EmailA"]) &&
393 isset($_REQUEST["EmailB"]) &&
394 isset($_REQUEST["EmailC"]) &&
395 isset($_REQUEST["EmailD"]) && sizeof($lines<2))
397 $PlayerA = $_REQUEST["PlayerA"];
398 $PlayerB = $_REQUEST["PlayerB"];
399 $PlayerC = $_REQUEST["PlayerC"];
400 $PlayerD = $_REQUEST["PlayerD"];
401 $EmailA = $_REQUEST["EmailA"] ;
402 $EmailB = $_REQUEST["EmailB"] ;
403 $EmailC = $_REQUEST["EmailC"] ;
404 $EmailD = $_REQUEST["EmailD"] ;
406 $hashA = md5("AGameOfDoko".$PlayerA.$EmailA);
407 $hashB = md5("AGameOfDoko".$PlayerB.$EmailB);
408 $hashC = md5("AGameOfDoko".$PlayerC.$EmailC);
409 $hashD = md5("AGameOfDoko".$PlayerD.$EmailD);
411 /* send out email, check for error with email */
414 "you are invited to play a game of DoKo (that is to debug the program ;).\n".
415 "Place comments and bug reports here:\n".
416 "http://wiki.nubati.net/index.php?title=EmailDoko\n\n".
417 "The whole round would consist of the following players:\n".
422 "If you want to join this game, please follow this link:\n\n".
425 mymail($EmailA,"Invite for a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
426 mymail($EmailB,"Invite for a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
427 mymail($EmailC,"Invite for a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
428 mymail($EmailD,"Invite for a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
430 /* read in random.txt */
431 if(file_exists("random.txt"))
432 $random = file("random.txt");
434 die("no random file");
436 $randomNR = explode( ":", $random[1] );
438 /* write initial status into file */
439 $output = fopen("status.txt","w");
442 fwrite($output, "$hashA:$PlayerA:$EmailA:::" );
444 fwrite($output,"$randomNR[$i];" );
445 fwrite($output,"$randomNR[11]:" ); $i++;
446 fwrite($output,"\n");
448 fwrite($output, "$hashB:$PlayerB:$EmailB:::" );
450 fwrite($output,"$randomNR[$i];" );
451 fwrite($output,"$randomNR[23]:" ); $i++;
452 fwrite($output,"\n");
454 fwrite($output, "$hashC:$PlayerC:$EmailC:::" );
456 fwrite($output,"$randomNR[$i];" );
457 fwrite($output,"$randomNR[35]:" ); $i++;
458 fwrite($output,"\n");
460 fwrite($output, "$hashD:$PlayerD:$EmailD:::");
462 fwrite($output,"$randomNR[$i];" );
463 fwrite($output,"$randomNR[47]:" );
464 fwrite($output,"\n");
469 echo "can't open file for writing";
472 /* test if a game is running, else output everything for a new game */
476 <p> no game in progress, please input 4 names and email addresses, please make sure that the addresses are correct! </p>
477 <form action="index.php" method="post">
478 Name: <input name="PlayerA" type="text" size="10" maxlength="20" />
479 Email: <input name="EmailA" type="text" size="20" maxlength="30" /> <br />
481 Name: <input name="PlayerB" type="text" size="10" maxlength="20" />
482 Email: <input name="EmailB" type="text" size="20" maxlength="30" /> <br />
484 Name: <input name="PlayerC" type="text" size="10" maxlength="20" />
485 Email: <input name="EmailC" type="text" size="20" maxlength="30" /> <br />
487 Name: <input name="PlayerD" type="text" size="10" maxlength="20" />
488 Email: <input name="EmailD" type="text" size="20" maxlength="30" /> <br />
490 <input type="submit" value="start game" />
495 { /* load game status */
502 * check if a player wants to accept a game
505 if(isset($_REQUEST["a"]))
509 if( ereg("[is]",$player[$a]["option"]) && $game["init"]<4)
511 echo "just wait for the game to start";
513 else if( !ereg("[is]",$player[$a]["option"]) )
517 <form action="index.php" method="post">
518 Do you want to play a game of DoKo?
519 yes<input type="radio" name="in" value="yes" />
520 no<input type="radio" name="in" value="no" /> <br />
522 Do you want to get an email for every card played or only if it your move?
523 every card<input type="radio" name="update" value="card" />
524 only on my turn<input type="radio" name="update" value="turn" /> <br />
526 echo "<input type=\"hidden\" name=\"b\" value=\"$a\" />\n";
528 echo "<input type=\"submit\" value=\"count me in\" />\n";
538 * yes? email him his hand, ask for solo, poverty, email every move or every card?
540 if(isset($_REQUEST["b"]))
544 if( ereg("s",$player[$b]["option"]) && $game["init"]<4)
546 echo "just wait for the game to start";
548 else if( (!isset($_REQUEST["in"])|| !isset($_REQUEST["update"])) && !ereg("i",$player[$b]["option"]))
551 echo "<a href=\"index.php?a=$b\"> here and fill out the form </a> <br />";
554 { /* show the hand */
555 if($_REQUEST["in"]=="no")
559 $message = "Hello ".$player[$hash[$i]]["name"].",\n\n".
560 "the game has been canceled due to the request of one of the players.\n";
561 mymail($player[$hash[$i]]["email"],"[DoKo-Debug] the game has been canceled",$message);
563 $output = fopen("status.txt","w");
567 echo "problem opening file";
571 if($_REQUEST["update"]=="card") $player[$b]["option"].="c";
572 if($_REQUEST["update"]=="turn") $player[$b]["option"].="t";
574 $player[$b]["option"].="i";
578 $allcards = $player[$b]["cards"];
579 $mycards = explode(";",$allcards);
582 echo "your cards are <br>";
583 foreach($mycards as $card)
589 <p>aehm... at the moment please just answer everything with no, still need to implement this</p>
590 <form action="index.php" method="post">
592 do you want to play solo?
593 <select name="solo" size="1">
595 <option>No trump</option>
596 <option>Normal solo</option>
597 <option>Queen solo</option>
598 <option>Jack solo</option>
599 <option>Club solo</option>
600 <option>Spade solo</option>
601 <option>Heart solo</option>
608 if(check_wedding($player[$b]["cards"]))
610 echo " yes<input type=\"radio\" name=\"wedding\" value=\"yes\" />";
611 echo " no <input type=\"radio\" name=\"wedding\" value=\"no\" /> <br />";
615 echo " no <input type=\"hidden\" name=\"wedding\" value=\"no\" /> <br />";
618 echo "do you have poverty?";
619 if(count_trump($player[$b]["cards"])<4)
621 echo " yes<input type=\"radio\" name=\"poverty\" value=\"yes\" />";
622 echo " no <input type=\"radio\" name=\"poverty\" value=\"no\" /> <br />";
626 echo " no <input type=\"hidden\" name=\"poverty\" value=\"no\" /> <br />";
629 echo "do you have too many nines?";
630 if(count_nines($player[$b]["cards"])>4)
632 echo " yes<input type=\"radio\" name=\"nines\" value=\"yes\" />";
633 echo " no <input type=\"radio\" name=\"nines\" value=\"no\" /> <br />";
637 echo " no <input type=\"hidden\" name=\"nines\" value=\"no\" /> <br />";
640 echo "<input type=\"hidden\" name=\"c\" value=\"$b\" />\n";
641 echo "<input type=\"submit\" value=\"count me in\" />\n";
647 if(isset($_REQUEST["c"]))
651 if(!isset($_REQUEST["solo"])|| !isset($_REQUEST["wedding"])|| !isset($_REQUEST["poverty"]) || !isset($_REQUEST["nines"]) )
654 echo "<a href=\"index.php?b=$c\"> here and fill out the form </a> <br />";
656 else if( ereg("s",$player[$c]["option"]) && $game["init"]<4 )
658 echo "just wait for the game to start";
660 else if($game["init"]<4)
662 if( $_REQUEST["solo"]!="No")
664 switch($_REQUEST["solo"])
667 $player[$c]["option"].="O";
670 $player[$c]["option"].="S";
673 $player[$c]["option"].="Q";
676 $player[$c]["option"].="J";
679 $player[$c]["option"].="C";
682 $player[$c]["option"].="A";
685 $player[$c]["option"].="H";
689 else if($_REQUEST["wedding"] == "yes")
691 echo "wedding was chosen<br>";
692 $player[$c]["option"].="W";
694 else if($_REQUEST["poverty"] == "yes")
696 echo "poverty was chosen<br>";
697 $player[$c]["option"].="P";
699 else if($_REQUEST["nines"] == "yes")
701 echo "nines was chosen<br>";
702 $player[$c]["option"].="N";
705 $message = "you're in. once everyone has filled out the form,".
706 "the game will start and you'll get an eamil on your turn\n";
707 mymail($player[$c]["email"],"[DoKo-debug] the game will start soon",$message);
709 $player[$c]["option"].="s";
711 if(file_exists("status.txt"))
712 $lines = file("status.txt");
719 $message = "The game can start now, it's your turn, please use this link to play a card:\n".
720 $host."?me=".$hash[$game["startplayer"]]."\n";
721 mymail($player[$hash[$game["startplayer"]]]["email"],"[DoKo-debug] let's go",$message);
728 /* check for sickness*/
729 /***** someone has 5 nines and no one is playing solo=> cance5Al game */
730 if($game["nines"]>=0 && $game["solo-who"]<0)
732 $message = $player[$hash[$game["poverty"]]]["nines"]." has more than 4 nines. Game aborted!\n";
735 mymail($player[$hash[$i]]["email"],"[DoKo-debug] the game has been canceled",$message);
737 $output = fopen("status.txt","w");
741 echo "problem opening file";
744 /* who is requesting this*/
745 if(!isset($_REQUEST["me"]))
747 if(!isset($_REQUEST["recovery"]))
749 echo "a game is in progress, but you are not playing.<br />";
750 echo "In case you are playing, but lost your email or can't access the game anymore, please input your email here:<br />";
752 <form action="index.php" method="post">
753 recorvery: <input name="recovery" type="text" size="20" maxlength="30" /> <br />
754 <input type="submit" value="get me back into the game" />
760 $recovery=$_REQUEST["recovery"];
763 if(trim($recovery)==trim($player[$hash[$i]]["email"]))
767 $message = "Please try this link: ".$host."?me=".$hash[$ok]."\n".
768 "\n if this doesn't work, contact the admin.\n";
769 mymail($recovery,"[DoKo-Debug] recovery ",$message);
770 echo "email has been sent.";
774 echo "can't find this email address, sorry.";
780 $me = $_REQUEST["me"];
782 echo "game in progress and you are in it<br />";
783 if($game["solo-who"]>=0)
784 echo $player[$hash[$game["solo-who"]]]["name"]." is playing a ".$game["solo-what"]." solo!<br />";
785 else if($game["wedding"]>=0)
786 echo $player[$hash[$game["wedding"]]]["name"]." is playing a wedding!<br />";
788 foreach($history as $play)
792 $trick = explode(":",$play);
795 /* found old trick, display it */
796 for($i=0;$i<sizeof($trick)-1;$i++)
801 $tmp = explode("->",$card);
802 echo $player[$hash[$tmp[0]]]["name"]." played ";
803 display_card($tmp[1]);
814 $next=$history[sizeof($history)-1][0];
818 if(isset($_REQUEST["card"]))
820 if($hash[$next]==$me)
822 $card=$_REQUEST["card"];
823 $mycards = explode(";",$player[$me]["cards"]);
824 if(in_array($card,$mycards))
827 foreach($mycards as $m)
831 for($i=0;$i<sizeof($tmp)-1;$i++)
836 $player[$me]["cards"]=$tmp2;
840 $history[sizeof($history)-1]="".$player[$me]["number"]."->".$card.":\n";
844 $tmp = explode(":",$history[sizeof($history)-1]);
845 $tmp[sizeof($tmp)-1] = "".$player[$me]["number"]."->".$card.":";
846 $history[sizeof($history)-1]=join(":",$tmp);
852 /* send out email to players who want/need to get informed */
855 $mynext=$next+1; if($mynext>3)$mynext-=4;
856 if((ereg("c",$player[$hash[$i]]["option"]) || $i==$mynext) && $hash[$i]!=$me)
858 $message = " Hello ".$player[$hash[$i]]["name"].",\n\n";
862 $message .= "it's your turn now.\n".
863 "Use this link to play a card: ".$host."?me=".$hash[$i]."\n\n" ;
865 $message .= $player[$me]["name"]. "has played the following card ".card_to_name($card)."\n";
867 if($game["solo-who"]>=0)
868 $message.= $player[$hash[$game["solo-who"]]]." is playing a ".$game["solo-what"]." solo!\n";
870 mymail($player[$hash[$i]]["email"],"[DoKo-debug] a card has been played",$message);
873 echo "<a href=\"index.php?me=".$hash[$mynext]."\"> next player </a> <br />";
878 echo "seems like you don't have that card<br>";
883 else if(isset($_REQUEST["win"]) && strlen($history[sizeof($history)-1])>3)
885 $win=$_REQUEST["win"];
886 $history[]=$win.":\n";
887 /* count points of the last trick */
890 $tmp = explode(":",$history[sizeof($history)-2]);
893 $tmp2 = explode("->",$tmp[$i]);
895 $points += card_value($c);
897 $player[$hash[$win]]["points"]+=$points;
898 echo "<br> ".$player[$hash[$win]]["name"]." won: $points Points <br>";
904 $tmp = explode(":",$history[sizeof($history)-1]);
909 <form action="index.php" method="post">
913 echo $player[$hash[$i]]["name"]." <input type=\"radio\" name=\"win\" value=\"$i\" />";
914 echo "<input type=\"hidden\" name=\"me\" value=\"$me\" />";
916 <input type="submit" value="submit" />
921 else if(sizeof($tmp)<5 && 1<sizeof($tmp) && !isset($_REQUEST["card"]))
923 if(sizeof($tmp)==2 && strlen($tmp[0])==1)
928 echo "DEBUG: the next move is for <a href=\"index.php?me=".$hash[$next]."\">the next player</a><br>";
930 if(strlen(trim($player[$me]["cards"]))==0)
932 echo "<br> game over, count points <br>";
935 echo $player[$hash[$i]]["name"]." got ".$player[$hash[$i]]["points"]."<br>";
939 if($hash[$next]==$me && strlen(trim($player[$me]["cards"]))>0 )
942 echo "ITS YOUR TURN<br>";
943 $allcards = trim($player[$me]["cards"]);
944 $mycards = explode(";",$allcards);
947 echo "your cards are <br>";
948 foreach($mycards as $card)
950 display_link_card($card,$me);