X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=index.php;h=bf96982f7a61e653a13b43df8631d604d086fb9c;hp=f2fa3d69d71a616b0d5cff7973b1925943257e72;hb=9732aef914603924915bde24684f322843ead085;hpb=c0e030bb5068085ef52cc8bd0c91f025fb78045e diff --git a/index.php b/index.php index f2fa3d6..bf96982 100644 --- a/index.php +++ b/index.php @@ -1,7 +1,7 @@ 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)"); @@ -102,7 +119,7 @@ else if(myisset("new")) { /* get ruleset information or create new one */ $ruleset = DB_get_ruleset($dullen,$schweinchen,$call); - if($ruleset <0) + if($ruleset <0) { myerror("Error defining ruleset: $ruleset"); output_footer(); @@ -112,33 +129,33 @@ else if(myisset("new")) /* 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(); + $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(); + $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(); + $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')"); @@ -148,7 +165,7 @@ else if(myisset("new")) 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". @@ -161,19 +178,19 @@ else if(myisset("new")) "$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!"; + + 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) @@ -184,9 +201,9 @@ else if(myisset("cancle","me")) DB_close(); exit(); } - + DB_update_user_timestamp($myid); - + /* get some information from the DB */ $gameid = DB_get_gameid_by_hash($me); $myname = DB_get_name_by_hash($me); @@ -197,19 +214,21 @@ else if(myisset("cancle","me")) if(time()-strtotime($r[0]) > 60*60*24*30) /* = 1 month */ { $message = "Hello, \n\n". - "Game ".DB_format_gameid($gameid)." has been cancled since nothing happend for a while and $myname requested it.\n"; - + "Game ".DB_format_gameid($gameid). + " has been cancled since nothing happend for a while and $myname requested it.\n"; + $userids = DB_get_all_userid_by_gameid($gameid); foreach($userids as $user) { $To = DB_get_email_by_userid($user); mymail($To,$EmailName."game ".DB_format_gameid($gameid)." cancled (timed out)",$message); } - + /* delete everything from the dB */ DB_cancel_game($me); - - echo "Game ".DB_format_gameid($gameid)." has been cancled.
Game ".DB_format_gameid($gameid).
+ " has been cancled.
You need to wait longer before you can cancle a game...
\n"; @@ -218,7 +237,7 @@ else if(myisset("cancle","me")) else if(myisset("remind","me")) { $me = $_REQUEST["me"]; - + /* test for valid ID */ $myid = DB_get_userid_by_hash($me); if(!$myid) @@ -229,9 +248,9 @@ else if(myisset("remind","me")) DB_close(); exit(); } - + DB_update_user_timestamp($myid); - + /* get some information from the DB */ $gameid = DB_get_gameid_by_hash($me); $myname = DB_get_name_by_hash($me); @@ -244,13 +263,13 @@ else if(myisset("remind","me")) $name = DB_get_name_by_userid($r[1]); $To = DB_get_email_by_userid($r[1]); $userhash = DB_get_hash_from_gameid_and_userid($gameid,$r[1]); - + $message = "Hello $name, \n\n". "It's your turn in game ".DB_format_gameid($gameid)." \n". "Actually everyone else is waiting for you for more than a week now ;)\n\n". "Please visit this link now to continue: \n". " ".$host."?me=".$userhash."\n\n" ; - + if(DB_get_reminder($r[1],$gameid)>0) { echo "An email has already been sent out.
\n"; @@ -259,8 +278,9 @@ else if(myisset("remind","me")) { 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.
Game ".DB_format_gameid($gameid).
+ ": an email has been sent out.
Session:
\n";
echo " p = pre-game phase ";
echo "P = game in progess ";
echo "F = game finished
";
echo "
\n"; echo implode(", ",$names)."\n"; - echo "
\n"; + echo "\n