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.
22 require_once("brisk.phh");
24 log_load($sess, "LOAD: index_rd.php");
29 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
30 echo "Debugging time!";
36 log_rd2("SHUTTA!", connection_status());
40 register_shutdown_function(shutta);
44 GLOBAL $is_page_streaming;
46 $is_page_streaming = TRUE;
47 return (sprintf('the_end=true; document.location.assign("index.php");'));
54 function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step)
56 GLOBAL $is_page_streaming, $first_loop;
61 /* Sync check (read only without modifications */
62 if (($sem = lock_data()) != FALSE) {
64 // Aggiorna l'expire time lato server
65 if ($first_loop == TRUE) {
66 if (($user = &get_user($bri, $sess, $idx)) == FALSE) {
67 return (unrecerror());
69 log_auth($sess, "update lacc");
70 $user->lacc = time() + EXPIRE_TIME;
75 $bri->garbage_manager(FALSE);
84 if (($user = &get_user(&$bri, $sess, $idx)) == FALSE) {
85 return (unrecerror());
88 /* Nothing changed, return. */
89 if ($cur_stat == $user->stat && $cur_step == $user->step)
92 log_rd2($sess, "do other ++".$cur_stat."++".$user->stat."++".$cur_step."++".$user->step);
94 if ($cur_step == -1) {
95 // FUNZIONE from_scratch DA QUI
98 if (($user = &get_user($bri, $sess, $idx)) == FALSE) {
99 return (unrecerror());
102 $is_page_streaming = TRUE;
105 if ($user->trans_step != -1) {
106 log_rd2($sess, "TRANS USATO ".$user->trans_step);
107 $cur_step = $user->trans_step;
108 $user->trans_step = -1;
115 log_rd2($sess, "TRANS NON ATTIVATO");
119 if ($cur_step == -1) {
120 log_rd2($sess, "PRE-NEWSTAT.");
122 if ($user->stat == 'room') {
123 log_rd($sess, "roomma");
124 $ret .= show_room(&$bri, &$user);
131 else if ($user->stat == 'table') {
132 $ret = show_table(&$bri,&$user,$user->step,FALSE,FALSE);
134 log_rd2($sess, "SENDED TO THE STREAM: ".$ret);
136 log_rd2($sess, "NEWSTAT: ".$user->stat);
138 $new_stat = $user->stat;
139 $new_subst = $user->subst;
140 $new_step = $user->step;
147 if (($user = &get_user($bri, $sess, $idx)) == FALSE) {
148 return (unrecerror());
150 if ($cur_step < $user->step) {
152 if ($cur_step + COMM_N < $user->step) {
153 log_rd2($sess, "lost history, refresh from scratch");
157 for ($i = $cur_step ; $i < $user->step ; $i++) {
158 log_rd2($sess, "ADDED TO THE STREAM: ".$user->comm[$i % COMM_N]);
159 $ret .= $user->comm[$i % COMM_N];
161 $new_stat = $user->stat;
162 $new_subst = $user->subst;
163 $new_step = $user->step;
166 if ($user->the_end == TRUE) {
167 log_rd2($sess, "LOGOUT BYE BYE!!");
168 log_auth($user->sess, "Explicit logout.");
171 $user->the_end = FALSE;
173 if ($user->subst == 'sitdown')
174 $bri->room_wakeup(&$user);
175 else if ($user->subst == 'standup')
176 $bri->room_outstandup(&$user);
178 log_rd2($sess, "LOGOUT FROM WHAT ???");
202 $is_page_streaming = ((stristr($HTTP_USER_AGENT, "linux") &&
203 stristr($HTTP_USER_AGENT, "firefox")) ? FALSE : TRUE);
206 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
207 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
209 log_rd2($sess, "FROM OUTSIDE - STAT: ".$stat." SUBST: ".$subst." STEP: ".$step." MYFROM: ".$myfrom. "IS_PAGE:" . $is_page_streaming);
212 $endtime = time() + STREAM_TIMEOUT;
215 $old_step = $ext_step = $step;
217 for ($i = 0 ; time() < $endtime ; $i++) {
218 // log_rd($sess, "PRE MAIN ".$step);;
219 if (($ret = maincheck($sess, $old_stat, $old_subst, $old_step, &$stat, &$subst, &$step)) != FALSE) {
221 // 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));
224 log_send($sess, "EXT_STEP: ".$ext_step." ENDTIME: [".$endtime."] ".$ret);
226 if ($is_page_streaming)
232 // log_rd($sess, "POST MAIN ".$step);;
235 // log_rd2($sess, "TIME: ".time());