X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2Fbriskin5%2FObj%2Fbriskin5.phh;h=024e8cd1362f88f8ada5f4bc0d8f557381e69d57;hb=18b16ce1ecd95cc5e8c632c8610f7bd736dc6e9e;hp=b4001cbec26fe6479abdcf869f86dc4b74518306;hpb=8861498f64b33d632aaf4f0b3b54a01503307531;p=brisk.git diff --git a/web/briskin5/Obj/briskin5.phh b/web/briskin5/Obj/briskin5.phh index b4001cb..024e8cd 100644 --- a/web/briskin5/Obj/briskin5.phh +++ b/web/briskin5/Obj/briskin5.phh @@ -1,5 +1,10 @@ user = array(); $this->table = array(); $this->the_end = FALSE; - - if (($this->tok = ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) { + $this->shm_sz = BRISKIN5_SHM_MIN; + if (($this->tok = @ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) { echo "FTOK FAILED"; exit; } @@ -49,7 +55,7 @@ class Briskin5 { GLOBAL $PHP_SELF, $G_false; if (validate_sess($sess)) { - for ($i = 0 ; $i < MAX_BRISKIN5_PLAYERS ; $i++) { + for ($i = 0 ; $i < BRISKIN5_MAX_PLAYERS ; $i++) { if (strcmp($sess, $this->user[$i]->sess) == 0) { // find it $idx = $i; @@ -58,7 +64,7 @@ class Briskin5 { } } log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF)); - // for ($i = 0 ; $i < MAX_PLAYERS ; $i++) + // for ($i = 0 ; $i < BRISKIN5_MAX_PLAYERS ; $i++) // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess)); } else { @@ -77,7 +83,7 @@ class Briskin5 { $curtime = time(); if ($force || $this->garbage_timeout < $curtime) { - for ($i = 0 ; $i < MAX_BRISKIN5_PLAYERS ; $i++) { + for ($i = 0 ; $i < BRISKIN5_MAX_PLAYERS ; $i++) { $user_cur = &$this->user[$i]; if ($user_cur->sess == "" || ($user_cur->stat == 'table' && ($user_cur->subst == 'shutdowned' || $user_cur->subst == 'shutdowner'))) @@ -121,20 +127,24 @@ class Briskin5 { function &load_data($table_idx, $table_token = "") { GLOBAL $G_false, $sess; + $doexit = FALSE; $shm = FALSE; log_wr("TABLE_IDX ".FTOK_PATH."/table".$table_idx); - if (($tok = ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) { - echo "FTOK FAILED"; - exit; - } do { - // if (shmchk_exists($tok) == FALSE) - if (locshm_exists($tok) == FALSE) + if (($tok = @ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) { + log_main("ftok failed"); + $doexit = TRUE; break; + } - if (($shm = shm_attach($tok, SHM_DIMS)) == FALSE) + 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) @@ -157,15 +167,55 @@ class Briskin5 { shm_detach($shm); log_wr("briskin5 load_data failed"); + if ($doexit) + exit(); return ($G_false); } + 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; + + // log_only("PUT_VAR DI ".strlen(serialize($room))); + if (@shm_put_var($shm, $bri->tok, $bri) != FALSE) { + shm_detach($shm); + return (TRUE); + } + if (shm_remove($shm) === FALSE) { + log_only("REMOVE FALLITA"); + break; + } + shm_detach($shm); + $bri->shm_sz += BRISKIN5_SHM_DLT; + } + + if ($shm) + shm_detach($shm); + + return ($ret); + } + + + + function save_data_orig(&$bri) + { + GLOBAL $sess; + $ret = FALSE; $shm = FALSE; $isacq = FALSE; @@ -179,7 +229,7 @@ class Briskin5 { do { $isacq = TRUE; - if (($shm = shm_attach($bri->tok, SHM_DIMS)) == FALSE) + if (($shm = shm_attach($bri->tok, BRISKIN5_SHM_DIMS)) == FALSE) break; // log_only("PUT_VAR DI ".strlen(serialize($bri))); @@ -204,25 +254,19 @@ class Briskin5 { $ret = FALSE; $shm = FALSE; - $isacq = FALSE; - log_main("DESTROY BRISKIN5 DATA"); - do { - $isacq = TRUE; - log_main("DESTROY2 BRISKIN5 DATA"); - if (($tok = ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) + if (($tok = @ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) break; - if (($shm = shm_attach($tok, SHM_DIMS)) === FALSE) + if (($shm = @shmop_open($tok, 'a', 0, 0)) == FALSE) break; - if (shm_remove($shm) === FALSE) { - log_only("REMOVE FALLITA ".strlen(serialize($bri))); - log_only(serialize($bri)); + if (shmop_delete($shm) == 0) { + log_only("REMOVE FALLITA "); break; } @@ -246,12 +290,13 @@ class Briskin5 { log_wr("LOCK_DATA ".FTOK_PATH."/table".$table_idx); // echo "LOCK: ".FTOK_PATH."/main"; // exit; - if (($tok = ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) { + // FIXME monitor this step + if (($tok = @ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) { echo "FTOK FAILED"; exit; } - // echo "FTOK ".$tok."
"; - if (($res = sem_get($tok)) == FALSE) { + // FIXME monitor this step + if (($res = @sem_get($tok)) == FALSE) { echo "SEM_GET FAILED"; exit; } @@ -301,7 +346,7 @@ class Briskin5 { // change // update local graph // update remote graphs - for ($i = 0 ; $i < MAX_PLAYERS ; $i++) { + for ($i = 0 ; $i < BRISKIN5_MAX_PLAYERS ; $i++) { $user_cur = &$this->user[$i]; // if ($user_cur->sess == '' || $user_cur->stat != 'room') if ($user_cur->sess == '') @@ -313,13 +358,13 @@ class Briskin5 { break; } } - if ($i == MAX_PLAYERS) { + if ($i == BRISKIN5_MAX_PLAYERS) { $user->name = $name_new; log_main($user->sess." chatt_send start set"); - for ($i = 0 ; $i < MAX_PLAYERS ; $i++) { + for ($i = 0 ; $i < BRISKIN5_MAX_PLAYERS ; $i++) { log_main($user->sess." chatt_send set loop"); $user_cur = &$this->user[$i]; @@ -343,11 +388,11 @@ class Briskin5 { $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; "; $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('set_names(" %s", " %s", " %s", " %s", " %s"); ', - xcape($this->user[$table->player[($user_cur->table_pos)%PLAYERS_N]]->name), - xcape($this->user[$table->player[($user_cur->table_pos+1)%PLAYERS_N]]->name), - xcape($this->user[$table->player[($user_cur->table_pos+2)%PLAYERS_N]]->name), - (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+3)%PLAYERS_N]]->name)), - (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+4)%PLAYERS_N]]->name))); + xcape($this->user[$table->player[($user_cur->table_pos) % BRISKIN5_PLAYERS_N]]->name), + xcape($this->user[$table->player[($user_cur->table_pos+1) % BRISKIN5_PLAYERS_N]]->name), + xcape($this->user[$table->player[($user_cur->table_pos+2) % BRISKIN5_PLAYERS_N]]->name), + (BRISKIN5_PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+3) % BRISKIN5_PLAYERS_N]]->name)), + (BRISKIN5_PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+4) % BRISKIN5_PLAYERS_N]]->name))); if ($user_cur == $user) $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "%s";', xcape($user->name,ENT_COMPAT,"UTF-8")); @@ -357,7 +402,7 @@ class Briskin5 { } } else { - for ($i = 0 ; $i < ($user->stat == 'room' ? MAX_PLAYERS : PLAYERS_N) ; $i++) { + for ($i = 0 ; $i < ($user->stat == 'room' ? BRISKIN5_MAX_PLAYERS : BRISKIN5_PLAYERS_N) ; $i++) { if ($user->stat == 'room') { $user_cur = &$this->user[$i]; if ($user_cur->sess == '' || $user_cur->stat != 'room') @@ -435,7 +480,7 @@ function locshm_exists($tok) { // return (TRUE); - if (($id = shmop_open($tok,"a", 0, 0)) == FALSE) { + if (($id = @shmop_open($tok,"a", 0, 0)) == FALSE) { log_main($tok." SHM NOT exists"); return (FALSE);