- // 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");
-
- do {
- if (($tok = @ftok(FTOK_PATH."/bin5/table".$table_idx."/table", "B")) == -1) {
- log_main("ftok failed");
- $doexit = TRUE;
- break;
- }
-
- 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)
- break;
-
- if ($table_token != "" && $bri->table_token != $table_token) {
- log_wr("bri->table_token: ".$bri->table_token."table_token: ".$table_token);
- break;
- }
- $bri->tok = $tok;
-
- shm_detach($shm);
-
- for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
- $bri->user[$i] = Bin5_user::load_data($table_idx, $i, FALSE);
- }
-
- return ($bri);
- } while (FALSE);
-
- if ($shm != FALSE)
- shm_detach($shm);
-
- log_wr("briskin5 load_data failed");
- if ($doexit)
- exit();
-
- return (FALSE);
- }
-
-
-
- function save_data($bri)
- {
- GLOBAL $sess;
-
- $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;
- }
-
- 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) {
- $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)
- {
- GLOBAL $sess;
-
- $ret = FALSE;
- $shm = FALSE;
- log_main("DESTROY BRISKIN5 DATA");
-
- do {
- log_main("DESTROY2 BRISKIN5 DATA");
-
- if (($tok = @ftok(FTOK_PATH."/bin5/table".$table_idx."/table", "B")) == -1)
- break;
-
- if (($shm = @shmop_open($tok, 'a', 0, 0)) == FALSE)
- break;
-
- if (shmop_delete($shm) == 0) {
- log_only("REMOVE FALLITA ");
- break;
- }
-
- $shm = FALSE;
- log_main("DESTROY2 BRISKIN5 DATA SUCCESS");
-
- // log_main("QUI CI ARRIVA [".$bri->user[0]->name."]");
- $ret = TRUE;
- } while (0);
-
- if ($shm)
- shm_detach($shm);
-
- return ($ret);
- }
-
- function lock_data($table_idx)
- {
- GLOBAL $sess;
-
- log_lock("LOCK_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)) == 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");
- return (FALSE);
- }
- }
-
- function unlock_data($res)
- {
- GLOBAL $sess;
-
- log_lock("UNLOCK table [res: ".$res."]");
-
- return (sem_release($res));
- }
-
-
- function chatt_send($user, $mesg)
- {
- GLOBAL $mlang_brisk, $G_lang;