0 ) { echo "
"; output_footer(); DB_close(); exit(); } else if ( DB_is_session_active($session) < 0 ) { echo " "; output_footer(); DB_close(); exit(); } if($session) mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',". "'$ruleset','$session' ,NULL)"); else { /* get max session */ $max = DB_get_max_session(); $max++; mysql_query("UPDATE Game SET session='".$max."' WHERE id=".DB_quote_smart($followup)); mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',". "'$ruleset','$max' ,NULL)"); } } else { /* get ruleset information or create new one */ $ruleset = DB_get_ruleset($dullen,$schweinchen,$call); if($ruleset <0) { myerror("Error defining ruleset: $ruleset"); output_footer(); DB_close(); exit(); }; /* get max session */ $max = DB_get_max_session(); $max++; mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre', ". "'$ruleset','$max' ,NULL)"); } $game_id = mysql_insert_id(); /* create hash */ $TIME = (string) time(); /* to avoid collisions */ $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA.$TIME); $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB.$TIME); $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC.$TIME); $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD.$TIME); /* create hands */ mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridA). ", ".DB_quote_smart($hashA).", 'start','1',NULL,NULL,NULL,NULL)"); $hand_idA = mysql_insert_id(); mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridB). ", ".DB_quote_smart($hashB).", 'start','2',NULL,NULL,NULL,NULL)"); $hand_idB = mysql_insert_id(); mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridC). ", ".DB_quote_smart($hashC).", 'start','3',NULL,NULL,NULL,NULL)"); $hand_idC = mysql_insert_id(); mysql_query("INSERT INTO Hand VALUES (NULL,".DB_quote_smart($game_id).",".DB_quote_smart($useridD). ", ".DB_quote_smart($hashD).", 'start','4',NULL,NULL,NULL,NULL)"); $hand_idD = mysql_insert_id(); /* save cards */ for($i=0;$i<12;$i++) mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idA', '".$randomNR[$i]."', 'false')"); for($i=12;$i<24;$i++) mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idB', '".$randomNR[$i]."', 'false')"); for($i=24;$i<36;$i++) mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idC', '".$randomNR[$i]."', 'false')"); for($i=36;$i<48;$i++) mysql_query("INSERT INTO Hand_Card VALUES (NULL, '$hand_idD', '".$randomNR[$i]."', 'false')"); /* send out email, TODO: check for error with email */ $message = "\n". "you are invited to play a game of DoKo (that is to debug the program ;).\n". "Place comments and bug reports here:\n". "http://wiki.nubati.net/index.php?title=EmailDoko\n\n". "The whole round would consist of the following players:\n". "$PlayerA\n". "$PlayerB\n". "$PlayerC\n". "$PlayerD\n\n". "If you want to join this game, please follow this link:\n\n". "".$host."?me="; mymail($EmailA,"You are invited to a game of DoKo","Hello $PlayerA,\n".$message.$hashA); mymail($EmailB,"You are invited to a game of DoKo","Hello $PlayerB,\n".$message.$hashB); mymail($EmailC,"You are invited to a game of DoKo","Hello $PlayerC,\n".$message.$hashC); mymail($EmailD,"You are invited to a game of DoKo","Hello $PlayerD,\n".$message.$hashD); echo "You started a new game. The emails have been sent out!"; } /* end set up a new game */ /* cancle a game, if nothing has happend in the last N minutes */ else if(myisset("cancle","me")) { $me = $_REQUEST["me"]; /* test for valid ID */ $myid = DB_get_userid_by_hash($me); if(!$myid) { echo "Can't find you in the database, please check the url.Game ".DB_format_gameid($gameid)." has been cancled.
You need to wait longer before you can cancle a game...
\n"; } /* send out a reminder */ else if(myisset("remind","me")) { $me = $_REQUEST["me"]; /* test for valid ID */ $myid = DB_get_userid_by_hash($me); if(!$myid) { echo "Can't find you in the database, please check the url.An email has already been sent out.
\n"; } else { DB_set_reminder($r[1],$gameid); mymail($To,$EmailName."Reminder: game ".DB_format_gameid($gameid)." it's your turn",$message); echo "Game ".DB_format_gameid($gameid).": an email has been sent out.
You need to wait longer before you can send out a reminder...
\n"; } /* handle request from one specific player for one game, * (the hash is set on a per game base) */ else if(myisset("me")) { $me = $_REQUEST["me"]; /* test for valid ID */ $myid = DB_get_userid_by_hash($me); if(!$myid) { echo "Can't find you in the database, please check the url.Session:
\n";
echo " p = pre-game phase ";
echo "P = game in progess ";
echo "F = game finished
";
echo "
\n"; while( $r = mysql_fetch_array($result,MYSQL_NUM)) { $game = DB_format_gameid($r[1]); $gamenr = (int) $game; if($gamenrold < $gamenr) { if($gamenrold!=-1) echo " | |||
$gamenr: | "; else echo "$gamenr: | "; $gamenrold = $gamenr; } if($r[4]=='pre') { echo "\n p "; } else if ($r[4]=='gameover') echo "\n F "; else { echo "\n P "; } if($r[4] != 'gameover') { echo " | \n "; if($r[3]) { if($r[3]==$myid) echo "(it's your turn)\n"; else { $name = DB_get_name_by_userid($r[3]); $gameid = $r[1]; if(DB_get_reminder($r[3],$gameid)==0) if(time()-strtotime($r[2]) > 60*60*24*7) echo "". "Send a reminder."; echo "(it's $name's turn)\n"; }; } if(time()-strtotime($r[2]) > 60*60*24*30) echo "". "Cancel?". " (clicking here is final and can't be restored)"; } } echo " |
\n"; echo implode(", ",$names)."\n"; echo "
\n