X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=index.php;h=eb52e4e1d2826467f74476a3ade6cd9c10d0ebf2;hp=de8dc1d309b7fe6501d30d01f0a4dadeccdffb60;hb=2264646817a59a6e3aefa835c492938dde4f25ee;hpb=465e73265bc236531832686a8ae54894be928b81
diff --git a/index.php b/index.php
index de8dc1d..eb52e4e 100644
--- a/index.php
+++ b/index.php
@@ -1,7 +1,7 @@
You are now logged out!
\n".
+ "(This will take you back to the home-page)";
}
else if(myisset("new"))
{
+ output_status();
if( isset($_SESSION["name"]) )
{
$names = DB_get_all_names();
+ echo "
ERROR: status of session $session couldn't be determined.
";
+ 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 +124,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 +134,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 +170,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".
@@ -160,33 +182,36 @@ else if(myisset("new"))
"$PlayerC\n".
"$PlayerD\n\n".
"If you want to join this game, please follow this link:\n\n".
- "".$host."?me=";
-
+ "".$HOST.$INDEX."?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!";
+
+ output_status();
+ echo "You started a new game. The emails have been sent out!
\n";
} /* end set up a new game */
-/* cancle a game, if nothing has happend in the last N minutes */
-else if(myisset("cancle","me"))
+/* cancel a game, if nothing has happend in the last N minutes */
+else if(myisset("cancel","me"))
{
+ output_status();
+
$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.
";
+
+ echo "Game ".DB_format_gameid($gameid).
+ " has been canceled.
";
}
else
- echo "You need to wait longer before you can cancle a game...
\n";
+ echo "You need to wait longer before you can cancel a game...
\n";
+ }
+/* send out a reminder */
+else if(myisset("remind","me"))
+ {
+ output_status();
+
+ $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.
";
+ }
+ }
+ else
+ echo "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.\n";
output_footer();
DB_close();
exit();
- }
-/* user status page */
+ }
+/* user status page */
else if( myisset("email","password") || isset($_SESSION["name"]) )
{
/* test id and password, should really be done in one step */
@@ -1569,7 +1946,7 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
$email = DB_get_email_by_name($name);
$password = DB_get_passwd_by_name($name);
};
-
+
if(myisset("forgot"))
{
$ok = 1;
@@ -1577,12 +1954,12 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
$myid = DB_get_userid_by_email($email);
if(!$myid)
$ok = 0;
-
+
if($ok)
{
/* check how many entries in recovery table */
$number = DB_get_number_of_passwords_recovery($myid);
-
+
/* if less than N recent ones, add a new one and send out email */
if( $number < 5 )
{
@@ -1591,12 +1968,12 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
echo "N.B. You tried this already $number times during the last day and it will only work ".
" 5 times during a day.";
echo "
These are all your games:
\n";
echo "
Session:
\n";
echo " p = pre-game phase ";
echo "P = game in progess ";
echo "F = game finished
";
echo "
\n";
-
+
$output = array();
$result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date,Game.player,Game.status from Hand".
" LEFT JOIN Game ON Game.id=Hand.game_id".
@@ -1748,14 +2127,14 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
}
if($r[4]=='pre')
{
- echo "\n
p ";
+ echo "\n
p ";
}
else if ($r[4]=='gameover')
- echo "\n
F ";
+ echo "\n
F ";
else
{
- echo "\n
P ";
+ echo "\n
P ";
}
if($r[4] != 'gameover')
{
@@ -1767,12 +2146,17 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
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 " The game has been running for over a month.".
- " Do you want to cancel it?
yes".
+ echo "".
+ "
Cancel?".
" (clicking here is final and can't be restored)";
}
@@ -1781,12 +2165,12 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
$names = DB_get_all_names();
echo "
Registered players:
\n
\n";
echo implode(", ",$names)."\n";
- echo "
\n";
+ echo "\n
";
}
}
else
{
- echo "Sorry email and password don't match. Please