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");
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");'));
56 function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step)
58 GLOBAL $is_page_streaming, $first_loop;
63 /* Sync check (read only without modifications */
64 ignore_user_abort(TRUE);
65 if (($sem = lock_data()) != FALSE) {
67 // Aggiorna l'expire time lato server
68 if ($first_loop == TRUE) {
69 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
71 ignore_user_abort(FALSE);
72 return (unrecerror());
74 log_auth($sess, "update lacc");
80 $bri->garbage_manager(FALSE);
85 ignore_user_abort(FALSE);
91 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
92 return (unrecerror());
95 /* Nothing changed, return. */
96 if ($cur_stat == $user->stat && $cur_step == $user->step)
99 log_rd2($sess, "do other ++".$cur_stat."++".$user->stat."++".$cur_step."++".$user->step);
101 if ($cur_step == -1) {
102 // FUNZIONE from_scratch DA QUI
103 ignore_user_abort(TRUE);
106 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
108 ignore_user_abort(FALSE);
109 return (unrecerror());
112 $is_page_streaming = TRUE;
115 if ($user->trans_step != -1) {
116 log_rd2($sess, "TRANS USATO ".$user->trans_step);
117 $cur_step = $user->trans_step;
118 $user->trans_step = -1;
123 ignore_user_abort(FALSE);
126 log_rd2($sess, "TRANS NON ATTIVATO");
128 ignore_user_abort(FALSE);
132 if ($cur_step == -1) {
133 log_rd2($sess, "PRE-NEWSTAT.");
135 if ($user->stat == 'room') {
136 log_rd($sess, "roomma");
137 $ret .= show_room(&$bri, &$user);
144 else if ($user->stat == 'table') {
145 $ret = show_table(&$bri,&$user,$user->step,FALSE,FALSE);
147 log_rd2($sess, "SENDED TO THE STREAM: ".$ret);
149 log_rd2($sess, "NEWSTAT: ".$user->stat);
151 $new_stat = $user->stat;
152 $new_subst = $user->subst;
153 $new_step = $user->step;
156 ignore_user_abort(TRUE);
159 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
161 ignore_user_abort(FALSE);
162 return (unrecerror());
164 if ($cur_step < $user->step) {
166 if ($cur_step + COMM_N < $user->step) {
167 log_rd2($sess, "lost history, refresh from scratch");
171 for ($i = $cur_step ; $i < $user->step ; $i++) {
172 log_rd2($sess, "ADDED TO THE STREAM: ".$user->comm[$i % COMM_N]);
173 $ret .= $user->comm[$i % COMM_N];
175 $new_stat = $user->stat;
176 $new_subst = $user->subst;
177 $new_step = $user->step;
180 if ($user->the_end == TRUE) {
181 log_rd2($sess, "LOGOUT BYE BYE!!");
182 log_auth($user->sess, "Explicit logout.");
185 $user->the_end = FALSE;
187 if ($user->subst == 'sitdown')
188 $bri->room_wakeup(&$user);
189 else if ($user->subst == 'standup')
190 $bri->room_outstandup(&$user);
192 log_rd2($sess, "LOGOUT FROM WHAT ???");
199 ignore_user_abort(FALSE);
217 $is_page_streaming = ((stristr($HTTP_USER_AGENT, "linux") &&
218 stristr($HTTP_USER_AGENT, "firefox")) ? FALSE : TRUE);
221 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
222 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
224 log_rd2($sess, "FROM OUTSIDE - STAT: ".$stat." SUBST: ".$subst." STEP: ".$step." MYFROM: ".$myfrom. "IS_PAGE:" . $is_page_streaming);
227 $endtime = time() + STREAM_TIMEOUT;
230 $old_step = $ext_step = $step;
232 for ($i = 0 ; time() < $endtime ; $i++) {
233 // log_rd($sess, "PRE MAIN ".$step);;
234 if (($ret = maincheck($sess, $old_stat, $old_subst, $old_step, &$stat, &$subst, &$step)) != FALSE) {
236 // 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));
239 log_send($sess, "EXT_STEP: ".$ext_step." ENDTIME: [".$endtime."] ".$ret);
241 if ($is_page_streaming)
247 // log_rd($sess, "POST MAIN ".$step);;
250 // log_rd2($sess, "TIME: ".time());