CLEANUP: cleaned up index.php a bit more by introducing an 'action' variable
authorArun Persaud <arun@nubati.net>
Sat, 26 Apr 2008 20:01:41 +0000 (13:01 -0700)
committerArun Persaud <arun@nubati.net>
Sat, 26 Apr 2008 20:01:41 +0000 (13:01 -0700)
no more if, but one nice switch statement in index.php
Signed-off-by: Arun Persaud <arun@nubati.net>
include/cancelgame.php
include/functions.php
include/game.php
include/login.php [new file with mode: 0644]
include/logout.php
include/newgame.php
include/newgameready.php [deleted file]
include/output.php
include/reminder.php
include/user.php
index.php

index 9f86142d66c0ec9b99227afd0e1fba70610fc57e..fba950ee7a20934306626f44599835ae063ec3e1 100644 (file)
@@ -7,6 +7,14 @@ if(!isset($HOST))
 
 output_status();
 
 
 output_status();
 
+if(!myisset("me"))
+  {
+    echo "Hmm, you really shouldn't mess with the urls.<br />\n";
+    output_footer();
+    DB_close();
+    exit();
+  }
+
 $me = $_REQUEST["me"];
 
 /* test for valid ID */
 $me = $_REQUEST["me"];
 
 /* test for valid ID */
index 991d53d1889abc50bc06a1022fa3564a8cbed38c..28e5937c5a1259f5c9841fcf16f8aa1ef2967789 100644 (file)
@@ -700,7 +700,7 @@ function display_table ()
       if(!$debug)
        echo "   $name \n";
       else
       if(!$debug)
        echo "   $name \n";
       else
-       echo "   <a href=\"".$INDEX."?me=".$hash."\">$name</a>\n";
+       echo "   <a href=\"".$INDEX."?action=game&me=".$hash."\">$name</a>\n";
 
       /* add hints for poverty, wedding, solo, etc */
       if($GT=="poverty" && $party=="re")
 
       /* add hints for poverty, wedding, solo, etc */
       if($GT=="poverty" && $party=="re")
@@ -823,10 +823,10 @@ function display_user_menu()
 
   while( $r = mysql_fetch_array($result,MYSQL_NUM))
     {
 
   while( $r = mysql_fetch_array($result,MYSQL_NUM))
     {
-      echo "<a href=\"".$INDEX."?me=".$r[0]."\">game ".DB_format_gameid($r[1])." </a><br />\n";
+      echo "<a href=\"".$INDEX."?action=game&me=".$r[0]."\">game ".DB_format_gameid($r[1])." </a><br />\n";
     }
 
     }
 
-  echo "<hr /> <a href=\"".$INDEX."?new\">Start a new game</a>\n";
+  echo "<hr /> <a href=\"".$INDEX."?action=new\">Start a new game</a>\n";
 
   echo "<hr /> <a href=\"".$STATS."\">Statistics</a>\n";
 
 
   echo "<hr /> <a href=\"".$STATS."\">Statistics</a>\n";
 
index 0e16292abd5fb4459152e7b507531260ff21d4f6..51d4320dfaa578315a21d32f42cb5eb51eb47b00 100644 (file)
@@ -5,6 +5,14 @@
 if(!isset($HOST))
   exit;
 
 if(!isset($HOST))
   exit;
 
+if(!myisset("me"))
+  {
+    echo "Hmm, you really shouldn't mess with the urls.<br />\n";
+    output_footer();
+    DB_close();
+    exit();
+  }
+
 $me = $_REQUEST["me"];
 
 /* test for valid ID */
 $me = $_REQUEST["me"];
 
 /* test for valid ID */
@@ -70,7 +78,7 @@ for($i=1;$i<5;$i++)
   };
 
 /* put everyting in a form */
   };
 
 /* put everyting in a form */
-echo "<form action=\"index.php?me=$me\" method=\"post\">\n";
+echo "<form action=\"index.php?action=game&me=$me\" method=\"post\">\n";
 
 /* output game */
 
 
 /* output game */
 
@@ -86,7 +94,7 @@ if($session)
        if($hash == $me)
          echo "$i \n";
        else
        if($hash == $me)
          echo "$i \n";
        else
-         echo "<a href=\"".$INDEX."?me=".$hash."\">$i</a> \n";
+         echo "<a href=\"".$INDEX."?action=game&me=".$hash."\">$i</a> \n";
        $i++;
       }
     echo "</div>\n";
        $i++;
       }
     echo "</div>\n";
@@ -174,7 +182,7 @@ switch($mystatus)
                     DB_set_player_by_gameid($gameid,$who);
 
                     $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
                     DB_set_player_by_gameid($gameid,$who);
 
                     $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
-                    "Use this link to go the game: ".$HOST.$INDEX."?me=".$hash."\n\n" ;
+                    "Use this link to go the game: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
                     mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
                    */
                  }
                     mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
                    */
                  }
@@ -208,7 +216,7 @@ switch($mystatus)
         * unless a user tries to cheat ;)
         * can also happen if user reloads the page!
         */
         * unless a user tries to cheat ;)
         * can also happen if user reloads the page!
         */
-       echo "<p class=\"message\"> You need to answer the <a href=\"$INDEX?me=$me&in=yes\">questions</a>.</p>";
+       echo "<p class=\"message\"> You need to answer the <a href=\"$INDEX?action=game&me=$me&in=yes\">questions</a>.</p>";
        DB_set_hand_status_by_hash($me,'init');
       }
     else
        DB_set_hand_status_by_hash($me,'init');
       }
     else
@@ -223,7 +231,7 @@ switch($mystatus)
        if($Nvorbehalt>1)
          {
            echo "<p class=\"message\"> You selected more than one vorbehalt, please go back ".
        if($Nvorbehalt>1)
          {
            echo "<p class=\"message\"> You selected more than one vorbehalt, please go back ".
-             "and answer the <a href=\"$INDEX?me=$me&in=yes\">question</a> again.</p>";
+             "and answer the <a href=\"$INDEX?action=game&me=$me&in=yes\">question</a> again.</p>";
            DB_set_hand_status_by_hash($me,'init');
          }
        else
            DB_set_hand_status_by_hash($me,'init');
          }
        else
@@ -274,7 +282,7 @@ switch($mystatus)
                DB_set_sickness_by_hash($me,"nines");
              }
 
                DB_set_sickness_by_hash($me,"nines");
              }
 
-           echo " Ok, done with checking, please go to the <a href=\"$INDEX?me=$me\">next step of the setup</a>.</p>";
+           echo " Ok, done with checking, please go to the <a href=\"$INDEX?action=game&me=$me\">next step of the setup</a>.</p>";
 
            /* move on to the next stage*/
            DB_set_hand_status_by_hash($me,'poverty');
 
            /* move on to the next stage*/
            DB_set_hand_status_by_hash($me,'poverty');
@@ -304,7 +312,7 @@ switch($mystatus)
                      {
                        $message = "Everyone finish the questionary in game ".DB_format_gameid($gameid).", ".
                          "please visit this link now to continue: \n".
                      {
                        $message = "Everyone finish the questionary in game ".DB_format_gameid($gameid).", ".
                          "please visit this link now to continue: \n".
-                         " ".$HOST.$INDEX."?me=".$userhash."\n\n" ;
+                         " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
                        mymail($To,$EmailName." finished setup in game ".DB_format_gameid($gameid),$message);
                      }
                  };
                        mymail($To,$EmailName." finished setup in game ".DB_format_gameid($gameid),$message);
                      }
                  };
@@ -513,7 +521,7 @@ switch($mystatus)
              DB_set_party_by_hash($me,"contra");
 
            echo "Whoever will make the first trick will be on the re team. <br />\n";
              DB_set_party_by_hash($me,"contra");
 
            echo "Whoever will make the first trick will be on the re team. <br />\n";
-           echo " Ok, the game can start now, please finish <a href=\"$INDEX?me=$me\">the setup</a>.<br />";
+           echo " Ok, the game can start now, please finish <a href=\"$INDEX?action=game&me=$me\">the setup</a>.<br />";
            DB_set_hand_status_by_hash($me,'play');
            break;
 
            DB_set_hand_status_by_hash($me,'play');
            break;
 
@@ -576,7 +584,7 @@ switch($mystatus)
                    DB_set_player_by_gameid($gameid,$userid);
 
                    $message = "Someone has poverty, it's your turn to decide, if you want to take the trump. Please visit:".
                    DB_set_player_by_gameid($gameid,$userid);
 
                    $message = "Someone has poverty, it's your turn to decide, if you want to take the trump. Please visit:".
-                     " ".$HOST.$INDEX."?me=".$userhash."\n\n" ;
+                     " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
                    mymail($To,$EmailName." poverty (game ".DB_format_gameid($gameid).")",$message);
                  }
 
                    mymail($To,$EmailName." poverty (game ".DB_format_gameid($gameid).")",$message);
                  }
 
@@ -658,7 +666,7 @@ switch($mystatus)
 
                            $message = "Someone has poverty, it's your turn to decide, ".
                              "if you want to take the trump. Please visit:".
 
                            $message = "Someone has poverty, it's your turn to decide, ".
                              "if you want to take the trump. Please visit:".
-                             " ".$HOST.$INDEX."?me=".$userhash."\n\n" ;
+                             " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
                            mymail($To,$EmailName." poverty (game ".DB_format_gameid($gameid).")",$message);
                          }
                      }
                            mymail($To,$EmailName." poverty (game ".DB_format_gameid($gameid).")",$message);
                          }
                      }
@@ -732,10 +740,10 @@ switch($mystatus)
                        /* count trump */
                        if($nrtrump<4)
                          echo "Player $name has $nrtrump trump. Do you want to take them?".
                        /* count trump */
                        if($nrtrump<4)
                          echo "Player $name has $nrtrump trump. Do you want to take them?".
-                           "<a href=\"index.php?me=$me&amp;trump=$user\">yes</a> <br />\n";
+                           "<a href=\"index.php?action=game&me=$me&amp;trump=$user\">yes</a> <br />\n";
                      }
                  }
                      }
                  }
-               echo "<a href=\"index.php?me=$me&amp;trump=no\">No,way I take those trump...</a> <br />\n";
+               echo "<a href=\"index.php?action=game&me=$me&amp;trump=no\">No,way I take those trump...</a> <br />\n";
                echo "</div><div>\n";
 
                echo "Your cards are: <br />\n";
                echo "</div><div>\n";
 
                echo "Your cards are: <br />\n";
@@ -803,11 +811,11 @@ switch($mystatus)
              {
                /* email startplayer) */
                $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
              {
                /* email startplayer) */
                $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
-                 "Use this link to play a card: ".$HOST.$INDEX."?me=".$hash."\n\n" ;
+                 "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
                mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
              }
            else
                mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
              }
            else
-             echo " Please, <a href=\"$INDEX?me=$me\">start</a> the game.<br />";
+             echo " Please, <a href=\"$INDEX?action=game&me=$me\">start</a> the game.<br />";
          }
        else
          echo "\n <br />";
          }
        else
          echo "\n <br />";
@@ -1260,7 +1268,7 @@ switch($mystatus)
 
                $message = "A card has been played in game ".DB_format_gameid($gameid).".\n\n".
                  "It's your turn  now.\n".
 
                $message = "A card has been played in game ".DB_format_gameid($gameid).".\n\n".
                  "It's your turn  now.\n".
-                 "Use this link to play a card: ".$HOST.$INDEX."?me=".$next_hash."\n\n" ;
+                 "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$next_hash."\n\n" ;
                if( DB_get_email_pref_by_uid($who)!="emailaddict" )
                  mymail($email,$EmailName."a card has been played in game ".DB_format_gameid($gameid),$message);
              }
                if( DB_get_email_pref_by_uid($who)!="emailaddict" )
                  mymail($email,$EmailName."a card has been played in game ".DB_format_gameid($gameid),$message);
              }
@@ -1526,7 +1534,7 @@ switch($mystatus)
                      $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
 
                      $link = "Use this link to have a look at game ".DB_format_gameid($gameid).": ".
                      $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
 
                      $link = "Use this link to have a look at game ".DB_format_gameid($gameid).": ".
-                       $HOST.$INDEX."?me=".$hash."\n\n" ;
+                       $HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
                      if( DB_get_email_pref_by_uid($user) != "emailaddict" )
                        mymail($To,$EmailName."game over (game ".DB_format_gameid($gameid).") part 2(2)",$link);
                    }
                      if( DB_get_email_pref_by_uid($user) != "emailaddict" )
                        mymail($To,$EmailName."game over (game ".DB_format_gameid($gameid).") part 2(2)",$link);
                    }
diff --git a/include/login.php b/include/login.php
new file mode 100644 (file)
index 0000000..346c71e
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+/* make sure that we are not called from outside the scripts, 
+ * use a variable defined in config.php to check this
+ */
+if(!isset($HOST))
+  exit;
+
+if(!myisset("email","password"))
+  {
+    "can't log you in";
+  }
+else
+  {
+    $email     = $_REQUEST["email"];
+    $password  = $_REQUEST["password"];
+
+    /* verify password and email */
+    if(strlen($password)!=32)
+      $password = md5($password);
+    
+    $ok  = 1;
+    $myid = DB_get_userid('email-password',$email,$password);
+    if(!$myid)
+      $ok = 0;
+    
+    if($ok)
+      {
+       /* user information is ok */
+       $myname = DB_get_name('email',$email);
+       $_SESSION["name"] = $myname;
+      }
+  }
+?>
\ No newline at end of file
index d74f0919e1929f56f413e6e71f34965fff8c3622..f2ebbaf00199c43842624d6d94810817cd94d8bd 100644 (file)
@@ -10,6 +10,4 @@ session_unset();
 session_destroy();
 $_SESSION = array();
     
 session_destroy();
 $_SESSION = array();
     
-echo "<div class=\"message\"><span class=\"bigger\">You are now logged out!</span><br />\n".
-"(<a href=\"$INDEX\">This will take you back to the home-page</a>)</div>";
 ?>
\ No newline at end of file
 ?>
\ No newline at end of file
index 5764568cefb7785295834645bf33b57da16189f3..5db0f2823300719ef22d54f178ba2a848b3da716 100644 (file)
@@ -7,16 +7,180 @@ if(!isset($HOST))
 
 output_status();
 /* user needs to be logged in to do this */
 
 output_status();
 /* user needs to be logged in to do this */
-if( isset($_SESSION["name"]) )
+if(! isset($_SESSION["name"]) )
   {
   {
-    $names = DB_get_all_names();
-    echo "<div class=\"user\">\n";
-    output_form_for_new_game($names);
-    echo "</div>\n";
-    display_user_menu();
+    echo "<div class=\"message\">Please <a href=\"$INDEX\">log in</a>.</div>";
   }
   }
- else
-   {
-     echo "<div class=\"message\">Please <a href=\"$INDEX\">log in</a>.</div>";
-   }
-?>
\ No newline at end of file
+else
+  {
+    if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","callrule" ))
+      {
+       /* get my name */
+       $name = $_SESSION["name"];
+       
+       /* the names of the four players */
+       $PlayerA = $_REQUEST["PlayerA"];
+       $PlayerB = $_REQUEST["PlayerB"];
+       $PlayerC = $_REQUEST["PlayerC"];
+       $PlayerD = $_REQUEST["PlayerD"];
+       
+       /* the person who sets up the game has to be one of the players */
+       if(!in_array($name,array($PlayerA,$PlayerB,$PlayerC,$PlayerD)))
+         {
+           echo "<div class=\"message\">You need to be one of the players to start a <a href=\"$INDEX?action=new\">new game</a>.</div>";
+           output_footer();
+           DB_close();
+           exit();
+         }
+       
+       /* what rules were selected */
+       $dullen      = $_REQUEST["dullen"];
+       $schweinchen = $_REQUEST["schweinchen"];
+       $call        = $_REQUEST["callrule"];
+       
+       /* get the emails addresses of the players */
+       $EmailA  = DB_get_email('name',$PlayerA);
+       $EmailB  = DB_get_email('name',$PlayerB);
+       $EmailC  = DB_get_email('name',$PlayerC);
+       $EmailD  = DB_get_email('name',$PlayerD);
+       
+       /* this is used to check if the player names are all ok */
+       if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="")
+         {
+           echo "couldn't find one of the names, please start a new game";
+           output_footer();
+           DB_close();
+           exit();
+         }
+       
+       /* get user ids */
+       $useridA  = DB_get_userid('name',$PlayerA);
+       $useridB  = DB_get_userid('name',$PlayerB);
+       $useridC  = DB_get_userid('name',$PlayerC);
+       $useridD  = DB_get_userid('name',$PlayerD);
+       
+       /* create random numbers */
+       $randomNR       = create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD);
+       $randomNRstring = join(":",$randomNR);
+       
+       /* create game */
+       $followup = NULL;
+       /* is this game a follow up in an already started session? */
+       if(myisset("followup") )
+         {
+           $followup= $_REQUEST["followup"];
+           $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)");
+           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."?action=game&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 "<div class=\"message\">You started a new game. The emails have been sent out!</div>\n";
+      }
+    else
+      {
+       $names = DB_get_all_names();
+       echo "<div class=\"user\">\n";
+       output_form_for_new_game($names);
+       echo "</div>\n";
+       display_user_menu();
+      }
+  }
+
+?>
diff --git a/include/newgameready.php b/include/newgameready.php
deleted file mode 100644 (file)
index 6d74af0..0000000
+++ /dev/null
@@ -1,175 +0,0 @@
-<?php
-/* make sure that we are not called from outside the scripts, 
- * use a variable defined in config.php to check this
- */
-if(!isset($HOST))
-  exit;
-
-output_status();
-/* user needs to be logged in */
-if( !isset($_SESSION["name"]) )
-  {
-    echo "<div class=\"message\">Please <a href=\"$INDEX\">log in</a>.</div>";
-  }
- else
-   {
-     /* get my name */
-     $name = $_SESSION["name"];
-
-     /* the names of the four players */
-     $PlayerA = $_REQUEST["PlayerA"];
-     $PlayerB = $_REQUEST["PlayerB"];
-     $PlayerC = $_REQUEST["PlayerC"];
-     $PlayerD = $_REQUEST["PlayerD"];
-
-     /* the person who sets up the game has to be one of the players */
-     if(!in_array($name,array($PlayerA,$PlayerB,$PlayerC,$PlayerD)))
-       {
-        echo "<div class=\"message\">You need to be one of the players to start a <a href=\"$INDEX?new\">new game</a>.</div>";
-        output_footer();
-        DB_close();
-        exit();
-       }
-       
-     /* what rules were selected */
-     $dullen      = $_REQUEST["dullen"];
-     $schweinchen = $_REQUEST["schweinchen"];
-     $call        = $_REQUEST["callrule"];
-
-     /* get the emails addresses of the players */
-     $EmailA  = DB_get_email('name',$PlayerA);
-     $EmailB  = DB_get_email('name',$PlayerB);
-     $EmailC  = DB_get_email('name',$PlayerC);
-     $EmailD  = DB_get_email('name',$PlayerD);
-
-     /* this is used to check if the player names are all ok */
-     if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="")
-       {
-        echo "couldn't find one of the names, please start a new game";
-        output_footer();
-        DB_close();
-        exit();
-       }
-
-     /* get user ids */
-     $useridA  = DB_get_userid('name',$PlayerA);
-     $useridB  = DB_get_userid('name',$PlayerB);
-     $useridC  = DB_get_userid('name',$PlayerC);
-     $useridD  = DB_get_userid('name',$PlayerD);
-
-     /* create random numbers */
-     $randomNR       = create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD);
-     $randomNRstring = join(":",$randomNR);
-
-     /* create game */
-     $followup = NULL;
-     /* is this game a follow up in an already started session? */
-     if(myisset("followup") )
-       {
-        $followup= $_REQUEST["followup"];
-        $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)");
-        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 "<div class=\"message\">You started a new game. The emails have been sent out!</div>\n";
-   }
-/* end set up a new game */
-?>
\ No newline at end of file
index 16376031c8d94a6f61f1e6de92ab405d97a9138e..b22b6efd577f4304882da686fb3d8fe9bcac4ad7 100644 (file)
@@ -56,7 +56,7 @@ function output_form_for_new_game($names)
     <h2> Players </h2>
     <p>Please select four players (or use the randomly pre-selected names)</p>
     <p>Remember: you need to be one of the players ;) </p>
     <h2> Players </h2>
     <p>Please select four players (or use the randomly pre-selected names)</p>
     <p>Remember: you need to be one of the players ;) </p>
-       <form action="index.php" method="post">
+       <form action="index.php?action=new" method="post">
 
    <div class="table">
      <img src="pics/table.png" alt="table" />
 
    <div class="table">
      <img src="pics/table.png" alt="table" />
@@ -278,7 +278,7 @@ function output_home_page($pre,$game,$done,$avgtime)
     <p> Please <a href="./register.php">register</a>, in case you have not done that yet  <br />
         or login with you email-address or name and password here:
     </p>
     <p> Please <a href="./register.php">register</a>, in case you have not done that yet  <br />
         or login with you email-address or name and password here:
     </p>
-        <form action="index.php" method="post">
+        <form action="index.php?action=login" method="post">
           <fieldset>
             <legend>Login</legend>
              <table>
           <fieldset>
             <legend>Login</legend>
              <table>
@@ -383,7 +383,7 @@ function output_status()
        /* logout info */
        echo "\n<div class=\"status\">";
        echo $name;
        /* logout info */
        echo "\n<div class=\"status\">";
        echo $name;
-       echo " <a href=\"index.php?logout=1\">logout</a>";
+       echo " <a href=\"index.php?action=logout\">logout</a>";
        echo "</div>\n";
 
        /* last logon time */
        echo "</div>\n";
 
        /* last logon time */
index 1e3135c66e0c153e3ab7f6664a67d7a0f8be23a6..a269478b5085d0856f781d7abd38c6612eb1db22 100644 (file)
@@ -7,6 +7,14 @@ if(!isset($HOST))
 
 output_status();
 
 
 output_status();
 
+if(!myisset("me"))
+  {
+    echo "Hmm, you really shouldn't mess with the urls.<br />\n";
+    output_footer();
+    DB_close();
+    exit();
+  }
+
 $me = $_REQUEST["me"];
 
 /* test for valid ID */
 $me = $_REQUEST["me"];
 
 /* test for valid ID */
@@ -39,7 +47,7 @@ if( (time()-strtotime($r[0]) > 60*60*24*7)  && ($r[2]!='gameover') ) /* = 1 week
       "It's your turn in game ".DB_format_gameid($gameid)." \n".
       "Actually everyone else is waiting for you for more than a week now ;)\n\n".
       "Please visit this link now to continue: \n".
       "It's your turn in game ".DB_format_gameid($gameid)." \n".
       "Actually everyone else is waiting for you for more than a week now ;)\n\n".
       "Please visit this link now to continue: \n".
-      " ".$HOST.$INDEX."?me=".$userhash."\n\n" ;
+      " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
 
     /* make sure we don't send too  many reminders to one person */
     if(DB_get_reminder($r[1],$gameid)>0)
 
     /* make sure we don't send too  many reminders to one person */
     if(DB_get_reminder($r[1],$gameid)>0)
index 0f67a68f9791ff9f7fc418421d46817dbc12494d..8feac019ec73fb2411a79b6a7503c7848e8a071d 100644 (file)
@@ -212,14 +212,14 @@ if(myisset("forgot"))
                   }
                 if($r[4]=='pre')
                   {
                   }
                 if($r[4]=='pre')
                   {
-                    echo "\n   <span class=\"gamestatuspre\"><a href=\"".$INDEX."?me=".$r[0]."\">p </a></span> ";
+                    echo "\n   <span class=\"gamestatuspre\"><a href=\"".$INDEX."?action=game&me=".$r[0]."\">p </a></span> ";
 
                   }
                 else if ($r[4]=='gameover')
 
                   }
                 else if ($r[4]=='gameover')
-                  echo "\n   <span class=\"gamestatusover\"><a href=\"".$INDEX."?me=".$r[0]."\">F </a></span> ";
+                  echo "\n   <span class=\"gamestatusover\"><a href=\"".$INDEX."?action=game&me=".$r[0]."\">F </a></span> ";
                 else
                   {
                 else
                   {
-                    echo "\n   <span class=\"gamestatusplay\"><a href=\"".$INDEX."?me=".$r[0]."\">P </a></span> ";
+                    echo "\n   <span class=\"gamestatusplay\"><a href=\"".$INDEX."?action=game&me=".$r[0]."\">P </a></span> ";
                   }
                 if($r[4] != 'gameover')
                   {
                   }
                 if($r[4] != 'gameover')
                   {
@@ -233,12 +233,12 @@ if(myisset("forgot"))
                         if(DB_get_reminder($r[3],$gameid)==0)
                           if(time()-strtotime($r[2]) > 60*60*24*7)
                             echo "".
                         if(DB_get_reminder($r[3],$gameid)==0)
                           if(time()-strtotime($r[2]) > 60*60*24*7)
                             echo "".
-                              "<a href=\"$INDEX?remind=1&amp;me=".$r[0]."\">Send a reminder.</a>";
+                              "<a href=\"$INDEX?action=reminder&amp;me=".$r[0]."\">Send a reminder.</a>";
                         echo "(it's $name's turn)\n";
                       };
                     if(time()-strtotime($r[2]) > 60*60*24*30)
                       echo "".
                         echo "(it's $name's turn)\n";
                       };
                     if(time()-strtotime($r[2]) > 60*60*24*30)
                       echo "".
-                        "<a href=\"$INDEX?cancel=1&amp;me=".$r[0]."\">Cancel?</a>".
+                        "<a href=\"$INDEX?action=cancel&amp;me=".$r[0]."\">Cancel?</a>".
                         " (clicking here is final and can't be restored)";
 
                   }
                         " (clicking here is final and can't be restored)";
 
                   }
index 54e2cb785c5e0297144d120b12e44a78dcdc0dad..31c497a74515f7e3ef7c4d89f6786f67cf69f17b 100644 (file)
--- a/index.php
+++ b/index.php
@@ -31,51 +31,41 @@ output_header();
 
 /* The rest of the file consists of handling user input.
  * The user sends information via html GET and POST variables,
 
 /* The rest of the file consists of handling user input.
  * The user sends information via html GET and POST variables,
- * the script checks if these are set via "myisset"
- * which can check a list of variables.
+ * and the action variable tells the prog what the user wants to do
  */
  */
+if(myisset("action"))
+  $action=$_REQUEST['action'];
+else
+  $action=""; /* so that we can use a default option below */
 
 
-/* does the user want to log out? */
-if(myisset("logout"))
-  {
-    require './include/logout.php';
-  }
-/* check if we want to start a new game */
-else if(myisset("new"))
+switch($action)
   {
   {
+  case 'new':
     require './include/newgame.php';
     require './include/newgame.php';
-  }
-/*check if everything is ready to set up a new game */
-else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","callrule" ))
-  {
-    require './include/newgameready.php';
-  }    
-/* cancel a game, if nothing has happend in the last N minutes */
-else if(myisset("cancel","me"))
-  {
+    break;
+  case 'cancel':
     require './include/cancelgame.php';
     require './include/cancelgame.php';
-  }
-/* send out a reminder */
-else if(myisset("remind","me"))
-  {
+    break;
+  case 'reminder':
     require './include/reminder.php';
     require './include/reminder.php';
-  }
-/* handle request from one specific player for one game,
- * (the hash is set on a per game base) */
-else if(myisset("me"))
-  {
+    break;
+  case 'logout':
+    require './include/logout.php'; 
+    require './include/welcome.php';
+    break;
+  case 'login':
+    require './include/login.php'; 
+    require './include/user.php';
+    break;
+  case 'game':
     require './include/game.php';
     require './include/game.php';
- }
-/* user status page */
-else if( myisset("email","password") || isset($_SESSION["name"]) )
-   {
-     require './include/user.php';
-   }
-/* default login page */
- else
-   {
-     require './include/welcome.php';
-   }
+    break;
+  default:
+    if(isset($_SESSION["name"]))
+      require './include/user.php';
+    else
+      require './include/welcome.php';
+  }
 
 output_footer();
 
 
 output_footer();