X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=index.php;h=f0a8e7451d185a1a28e45021b574282073293040;hp=f2fa3d69d71a616b0d5cff7973b1925943257e72;hb=ad64e0259097c91f67ea896134128c6883e42900;hpb=c0e030bb5068085ef52cc8bd0c91f025fb78045e
diff --git a/index.php b/index.php
index f2fa3d6..f0a8e74 100644
--- a/index.php
+++ b/index.php
@@ -1,256 +1,329 @@
You are now logged out!
\n".
+ "(This will take you back to the home-page)";
}
+/* check if we want to start a new game */
else if(myisset("new"))
{
+ output_status();
+ /* user needs to be logged in to do this */
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)");
+ else
+ {
+ /* get max session and start a new one */
+ $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 /* no follow up, start a new session */
+ {
+ /* 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.$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!
\n";
}
- $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"))
+ /* end set up a new game */
+ }
+/* 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);
+ $myid = DB_get_userid('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);
+ $myid = DB_get_userid('hash',$me);
if(!$myid)
{
echo "Can't find you in the database, please check the url.An email has already been sent out.
\n";
@@ -259,8 +332,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.
";
+
+ echo "Game ".DB_format_gameid($gameid).
+ ": an email has been sent out.
";
}
}
else
@@ -271,36 +345,36 @@ else if(myisset("remind","me"))
else if(myisset("me"))
{
$me = $_REQUEST["me"];
-
+
/* test for valid ID */
- $myid = DB_get_userid_by_hash($me);
+ $myid = DB_get_userid('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 */
@@ -1612,23 +2112,25 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
else
{
$name = $_SESSION["name"];
- $email = DB_get_email_by_name($name);
+ $email = DB_get_email('name',$name);
$password = DB_get_passwd_by_name($name);
};
-
+
+ /* user has forgotten his password */
if(myisset("forgot"))
{
+ /* check if player is in the database */
$ok = 1;
- $myid = DB_get_userid_by_email($email);
+ $myid = DB_get_userid('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 )
{
@@ -1637,12 +2139,13 @@ 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".
@@ -1794,50 +2308,57 @@ 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')
{
echo "
\n ";
- if($r[3])
+ if($r[3]==$myid || !$r[3])
+ echo "(it's your turn)\n";
+ else
{
- 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";
- };
- }
+ $name = DB_get_name('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?".
+ "Cancel?".
" (clicking here is final and can't be restored)";
}
}
echo " | \n\n";
- $names = DB_get_all_names();
- echo "
Registered players:
\n
\n";
- echo implode(", ",$names)."\n";
+
+ /* display last 5 users that have signed up to e-DoKo */
+ $names = DB_get_names_of_new_logins(5);
+ echo "
New Players:
\n
\n";
+ echo implode(", ",$names).",...\n";
echo "
\n";
+
+ /* display last 5 users that logged on */
+ $names = DB_get_names_of_last_logins(5);
+ echo "
Players last logged in:
\n
\n";
+ echo implode(", ",$names).",...\n";
+ echo "
\n";
+
+ echo "
\n";
}
}
else
{
- echo "Sorry email and password don't match. Please