X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2FObj%2Fbrisk.phh;h=8136f8f5ee52f72b80e0c66add6fb737ed31cf84;hb=971fb704f6cb6091d0c597209f5f878c04336d51;hp=c2480221c0fb0705e09b346130aefbf021b3c80c;hpb=22a55ef9afd99554893f5633d0a37e7fdbfe449b;p=brisk.git diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index c248022..8136f8f 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -32,7 +32,8 @@ define(COMM_N, 12); define(COMM_GEN_N, 50); define(SESS_LEN, 13); define(STREAM_TIMEOUT, 20); -define(EXPIRE_TIME_RD, 180); +// FIXME original: define(EXPIRE_TIME_RD, 180); +define(EXPIRE_TIME_RD, 60); define(EXPIRE_TIME_SMAMMA, 360); // BAN_TIME da allineare anche in commons.js define(BAN_TIME, 900); @@ -44,7 +45,7 @@ define(BRISK_DEBUG, FALSE); $G_false = FALSE; $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 ); -$G_brisk_version = "0.8.2"; +$G_brisk_version = "spawn-0.0.3"; $root_wellarr = Array ( 'Benvenuto in brisk (Ver. '.$G_brisk_version.'), NOVITA\': nuovo layout che permette più tavoli, più tavoli.', 'Se vuoi iscriverti alla Mailing List, cliccala!' ); @@ -459,6 +460,7 @@ class User { var $exitislock; // Player can exit from the table ? var $table; // id of the current table (if in table state) var $table_pos; // idx on the table + var $table_token;// token that identify a game on a table var $the_end; // Flag to change the end of the session function User() { @@ -487,7 +489,9 @@ class User { $thiz->exitislock = TRUE; $thiz->table = $table; - + $thiz->table_pos = -1; + $thiz->table_token = ""; + return ($thiz); } @@ -498,30 +502,31 @@ class User { if (($thiz = new User()) == FALSE) return ($G_false); - $thiz->name = $from->name; - $thiz->sess = $from->sess; - $thiz->ip = $from->ip; - $thiz->lacc = $from->lacc; - $thiz->laccwr = $from->laccwr; - $thiz->bantime = $from->bantime; - $thiz->stat = $from->stat; - $thiz->subst = $from->subst; - $thiz->step = $from->step; + $thiz->name = $from->name; + $thiz->sess = $from->sess; + $thiz->ip = $from->ip; + $thiz->lacc = $from->lacc; + $thiz->laccwr = $from->laccwr; + $thiz->bantime = $from->bantime; + $thiz->stat = $from->stat; + $thiz->subst = $from->subst; + $thiz->step = $from->step; $thiz->trans_step = $from->trans_step; - $thiz->comm = array(); + $thiz->comm = array(); $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N)); for ($i = $i_start ; $i < $from->step ; $i++) { $ii = $i % COMM_N; - $thiz->comm[$ii] = $from->comm[$ii]; + $thiz->comm[$ii] = $from->comm[$ii]; } - $thiz->asta_card = $from->asta_card; - $thiz->asta_pnt = $from->asta_pnt; - $thiz->handpt = $from->handpt; + $thiz->asta_card = $from->asta_card; + $thiz->asta_pnt = $from->asta_pnt; + $thiz->handpt = $from->handpt; $thiz->exitislock = $from->exitislock; - $thiz->table = $from->table; - $thiz->table_pos = $from->table_pos; - $thiz->the_end = $from->the_end; + $thiz->table = $from->table; + $thiz->table_pos = $from->table_pos; + $thiz->table_token = $from->table_token; + $thiz->the_end = $from->the_end; return ($thiz); } @@ -560,6 +565,7 @@ class User { $thiz->table = $table; $thiz->table_pos = $table_pos; + $thiz->table_token = $from->table_token; return ($thiz); } @@ -653,6 +659,7 @@ class Room { function Room () { $this->user = array(); + $this->table = array(); for ($i = 0 ; $i < MAX_PLAYERS ; $i++) { $this->user[$i] =& User::create("", ""); @@ -665,11 +672,74 @@ class Room { function garbage_manager($force) { - + $ismod = FALSE; + /* Garbage collector degli utenti in timeout */ $curtime = time(); if ($force || $this->garbage_timeout < $curtime) { + // 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) { + if (($sem = Briskin5::lock_data($table_idx)) != FALSE) { + if (($bri = &Briskin5::load_data($table_idx)) != FALSE) { + if ($bri->garbage_manager(TRUE) == TRUE) { + // if garbaged you need to save data + Briskin5::save_data(&$bri); + if ($bri->is_abandoned()) { + // FIXME recovery of room and clean of the table + /* + + # + # KILL USERS + # + + if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) { // Auto logout dell'utente + log_rd2($user_cur->sess, "AUTO LOGOUT."); + + if ($user_cur->stat == 'table' || $user_cur->stat == 'room') { + log_auth($user_cur->sess, "Autologout session."); + + $tmp_sess = $user_cur->sess; + $user_cur->sess = ""; + step_unproxy($tmp_sess); + $user_cur->name = ""; + $user_cur->step = 0; + $user_cur->the_end = FALSE; + + log_rd2($user_cur->sess, "AUTO LOGOUT."); + if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table') + $this->room_wakeup(&$user_cur); + else if ($user_cur->subst == 'standup') + $this->room_outstandup(&$user_cur); + else + log_rd2($sess, "LOGOUT FROM WHAT ???"); + } + } + + # + # destroy shared + # + + Briskin5::destroy_data($user->table); + + + */ + } + } + $table_bri = &$bri->table[0]; + for ($i = 0 ; $i < PLAYERS_N ; $i++) { + $this->user[$table_cur->player[$i]]->lacc = + $bri->user[$table_bri->player[$i]]->lacc; + } + } + Briskin5::unlock_data($sem); + } + } + } + for ($i = 0 ; $i < MAX_PLAYERS ; $i++) { $user_cur = &$this->user[$i]; if ($user_cur->sess == "") @@ -685,6 +755,7 @@ class Room { $user_cur->sess = ""; step_unproxy($tmp_sess); $user_cur->name = ""; + $user_cur->step = 0; $user_cur->the_end = FALSE; log_rd2($user_cur->sess, "AUTO LOGOUT."); @@ -709,10 +780,10 @@ class Room { log_rd2($user_cur->sess, "GARBAGE UPDATED!"); $this->garbage_timeout = time() + GARBAGE_TIMEOUT; + $ismod = TRUE; } - // BAN_IP_CLEAN - + return ($ismod); } @@ -797,22 +868,26 @@ class Room { } } - function room_join_wakeup(&$user) + function room_join_wakeup(&$user, $update_lacc = FALSE) { $table_idx = $user->table; $table = &$this->table[$table_idx]; - - log_main("JOIN_WAKEUP", "begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst); + + log_main($user->sess, "JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst); $curtime = time(); - - log_main("JOIN WAKEUP", "from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n); + $user_wup = array(); + $user_wup_n = 0; + log_main($user->sess, "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); + log_main($user->sess, "PREIMPOST INLOOP name: ".$user_cur->name); if ($user_cur->sess != "") { - $user_cur->laccwr = $curtime; + if ($update_lacc == TRUE) { + $user_cur->laccwr = $curtime; + } + log_load($user->sess, "cur: ".$user_cur->name." subst: ".$user_cur->subst); if ($user_cur->subst == "shutdowned") { $user_cur->stat_set("room"); $user_cur->subst = "sitdown"; @@ -821,47 +896,62 @@ class Room { $user_cur->stat_set("room"); $user_cur->subst = "standup"; $user_cur->table = -1; - $user_wup = &$user_cur; + $user_wup[$user_wup_n++] = &$user_cur; } } } + 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. */ - $table->user_rem(&$this, &$user_wup); for ($i = 0 ; $i < MAX_PLAYERS ; $i++) { + log_main($user_cur->sess, "START LOOP"); $user_cur = &$this->user[$i]; - if ($user_cur->sess == '' || $user_cur->stat != 'room') + if ($user_cur->sess == '' || $user_cur->stat != 'room') { + log_main($user_cur->sess, "name: ".$user_cur->name."skip subst: ".$user_cur->subst); continue; - - log_main("VALORI", "name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user); + } + + log_main($user->sess, "___"); + log_main($user->sess, "VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user); $ret = "gst.st = ".($user_cur->step+1)."; "; if ($user_cur->stat == "room") { - log_main("DOCUMENT.index.php", "from table"); + log_main($user->sess, "DOCUMENT.index.php from table"); $ret .= table_content($this, $user_cur, $table_idx); $ret .= standup_content($this, $user_cur); - $act_content = table_act_content(FALSE, 0, $table_idx, $user->table); + $act_content = table_act_content(FALSE, 0, $table_idx, $user_cur->table); $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content); - - if ($user_cur == $user_wup) { + for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++) + if ($user_cur == $user_wup[$wup_idx]) + break; + + log_main($user->sess, "JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n); + + if ($wup_idx < $user_wup_n) { + log_main($user->sess, "JOIN_WAKEUP less"); // set the new status $ret .= 'subst = "standup"; '; // clean the action buttons in other tables for ($e = 0 ; $e < TABLES_N ; $e++) { if ($this->table[$e]->player_n < PLAYERS_N) - $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $e, table_act_content(TRUE, 0, $e, $user->table)); + $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $e, table_act_content(TRUE, 0, $e, $user_cur->table)); } + log_main($user->sess, "JOIN_WAKEUP end less"); } else { + log_main($user->sess, "JOIN_WAKEUP more"); $act_content = table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table); $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content); + log_main($user->sess, "JOIN_WAKEUP end more"); } } - log_wr($user_cur->sess, "ROOM_JOIN_WAKEUP: ".$ret); + log_wr($user->sess, "ROOM_JOIN_WAKEUP: ".$ret); $user_cur->comm[$user_cur->step % COMM_N] = $ret; $user_cur->step_inc(); } @@ -1744,6 +1834,10 @@ function show_table(&$room, &$user, $sendstep, $is_transition, $is_again) /* GENERAL STATUS */ $ret .= sprintf( 'gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;', $sendstep, $user->stat, $user->subst, $table_pos); + + log_rd($user->sess, sprintf( 'SHOW_TABLE: gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;', + $sendstep, $user->stat, $user->subst, $table_pos)); + /* BACKGROUND */ $ret .= "background_set();";