BUGFIX: no check for a followup game if someone else already started one
authorArun Persaud <arun@nubati.net>
Wed, 31 Oct 2007 09:45:28 +0000 (10:45 +0100)
committerArun Persaud <arun@nubati.net>
Wed, 31 Oct 2007 09:45:28 +0000 (10:45 +0100)
several people could start a followup game (or one person hitting reload) and several games were started. Now the prog checks if there is already an active game.

db.php
index.php

diff --git a/db.php b/db.php
index 646f0043a27b66c7facf5cc57d59ce9e2b896fa2..4afa9e1412c74b5db473fe43b69c19a1bad3fc33 100644 (file)
--- a/db.php
+++ b/db.php
@@ -939,5 +939,17 @@ function DB_set_reminder($user,$gameid)
   return 0;
 }
 
   return 0;
 }
 
+function DB_is_session_active($session)
+{
+  $queryresult = mysql_query("SELECT COUNT(*) FROM Game ".
+                            "  WHERE session=$session ".
+                            "  AND status<>'gameover' ");
+
+  $r = mysql_fetch_array($queryresult,MYSQL_NUM);
+  if($r)
+    return $r[0];
+  else
+    return -1;
+}
 
 ?>
\ No newline at end of file
 
 ?>
\ No newline at end of file
index 2a688fd1a60b60f4725e30e6ca4410c3682e2881..f6e2d571ed4bfd3bb803a2bf0c807116edc2c4cb 100644 (file)
--- a/index.php
+++ b/index.php
@@ -85,6 +85,23 @@ else if(myisset("new"))
        $session = DB_get_session_by_gameid($followup);
        $ruleset = DB_get_ruleset_by_gameid($followup); /* just copy ruleset from old game, 
                                                         this way no manipulation is possible */
        $session = DB_get_session_by_gameid($followup);
        $ruleset = DB_get_ruleset_by_gameid($followup); /* just copy ruleset from old game, 
                                                         this way no manipulation is possible */
+
+       /* check if there is a game in pre or play mode, in that case do nothing */
+       if( DB_is_session_active($session) > 0 )
+         {
+           echo "<p class=\"message\"> There is already a game going on in session $session, you can't start a new one</p>";
+           output_footer();
+           DB_close();
+           exit();
+         }
+       else if ( DB_is_session_active($session) < 0 )
+         {
+           echo "<p class=\"message\"> ERROR: status of session $session couldn't be determined.</p>";
+           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)");
        if($session)
          mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',".
                      "'$ruleset','$session' ,NULL)");