PageFlush added, log_legal without remote address
[brisk.git] / web / briskin5 / Obj / briskin5.phh
index 9484067..48774fb 100644 (file)
  * Suite 330, Boston, MA 02111-1307, USA.
  *
  */
-define(BIN5_PLAYERS_N, 3);
-define(BIN5_MAX_PLAYERS, BIN5_PLAYERS_N);
-// define(BIN5_SHM_MIN, (50000 * BIN5_MAX_PLAYERS));
-define(BIN5_SHM_MIN, 32768);
-define(BIN5_SHM_MAX, (BIN5_SHM_MIN + 1048576));
-define(BIN5_SHM_DLT, 32768);
-define(BIN5_PROXY_PATH, PROXY_PATH."/bin5");
+define('BIN5_PLAYERS_N', 3);
+define('BIN5_MAX_PLAYERS', BIN5_PLAYERS_N);
+// define(BIN5_SHM_MIN', (50000 * BIN5_MAX_PLAYERS));
+define('BIN5_SHM_MIN', 32768);
+define('BIN5_SHM_MAX', (BIN5_SHM_MIN + 1048576));
+define('BIN5_SHM_DLT', 32768);
+define('BIN5_PROXY_PATH', PROXY_PATH."/bin5");
 
 $mlang_bin5_bin5 = array( 
                          'info_part' => array( 'it' => '<hr>Nell\'ultima mano ha chiamato <b>%s</b>, il socio era <b>%s</b>,<br>',
@@ -420,7 +420,7 @@ class Bin5_table extends Table {
 
 
 
-define(BIN5_USER_FLAG_RING_ENDAUCT, 0x01);
+define('BIN5_USER_FLAG_RING_ENDAUCT', 0x01);
 
 class Bin5_user extends User {
     var $asta_card;  // 
@@ -527,8 +527,8 @@ class Bin5_user extends User {
             if (validate_sess($sess) == FALSE)
                 break;
             
-            if (file_exists(BIN5_PROXY_PATH) == FALSE)
-                mkdir(BIN5_PROXY_PATH, 0775, TRUE);
+            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)
@@ -555,8 +555,8 @@ class Bin5_user extends User {
         do {
             if (validate_sess($this->sess) == FALSE)
                 break;
-            if (file_exists(BIN5_PROXY_PATH) == FALSE)
-                mkdir(BIN5_PROXY_PATH, 0775, TRUE);
+            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));
@@ -994,30 +994,16 @@ class Bin5 {
 
   static function lock_data($is_exclusive, $table_idx)
   {
-    GLOBAL $sess; 
-    
-    log_main("lockinfo: DATA ".FTOK_PATH."/bin5/table".$table_idx."/table");
-    //  echo "LOCK: ".FTOK_PATH."/main";
-    //  exit;
-    // WARNING monitor this step
-    if (($tok = @ftok(FTOK_PATH."/bin5/table".$table_idx."/table", "B")) == -1) {
-      return (FALSE);
-    }
-    // WARNING monitor this step
-    if (($res = @sem_get($tok, ($is_exclusive ? 1 : LOCK_SHARE_MAX) )) == FALSE) {
+      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);
-    }
-    if (sem_acquire($res)) {   
-        self::$delta_t[$table_idx] = microtime(TRUE);
-        log_lock("LOCK   table [".$table_idx."]         [".self::$delta_t[$table_idx]."]");
-
-        return (new Vect(array('res' => $res, 'tab' => $table_idx)));
-    }
-    else {
-        log_lock("LOCK table ".$table_idx.":FAILED");
-        return (FALSE);
-    }
   }
+
   
   static function unlock_data($res_vect)
   {
@@ -1028,7 +1014,7 @@ class Bin5 {
 
     log_lock("UNLOCK table [".$tab."]         [".(microtime(TRUE) - (self::$delta_t[$tab]))."]");
 
-    return (sem_release($res));
+    file_unlock($res);
   }
 
 
@@ -1065,7 +1051,7 @@ class Bin5 {
        //      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));
@@ -1119,10 +1105,7 @@ class Bin5 {
                       (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();
          }
@@ -1145,7 +1128,7 @@ class Bin5 {
                                                             $dt, $user->flags, xcape($user->name), xcape($user_mesg));
        $user_cur->step_inc();
       }
-      log_legal($curtime, $user, ($user->stat == 'room' ? 'room' : 'table '.$user->table_orig),$user_mesg);
+      log_legal($curtime, 'xxx', $user, ($user->stat == 'room' ? 'room' : 'table '.$user->table_orig),$user_mesg);
     }
   }
 
@@ -1170,7 +1153,7 @@ class Bin5 {
       $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;
@@ -1208,8 +1191,8 @@ class Bin5 {
       $ret = TRUE;
       $fp = FALSE;
       do {
-          if (file_exists(BIN5_PROXY_PATH) == FALSE)
-              mkdir(BIN5_PROXY_PATH, 0775, TRUE);
+          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)
@@ -1232,8 +1215,8 @@ class Bin5 {
   static function garbage_time_expire_set($tab_id, $tm) 
   {
       do {
-          if (file_exists(BIN5_PROXY_PATH) == FALSE)
-              mkdir(BIN5_PROXY_PATH, 0775, TRUE);
+          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));
@@ -1386,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),