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 to do this */
10 if(! isset($_SESSION["name"]) )
12 echo "<div class=\"message\">Please <a href=\"$INDEX\">log in</a>.</div>";
16 if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","callrule" ))
19 $name = $_SESSION["name"];
21 /* the names of the four players */
22 $PlayerA = $_REQUEST["PlayerA"];
23 $PlayerB = $_REQUEST["PlayerB"];
24 $PlayerC = $_REQUEST["PlayerC"];
25 $PlayerD = $_REQUEST["PlayerD"];
27 /* the person who sets up the game has to be one of the players */
28 if(!in_array($name,array($PlayerA,$PlayerB,$PlayerC,$PlayerD)))
30 echo "<div class=\"message\">You need to be one of the players to start a <a href=\"$INDEX?action=new\">new game</a>.</div>";
36 /* what rules were selected */
37 $dullen = $_REQUEST["dullen"];
38 $schweinchen = $_REQUEST["schweinchen"];
39 $call = $_REQUEST["callrule"];
41 /* get the emails addresses of the players */
42 $EmailA = DB_get_email('name',$PlayerA);
43 $EmailB = DB_get_email('name',$PlayerB);
44 $EmailC = DB_get_email('name',$PlayerC);
45 $EmailD = DB_get_email('name',$PlayerD);
47 /* this is used to check if the player names are all ok */
48 if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="")
50 echo "couldn't find one of the names, please start a new game";
57 $useridA = DB_get_userid('name',$PlayerA);
58 $useridB = DB_get_userid('name',$PlayerB);
59 $useridC = DB_get_userid('name',$PlayerC);
60 $useridD = DB_get_userid('name',$PlayerD);
62 /* create random numbers */
63 $randomNR = create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD);
64 $randomNRstring = join(":",$randomNR);
68 /* is this game a follow up in an already started session? */
69 if(myisset("followup") )
71 $followup= $_REQUEST["followup"];
72 $session = DB_get_session_by_gameid($followup);
73 $ruleset = DB_get_ruleset_by_gameid($followup); /* just copy ruleset from old game,
74 this way no manipulation is possible */
76 /* check if there is a game in pre or play mode, in that case do nothing */
77 if( DB_is_session_active($session) > 0 )
79 echo "<p class=\"message\"> There is already a game going on in session $session, you can't start a new one</p>";
84 else if ( DB_is_session_active($session) < 0 )
86 echo "<p class=\"message\"> ERROR: status of session $session couldn't be determined.</p>";
93 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',".
94 "'$ruleset','$session' ,NULL)");
97 /* get max session and start a new one */
98 $max = DB_get_max_session();
100 mysql_query("UPDATE Game SET session='".$max."' WHERE id=".DB_quote_smart($followup));
101 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',".
102 "'$ruleset','$max' ,NULL)");
105 else /* no follow up, start a new session */
107 /* get ruleset information or create new one */
108 $ruleset = DB_get_ruleset($dullen,$schweinchen,$call);
111 myerror("Error defining ruleset: $ruleset");
116 /* get max session */
117 $max = DB_get_max_session();
120 mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre', ".
121 "'$ruleset','$max' ,NULL)");
123 $game_id = mysql_insert_id();
126 $TIME = (string) time(); /* to avoid collisions */
127 $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA.$TIME);
128 $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB.$TIME);
129 $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC.$TIME);
130 $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD.$TIME);
133 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridA).
134 ", ".DB_quote_smart($hashA).", 'start','1',NULL,NULL,NULL,NULL)");
135 $hand_idA = mysql_insert_id();
136 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridB).
137 ", ".DB_quote_smart($hashB).", 'start','2',NULL,NULL,NULL,NULL)");
138 $hand_idB = mysql_insert_id();
139 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridC).
140 ", ".DB_quote_smart($hashC).", 'start','3',NULL,NULL,NULL,NULL)");
141 $hand_idC = mysql_insert_id();
142 mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridD).
143 ", ".DB_quote_smart($hashD).", 'start','4',NULL,NULL,NULL,NULL)");
144 $hand_idD = mysql_insert_id();
148 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idA', '".$randomNR[$i]."', 'false')");
149 for($i=12;$i<24;$i++)
150 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idB', '".$randomNR[$i]."', 'false')");
151 for($i=24;$i<36;$i++)
152 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idC', '".$randomNR[$i]."', 'false')");
153 for($i=36;$i<48;$i++)
154 mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idD', '".$randomNR[$i]."', 'false')");
156 /* send out email, TODO: check for error with email */
158 "you are invited to play a game of DoKo (that is to debug the program ;).\n".
159 "Place comments and bug reports here:\n".
160 "http://wiki.nubati.net/index.php?title=EmailDoko\n\n".
161 "The whole round would consist of the following players:\n".
166 "If you want to join this game, please follow this link:\n\n".
167 "".$HOST.$INDEX."?action=game&me=";
169 mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA);
170 mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB);
171 mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC);
172 mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD);
174 echo "<div class=\"message\">You started a new game. The emails have been sent out!</div>\n";
178 $names = DB_get_all_names();
179 echo "<div class=\"user\">\n";
180 output_form_for_new_game($names);