X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2Fbriskin5%2FObj%2Fbriskin5.phh;h=164fb50af7135ee02e192b4ab51cf50c63f25c2e;hb=e47ddcae6cc33ed9d2471a54936db7d8efd5d46a;hp=3ca912b40c3db0a3f010da2d854582c77d3043ce;hpb=fe84f64017120e8fad375029239cdf1895fb9533;p=brisk.git diff --git a/web/briskin5/Obj/briskin5.phh b/web/briskin5/Obj/briskin5.phh index 3ca912b..164fb50 100644 --- a/web/briskin5/Obj/briskin5.phh +++ b/web/briskin5/Obj/briskin5.phh @@ -528,12 +528,12 @@ class Bin5_user extends User { break; if (file_exists(BIN5_PROXY_PATH) == FALSE) - mkdir(BIN5_PROXY_PATH); + mkdir(BIN5_PROXY_PATH, 0775, TRUE); if (($fp = @fopen(BIN5_PROXY_PATH."/".$sess.".step", 'rb')) == FALSE) break; if (($s = fread($fp, 8)) == FALSE) break; - if (strlen($s) != 8) + if (mb_strlen($s, "ASCII") != 8) break; $arr = unpack('Ls/Li', $s); fclose($fp); @@ -575,11 +575,9 @@ class Bin5_user extends User { { log_main("Bin5_user::load_data: tab_id [".$tab_id."] id [".$id."] sess [".($sess == FALSE ? "FALSE" : $sess)."] "); - $doexit = FALSE; do { if (($tok = @ftok(FTOK_PATH."/bin5/table".$tab_id."/user".$id, "B")) == -1) { log_main("ftok failed"); - $doexit = TRUE; break; } @@ -591,10 +589,11 @@ class Bin5_user extends User { $shm_sz = SHM_DIMS_U_MIN; if ($shm = shm_attach($tok, $shm_sz)) { - $user = @shm_get_var($shm, $tok); + if (($user = @shm_get_var($shm, $tok)) == FALSE) { + break; + } if ($sess != FALSE && $user->sess != $sess) { - $doexit = TRUE; break; } log_only("user == ".($user == FALSE ? "FALSE" : "TRUE")." user === ".($user === FALSE ? "FALSE" : "TRUE")." user isset ".(isset($user) ? "TRUE" : "FALSE")); @@ -609,6 +608,19 @@ class Bin5_user extends 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($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; @@ -621,8 +633,7 @@ class Bin5_user extends User { return ($user); } while (0); - if ($doexit) - exit(); + log_crit("Bin5_user::load_data:ret FALSE"); return (FALSE); } @@ -666,6 +677,8 @@ class Bin5_user extends User { class Bin5 { + static $delta_t = array(); + var $user; var $table; var $comm; // commands for many people @@ -794,7 +807,6 @@ class Bin5 { // Bin5::load_data static function load_data($table_idx, $table_token = "") { - $doexit = FALSE; $shm = FALSE; log_wr("TABLE_FTOK ".FTOK_PATH."/bin5/table".$table_idx."/table"); @@ -802,7 +814,6 @@ class Bin5 { do { if (($tok = @ftok(FTOK_PATH."/bin5/table".$table_idx."/table", "B")) == -1) { log_main("ftok failed"); - $doexit = TRUE; break; } @@ -826,7 +837,13 @@ class Bin5 { 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); @@ -836,8 +853,6 @@ class Bin5 { shm_detach($shm); log_wr("briskin5 load_data failed"); - if ($doexit) - exit(); return (FALSE); } @@ -932,7 +947,7 @@ class Bin5 { { GLOBAL $sess; - log_lock("LOCK_DATA ".FTOK_PATH."/bin5/table".$table_idx."/table"); + log_main("lockinfo: DATA ".FTOK_PATH."/bin5/table".$table_idx."/table"); // echo "LOCK: ".FTOK_PATH."/main"; // exit; // WARNING monitor this step @@ -944,20 +959,25 @@ class Bin5 { return (FALSE); } if (sem_acquire($res)) { - log_lock("LOCK table ".$table_idx."[res: ".$res."]"); - return ($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); + log_lock("LOCK table ".$table_idx.":FAILED"); + return (FALSE); } } - function unlock_data($res) + function unlock_data($res_vect) { GLOBAL $sess; - - log_lock("UNLOCK table [res: ".$res."]"); + + $res = $res_vect->getbyid('res'); + $tab = $res_vect->getbyid('tab'); + + log_lock("UNLOCK table [".$tab."] [".(microtime(TRUE) - (self::$delta_t[$tab]))."]"); return (sem_release($res)); } @@ -1140,12 +1160,12 @@ class Bin5 { $fp = FALSE; do { if (file_exists(BIN5_PROXY_PATH) == FALSE) - mkdir(BIN5_PROXY_PATH); + mkdir(BIN5_PROXY_PATH, 0775, TRUE); if (($fp = @fopen(BIN5_PROXY_PATH."/garbage_time.expired", 'rb')) == FALSE) break; if (($s = fread($fp, 4)) == FALSE) break; - if (strlen($s) != 4) + if (mb_strlen($s, "ASCII") != 4) break; $arr = unpack('Le', $s); if ($arr['e'] > $tm) @@ -1164,7 +1184,7 @@ class Bin5 { { do { if (file_exists(BIN5_PROXY_PATH) == FALSE) - mkdir(BIN5_PROXY_PATH); + mkdir(BIN5_PROXY_PATH, 0775, TRUE); if (($fp = @fopen(BIN5_PROXY_PATH."/garbage_time.expired", 'wb')) == FALSE) break; fwrite($fp, pack("L",$tm));