X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=index.php;h=eb52e4e1d2826467f74476a3ade6cd9c10d0ebf2;hp=95ccfcfa3da68cd614e074c46d60bc343909a7ca;hb=2264646817a59a6e3aefa835c492938dde4f25ee;hpb=330c4ad8114934ccd906eee471c9986e27549c47
diff --git a/index.php b/index.php
index 95ccfcf..eb52e4e 100644
--- a/index.php
+++ b/index.php
@@ -1,37 +1,55 @@
You are now logged out!
\n".
+ "(This will take you back to the home-page)";
+ }
+else if(myisset("new"))
{
- $names = DB_get_all_names();
- output_form_for_new_game($names);
+ 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,'1','pre',".
+ 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("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre',".
- "'$ruleset','$max' ,NULL)");
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
- mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre', ".
- "'$ruleset',NULL ,NULL)");
+ {
+ /* 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 */
- $hashA = md5("AGameOfDoko".$game_id.$PlayerA.$EmailA);
- $hashB = md5("AGameOfDoko".$game_id.$PlayerB.$EmailB);
- $hashC = md5("AGameOfDoko".$game_id.$PlayerC.$EmailC);
- $hashD = md5("AGameOfDoko".$game_id.$PlayerD.$EmailD);
-
+ $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,'false','false',NULL)");
- $hand_idA = mysql_insert_id();
+ ", ".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,'false','false',NULL)");
- $hand_idB = mysql_insert_id();
+ ", ".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,'false','false',NULL)");
- $hand_idC = mysql_insert_id();
+ ", ".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,'false','false',NULL)");
+ ", ".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')");
@@ -126,7 +170,7 @@ 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".
@@ -138,117 +182,177 @@ 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 */
-else if(myisset("cancle","me"))
+/* cancel a game, if nothing has happend in the last N minutes */
+else if(myisset("cancel","me"))
{
- /* cancle a game, if it is older than N minutes */
-
+ 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 $gameid has been cancled.
";
+
+ echo "Game ".DB_format_gameid($gameid).
+ " has been canceled.
";
+ }
+ else
+ 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 cancle a game...
\n";
+ 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"))
{
- /* handle request from one specific player,
- * the hash is set on a per game base
- */
-
$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";
- $result = mysql_query("SELECT * FROM Rulesets LEFT JOIN Game ON Game.ruleset=Rulesets.id WHERE Game.id='$gameid'" );
+ /* get rule set for this game */
+ $result = mysql_query("SELECT * FROM Rulesets".
+ " LEFT JOIN Game ON Game.ruleset=Rulesets.id ".
+ " WHERE Game.id='$gameid'" );
$r = mysql_fetch_array($result,MYSQL_NUM);
- $RULES["dullen"]=$r[2];
- $RULES["schweinchen"]=$r[3];
-
+ $RULES["dullen"] = $r[2];
+ $RULES["schweinchen"] = $r[3];
+ $RULES["call"] = $r[4];
+
/* get some infos about the game */
- $gametype = DB_get_gametype_by_gameid($gameid);
+ $gametype = DB_get_gametype_by_gameid($gameid);
$gamestatus = DB_get_game_status_by_gameid($gameid);
- $GT = $gametype;
+ $GT = $gametype;
if($gametype=="solo")
{
$gametype = DB_get_solo_by_gameid($gameid);
- $GT = $gametype." ".$GT;
+ $GT = $gametype." ".$GT;
}
- else
- $gametype="normal";
-
- if($gamestatus != 'pre')
- echo " Gametype: $GT
\n";
-
- echo "Rules:
\n";
- echo "10ofhearts : ".$r[2]."
\n";
- echo "schweinchen: ".$r[3]."
\n";
- echo "
\n";
-
+
/* does anyone have both foxes */
- $GAME["schweinchen"]=0;
+ $GAME["schweinchen"]=0;
for($i=1;$i<5;$i++)
{
$hash = DB_get_hash_from_game_and_pos($gameid,$i);
@@ -260,6 +364,32 @@ else if(myisset("me"))
}
};
+ /* put everyting in a form */
+ echo "\n";
output_footer();
- exit();
- }
-/* user status page */
- else if(myisset("email","password"))
+ DB_close();
+ exit();
+ }
+/* user status page */
+else if( myisset("email","password") || isset($_SESSION["name"]) )
{
/* test id and password, should really be done in one step */
- $email = $_REQUEST["email"];
- $password = $_REQUEST["password"];
-
- if(strlen($password)!=32)
- $password = md5($password);
-
- $ok=1;
- $uid = DB_get_userid_by_email_and_password($email,$password);
- if(!$uid)
- $ok=0;
-
- if($ok)
+ if(!isset($_SESSION["name"]))
{
- $time = DB_get_user_timestamp($uid);
- $unixtime =strtotime($time);
-
- $offset = DB_get_user_timezone($uid);
- $zone = return_timezone($offset);
- date_default_timezone_set($zone);
-
- echo "last login: ".date("r",$unixtime)."