2 /* make sure that we are not called from outside the scripts,
3 * use a variable defined in config.php to check this
9 /* user needs to be logged in */
10 if( !isset($_SESSION["name"]) )
12 echo "<div class=\"message\">Please <a href=\"$INDEX\">log in</a>.</div>";
17 $name = $_SESSION["name"];
19 /* the names of the four players */
20 $PlayerA = $_REQUEST["PlayerA"];
21 $PlayerB = $_REQUEST["PlayerB"];
22 $PlayerC = $_REQUEST["PlayerC"];
23 $PlayerD = $_REQUEST["PlayerD"];
25 /* the person who sets up the game has to be one of the players */
26 if(!in_array($name,array($PlayerA,$PlayerB,$PlayerC,$PlayerD)))
28 echo "<div class=\"message\">You need to be one of the players to start a <a href=\"$INDEX?new\">new game</a>.</div>";
34 /* what rules were selected */
35 $dullen = $_REQUEST["dullen"];
36 $schweinchen = $_REQUEST["schweinchen"];
37 $call = $_REQUEST["callrule"];
39 /* get the emails addresses of the players */
40 $EmailA = DB_get_email('name',$PlayerA);
41 $EmailB = DB_get_email('name',$PlayerB);
42 $EmailC = DB_get_email('name',$PlayerC);
43 $EmailD = DB_get_email('name',$PlayerD);
45 /* this is used to check if the player names are all ok */
46 if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="")
48 echo "couldn't find one of the names, please start a new game";
55 $useridA = DB_get_userid('name',$PlayerA);
56 $useridB = DB_get_userid('name',$PlayerB);
57 $useridC = DB_get_userid('name',$PlayerC);
58 $useridD = DB_get_userid('name',$PlayerD);
60 /* create random numbers */
61 $randomNR = create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD);
62 $randomNRstring = join(":",$randomNR);
66 /* is this game a follow up in an already started session? */
67 if(myisset("followup") )
69 $followup= $_REQUEST["followup"];
70 $session = DB_get_session_by_gameid($followup);
71 $ruleset = DB_get_ruleset_by_gameid($followup); /* just copy ruleset from old game,
72 this way no manipulation is possible */
74 /* check if there is a game in pre or play mode, in that case do nothing */
75 if( DB_is_session_active($session) > 0 )
77 echo "<p class=\"message\"> There is already a game going on in session $session, you can't start a new one</p>";
82 else if ( DB_is_session_active($session) < 0 )
84 echo "<p class=\"message\"> ERROR: status of session $session couldn't be determined.</p>";
91 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',".
92 "'$ruleset','$session' ,NULL)");
95 /* get max session and start a new one */
96 $max = DB_get_max_session();
98 mysql_query("UPDATE Game SET session='".$max."' WHERE id=".DB_quote_smart($followup));
99 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',".
100 "'$ruleset','$max' ,NULL)");
103 else /* no follow up, start a new session */
105 /* get ruleset information or create new one */
106 $ruleset = DB_get_ruleset($dullen,$schweinchen,$call);
109 myerror("Error defining ruleset: $ruleset");
114 /* get max session */
115 $max = DB_get_max_session();
118 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre', ".
119 "'$ruleset','$max' ,NULL)");
121 $game_id = mysql_insert_id();
124 $TIME = (string) time(); /* to avoid collisions */
125 $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA.$TIME);
126 $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB.$TIME);
127 $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC.$TIME);
128 $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD.$TIME);
131 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridA).
132 ", ".DB_quote_smart($hashA).", 'start','1',NULL,NULL,NULL,NULL)");
133 $hand_idA = mysql_insert_id();
134 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridB).
135 ", ".DB_quote_smart($hashB).", 'start','2',NULL,NULL,NULL,NULL)");
136 $hand_idB = mysql_insert_id();
137 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridC).
138 ", ".DB_quote_smart($hashC).", 'start','3',NULL,NULL,NULL,NULL)");
139 $hand_idC = mysql_insert_id();
140 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridD).
141 ", ".DB_quote_smart($hashD).", 'start','4',NULL,NULL,NULL,NULL)");
142 $hand_idD = mysql_insert_id();
146 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idA', '".$randomNR[$i]."', 'false')");
147 for($i=12;$i<24;$i++)
148 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idB', '".$randomNR[$i]."', 'false')");
149 for($i=24;$i<36;$i++)
150 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idC', '".$randomNR[$i]."', 'false')");
151 for($i=36;$i<48;$i++)
152 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idD', '".$randomNR[$i]."', 'false')");
154 /* send out email, TODO: check for error with email */
156 "you are invited to play a game of DoKo (that is to debug the program ;).\n".
157 "Place comments and bug reports here:\n".
158 "http://wiki.nubati.net/index.php?title=EmailDoko\n\n".
159 "The whole round would consist of the following players:\n".
164 "If you want to join this game, please follow this link:\n\n".
165 "".$HOST.$INDEX."?me=";
167 mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
168 mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
169 mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
170 mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
172 echo "<div class=\"message\">You started a new game. The emails have been sent out!</div>\n";
174 /* end set up a new game */