+ do {
+ if (($tok = @ftok(FTOK_PATH."/user".$id, "B")) == -1) {
+ log_main("ftok failed");
+ break;
+ }
+
+ if (($shm_sz = sharedmem_sz($tok)) == -1) {
+ log_main("shmop_open failed");
+ }
+
+ if ($shm_sz == -1)
+ $shm_sz = SHM_DIMS_U_MIN;
+
+ if ($shm = shm_attach($tok, $shm_sz)) {
+ if (($user = @shm_get_var($shm, $tok)) == FALSE) {
+ break;
+ }
+ if ($sess != FALSE && $user->sess != $sess) {
+ break;
+ }
+ log_only("user == ".($user == FALSE ? "FALSE" : "TRUE")." user === ".($user === FALSE ? "FALSE" : "TRUE")." user isset ".(isset($user) ? "TRUE" : "FALSE"));
+
+ if ($user == FALSE) {
+ log_only("INIT MAIN DATA");
+
+ // SHSPLIT FIXME: init_data for User class ??
+ $user = User::create($id, "", "");
+ if (@shm_put_var($shm, $tok, $user) == FALSE) {
+ log_only("PUT_VAR FALLITA ".strlen(serialize($user)));
+ log_only(serialize($user));
+ }
+ log_shme("User::save_data2");
+ }
+ else {
+ if ($sess != FALSE) {
+ /*
+ * NOTE: this part is for check only, theoretically
+ * user->step anch proxy_step are set allways at the same value
+ */
+ $old_step = $user->step;
+ $arr = User::load_step($sess);
+ $user->step = $arr['s'];
+ if ($old_step != $user->step) {
+ log_crit("steps are diffetents User->step ".$user->step." Old_step: ".$old_step);
+ }
+ }
+ }
+ $user->shm_sz = $shm_sz;
+
+ shm_detach($shm);
+ }
+
+ //
+ // SHSPLIT: load users from the shared memory
+ //
+ return ($user);
+ } while (0);
+
+ return (FALSE);
+ }
+
+
+ static function save_data($user, $id)
+ {
+ GLOBAL $sess;
+
+ $shm = FALSE;
+
+ if (($tok = @ftok(FTOK_PATH."/user".$id, "B")) == -1) {
+ return (FALSE);
+ }
+ while ($user->shm_sz < SHM_DIMS_U_MAX) {
+ if (($shm = shm_attach($tok, $user->shm_sz)) == FALSE)
+ break;
+
+ // log_only("PUT_VAR DI ".strlen(serialize($user)));
+ if (@shm_put_var($shm, $tok, $user) != FALSE) {
+ shm_detach($shm);
+ if ($user->sess != "")
+ $user->save_step();
+
+ log_shme("User::save_data");
+
+ log_main("User[".$id."] saved.");
+ return (TRUE);
+ }
+ if (shm_remove($shm) === FALSE) {
+ log_only("REMOVE FALLITA");
+ break;
+ }
+ shm_detach($shm);
+ $user->shm_sz += SHM_DIMS_U_DLT;
+ }
+
+ if ($shm)
+ shm_detach($shm);
+
+ return (FALSE);
+ }
+
+ function myname_innerHTML()
+ {
+ $class_id = ($this->flags & USER_FLAG_AUTH) + 1;
+
+ return (sprintf('$("myname").innerHTML = "<span class=\"au%d\">%s</span>";', $class_id,
+ xcape($this->name,ENT_COMPAT,"UTF-8")));
+ }
+
+} // end class User
+
+
+
+class Room {
+ static $delta_t;
+
+ var $user;
+ var $table;
+ var $comm; // commands for many people
+ var $step; // current step of the comm array
+ // externalized var $garbage_timeout;
+ var $shm_sz;
+
+ function Room () {
+ $this->user = array();
+ $this->table = array();
+
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $this->user[$i] = User::create($i, "", "");
+ }
+
+ for ($i = 0 ; $i < TABLES_N ; $i++) {
+ $this->table[$i] = Table::create($i);
+ /* OLD METHOD
+ if ($i < 12) {
+ $row = ( (((int)($i / 4)) % 2) == 0 );
+ $col = ($i % 2 == 0);
+ $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
+ }
+ else {
+ $this->table[$i]->auth_only = FALSE;
+ }
+ */
+ if ($i < TABLES_AUTH_N)
+ $this->table[$i]->auth_only = TRUE;
+ else
+ $this->table[$i]->auth_only = FALSE;
+ }
+ // externalized $this->garbage_timeout = 0;
+ Room::garbage_time_expire_set(0);
+ $this->shm_sz = SHM_DIMS_MIN;
+ }
+
+ function garbage_manager($force)
+ {
+ GLOBAL $G_lang, $mlang_brisk, $G_base;
+
+ $ismod = FALSE;
+
+ log_rd2("garbage_manager START");
+
+ /* Garbage collector degli utenti in timeout */
+ $curtime = time();
+
+ // externalized if ($force || $this->garbage_timeout < $curtime) {
+ if (!$force && !Room::garbage_time_is_expired($curtime)) {
+ return ($ismod);
+ }
+
+ webservers_check();
+ // FIXME BRISK4: include for each kind of table
+ require_once("${G_base}briskin5/Obj/briskin5.phh");
+
+ // Before all align times with table timeout
+ for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
+ $table_cur = $this->table[$table_idx];
+ // if the table is complete and exists its shared mem we get the info about users lacc
+
+ if ($table_cur->player_n == PLAYERS_N) {
+ log_main("PLAYERS == N TABLE ".$table_idx);
+
+ if (($sem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) {
+ log_main("bin5 lock data success");