- 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) {
-
- log_shme("Bin5::save_data");
-
- $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()
- {
- GLOBAL $sess;
-
- $ret = FALSE;
- $shm = FALSE;
- log_main("DESTROY BRISKIN5 DATA");
-
- do {
- 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)
- 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);
- }
-
- static function lock_data($is_exclusive, $table_idx)
- {
- 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);
- }
-
-
- static function unlock_data($res_vect)
- {
- GLOBAL $sess;
-
- $res = $res_vect->getbyid('res');
- $tab = $res_vect->getbyid('tab');
-
- log_lock("UNLOCK table [".$tab."] [".(microtime(TRUE) - (self::$delta_t[$tab]))."]");
-
- file_unlock($res);
- }
-
-
- function chatt_send($user, $mesg)
- {
- GLOBAL $mlang_brisk, $G_lang;
-
- if ($user->stat == 'table') {
- $table = &$this->table[$user->table];
- }
-
- $user_mesg = substr($mesg,6);
-
- $curtime = time();
-
- $dt = date("H:i ", $curtime);
- if (strncmp($user_mesg, "/nick ", 6) == 0) {
- log_main($user->sess." chatt_send BEGIN");
-
- if (($name_new = validate_name(substr($user_mesg, 6))) == FALSE) {
- $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
- $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['nickmust'][$G_lang]);
- $user->step_inc();
-
- return;
- }
- $user_mesg = "COMMAND ".$user_mesg;
- // Search dup name
- // change
- // update local graph
- // update remote graphs
- for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
- $user_cur = $this->user[$i];
- // if ($user_cur->sess == '' || $user_cur->stat != 'room')
- if ($user_cur->sess == '')
- continue;
- 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));
- $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $premsg);
- $user->step_inc();
- break;
- }
- }
- if ($i == BIN5_MAX_PLAYERS) {
- if ($user->flags & USER_FLAG_AUTH && strcasecmp($user->name,$name_new) != 0) {
- if ($this->table[$user->table]->auth_only == TRUE) {
- $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
- $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"<b>%s</b>");', $dt, NICKSERV, $mlang_brisk['authchan'][$G_lang]);
- $user->step_inc();
- return;
- }
- else {
- $user->flags &= ~USER_FLAG_AUTH; // Remove auth if name changed
- }
- }
+ return;
+ }
+ $user_mesg = "COMMAND ".$user_mesg;
+ // Search dup name
+ // change
+ // update local graph
+ // update remote graphs
+ for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
+ $user_cur = $this->user[$i];
+ // if ($user_cur->sess == '' || $user_cur->stat != 'room')
+ if ($user_cur->sess == '')
+ continue;
+ 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));
+ $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $premsg);
+ $user->step_inc();
+ break;
+ }
+ }
+ if ($i == BIN5_MAX_PLAYERS) {
+ if ($user->flags & USER_FLAG_AUTH && strcasecmp($user->name,$name_new) != 0) {
+ if ($this->table[$user->table]->auth_only == TRUE) {
+ $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
+ $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"<b>%s</b>");', $dt, NICKSERV, $mlang_brisk['authchan'][$G_lang]);
+ $user->step_inc();
+ return;
+ }
+ else {
+ $user->flags &= ~USER_FLAG_AUTH; // Remove auth if name changed
+ }
+ }