+ function Bin5 ($room, $table_idx, $table_token, $get, $post, $cookie) {
+ $this->user = array();
+ $this->table = array();
+
+ $this->the_end = FALSE;
+ $this->shm_sz = BIN5_SHM_MIN;
+ if (($this->tok = @ftok(FTOK_PATH."/bin5/table".$table_idx."/table", "B")) == -1) {
+ echo "FTOK FAILED";
+ exit;
+ }
+
+ $user = $room->user;
+ $table = $room->table[$table_idx];
+
+ log_wr("Bin5 constructor");
+
+ for ($i = 0 ; $i < $table->player_n ; $i++) {
+ $user[$table->player[$i]]->table_token = $table_token;
+ $this->user[$i] = Bin5_user::spawn($user[$table->player[$i]], $this, $table_idx, $i, $get, $post, $cookie);
+ }
+ $this->table[0] = Bin5_table::spawn(&$table);
+
+ log_main("TABLE_OLD_WIN - Bin5:".$this->table[0]->old_win);
+
+ $this->table_idx = $table_idx;
+ $this->table_token = $table_token;
+ $this->garbage_timeout = 0;
+
+ log_wr("Bin5 constructor end");
+ }
+
+
+ function get_user($sess, &$idx)
+ {
+ GLOBAL $PHP_SELF;
+
+ if (validate_sess($sess)) {
+ for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
+ if (strcmp($sess, $this->user[$i]->sess) == 0) {
+ // find it
+ $idx = $i;
+ $ret = &$this->user[$i];
+ return ($ret);
+ }
+ }
+ log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
+ // for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++)
+ // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
+ }
+ else {
+ log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
+ }
+
+ return (FALSE);
+ }
+
+
+ function garbage_manager($force)
+ {
+ GLOBAL $G_base;
+
+ /* Garbage collector degli utenti in timeout */
+ $ismod = FALSE;
+ $curtime = time();
+ if ($force || $this->garbage_timeout < $curtime) {
+ for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
+ $user_cur = $this->user[$i];
+ if ($user_cur->sess == "" ||
+ ($user_cur->stat == 'table' && ($user_cur->subst == 'shutdowned' || $user_cur->subst == 'shutdowner')))
+ continue;
+
+ if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) { // Auto logout dell'utente
+ log_rd2($user_cur->sess." bin5 AUTO LOGOUT.");
+
+ if ($user_cur->stat == 'table') {
+ log_auth($user_cur->sess," bin5 Autologout session.");
+
+ /* SI DELEGA AL garbage_manager principale LA RIMOZIONE DELL'UTENTE
+
+ $tmp_sess = $user_cur->sess;
+ $user_cur->sess = "";
+ Bin5_user::step_unproxy($tmp_sess);
+ $user_cur->name = "";
+ $user_cur->the_end = FALSE;
+
+ */
+
+ /* se gli altri utenti non erano d'accordo questo utente viene bannato */
+ $remcalc = $this->table[0]->exitlock_calc(&$this->user, $user_cur->table_pos);
+ if ($remcalc < 3) {
+ require_once("${G_base}Obj/hardban.phh");
+ Hardbans::add(($user_cur->flags & USER_FLAG_AUTH ? $user_cur->name : FALSE),
+ $user_cur->ip, $user_cur->sess, $user_cur->laccwr + BAN_TIME);
+ }
+ // $user->bantime = $user->laccwr + BAN_TIME;
+
+ $this->table_wakeup($user_cur);
+ }
+ }
+ }
+ log_rd2($user_cur->sess." GARBAGE UPDATED!");
+
+ $this->garbage_timeout = $curtime + GARBAGE_TIMEOUT;
+
+ $ismod = TRUE;
+ }
+
+ return ($ismod);
+ }
+
+ // Bin5::load_data
+ static function load_data($table_idx, $table_token = "")
+ {
+ $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");
+ break;
+ }
+
+ if (($shm_sz = sharedmem_sz($tok)) == -1) {
+ log_main("shmop_open failed");
+ break;
+ }