xhr refactoring: renaming xhr_rd to xhr, remove all xhr_rd_ prefixies from http_strea...
[brisk.git] / web / briskin5 / Obj / briskin5.phh
index 90cc082..d298928 100644 (file)
@@ -415,100 +415,318 @@ class Bin5_table extends Table {
 
     return ($ct);
   }
-} // end class Table_briskin5
+} // end class Bin5_table
 
 
 
 
 define(BIN5_USER_FLAG_RING_ENDAUCT, 0x01);
 
-class User_briskin5 extends User {
-  var $asta_card;  // 
-  var $asta_pnt;   //
-  var $handpt;     // Total card points at the beginning of the current hand.
-  var $exitislock; // Player can exit from the table ?
-  var $privflags;  // Flags for briskin5 only 
-
-  function User() {
-  }
+class Bin5_user extends User {
+    var $asta_card;  // 
+    var $asta_pnt;   //
+    var $handpt;     // Total card points at the beginning of the current hand.
+    var $exitislock; // Player can exit from the table ?
+    var $privflags;  // Flags for briskin5 only 
+    
+    function User() {
+    }
+    
+    /* CREATE NOT USED
+     function create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
+     if (($thiz =& new User()) == FALSE)
+     return (FALSE);
+     
+     $thiz->asta_card = -2;
+     $thiz->asta_pnt  = -1;
+     $thiz->handpt = -1;
+     $thiz->exitislock = TRUE;
+     $thiz->privflags = 0;
+     
+     return ($thiz);
+     }
+    */
+    
+    function parentcopy(&$from)
+    {
+        parent::copy($from);
+    }
+    
+    function copy(&$from)
+    {
+        $this->parentcopy($from);
+        
+        $this->asta_card  = $from->asta_card;
+        $this->asta_pnt   = $from->asta_pnt;
+        $this->handpt     = $from->handpt;
+        $this->exitislock = $from->exitislock;
+        $this->privflags  = $from->privflags;
+    }
+    
+    /* CLONE NOT USED
+     function myclone(&$from)
+     {
+     if (($thiz =& new User()) == FALSE)
+     return (FALSE);
+     
+     $thiz->copy($from);
+     
+     return ($thiz);
+     } 
+    */
+    
+    function spawn($from, $table, $table_pos)
+    {
+        GLOBAL $CO_bin5_pref_ring_endauct;
+        
+        if (($thiz = new Bin5_user()) == FALSE)
+            return (FALSE);
+        
+        $thiz->parentcopy($from);
+        
+        /* NOTE: at this moment idx and table_pos fields have the same value 
+                 but diffentent functions, we keep them separated for a while */
+        $thiz->idx        = $table_pos;
+        $thiz->asta_card  = -2;
+        $thiz->asta_pnt   = -1;
+        $thiz->handpt     = -1;
+        $thiz->exitislock = TRUE;
+        
+        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;
+        
+        $thiz->step_inc();
+
+        return ($thiz);
+    }
 
-  /* CREATE NOT USED
-  function create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
-    if (($thiz =& new User()) == FALSE)
-      return (FALSE);
+    function step_set($step) 
+    {
+        $this->step = $step & 0x7fffffff;
+        
+        return TRUE;
+    }
+    
+    function step_inc($delta = 1) {
+        $this->step += $delta;
+        /* modularization because unpack() not manage unsigned 32bit int correctly */
+        $this->step &= 0x7fffffff;
+        
+        return (TRUE);
+    }
 
-    $thiz->asta_card = -2;
-    $thiz->asta_pnt  = -1;
-    $thiz->handpt = -1;
-    $thiz->exitislock = TRUE;
-    $thiz->privflags = 0;
+    static function load_step($tab_id, $sess)
+    {
+        $fp = FALSE;
+        do {
+            if (validate_sess($sess) == FALSE)
+                break;
+            
+            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."/".$sess.".step", 'rb')) == FALSE)
+                break;
+            if (($s = fread($fp, 8)) == FALSE)
+                break;
+            if (mb_strlen($s, "ASCII") != 8)
+                break;
+            $arr = unpack('Ls/Li', $s);
+            fclose($fp);
+            
+            // log_rd2("A0: ".$arr[0]."  A1: ".$arr[1]);
+            return ($arr);
+        } while (0);
+        
+        if ($fp != FALSE)
+            fclose($fp);
+        
+        log_rd2("STEP_GET [".$sess."]: return false ");
+        
+        return (FALSE);
+    }
 
-    return ($thiz);
-  }
-  */
+    function save_step() 
+    {
+        do {
+            if (validate_sess($this->sess) == FALSE)
+                break;
+            if (file_exists(BIN5_PROXY_PATH."/table".$this->table_orig) == FALSE)
+                mkdir(BIN5_PROXY_PATH."/table".$this->table_orig, 0775, TRUE);
+            if (($fp = @fopen(BIN5_PROXY_PATH."/table".$this->table_orig."/".$this->sess.".step", 'w')) == FALSE)
+                break;
+            fwrite($fp, pack("LL",$this->step, $this->idx));
+            fclose($fp);
+            
+            log_main("step_set [".$this->sess. "] [".$this->step."]"); 
+            
+            return (TRUE);
+        } while (0);
+        
+        return (FALSE);
+    }
+    
+    static function unproxy_step($tab_id, $sess)
+    {
+        log_rd2("UNPROXY: ".BIN5_PROXY_PATH."/table".$tab_id."/".$sess.".step");
+        if (file_exists(BIN5_PROXY_PATH."/table".$tab_id) == FALSE)
+            return;
 
-  function parentcopy(&$from)
-  {
-    parent::copy($from);
-  }
+        @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);
+    }
 
-  function copy(&$from)
+  static function save_data($user, $tab_id, $id) 
   {
-    $this->parentcopy($from);
+      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.");
 
-    $this->asta_card  = $from->asta_card;
-    $this->asta_pnt   = $from->asta_pnt;
-    $this->handpt     = $from->handpt;
-    $this->exitislock = $from->exitislock;
-    $this->privflags  = $from->privflags;
-  }
+              log_shme("Bin5_user::save_data");
 
-  /* CLONE NOT USED
-  function myclone(&$from)
-  {
-    if (($thiz =& new User()) == FALSE)
+              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);
+  }
 
-    $thiz->copy($from);
-
-    return ($thiz);
-  } 
-  */
-  
-  function spawn(&$from, $table, $table_pos)
+  function destroy_data($tab_id) 
   {
-    GLOBAL $CO_bin5_pref_ring_endauct;
-    
-    if (($thiz =& new User_briskin5()) == FALSE)
-      return (FALSE);
-    
-    $thiz->parentcopy($from);
-
-    $thiz->asta_card = -2;
-    $thiz->asta_pnt  = -1;
-    $thiz->handpt = -1;
-    $thiz->exitislock = TRUE;
-
-    log_wr("Briskin5 constructor");
+      do {
+          if (($tok = @ftok(FTOK_PATH."/bin5/table".$tab_id."/user".$this->table_pos, "B")) == -1) {
+              log_crit("BIN5 USER DATA REMOVE FAILED 1 [".FTOK_PATH."/bin5/table".$tab_id."/user".$this->table_pos."]");
+              break;
+          }
+          
+          if (($shm = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
+              log_crit("BIN5 USER DATA REMOVE FAILED 2");
+              break;
+          }
+          if (shmop_delete($shm) == 0) {
+              log_crit("BIN5 USER DATA REMOVE FAILED 3");
+              break;
+          }
+          $shm = FALSE;
 
-    $this->privflags  = ($CO_bin5_pref_ring_endauct == "true" ? BIN5_USER_FLAG_RING_ENDAUCT : 0) | 0;
+          log_main("BIN5 USER DATA DESTROY SUCCESS");
+          
+          // log_main("QUI CI ARRIVA [".$bri->user[0]->name."]");
+          $ret = TRUE;
+      } while (0);
+      
+      if ($shm)
+          shm_detach($shm);
+      
+      return ($ret);
+  }
 
-    $thiz->table_orig = $table;
-    $thiz->table      = 0;
-    $thiz->table_pos  = $table_pos;
+} // end class Bin5_user
 
-    return ($thiz);
-  }
-} // end class User_briskin5
 
 
+class Bin5 {
+    static $delta_t = array();
 
-class Briskin5 {
   var $user;
   var $table;
   var $comm; // commands for many people
   var $step; // current step of the comm array
-  var $garbage_timeout;
+  // externalized var $garbage_timeout;
   var $shm_sz;
 
   var $table_idx;
@@ -543,7 +761,7 @@ class Briskin5 {
 
     $this->table_idx = $table_idx;
     $this->table_token = $table_token;
-    Bin5::garbage_time_expire_set(0);
+    Bin5::garbage_time_expire_set($table_idx, 0);
     
     log_wr("Bin5 constructor end");
   }
@@ -582,7 +800,7 @@ class Briskin5 {
     $ismod = FALSE;
     $curtime = time();
     // externalized if ($force || $this->garbage_timeout < $curtime) {
-    if ($force || Bin5::garbage_time_is_expired($curtime)) {
+    if ($force || Bin5::garbage_time_is_expired($this->table_idx, $curtime)) {
       for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
        $user_cur = $this->user[$i];
        if ($user_cur->sess == "" || 
@@ -599,7 +817,7 @@ class Briskin5 {
 
            $tmp_sess = $user_cur->sess;
            $user_cur->sess = "";
-           step_unproxy($tmp_sess);
+           Bin5_user::step_unproxy($tmp_sess);
            $user_cur->name = "";
            $user_cur->the_end = FALSE;
            
@@ -620,31 +838,25 @@ class Briskin5 {
       }
       log_rd2($user_cur->sess." GARBAGE UPDATED!");
       
-      $this->garbage_timeout = $curtime + GARBAGE_TIMEOUT;
+      // externalized $this->garbage_timeout = $curtime + GARBAGE_TIMEOUT;
+      Bin5::garbage_time_expire_set($this->table_idx, $curtime + GARBAGE_TIMEOUT);
+
       $ismod = TRUE;
     }
 
     return ($ismod);
   }
 
-
-
-
-  //
-  //  static functions
-  //
-  function load_data($table_idx, $table_token = "") 
+  // Bin5::load_data
+  static function load_data($table_idx, $table_token = "") 
   {
-    GLOBAL $G_false, $sess;
-    $doexit = FALSE;
     $shm = FALSE;
 
-    log_wr("TABLE_IDX ".FTOK_PATH."/table".$table_idx);
+    log_wr("TABLE_FTOK ".FTOK_PATH."/bin5/table".$table_idx."/table");
     
     do {
-      if (($tok = @ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) {
+      if (($tok = @ftok(FTOK_PATH."/bin5/table".$table_idx."/table", "B")) == -1) {
        log_main("ftok failed");
-       $doexit = TRUE;
        break;
       }
 
@@ -668,7 +880,13 @@ class Briskin5 {
       shm_detach($shm);
       
       for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
-          $bri->user[$i] = Bin5_user::load_data($table_idx, $i, FALSE);
+          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); 
@@ -678,53 +896,65 @@ class Briskin5 {
       shm_detach($shm);
 
     log_wr("briskin5 load_data failed");
-    if ($doexit)
-      exit();
     
     return (FALSE);
   }
   
 
 
-  function save_data(&$bri) 
+  function save_data($bri) 
   {
-    GLOBAL $sess;
-    
-    $ret =   FALSE;
-    $shm =   FALSE;
-    
-    log_main("SAVE BRISKIN5 DATA");
-    
-    if (!isset($bri->tok))
-      return (FALSE);
-    
-    while ($bri->shm_sz < BRISKIN5_SHM_MAX) {
-      if (($shm = shm_attach($bri->tok, $bri->shm_sz)) == FALSE)
-       break;
+      GLOBAL $sess;
       
-      if (@shm_put_var($shm, $bri->tok, $bri) != FALSE) {
-       shm_detach($shm);
-       return (TRUE);
-      }
-      if (shm_remove($shm) === FALSE) {
-       log_only("REMOVE FALLITA");
-       break;
+      $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;
       }
-      shm_detach($shm);
-      $bri->shm_sz += BRISKIN5_SHM_DLT;
-    } 
+      
+      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_crit("save data failed!");
+              log_shme("Bin5::save_data");
 
-    if ($shm)
-      shm_detach($shm);
-    
-    return ($ret);
+              $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($table_idx) 
+  function destroy_data() 
   {
     GLOBAL $sess;
 
@@ -733,9 +963,12 @@ class Briskin5 {
     log_main("DESTROY BRISKIN5 DATA");
     
     do {
-      log_main("DESTROY2 BRISKIN5 DATA");
-
-      if (($tok = @ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) 
+      log_main("DESTROY2 BRISKIN5 DATA [".$this->table_idx."]");
+      for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
+          $this->user[$i]->destroy_data($this->table_idx);
+          Bin5_user::unproxy_step($this->table_idx, $this->user[$i]->sess);
+      }
+      if (($tok = @ftok(FTOK_PATH."/bin5/table".$this->table_idx."/table", "B")) == -1) 
        break;
 
       if (($shm = @shmop_open($tok, 'a', 0, 0)) == FALSE)
@@ -759,38 +992,29 @@ class Briskin5 {
     return ($ret);
   }
 
-  function lock_data($table_idx)
+  static function lock_data($is_exclusive, $table_idx)
   {
-    GLOBAL $sess; 
-    
-    log_lock("LOCK_DATA ".FTOK_PATH."/table".$table_idx);
-    //  echo "LOCK: ".FTOK_PATH."/main";
-    //  exit;
-    // WARNING monitor this step
-    if (($tok = @ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) {
-      return (FALSE);
-    }
-    // WARNING monitor this step
-    if (($res = @sem_get($tok)) == FALSE) {
-      return (FALSE);
-    }
-    if (sem_acquire($res)) {   
-      log_lock("LOCK table ".$table_idx."[res: ".$res."]");
-      return ($res);
-    }
-    else {
-      log_lock("LOCK table ".$table_idx.":FAILED");
+      if (($res = file_lock(FTOK_PATH."/bin5/table".$table_idx."/table", $is_exclusive)) != FALSE) {
+          self::$delta_t = microtime(TRUE);
+          log_lock("LOCK   table [".$table_idx."]         [".self::$delta_t[$table_idx]."]");
+          
+          return (new Vect(array('res' => $res, 'tab' => $table_idx)));
+      }
+      
       return (FALSE);
-    }
   }
+
   
-  function unlock_data($res)
+  static function unlock_data($res_vect)
   {
     GLOBAL $sess; 
-    
-    log_lock("UNLOCK table [res: ".$res."]");
 
-    return (sem_release($res));
+    $res = $res_vect->getbyid('res');
+    $tab = $res_vect->getbyid('tab');
+
+    log_lock("UNLOCK table [".$tab."]         [".(microtime(TRUE) - (self::$delta_t[$tab]))."]");
+
+    file_unlock($res);
   }
 
 
@@ -827,7 +1051,7 @@ class Briskin5 {
        //      if ($user_cur->sess == '' || $user_cur->stat != 'room')
        if ($user_cur->sess == '')
          continue;
-       if ($user_cur->name == $name_new) {
+        if (strcasecmp($user_cur->name, $name_new) == 0) {
          $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
 
           $premsg = sprintf($mlang_brisk['nickdupl'][$G_lang], xcape($name_new));
@@ -881,10 +1105,7 @@ class Briskin5 {
                       (BIN5_PLAYERS_N == 3 ? 0:  $this->user[$table->player[($user_cur->table_pos+4) % BIN5_PLAYERS_N]]->flags),
                       (BIN5_PLAYERS_N == 3 ? "" :  xcape($this->user[$table->player[($user_cur->table_pos+4) % BIN5_PLAYERS_N]]->name)));
            if ($user_cur == $user) {
-              $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
-              $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
-             $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>";', 
-                                                                  $itin, xcape($user->name,ENT_COMPAT,"UTF-8"), $itou);
+                $user_cur->comm[$user_cur->step % COMM_N] .= $user_cur->myname_innerHTML();
             }
            $user_cur->step_inc();
          }
@@ -932,7 +1153,7 @@ class Briskin5 {
       $user_cur->laccwr = $curtime;
 
       $ret = "gst.st = ".($user_cur->step+1)."; ";
-      $ret .= 'gst.st_loc++; the_end=true; window.onbeforeunload = null; window.onunload = null; document.location.assign("../index.php");|';
+      $ret .= 'gst.st_loc++; hstm.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;
@@ -963,7 +1184,51 @@ class Briskin5 {
 
     return ($is_ab);
   }
-} // end class Briskin5
+
+
+  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);
+  }
+
+} // end class Bin5
 
 function locshm_exists($tok)
 {
@@ -1104,10 +1369,7 @@ function show_table(&$room, &$user, $sendstep, $is_transition, $is_again)
     $ret .= "background_set();";
     
     /* USERS INFO */
-    $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
-    $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
-
-    $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>";', $itin, xcape($user->name), $itou);
+    $ret .= $user->myname_innerHTML();
     $ret .= sprintf('set_names([%d, "%s"], [%d, "%s"], [%d, "%s"], [%d, "%s"], [%d, "%s"]); ',
                    $room->user[$table->player[($table_pos) % BIN5_PLAYERS_N]]->flags,
                    xcape($room->user[$table->player[($table_pos) % BIN5_PLAYERS_N]]->name),