when starting a new game, games can't be selected twice anymore and are randomly...
[e-DoKo.git] / index.php
index 7996e0d2f9ef6db64e2e275b64cb653b5add3b25..216a431b50ecc11e556fedc7138c055b431c88db 100644 (file)
--- a/index.php
+++ b/index.php
@@ -63,7 +63,17 @@ else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD" ))
   if(myisset("followup") )
     {
       $followup= $_REQUEST["followup"];
-      mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre','$followup' ,NULL)");
+      $session = DB_get_session_by_gameid($followup);
+      if($session)
+       mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre','$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','$max' ,NULL)");
+         mysql_query("UPDATE Game SET session='".$max."' WHERE id=".DB_quote_smart($followup));
+       }
     }
   else
     mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,'1','pre', NULL ,NULL)");
@@ -146,7 +156,7 @@ else if(myisset("cancle","me"))
   if(time()-strtotime($r[0]) > 60*60*24*30)
     {
       $message = "Hello, \n\n".
-       "Game $gameid has been cancled because, since nothing happend for a while and $myname requested it.\n";
+       "Game $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)
@@ -772,9 +782,22 @@ else if(myisset("me"))
            while( $r = mysql_fetch_array($result,MYSQL_NUM))
              echo " FINAL SCORE: ".$r[0]." ".$r[1]."<br />";
 
-           /* suggest a new game with the same people in it, just rotated once */
-           $names = DB_get_all_names_by_gameid($gameid);
-           output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);
+
+           $session = DB_get_session_by_gameid($gameid);
+           $result  = mysql_query("SELECT id,create_date FROM Game".
+                                  " WHERE session=$session".
+                                  " ORDER BY create_date DESC".
+                                  " LIMIT 1");
+           $r=-1;
+           if($result)
+             $r = mysql_fetch_array($result,MYSQL_NUM);
+
+           if(!$session || $gameid==$r)
+             {
+               /* suggest a new game with the same people in it, just rotated once */
+               $names = DB_get_all_names_by_gameid($gameid);
+               output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);
+             }
          }
        break;
       default:
@@ -824,20 +847,19 @@ else if(myisset("me"))
        echo "</p>\n";
 
 
-       echo "<p>and these are your games that are already done:<br />\n";
+       echo "<p>and these are your games that are already done:<br />Game: \n";
        $result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status='gameover'" );
        while( $r = mysql_fetch_array($result,MYSQL_NUM))
-         echo "<a href=\"".$host."?me=".$r[0]."\">game #".$r[1]." </a><br />";
+         echo "<a href=\"".$host."?me=".$r[0]."\">#".$r[1]." </a>, ";
        echo "</p>\n";
 
        $names = DB_get_all_names();
        echo "<p>registered players:<br />\n";
        foreach ($names as $name)
-         echo "$name <br />\n";
+         echo "$name\n";
        echo "</p>\n";
 
-       echo "<p>Want to start a new game? remember 4 names from the list above and visit ".
-         "<a href=\"".$host."?new\">this page.</a></p>";
+       echo "<p>Want to start a new game? Visit <a href=\"".$host."?new\">this page.</a></p>";
       }
     else
       {