5 * Copyright (C) 2006 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("brisk.phh");
26 log_load($sess, "LOAD: index_rd.php ".$QUERY_STRING);
31 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
32 echo "Debugging time!";
38 log_rd2("SHUTTA!", connection_status());
42 register_shutdown_function(shutta);
46 GLOBAL $is_page_streaming;
48 $is_page_streaming = TRUE;
49 return (sprintf('the_end=true; window.onunload = null; document.location.assign("index.php");'));
52 function page_sync($page)
54 GLOBAL $is_page_streaming;
56 $is_page_streaming = TRUE;
57 return (sprintf('the_end=true; window.onunload = null; document.location.assign("%s");', $page));
63 function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step)
65 GLOBAL $is_page_streaming, $first_loop;
71 /* Sync check (read only without modifications */
72 ignore_user_abort(TRUE);
73 if (($sem = lock_data()) != FALSE) {
74 // Aggiorna l'expire time lato server
75 if ($first_loop == TRUE) {
78 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
80 ignore_user_abort(FALSE);
81 return (unrecerror());
83 log_auth($sess, "update lacc");
86 $bri->garbage_manager(FALSE);
92 ignore_user_abort(FALSE);
98 if (($proxy_step = step_get($sess)) != FALSE) {
99 // log_rd2($sess, "Postget".$proxy_step."zizi");
101 if ($cur_step == $proxy_step) {
110 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
111 return (unrecerror());
114 /* Nothing changed, return. */
115 if ($cur_step == $user->step)
118 log_rd2($sess, "do other ++".$cur_stat."++".$user->stat."++".$cur_step."++".$user->step);
120 if ($cur_step == -1) {
121 // FUNZIONE from_scratch DA QUI
122 ignore_user_abort(TRUE);
125 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
127 ignore_user_abort(FALSE);
128 return (unrecerror());
131 $is_page_streaming = TRUE;
134 if ($user->trans_step != -1) {
135 log_rd2($sess, "TRANS USATO ".$user->trans_step);
136 $cur_step = $user->trans_step;
137 $user->trans_step = -1;
142 ignore_user_abort(FALSE);
145 log_rd2($sess, "TRANS NON ATTIVATO");
147 ignore_user_abort(FALSE);
151 if ($cur_step == -1) {
152 log_rd2($sess, "PRE-NEWSTAT.");
154 if ($user->stat == 'room') {
155 log_rd($sess, "roomma");
156 $ret .= show_room(&$bri, &$user);
163 else if ($user->stat == 'table') {
164 $ret = show_table(&$bri,&$user,$user->step,FALSE,FALSE);
166 log_rd2($sess, "SENDED TO THE STREAM: ".$ret);
168 log_rd2($sess, "NEWSTAT: ".$user->stat);
170 $new_stat = $user->stat;
171 $new_subst = $user->subst;
172 $new_step = $user->step;
175 ignore_user_abort(TRUE);
178 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
180 ignore_user_abort(FALSE);
181 return (unrecerror());
183 if ($cur_step < $user->step) {
185 if ($cur_step + COMM_N < $user->step) {
186 if (($cur_stat != $user->stat)) {
187 $to_stat = $user->stat;
189 ignore_user_abort(FALSE);
190 return (page_sync($to_stat == "table" ? "table.php" : "index.php"));
192 log_rd2($sess, "lost history, refresh from scratch");
196 for ($i = $cur_step ; $i < $user->step ; $i++) {
197 log_rd2($sess, "ADDED TO THE STREAM: ".$user->comm[$i % COMM_N]);
198 $ret .= $user->comm[$i % COMM_N];
200 $new_stat = $user->stat;
201 $new_subst = $user->subst;
202 $new_step = $user->step;
205 if ($user->the_end == TRUE) {
206 log_rd2($sess, "LOGOUT BYE BYE!!");
207 log_auth($user->sess, "Explicit logout.");
208 $tmp_sess = $user->sess;
210 step_unproxy($tmp_sess);
213 $user->the_end = FALSE;
215 if ($user->subst == 'sitdown')
216 $bri->room_wakeup(&$user);
217 else if ($user->subst == 'standup')
218 $bri->room_outstandup(&$user);
220 log_rd2($sess, "LOGOUT FROM WHAT ???");
227 ignore_user_abort(FALSE);
245 $is_page_streaming = ((stristr($HTTP_USER_AGENT, "linux") &&
246 stristr($HTTP_USER_AGENT, "firefox")) ? FALSE : TRUE);
249 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
250 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
252 log_rd2($sess, "FROM OUTSIDE - STAT: ".$stat." SUBST: ".$subst." STEP: ".$step." MYFROM: ".$myfrom. "IS_PAGE:" . $is_page_streaming);
255 $endtime = time() + STREAM_TIMEOUT;
258 $old_step = $ext_step = $step;
260 for ($i = 0 ; time() < $endtime ; $i++) {
261 // log_rd($sess, "PRE MAIN ".$step);;
262 if (($ret = maincheck($sess, $old_stat, $old_subst, $old_step, &$stat, &$subst, &$step)) != FALSE) {
264 // 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));
267 log_send($sess, "EXT_STEP: ".$ext_step." ENDTIME: [".$endtime."] ".$ret);
269 if ($is_page_streaming)
275 // log_rd($sess, "POST MAIN ".$step);;
277 if (($i % 10) == 0) {
278 // log_rd2($sess, "TIME: ".time());