5 * Copyright (C) 2006-2007 matteo.nastasi@milug.org
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details. You should have received a
16 * copy of the GNU General Public License along with this program; if
17 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
18 * Suite 330, Boston, MA 02111-1307, USA.
24 require_once("../Obj/brisk.phh");
25 require_once("Obj/briskin5.phh");
27 log_load($sess, "LOAD: index_rd.php ".$QUERY_STRING);
32 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
33 echo "Debugging time!";
39 log_rd2("SHUTTA!", connection_status());
43 register_shutdown_function(shutta);
47 GLOBAL $is_page_streaming;
49 $is_page_streaming = TRUE;
50 log_rd2("XXX", "UNREC_ERROR");
51 return (sprintf('the_end=true; window.onunload = null; document.location.assign("index.php");'));
54 function page_sync($sess, $page)
56 GLOBAL $is_page_streaming;
58 $is_page_streaming = TRUE;
59 log_rd2($sess, "PAGE_SYNC");
60 return (sprintf('the_end=true; window.onunload = null; document.location.assign("%s");', $page));
66 function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step, $table_idx)
68 GLOBAL $is_page_streaming, $first_loop;
74 /* Sync check (read only without modifications */
75 ignore_user_abort(TRUE);
76 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
77 // Aggiorna l'expire time lato server
78 if ($first_loop == TRUE) {
80 $bri = &Briskin5::load_data($table_idx);
81 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
82 Briskin5::unlock_data($sem);
83 ignore_user_abort(FALSE);
84 return (unrecerror());
86 log_auth($sess, "update lacc");
89 $bri->garbage_manager(FALSE);
91 Briskin5::save_data($bri);
96 Briskin5::unlock_data($sem);
97 ignore_user_abort(FALSE);
103 if (($proxy_step = step_get($sess)) != FALSE) {
104 // log_rd2($sess, "Postget".$proxy_step."zizi");
106 if ($cur_step == $proxy_step) {
107 log_only2($sess, "P");
111 log_only2($sess, "R");
115 log_only2($sess, "R");
119 ignore_user_abort(TRUE);
120 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
121 log_only($sess, "P");
122 $bri = &Briskin5::load_data($table_idx);
123 Briskin5::unlock_data($sem);
124 ignore_user_abort(FALSE);
131 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
132 return (unrecerror());
135 /* Nothing changed, return. */
136 if ($cur_step == $user->step)
139 log_rd2($sess, "do other ++".$cur_stat."++".$user->stat."++".$cur_step."++".$user->step);
141 if ($cur_step == -1) {
142 // FUNZIONE from_scratch DA QUI
143 ignore_user_abort(TRUE);
144 $sem = Briskin5::lock_data($table_idx);
145 $bri = &Briskin5::load_data($table_idx);
146 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
147 Briskin5::unlock_data($sem);
148 ignore_user_abort(FALSE);
149 return (unrecerror());
152 $is_page_streaming = TRUE;
155 if ($user->trans_step != -1) {
156 log_rd2($sess, "TRANS USATO ".$user->trans_step);
157 $cur_step = $user->trans_step;
158 $user->trans_step = -1;
161 Briskin5::save_data($bri);
162 Briskin5::unlock_data($sem);
163 ignore_user_abort(FALSE);
166 log_rd2($sess, "TRANS NON ATTIVATO");
167 Briskin5::unlock_data($sem);
168 ignore_user_abort(FALSE);
172 if ($cur_step == -1) {
173 log_rd2($sess, "PRE-NEWSTAT.");
175 if ($user->stat == 'room') {
176 log_rd($sess, "roomma");
177 $ret .= show_room(&$bri, &$user);
184 else if ($user->stat == 'table') {
185 $ret = show_table(&$bri,&$user,$user->step,FALSE,FALSE);
187 log_rd2($sess, "SENDED TO THE STREAM: ".$ret);
189 log_rd2($sess, "NEWSTAT: ".$user->stat);
191 $new_stat = $user->stat;
192 $new_subst = $user->subst;
193 $new_step = $user->step;
196 ignore_user_abort(TRUE);
197 $sem = Briskin5::lock_data($table_idx);
198 $bri = &Briskin5::load_data($table_idx);
199 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
200 Briskin5::unlock_data($sem);
201 ignore_user_abort(FALSE);
202 return (unrecerror());
204 if ($cur_step < $user->step) {
206 if ($cur_step + COMM_N < $user->step) {
207 if (($cur_stat != $user->stat)) {
208 $to_stat = $user->stat;
209 Briskin5::unlock_data($sem);
210 ignore_user_abort(FALSE);
211 return (page_sync($user->sess, $to_stat == "table" ? "table.php" : "index.php"));
213 log_rd2($sess, "lost history, refresh from scratch");
217 for ($i = $cur_step ; $i < $user->step ; $i++) {
219 log_wr($sess, "TRY RET ".$i." COMM_N ".COMM_N." II ".$ii);
220 $ret .= $user->comm[$ii];
222 $new_stat = $user->stat;
223 $new_subst = $user->subst;
224 $new_step = $user->step;
227 if ($user->the_end == TRUE) {
228 log_rd2($sess, "LOGOUT BYE BYE!!");
229 log_auth($user->sess, "Explicit logout.");
230 $tmp_sess = $user->sess;
232 step_unproxy($tmp_sess);
235 $user->the_end = FALSE;
237 if ($user->subst == 'sitdown')
238 $bri->room_wakeup(&$user);
239 else if ($user->subst == 'standup')
240 $bri->room_outstandup(&$user);
242 log_rd2($sess, "LOGOUT FROM WHAT ???");
244 Briskin5::save_data($bri);
248 Briskin5::unlock_data($sem);
249 ignore_user_abort(FALSE);
267 $is_page_streaming = ((stristr($HTTP_USER_AGENT, "linux") &&
268 stristr($HTTP_USER_AGENT, "firefox")) ? FALSE : TRUE);
271 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
272 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
278 log_rd2($sess, "FROM OUTSIDE - STAT: ".$stat." SUBST: ".$subst." STEP: ".$step." MYFROM: ".$myfrom. "IS_PAGE:" . $is_page_streaming);
281 $endtime = time() + STREAM_TIMEOUT;
284 $old_step = $ext_step = $step;
286 for ($i = 0 ; time() < $endtime ; $i++) {
287 // log_rd($sess, "PRE MAIN ".$step);;
288 if (($ret = maincheck($sess, $old_stat, $old_subst, $old_step, &$stat, &$subst, &$step, $table_idx)) != FALSE) {
290 // log_rd2($sess, sprintf("\nSESS: [%s]\nOLD_STAT: [%s] OLD_SUBST: [%s] OLD_STEP: [%s] \nSTAT: [%s] SUBST: [%s] STEP: [%s] \nCOMM: [%s]\n", $sess, $old_stat, $old_subst, $old_step, $stat, $subst, $step, $ret));
293 log_send($sess, "EXT_STEP: ".$ext_step." ENDTIME: [".$endtime."] ".$ret);
295 if ($is_page_streaming)
301 // log_rd($sess, "POST MAIN ".$step);;
304 // log_rd2($sess, "TIME: ".time());