2 define(MAX_BRISKIN5_PLAYERS, 3);
8 var $comm; // commands for many people
9 var $step; // current step of the comm array
12 function Briskin5 (&$room, $table_idx) {
13 $this->user = array();
14 $this->table = array();
17 $table =& $room->table[$table_idx];
19 log_wr("xxx", "Briskin5 constructor");
21 for ($i = 0 ; $i < $table->player_n ; $i++)
22 $this->user[$i] =& User::spawn(&$user[$table->player[$i]], 0, $i);
24 $this->table[0] =& Table::spawn(&$table);
25 $this->table_idx = $table_idx;
26 $this->garbage_timeout = 0;
28 log_wr("xxx", "Briskin5 constructor end");
32 function &get_user($sess, &$idx)
34 GLOBAL $PHP_SELF, $G_false;
36 if (validate_sess($sess)) {
37 for ($i = 0 ; $i < MAX_BRISKIN5_PLAYERS ; $i++) {
38 if (strcmp($sess, $this->user[$i]->sess) == 0) {
41 $ret = &$this->user[$i];
45 log_main($sess, sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
46 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
47 // log_main($sess, sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
50 log_main($sess, sprintf("get_user: Wrong strlen [%s]",$sess));
57 function garbage_manager($force)
60 /* Garbage collector degli utenti in timeout */
62 if ($force || $this->garbage_timeout < $curtime) {
64 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
65 $user_cur = &$this->user[$i];
66 if ($user_cur->sess == "")
69 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) { // Auto logout dell'utente
70 log_rd2($user_cur->sess, "AUTO LOGOUT.");
72 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
73 log_auth($user_cur->sess, "Autologout session.");
75 $tmp_sess = $user_cur->sess;
77 step_unproxy($tmp_sess);
79 $user_cur->the_end = FALSE;
81 log_rd2($user_cur->sess, "AUTO LOGOUT.");
82 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
83 $this->room_wakeup(&$user_cur);
84 else if ($user_cur->subst == 'standup')
85 $this->room_outstandup(&$user_cur);
87 log_rd2($sess, "LOGOUT FROM WHAT ???");
91 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
92 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
93 $this->room_wakeup(&$user_cur);
94 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
95 $user_cur->comm[$user_cur->step % COMM_N] .= show_notify("<br>Sei stato inattivo per ".(EXPIRE_TIME_SMAMMA/60.0)." minuti. <br><br>Quindi ritorni tra i <b>Giocatori in piedi</b>.", 0, "torna ai tavoli", 400, 100);
96 $user_cur->step_inc();
100 log_rd2($user_cur->sess, "GARBAGE UPDATED!");
102 $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
115 function &load_data($table_idx)
117 GLOBAL $G_false, $sess;
120 log_wr($sess, "TABLE_IDX ".FTOK_PATH."/table".$table_idx);
121 if (($tok = ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) {
127 if (($shm = shm_attach($tok, SHM_DIMS)) == FALSE)
130 if (($bri = @shm_get_var($shm, $tok)) == FALSE)
146 function save_data(&$bri)
156 if (($tok = ftok(FTOK_PATH."/table".$bri->table_idx, "B")) == -1)
162 if (($shm = shm_attach($tok, SHM_DIMS)) == FALSE)
165 // log_only($sess, "PUT_VAR DI ".strlen(serialize($bri)));
166 if (shm_put_var($shm, $tok, $bri) == FALSE) {
167 log_only($sess, "PUT_VAR FALLITA ".strlen(serialize($bri)));
168 log_only($sess, serialize($bri));
171 // log_main("XXX", "QUI CI ARRIVA [".$bri->user[0]->name."]");
181 function lock_data($table_idx)
185 log_wr($sess, "LOCK_DATA ".FTOK_PATH."/table".$table_idx);
186 // echo "LOCK: ".FTOK_PATH."/main";
188 if (($tok = ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) {
192 // echo "FTOK ".$tok."<br>";
193 if (($res = sem_get($tok)) == FALSE) {
194 echo "SEM_GET FAILED";
197 if (sem_acquire($res)) {
198 log_only($sess, "LOCK");
205 function unlock_data($res)
209 log_only($sess, "UNLOCK");
211 return (sem_release($res));