chat reset in user class
[brisk.git] / web / index_rd.php
index d91afd0..fb97713 100644 (file)
@@ -2,7 +2,10 @@
 /*
  *  brisk - index_rd.php
  *
- *  Copyright (C) 2006-2007 matteo.nastasi@milug.org
+ *  Copyright (C) 2006-2008 Matteo Nastasi
+ *                          mailto: nastasi@alternativeoutput.it 
+ *                                  matteo.nastasi@milug.org
+ *                          web: http://www.alternativeoutput.it
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  */
 
 require_once("Obj/brisk.phh");
+// require_once("Obj/proxyscan.phh");
 require_once("briskin5/Obj/briskin5.phh");
 
+// Use of proxies isn't allowed.
+// if (is_proxy()) {
+//   sleep(5);
+//   exit;
+//}
 log_load("index_rd.php");
 
 $first_loop = TRUE;
@@ -89,13 +98,14 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su
       log_auth($sess, "update lacc");
       $user->lacc = time();
 
+      log_main("pre garbage_manager TRE");
       $room->garbage_manager(FALSE);
       
       Room::save_data($room);
       $first_loop = FALSE;
     }
 
-    log_only("U");
+    log_lock("U");
     Room::unlock_data($sem);
     ignore_user_abort(FALSE);
   }
@@ -107,7 +117,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su
     // log_rd2("Postget".$proxy_step."zizi");
 
     if ($cur_step == $proxy_step) {
-      log_only2("P");
+      log_lock("P");
       return (FALSE);
     }
     else {
@@ -124,7 +134,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su
       if (($sem = Room::lock_data()) == FALSE) 
        break;
       
-      log_only("P");
+      log_lock("P");
       if (($room = &Room::load_data()) == FALSE) 
        break;
     } while (0);
@@ -173,9 +183,18 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su
       ignore_user_abort(FALSE);
     }
     else {
-      log_rd2("TRANS NON ATTIVATO");
-      Room::unlock_data($sem);
-      ignore_user_abort(FALSE);
+       log_rd2("TRANS NON ATTIVATO");
+//        ARRAY_POP DISABLED
+//        log_rd2("TRANS NON ATTIVATO, clean del comm array");
+//        while (($el = array_pop($user->comm)) != NULL) { 
+//          log_rd2("clean element [".$el."]");
+//        }
+//        //        $user->step_inc(COMM_N + 1);
+//        Room::save_data($room);
+//        //        $new_step = $user->step;
+        
+       Room::unlock_data($sem);
+       ignore_user_abort(FALSE);
     }
   }
       
@@ -183,9 +202,10 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su
     log_rd2("PRE-NEWSTAT: ".$user->stat);
 
     if ($user->stat == 'room') {
-      log_rd("roomma");
-      $ret .= show_room(&$room, &$user);
+      log_rd("roomma ".$user->step);
+      $ret .= $room->show_room($user->step, &$user);
 
+      // TODO uncomment and test
       /* NOTE the sets went common */
       $new_stat =  $user->stat;
       $new_subst = $user->subst;
@@ -222,7 +242,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su
            return (page_sync($user->sess, ($to_stat == "table" ? "briskin5/index.php" : "index.php"), $user->table, $user->table_token));
          }
          log_rd2("lost history, refresh from scratch");
-         $new_step = -1;
+          $new_step = -1;
          break;
        } 
        for ($i = $cur_step ; $i < $user->step ; $i++) {
@@ -237,13 +257,18 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su
       if ($user->the_end == TRUE) {
        log_rd2("LOGOUT BYE BYE!!");
        log_auth($user->sess, "Explicit logout.");
+
+       $user->reset();
+       /* factorized with ->reset()
        $tmp_sess = $user->sess;
        $user->sess = "";
        step_unproxy($tmp_sess);
-       
        $user->name = "";
+       while (array_pop($user->comm) != NULL); 
+       $user->step = 0;
        $user->the_end = FALSE;
-       
+       */
+
        if ($user->subst == 'sitdown') {
          log_load("ROOM WAKEUP");
          $room->room_wakeup(&$user);
@@ -311,8 +336,8 @@ for ($i = 0 ; time() < $endtime ; $i++) {
   $old_subst = $subst;
   $old_step =  $step;
   // log_rd("POST MAIN ".$step);;
-  usleep(400000);
-  if (($i % 5) == 0) {
+  usleep(200000);
+  if (($i % 10) == 0) {
     // log_rd2("TIME: ".time());
     echo '_';
     flush();