+ function show_room($user_step, $user)
+ {
+ GLOBAL $G_lang, $mlang_brisk;
+ log_main("show_room: username: ".$user->name);
+
+ $ret = sprintf('gst.st = %d; ', $user_step);
+
+ $prefs = Client_prefs::from_user($user);
+ $ret .= sprintf('prefs_load(\'%s\', false, false);', json_encode($prefs));
+
+ if(false) {
+ if ($user->flags & USER_FLAG_ISOLAUTH) {
+ $ret .= 'list_set(\'isolation\', false, \''.$mlang_brisk['tit_onisol'][$G_lang].'\' ); ';
+ }
+ else if ($user->flags & USER_FLAG_LISTAUTH) {
+ $ret .= 'list_set(\'auth\', false, \''.$mlang_brisk['tit_onauth'][$G_lang].'\' ); ';
+ }
+ else {
+ $ret .= 'list_set(\'all\', false, \'\' ); ';
+ }
+ }
+
+ if ($user->subst == 'standup')
+ $ret .= "tra.show(); ";
+ else
+ $ret .= "tra.hide(); ";
+
+ $ret .= sprintf('stat = "%s";', $user->stat);
+
+ $ret .= root_welcome($user);
+ if ($user->flags & USER_FLAG_DBFAILED) {
+ $ret .= "gst.st = ".($user->step+1)."; ";
+ $ret .= show_notify($mlang_brisk['db_failed'][$G_lang], 0, $mlang_brisk['btn_close'][$G_lang], 400, 140);
+ }
+
+ $ret .= sprintf('subst = "%s";', $user->subst);
+ $ret .= $user->myname_innerHTML();
+
+ for ($i = 0 ; $i < TABLES_N ; $i++) {
+
+ $ret .= $this->table_content($user, $i);
+
+ $ret .= $this->table[$i]->act_content($user);
+ if ($this->table[$i]->wag_own != -1)
+ $ret .= sprintf('tra.add(%d, "%s: %s"); ', $i, $this->user[$this->table[$i]->wag_own]->name, $this->table[$i]->wag_com);
+ else
+ $ret .= sprintf('tra.rem(%d); ', $i);
+ }
+ $ret .= $this->standup_content($user);
+ $ret .= "setTimeout(preload_images, 0, g_preload_img_arr, g_imgct); ";
+
+ return ($ret);
+ }
+
+ function room_wakeup($user)
+ {
+ $table_idx = $user->table;
+ $table = $this->table[$table_idx];
+
+ log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
+
+ $curtime = time();
+
+ $from_table = ($user->stat == "table");
+ if ($from_table) {
+ log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
+
+ for ($i = 0 ; $i < $table->player_n ; $i++) {
+ $user_cur = $this->user[$table->player[$i]];
+ log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
+
+ if ($user->idx_get() != $table->player[$i]) {
+ $user_cur->stat_set("room");
+ $user_cur->subst = "sitdown";
+ $user_cur->laccwr = $curtime;
+ }
+ else if ($user->is_active()) {
+ $user_cur->stat_set("room");
+ $user_cur->subst = "standup";
+ $user_cur->laccwr = $curtime;
+ $user_cur->table = -1;
+ }
+ }
+ }
+ else {
+ $user->stat_set("room");
+ $user->subst = "standup";
+ $user->laccwr = $curtime;
+ }
+
+ $remove_wagon = FALSE;
+ if($table->wag_own == $user->idx_get()) {
+ $table->wag_reset($curtime);
+ $remove_wagon = TRUE;
+ }
+
+ /* aggiorna l'array dei giocatori al tavolo. */
+ $table->user_rem($this, $user);
+
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $user_cur = $this->user[$i];
+ if ($user_cur->is_active() == FALSE || $user_cur->stat != 'room') // is not active user or the stat isn't 'room'
+ continue;
+
+ // log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
+
+ $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
+ if ($from_table && ($user_cur->table == $table_idx || $user->idx_get() == $i)) {
+ $ret .= 'gst.st_loc++; xstm.stop(); window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|';
+ // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
+ log_main("DOCUMENT.index.php: from table");
+ }
+ else if ($user_cur->stat == "room") {
+ log_main("DOCUMENT.index.php: from table");
+
+ $ret .= $this->table_content($user_cur, $table_idx);
+ $ret .= $this->standup_content($user_cur);
+
+ // $ret .= table_act_content(FALSE, 0, $table_idx, $user->table, FALSE);
+ $ret .= $table->act_content($user);
+
+ if ($user->idx_get() == $i) {
+ // set the new status
+ $ret .= 'subst = "standup"; tra.show(); ';
+ // clean the action buttons in other tables
+ for ($e = 0 ; $e < TABLES_N ; $e++) {
+ if ($this->table[$e]->player_n < PLAYERS_N) {
+ $ret .= $this->table[$e]->act_content($user);
+ }
+ }
+ }
+ else {
+ $ret .= $table->act_content($user_cur);
+ }
+ }
+ log_wr("ROOM_WAKEUP: ".$ret);
+ $user_cur->comm[$user_cur->step % COMM_N] = $ret;
+ $user_cur->step_inc();
+ }
+ }
+
+ function room_join_wakeup($user, $update_lacc = FALSE, $trans_delta)
+ {
+ $table_idx = $user->table;
+ $table = $this->table[$table_idx];
+
+ log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
+
+ $curtime = time();
+ $user_wup = array();
+ $user_wup_n = 0;
+ $user_tab = array();
+ $user_tab_n = 0;
+ log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
+
+ for ($i = 0 ; $i < $table->player_n ; $i++) {
+ $user_cur = $this->user[$table->player[$i]];
+ log_main("PREIMPOST INLOOP name: ".$user_cur->name);
+ if ($user_cur->is_empty()) {
+ continue;
+ }
+ if ($update_lacc == TRUE) {
+ $user_cur->laccwr = $curtime;
+ }
+ log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
+ if ($user_cur->subst == "shutdowned") {
+ $user_cur->stat_set("room");
+ $user_cur->subst = "sitdown";
+ }
+ else if ($user_cur->subst == "shutdowner") {
+ $user_cur->stat_set("room");
+ $user_cur->subst = "standup";
+ $user_cur->table = -1;
+ $user_wup[$user_wup_n++] = $user_cur;
+
+ $remove_wagon = FALSE;
+ if($table->wag_own == $table->player[$i]) {
+ $remove_wagon = TRUE;
+ $table->wag_reset($curtime);
+ }
+ }
+ $user_tab[$user_tab_n++] = $table->player[$i];
+ }
+
+ for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
+ $table->user_rem($this, $user_wup[$wup_idx]);
+
+ /* aggiorna l'array dei giocatori al tavolo. */
+
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ log_main("START LOOP");
+ $user_cur = $this->user[$i];
+ if ($user_cur->is_active() == FALSE || $user_cur->stat != 'room') { // is not active user or the stat isn't 'room'
+ log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
+ continue;
+ }
+
+ log_main("___");
+ log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx);
+
+ $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
+ if ($user_cur->stat == "room") {
+ log_main("DOCUMENT.index.php from table");
+
+ $ret .= $this->table_content($user_cur, $table_idx);
+ $ret .= $this->standup_content($user_cur);
+
+ $ret .= $table->act_content($user_cur);
+
+
+ for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
+ if ($user_tab[$tab_idx] == $i)
+ break;
+
+ // for users that wakeup the room will be reconstructed by index_rd.php
+ if ($tab_idx < $user_tab_n) {
+ log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
+
+// ARRAY_POP DISABLED
+// if ($trans_delta == 0)
+// while (array_pop($user_cur->comm) != NULL);
+
+ $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
+ $user_cur->comm[$user_cur->step % COMM_N] = "";
+ $user_cur->step_inc();
+ $user_cur->comm[$user_cur->step % COMM_N] = $this->show_room(($user_cur->step + 1), $user_cur);
+ $user_cur->step_inc();
+ log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
+
+ continue;
+ }
+ log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
+
+ log_main("JOIN_WAKEUP more");
+
+ $ret .= $table->act_content($user_cur);
+
+ log_main("JOIN_WAKEUP end more");
+ }
+ log_wr("ROOM_JOIN_WAKEUP: ".$ret);
+ $user_cur->comm[$user_cur->step % COMM_N] = $ret;
+ $user_cur->step_inc();
+ }
+ }
+
+ /*
+ function info_show($user, $target, $dt)
+
+ if success return assoc. array with "ret" => 0 and other fields
+ else return an assoc. array with "ret: != 0 and "mesg" with an error description
+ */
+ function info_show($user, $target, $dt)