unused Brisk::load_data and save_data static methods removed
[brisk.git] / web / Obj / brisk.phh
index 6a9547d..9e0eb12 100644 (file)
@@ -150,10 +150,10 @@ $mlang_brisk = array( 'btn_backstand'=> array( 'it' => 'torna in piedi',
 $G_lng = langtolng($G_lang);
 
 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
-$G_brisk_version = "4.14.1";
+$G_brisk_version = "4.14.2";
 
 /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
-$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: nuovo sistema di registrazione degli utenti',
+$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: nuovo sistema di registrazione degli utenti, aggiunto reinvio dell\' email di verifica',
                                        'Se vuoi iscriverti alla <a target="_blank" href="mailto:ml-briscola+subscribe@milug.org">Mailing List</a>, cliccala!' ),
                        'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NEWS</b>: new users subscription system.',
                                        'If you want to subscribe our <a target="_blank" href="ml-briscola+subscribe@milug.org">Mailing List</a>, click it!' ) );
@@ -954,39 +954,59 @@ class Brisk
 
     public static $sess_cur;
 
-    function Brisk($crystal_filename) {
-        $this->crystal_filename = $crystal_filename;
-        $this->user  = array();
-        $this->table = array();
-        $this->match = array();
+    function Brisk()
+    {
+    }
+
+    // constructor
+    static function create($crystal_filename)
+    {
+        if (($brisk_ser = @file_get_contents($crystal_filename)) != FALSE) {
+            if (($brisk = unserialize($brisk_ser)) != FALSE) {
+                fprintf(STDERR, "ROOM FROM FILE\n");
+                rename($crystal_filename, $crystal_filename.".old");
+
+                return($brisk);
+            }
+        }
+
+        fprintf(STDERR, "NEW ROOM\n");
+        $thiz = new Brisk();
+
+        $thiz->crystal_filename = $crystal_filename;
+        $thiz->user  = array();
+        $thiz->table = array();
+        $thiz->match = array();
         
         for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
-            $this->user[$i] = User::create($this, $i, "", "");
+            $thiz->user[$i] = User::create($thiz, $i, "", "");
         }
         
         for ($i = 0 ; $i < TABLES_N ; $i++) {
-            $this->table[$i] = Table::create($i);
+            $thiz->table[$i] = Table::create($i);
             /* OLD METHOD
                if ($i < 12) {
                $row = ( (((int)($i / 4)) % 2) == 0 );
                $col = ($i % 2 == 0);
-               $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
+               $thiz->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
                }
                else {
-               $this->table[$i]->auth_only = FALSE;
+               $thiz->table[$i]->auth_only = FALSE;
                }
             */
             if ($i < TABLES_AUTH_N) 
-                $this->table[$i]->auth_only = TRUE;
+                $thiz->table[$i]->auth_only = TRUE;
             else
-                $this->table[$i]->auth_only = FALSE;
+                $thiz->table[$i]->auth_only = FALSE;
         }
-        $this->garbage_timeout = 0;
-        $this->shm_sz = SHM_DIMS_MIN;
+        $thiz->garbage_timeout = 0;
+        $thiz->shm_sz = SHM_DIMS_MIN;
 
-        $this->delay_mgr = new Delay_Manager(1.5);
+        $thiz->delay_mgr = new Delay_Manager(1.5);
 
         static::$sess_cur = FALSE;
+
+        return ($thiz);
     }
 
   function garbage_manager($force)
@@ -2224,118 +2244,6 @@ class Brisk
     }
   }
 
-  // Static functions
-  static function create($crystal_filename)
-  {
-      if (($brisk_ser = @file_get_contents($crystal_filename)) == FALSE ||
-          ($brisk = unserialize($brisk_ser)) == FALSE) {
-          fprintf(STDERR, "NEW ROOM\n");
-          $brisk = new Brisk($crystal_filename);
-      }
-      else {
-          fprintf(STDERR, "ROOM FROM FILE\n");
-          rename($crystal_filename, $crystal_filename.".old");
-      }
-
-    return $brisk;
-  }
-  
-  
-  function load_data() 
-  {
-    GLOBAL $sess;
-
-    do {
-      if (($tok = @ftok(FTOK_PATH."/main", "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_MIN;
-
-      if ($shm = shm_attach($tok, $shm_sz)) {
-          $brisk = @shm_get_var($shm, $tok); // CHECKED BELOW
-          
-          log_only("bri ==  ".($brisk == FALSE ?   "FALSE" : "TRUE")."  bri ===  ".($brisk === FALSE ? "FALSE" : "TRUE")."  bri isset ".(isset($brisk) ?   "TRUE" : "FALSE"));
-          if (isset($brisk))
-              log_only("bri count ".count($brisk));
-          
-          if ($brisk == FALSE) {
-              log_only("INIT MAIN DATA");
-              shm_detach($shm);
-              
-              $brisk = Brisk::create();
-              
-              log_shme("Brisk::create");
-
-              if (Brisk::save_data($brisk) == FALSE)
-                  return FALSE;
-
-              return $brisk;
-          }
-          $brisk->shm_sz = $shm_sz;
-          
-          shm_detach($shm);
-
-          for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
-              if (($brisk->user[$i] = User::load_data($i, FALSE)) == FALSE) {
-                  log_crit("User::load_data failed");
-                  break;
-              }
-          }
-          if ($i < MAX_PLAYERS) {
-              break;
-          }
-      }
-      
-      //  
-      // SHSPLIT: load users from the shared memory
-      //
-      return ($brisk);
-    } while (0);
-    
-    return (FALSE);
-  }
-  
-
-  function save_data_orig($brisk) 
-  {
-    GLOBAL $sess;
-    
-    $shm =   FALSE;
-    
-    // var_dump($brisk);
-    
-    if (($tok = @ftok(FTOK_PATH."/main", "C")) == -1) 
-      return (FALSE);
-    
-    while ($brisk->shm_sz < SHM_DIMS_MAX) {
-      if (($shm = shm_attach($tok, $brisk->shm_sz)) == FALSE)
-       break;
-      
-      // log_only("PUT_VAR DI ".strlen(serialize($brisk)));
-      if (@shm_put_var($shm, $tok, $brisk) != FALSE) {
-       shm_detach($shm);
-       return (TRUE);
-      }
-      if (shm_remove($shm) === FALSE) {
-       log_only("REMOVE FALLITA");
-       break;
-      }
-      shm_detach($shm);
-      $brisk->shm_sz += SHM_DIMS_DLT;
-    } 
-
-    if ($shm)
-      shm_detach($shm);
-    
-    return (FALSE);
-  }
   function dump_data()
   {
       $brisk_ser = serialize($this);
@@ -2347,55 +2255,6 @@ class Brisk
       return (FALSE);
   }
 
-  function save_data($brisk) 
-  {
-      GLOBAL $sess;
-    
-      $ret =   FALSE;
-      $shm =   FALSE;
-    
-      if (($tok = @ftok(FTOK_PATH."/main", "C")) == -1) 
-          return (FALSE);
-    
-      // SHSPLIT: before save the $brisk you must save users, 
-      //          detach from main struct and (then) reattach
-      $user_park = array();
-      for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
-          $user_park[$i]  = $brisk->user[$i];
-          $brisk->user[$i] = FALSE;
-      }
-
-      while ($brisk->shm_sz < SHM_DIMS_MAX) {
-          if (($shm = shm_attach($tok, $brisk->shm_sz)) == FALSE)
-              break;
-      
-          // log_only("PUT_VAR DI ".strlen(serialize($brisk)));
-          if (@shm_put_var($shm, $tok, $brisk) != FALSE) {
-              log_shme("Brisk::save_data");
-              $ret = TRUE;
-              break;
-          }
-          if (shm_remove($shm) === FALSE) {
-              log_only("REMOVE FALLITA");
-              break;
-          }
-          shm_detach($shm);
-          $brisk->shm_sz += SHM_DIMS_DLT;
-      } 
-
-      if ($shm)
-          shm_detach($shm);
-    
-      // SHSPLIT: reattach users to the room class
-      for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
-          User::save_data($user_park[$i], $i);
-          $brisk->user[$i] = $user_park[$i];
-      }
-      log_load("FINISH: ".($ret == TRUE ? "TRUE" : "FALSE"));
-
-      return ($ret);
-  }
-
   static function lock_data($is_exclusive)
   {
       if (($res = file_lock(FTOK_PATH."/main", $is_exclusive)) != FALSE) {