preload_images start added to first initializiation stream's data
[brisk.git] / web / briskin5 / Obj / briskin5.phh
index a9813e5..fc3a670 100644 (file)
@@ -2,7 +2,7 @@
 /*
  *  brisk - briskin5.phh
  *
- *  Copyright (C) 2006-2011 Matteo Nastasi
+ *  Copyright (C) 2006-2012 Matteo Nastasi
  *                          mailto: nastasi@alternativeoutput.it 
  *                                  matteo.nastasi@milug.org
  *                          web: http://www.alternativeoutput.it
@@ -477,13 +477,15 @@ class Bin5_user extends User {
        } 
     */
     
-    function spawn($from, &$bri, $table, $table_pos)
+    function spawn($from, &$bri, $table, $table_pos, $get, $post, $cookie)
     {
-        GLOBAL $CO_bin5_pref_ring_endauct;
-        
         if (($thiz = new Bin5_user()) == FALSE)
             return (FALSE);
-        
+
+        if (($CO_bin5_pref_ring_endauct = gpcs_var("CO_bin5_pref_ring_endauct", $get, $post, $cookie)) === FALSE) {
+            $CO_bin5_pref_ring_endauct = "";
+        }
+
         $thiz->parentcopy($from);
         
         /* NOTE: at this moment idx and table_pos fields have the same value 
@@ -498,7 +500,7 @@ class Bin5_user extends User {
         log_wr("Bin5 constructor");
         
         $this->privflags  = ($CO_bin5_pref_ring_endauct == "true" ? BIN5_USER_FLAG_RING_ENDAUCT : 0) | 0;
-        
+
         $thiz->table_orig = $table;
         $thiz->table      = 0;
         $thiz->table_pos  = $table_pos;
@@ -782,23 +784,6 @@ push(\"%s\");
         $ret = FALSE;
         $curtime = time();
         
-        /* if ((($curtime - $this->lacc) >  STREAM_TIMEOUT) || Room::garbage_time_is_expired($curtime)) { */
-        /*     $S_load_stat['lL_laccgarb']++; */
-        
-        /*     if (($curtime - $this->lacc) >=  STREAM_TIMEOUT) { */
-        /*         $S_load_stat['wU_lacc_upd']++; */
-        /*         $this->lacc = $curtime; */
-        /*     } */
-        
-        /*     if (Room::garbage_time_is_expired($curtime)) { */
-        /*         log_only("F"); */
-        
-        /*         $S_load_stat['wR_garbage']++; */
-        /*         log_main("pre garbage_manager TRE"); */
-        /*         $this->room->garbage_manager(FALSE); */
-        /*     } */
-        /* } */
-        
       /* Nothing changed, return. */
       if ($cur_step == $this->step) 
           return (FALSE);
@@ -924,7 +909,7 @@ class Bin5 {
     var $table;
     var $comm; // commands for many people
     var $step; // current step of the comm array
-    // externalized var $garbage_timeout;
+    var $garbage_timeout;
     var $shm_sz;
     
     var $table_idx;
@@ -956,7 +941,7 @@ class Bin5 {
         return TRUE;
     }
 
-    function Bin5 ($room, $table_idx, $table_token) {
+    function Bin5 ($room, $table_idx, $table_token, $get, $post, $cookie) {
         $this->user = array();
         $this->table = array();
         
@@ -974,7 +959,7 @@ class Bin5 {
         
         for ($i = 0 ; $i < $table->player_n ; $i++) {
             $user[$table->player[$i]]->table_token = $table_token;
-            $this->user[$i] = Bin5_user::spawn($user[$table->player[$i]], $this, $table_idx, $i);
+            $this->user[$i] = Bin5_user::spawn($user[$table->player[$i]], $this, $table_idx, $i, $get, $post, $cookie);
         }
         $this->table[0] = Bin5_table::spawn(&$table);
         
@@ -982,7 +967,7 @@ class Bin5 {
         
         $this->table_idx = $table_idx;
         $this->table_token = $table_token;
-        Bin5::garbage_time_expire_set($table_idx, 0);
+        $this->garbage_timeout = 0;
         
         log_wr("Bin5 constructor end");
     }
@@ -1020,8 +1005,7 @@ class Bin5 {
         /* Garbage collector degli utenti in timeout */
         $ismod = FALSE;
         $curtime = time();
-        // externalized if ($force || $this->garbage_timeout < $curtime) {
-        if ($force || Bin5::garbage_time_is_expired($this->table_idx, $curtime)) {
+        if ($force || $this->garbage_timeout < $curtime) {
             for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
                 $user_cur = $this->user[$i];
                 if ($user_cur->sess == "" || 
@@ -1059,8 +1043,7 @@ class Bin5 {
             }
             log_rd2($user_cur->sess." GARBAGE UPDATED!");
             
-            // externalized $this->garbage_timeout = $curtime + GARBAGE_TIMEOUT;
-            Bin5::garbage_time_expire_set($this->table_idx, $curtime + GARBAGE_TIMEOUT);
+            $this->garbage_timeout = $curtime + GARBAGE_TIMEOUT;
             
             $ismod = TRUE;
         }
@@ -1406,49 +1389,6 @@ class Bin5 {
         return ($is_ab);
     }
 
-
-    static function garbage_time_is_expired($tab_id, $tm) 
-    {
-        $ret = TRUE;
-        $fp = FALSE;
-        do {
-            if (file_exists(BIN5_PROXY_PATH."/table".$tab_id) == FALSE)
-                mkdir(BIN5_PROXY_PATH."/table".$tab_id, 0775, TRUE);
-            if (($fp = @fopen(BIN5_PROXY_PATH."/table".$tab_id."/garbage_time.expired", 'rb')) == FALSE)
-                break;
-            if (($s = fread($fp, 4)) == FALSE)
-                break;
-            if (mb_strlen($s, "ASCII") != 4)
-                break;
-            $arr = unpack('Le', $s);
-            if ($arr['e'] > $tm)
-                $ret = FALSE;
-        } while (0);
-      
-        if ($fp != FALSE)
-            fclose($fp);
-      
-        log_rd2("END: return ".($ret ? "TRUE" : "FALSE"));
-      
-        return ($ret);
-    }
-
-    static function garbage_time_expire_set($tab_id, $tm) 
-    {
-        do {
-            if (file_exists(BIN5_PROXY_PATH."/table".$tab_id) == FALSE)
-                mkdir(BIN5_PROXY_PATH."/table".$tab_id, 0775, TRUE);
-            if (($fp = @fopen(BIN5_PROXY_PATH."/table".$tab_id."/garbage_time.expired", 'wb')) == FALSE)
-                break;
-            fwrite($fp, pack("L",$tm));
-            fclose($fp);
-          
-            return (TRUE);
-        } while (0);
-      
-        return (FALSE);
-    }
-
     static function request_mgr(&$s_a_p, &$header_out, &$new_socket, $path, $addr, $get, $post, $cookie)
     {
         printf("NEW_SOCKET (root): %d\n", intval($new_socket));
@@ -1459,6 +1399,8 @@ class Bin5 {
         if (($table_token = gpcs_var('table_token', $get, $post, $cookie)) === FALSE) 
             unset($table_token);
 
+        force_no_cache($header_out);
+
         switch ($path) {
         case "":
         case "index.php":
@@ -1467,8 +1409,6 @@ class Bin5 {
             $content = ob_get_contents();
             ob_end_clean();
         
-            force_no_cache($header_out);
-
             $s_a_p->pgflush_try_add($new_socket, 20, $header_out, $content);
             return TRUE;
         
@@ -1480,8 +1420,6 @@ class Bin5 {
             $content = ob_get_contents();
             ob_end_clean();
             
-            force_no_cache($header_out);
-
             $s_a_p->pgflush_try_add($new_socket, 20, $header_out, $content);
             return TRUE;
             
@@ -1702,6 +1640,7 @@ function show_table(&$bri, &$user, $sendstep, $is_transition, $is_again)
     /* NOTIFY FOR THE CARD MAKER */
     if ($is_transition) { //  && $user->subst ==  "asta" superfluo
         $ret .= show_table_info(&$bri, &$table, $table_pos);
+        $ret .= "setTimeout(preload_images, 500, g_preload_img_arr, g_imgct);";
     }
     if (!$is_again) 
         $ret .= table_wellcome($user);