X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=index.php;h=77c2c2270b739ead0ee4e0d0be7932ddd4f8033c;hp=c8c88041558c6b2e14903b5cd599ffb4b7155a83;hb=19f70fcd8c26c4a6279addcf8c29fba8f21e13da;hpb=d7c42361bda4c64a0594a8640156a504fc334f11 diff --git a/index.php b/index.php index c8c8804..77c2c22 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)"); @@ -95,40 +119,43 @@ 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(); 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',NULL ,NULL)"); + "'$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')"); @@ -138,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". @@ -151,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) @@ -174,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); @@ -187,29 +214,84 @@ else if(myisset("cancle","me")) if(time()-strtotime($r[0]) > 60*60*24*30) /* = 1 month */ { $message = "Hello, \n\n". - "Game $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 $gameid cancled (timed out)",$message); + mymail($To,$EmailName."game ".DB_format_gameid($gameid)." cancled (timed out)",$message); } - + /* delete everything from the dB */ DB_cancel_game($me); - - echo "Game $gameid has been cancled.
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) @@ -226,7 +308,7 @@ else if(myisset("me")) /* the user had done something, update the timestamp */ 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); @@ -238,7 +320,7 @@ else if(myisset("me")) /* get prefs and save them */ DB_get_PREF($myid); /* end set pref */ - + /* get rule set for this game */ $result = mysql_query("SELECT * FROM Rulesets". " LEFT JOIN Game ON Game.ruleset=Rulesets.id ". @@ -258,9 +340,9 @@ else if(myisset("me")) $gametype = DB_get_solo_by_gameid($gameid); $GT = $gametype." ".$GT; } - + /* 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); @@ -275,63 +357,6 @@ else if(myisset("me")) /* put everyting in a form */ echo "\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 */ @@ -1559,20 +1822,20 @@ 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; - $uid = DB_get_userid_by_email($email); - if(!$uid) + $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($uid); - + $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 ) { @@ -1582,11 +1845,11 @@ else if( myisset("email","password") || isset($_SESSION["name"]) ) " 5 times during a day.These are your games that haven't started yet:
\n";
- $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date,Game.player from Hand".
- " LEFT JOIN Game On Hand.game_id=Game.id".
- " WHERE Hand.user_id='$uid' AND Game.status='pre'" );
- while( $r = mysql_fetch_array($result,MYSQL_NUM))
- {
- echo "game #".$r[1]." ";
- if($r[3]==$uid || $r[3]==NULL)
- echo "(it's your turn)\n";
- else
- {
- $name = DB_get_name_by_userid($r[3]);
- 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".
- " (clicking here is final and can't be restored)";
- echo "
";
- }
+ output_user_settings();
+
+ echo "
Session:
\n";
+ echo " p = pre-game phase ";
+ echo "P = game in progess ";
+ echo "F = game finished
";
echo "
These are the games you are playing in:
\n";
- $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.mod_date,Game.player from Hand".
- " LEFT JOIN Game On Hand.game_id=Game.id".
- " WHERE Hand.user_id='$uid' AND Game.status='play'" );
+ $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".
+ " WHERE user_id='$myid'".
+ " ORDER BY Game.session,Game.create_date" );
+ $gamenrold = -1;
+ echo "
\n"; while( $r = mysql_fetch_array($result,MYSQL_NUM)) { - echo "game #".$r[1]." "; - if($r[3]) + $game = DB_format_gameid($r[1]); + $gamenr = (int) $game; + if($gamenrold < $gamenr) { - if($r[3]==$uid) - echo "(it's your turn)\n"; + 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])
{
- $name = DB_get_name_by_userid($r[3]);
- echo "(it's $name's turn)\n";
- };
+ 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)";
+
}
- 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".
- " (clicking here is final and can't be restored)";
- echo " "; } - echo "\n"; - - - echo " And these are your games that are already done: |
Registered players:
\n";
+ echo "
\n"; echo implode(", ",$names)."\n"; - echo "
\n"; - - echo "Want to start a new game? Visit this page.
"; + echo "\n