removed save_ and load_ data from Users Bin5Users and Bin5 classes
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Mon, 19 Nov 2012 07:16:13 +0000 (08:16 +0100)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Mon, 19 Nov 2012 07:16:13 +0000 (08:16 +0100)
web/Obj/user.phh
web/briskin5/Obj/briskin5.phh

index d42d0de..e195019 100644 (file)
@@ -471,110 +471,6 @@ class User {
     $this->the_end = FALSE;
   }
 
-  static function load_data($id, $sess) 
-  {
-      log_main("load_data: id [".$id."] sess [".($sess == FALSE ? "FALSE" : $sess)."] ");
-      
-      do {
-          if (($tok = @ftok(FTOK_PATH."/user".$id, "C")) == -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 = self::create($id, "", "");
-                  if (@shm_put_var($shm, $tok, $user) == FALSE) {
-                      log_only("PUT_VAR FALLITA ".strlen(serialize($user)));
-                      log_only(serialize($user));
-                  }
-                  log_shme("User::save_data2");
-              }
-              else {
-                  if ($sess != FALSE) {
-                      /*
-                       *  NOTE:  this part is for check only, theoretically 
-                       *         user->step anch proxy_step are set allways at the same value
-                       */
-                      $old_step = $user->step;
-                      $arr = self::load_step($sess);
-                      $user->step = $arr['s'];
-                      if ($old_step != $user->step) {
-                          log_crit("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);
-      
-      return (FALSE);
-  }
-  
-
-  static function save_data($user, $id) 
-  {
-      GLOBAL $sess;
-      
-      $shm =   FALSE;
-      
-      if (($tok = @ftok(FTOK_PATH."/user".$id, "C")) == -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);
-              if ($user->sess != "")
-                  $user->save_step();
-
-              log_shme("User::save_data");
-
-              log_main("User[".$id."] saved.");
-              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 myname_innerHTML()
   {
       $class_id = ($this->flags & USER_FLAG_AUTH) + 1;
index 94a8940..b29a580 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 {
@@ -1014,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() 
     {