more consistent assignement during failure branches
[brisk.git] / web / briskin5 / Obj / briskin5.phh
index 22b75d1..356c579 100644 (file)
@@ -584,112 +584,6 @@ class Bin5_user extends User {
         @unlink(BIN5_PROXY_PATH."/table".$tab_id."/".$sess.".step");
     }
     
-    static function load_data($tab_id, $id, $sess) 
-    {
-        log_load("Bin5_user::load_data: tab_id [".$tab_id."] id [".$id."] sess [".($sess == FALSE ? "FALSE" : $sess)."] ");
-        
-        do {
-            if (($tok = @ftok(FTOK_PATH."/bin5/table".$tab_id."/user".$id, "B")) == -1) {
-                log_main("ftok failed");
-                break;
-            }
-            
-            if (($shm_sz = sharedmem_sz($tok)) == -1) {
-                log_main("shmop_open failed");
-            }
-            
-            if ($shm_sz == -1)
-                $shm_sz = SHM_DIMS_U_MIN;
-            
-            if ($shm = shm_attach($tok, $shm_sz)) {
-                if (($user = @shm_get_var($shm, $tok)) == FALSE) {
-                    break;
-                }
-                
-                if ($sess != FALSE && $user->sess != $sess) {
-                    break;
-                }
-                log_only("user ==  ".($user == FALSE ?   "FALSE" : "TRUE")."  user ===  ".($user === FALSE ? "FALSE" : "TRUE")."  user isset ".(isset($user) ?   "TRUE" : "FALSE"));
-                
-                if ($user == FALSE) {
-                    log_only("INIT MAIN DATA");
-                    
-                    // SHSPLIT FIXME: init_data for User class ??
-                    $user = User::create($id, "", "");
-                    if (@shm_put_var($shm, $tok, $user) == FALSE) {
-                        log_shme("Bin5_user::save_data2");
-
-                        log_only("PUT_VAR FALLITA ".strlen(serialize($user)));
-                        log_only(serialize($user));
-                    }
-                }
-                else {
-                    if ($sess != FALSE) {
-                        // This part isn't strictly required but is good to verify
-                        // the coerence of cached and User class saved value of step field.
-                        $old_step = $user->step;
-                        $arr = Bin5_user::load_step($tab_id, $sess);
-                        $user->step = $arr['s'];
-                        if ($old_step != $user->step) {
-                            log_crit("Bin5:: steps are diffetents User->step ".$user->step." Old_step: ".$old_step);
-                        }
-
-                    }
-                }
-                
-                $user->shm_sz = $shm_sz;
-                
-                shm_detach($shm);
-            }
-            
-            //  
-            // SHSPLIT: load users from the shared memory
-            //
-            return ($user);
-        } while (0);
-        
-        log_crit("Bin5_user::load_data:ret FALSE");
-        
-        return (FALSE);
-    }
-
-    static function save_data($user, $tab_id, $id) 
-    {
-        GLOBAL $sess;
-      
-        $shm =   FALSE;
-      
-        if (($tok = @ftok(FTOK_PATH."/bin5/table".$tab_id."/user".$id, "B")) == -1) {
-            return (FALSE);
-        }
-        while ($user->shm_sz < SHM_DIMS_U_MAX) {
-            if (($shm = shm_attach($tok, $user->shm_sz)) == FALSE)
-                break;
-          
-            // log_only("PUT_VAR DI ".strlen(serialize($user)));
-            if (@shm_put_var($shm, $tok, $user) != FALSE) {
-                shm_detach($shm);
-                $user->save_step();
-                log_main("User[".$id."] saved.");
-
-                log_shme("Bin5_user::save_data");
-
-                return (TRUE);
-            }
-            if (shm_remove($shm) === FALSE) {
-                log_only("REMOVE FALLITA");
-                break;
-            }
-            shm_detach($shm);
-            $user->shm_sz += SHM_DIMS_U_DLT;
-        } 
-      
-        if ($shm)
-            shm_detach($shm);
-      
-        return (FALSE);
-    }
-
     function destroy_data($tab_id) 
     {
         do {
@@ -720,56 +614,22 @@ class Bin5_user extends User {
         return ($ret);
     }
 
-    public static function stream_fini($init_string, $is_unrecoverable)
-{
-    printf("xXx user::stream_fini\n");
-
-    // IF IFRAME THEN:
-    $body = "";
-    $body .= sprintf("<html>
-<head>
-<script type=\"text/javascript\" src=\"%scommons.js\"></script>
-<script type=\"text/javascript\" src=\"%sxynt-http-streaming-ifra.js\"></script>
-<script type=\"text/javascript\">
-var http_streaming = \"ready\";", self::base_get(), self::base_get());
-    $body .= sprintf("
-window.onload = function () { if (http_streaming != \"ready\") { http_streaming.reload(); } };
-</script>
-</head>
-<body>");
-    $body .= sprintf("<!-- \n%s -->\n", $init_string);
-    $body .= sprintf("<script id='hs%d' type='text/javascript'><!--
-push(\"%s\");
-// -->
-</script>", 0, escpush(self::blocking_error($is_unrecoverable)) );
-    // ELSE IF XHR THEN:
-    // return (self::blocking_error($is_unrecoverable));
-    return ($body);
-}
-
-
     protected function blocking_error($is_unrecoverable)
     {
-        GLOBAL $is_page_streaming;
-        
-        $is_page_streaming = TRUE;
         log_crit("BLOCKING_ERROR UNREC: ".($is_unrecoverable ? "TRUE" : "FALSE"));
-        return (sprintf(($is_unrecoverable ? 'hstm.stop(); ' : '').'window.onbeforeunload = null; window.onunload = null; document.location.assign("../index.php");'));
+        return (sprintf(($is_unrecoverable ? 'xstm.stop(); ' : '').'window.onbeforeunload = null; window.onunload = null; document.location.assign("../index.php");'));
     }
     
     protected function page_sync($sess, $page)
     {
-        GLOBAL $is_page_streaming;
-        
-        $is_page_streaming = TRUE;
         log_rd2("PAGE_SYNC");
         printf("xXx BIN5_USER::PAGE_SYNC\n");
-        return (sprintf('hstm.stop(); window.onbeforeunload = null; window.onunload = null; document.location.assign("%s");', $page));
+        return (sprintf('xstm.stop(); window.onbeforeunload = null; window.onunload = null; document.location.assign("%s");', $page));
     }
 
     protected function maincheck($cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step, $splashdate, $table_idx, $table_token)
     {
-        GLOBAL $G_lang, $mlang_indrd, $is_page_streaming;
+        GLOBAL $G_lang, $mlang_indrd;
         GLOBAL $G_with_splash, $G_splash_content, $G_splash_interval, $G_splash_idx;
         GLOBAL $G_splash_w, $G_splash_h, $G_splash_timeout;
         $CO_splashdate = "CO_splashdate".$G_splash_idx;
@@ -795,10 +655,9 @@ push(\"%s\");
           
           $S_load_stat['wR_minusone']++;
           
-          if ($this->the_end == TRUE) { 
-              log_rd2("main_check: the end".var_export(debug_backtrace()));
-              $is_page_streaming = TRUE;
-          }
+          // if ($this->the_end == TRUE) {
+          // log_rd2("main_check: the end".var_export(debug_backtrace()));
+          // }
           
           if ($this->trans_step != -1) {
               log_rd2("TRANS USATO ".$this->trans_step);
@@ -1049,112 +908,6 @@ class Bin5 {
         return ($ismod);
     }
     
-    // Bin5::load_data
-    static function load_data($table_idx, $table_token = "") 
-    {
-        $shm = FALSE;
-        
-        log_wr("TABLE_FTOK ".FTOK_PATH."/bin5/table".$table_idx."/table");
-        
-        do {
-            if (($tok = @ftok(FTOK_PATH."/bin5/table".$table_idx."/table", "B")) == -1) {
-                log_main("ftok failed");
-                break;
-            }
-            
-            if (($shm_sz = sharedmem_sz($tok)) == -1) {
-                log_main("shmop_open failed");
-                break;
-            }
-       
-            if (($shm = shm_attach($tok, $shm_sz)) == FALSE)
-                break;
-
-            if (($bri = @shm_get_var($shm, $tok)) == FALSE) 
-                break;
-
-            if ($table_token != "" && $bri->table_token != $table_token) {
-                log_wr("bri->table_token: ".$bri->table_token."table_token: ".$table_token);
-                break;
-            }
-            $bri->tok = $tok;
-
-            shm_detach($shm);
-      
-            for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
-                if (($bri->user[$i] = Bin5_user::load_data($table_idx, $i, FALSE)) == FALSE) {
-                    log_crit("Bin5_user::load_data failed");
-                    break;
-                }
-            }
-            if ($i < BIN5_MAX_PLAYERS) {
-                break;
-            }
-      
-            return ($bri); 
-        } while (FALSE);
-
-        if ($shm != FALSE)
-            shm_detach($shm);
-
-        log_wr("briskin5 load_data failed");
-    
-        return (FALSE);
-    }
-  
-
-
-    function save_data($bri) 
-    {
-        GLOBAL $sess;
-      
-        $ret =   FALSE;
-        $shm =   FALSE;
-      
-        log_main("SAVE BRISKIN5 DATA");
-      
-        if (!isset($bri->tok))
-            return (FALSE);
-      
-        $user_park = array();
-        for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
-            $user_park[$i] = $bri->user[$i];
-            $bri->user[$i] = FALSE;
-        }
-      
-        while ($bri->shm_sz < BIN5_SHM_MAX) {
-            if (($shm = shm_attach($bri->tok, $bri->shm_sz)) == FALSE)
-                break;
-          
-            if (@shm_put_var($shm, $bri->tok, $bri) != FALSE) {
-
-                log_shme("Bin5::save_data");
-
-                $ret = TRUE;
-                break;
-            }
-            if (shm_remove($shm) === FALSE) {
-                log_only("REMOVE FALLITA");
-                break;
-            }
-            shm_detach($shm);
-            $bri->shm_sz += BIN5_SHM_DLT;
-        } 
-      
-        if ($shm)
-            shm_detach($shm);
-      
-        // SHSPLIT: reattach users to the room class
-        for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
-            Bin5_user::save_data($user_park[$i], $bri->table_idx, $i);
-            $bri->user[$i] = $user_park[$i];
-        }
-        log_load("FINISH: ".($ret == TRUE ? "TRUE" : "FALSE"));
-      
-        return ($ret);
-    }
-  
-
 
     function destroy_data() 
     {
@@ -1355,7 +1108,7 @@ class Bin5 {
             $user_cur->laccwr = $curtime;
 
             $ret = "gst.st = ".($user_cur->step+1)."; ";
-            $ret .= 'gst.st_loc++; hstm.stop(); window.onbeforeunload = null; window.onunload = null; document.location.assign("../index.php");|';
+            $ret .= 'gst.st_loc++; xstm.stop(); window.onbeforeunload = null; window.onunload = null; document.location.assign("../index.php");|';
 
             log_wr($user_cur->sess." BIN5_WAKEUP: ".$ret);
             $user_cur->comm[$user_cur->step % COMM_N] = $ret;
@@ -1387,23 +1140,31 @@ class Bin5 {
         return ($is_ab);
     }
 
-    static function request_mgr(&$s_a_p, $enc, &$header_out, &$new_socket, $path, $addr, $get, $post, $cookie)
+    static function request_mgr(&$s_a_p, $header, &$header_out, &$new_socket, $path, $addr, $get, $post, $cookie)
     {
         printf("NEW_SOCKET (root): %d\n", intval($new_socket));
         
+        $enc = get_encoding($header);
+        if (isset($header['User-Agent']) && strstr($header['User-Agent'], "MSIE")) {
+            $transp_type = "htmlfile";
+        }
+        else {
+            $transp_type = "iframe";
+        }
+        force_no_cache($header_out);
+
         if (($table_idx = gpcs_var('table_idx', $get, $post, $cookie)) === FALSE) 
             unset($table_idx);
         
         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":
             ob_start();
-            bin5_index_main($header_out, $addr, $get, $post, $cookie);
+            bin5_index_main($transp_type, $header_out, $addr, $get, $post, $cookie);
             $content = ob_get_contents();
             ob_end_clean();
         
@@ -1412,6 +1173,7 @@ class Bin5 {
         
         break;
         case "index_wr.php":
+            // FIXME $content can be unset
             if (isset($table_idx) && isset($table_token)) {
                 if (($bri = $s_a_p->app->match_get($table_idx, $table_token)) != FALSE) {
                     ob_start();
@@ -1419,6 +1181,12 @@ class Bin5 {
                     $content = ob_get_contents();
                     ob_end_clean();
                 }
+                else {
+                    $content = "Bin5 Load data error";
+                }
+            }
+            else {
+                $content = "Bin5 Load data error";
             }
             $s_a_p->pgflush_try_add($enc, $new_socket, 20, $header_out, $content);
             return TRUE;