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/proxyscan.phh");
26 require_once("Obj/briskin5.phh");
28 // Use of proxies isn't allowed.
34 log_load("LOAD: bin5/index_rd.php ".$QUERY_STRING);
39 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
40 echo "Debugging time!";
46 log_rd2("bin5 SHUTTA!".connection_status());
50 register_shutdown_function(shutta);
54 GLOBAL $is_page_streaming;
56 $is_page_streaming = TRUE;
57 log_rd2("UNREC_ERROR");
58 return (sprintf('the_end=true; window.onunload = null; document.location.assign("../index.php");'));
61 function page_sync($sess, $page)
63 GLOBAL $is_page_streaming;
65 $is_page_streaming = TRUE;
67 return (sprintf('the_end=true; window.onunload = null; document.location.assign("%s");', $page));
73 function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step, $table_idx, $table_token)
75 GLOBAL $is_page_streaming, $first_loop;
81 /* Sync check (read only without modifications */
82 ignore_user_abort(TRUE);
83 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
84 // Aggiorna l'expire time lato server
85 if ($first_loop == TRUE) {
88 // VERIFICARE TUTTE LE LOAD_DATA E PRENDERE CONTROMISURE NEL CASO FALLISCANO //
90 if (($bri = &Briskin5::load_data($table_idx, $table_token)) == FALSE) {
91 Briskin5::unlock_data($sem);
92 ignore_user_abort(FALSE);
93 return (unrecerror());
95 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
96 Briskin5::unlock_data($sem);
97 ignore_user_abort(FALSE);
98 return (unrecerror());
100 log_auth($sess, "bin5::update lacc");
101 $user->lacc = time();
103 $bri->garbage_manager(FALSE);
105 Briskin5::save_data($bri);
110 Briskin5::unlock_data($sem);
111 ignore_user_abort(FALSE);
117 if (($proxy_step = step_get($sess)) != FALSE) {
118 // log_rd2("Postget".$proxy_step."zizi");
120 if ($cur_step == $proxy_step) {
134 ignore_user_abort(TRUE);
135 if (($sem = Briskin5::lock_data($table_idx)) == FALSE)
139 if (($bri = &Briskin5::load_data($table_idx, $table_token)) == FALSE)
144 Briskin5::unlock_data($sem);
146 ignore_user_abort(FALSE);
148 return (unrecerror());
151 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
152 return (unrecerror());
155 /* Nothing changed, return. */
156 if ($cur_step == $user->step)
159 log_rd2("do other ++".$cur_stat."++".$user->stat."++".$cur_step."++".$user->step);
161 if ($cur_step == -1) {
162 // FUNZIONE from_scratch DA QUI
163 ignore_user_abort(TRUE);
164 $sem = Briskin5::lock_data($table_idx);
165 $bri = &Briskin5::load_data($table_idx, $table_token);
166 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
167 Briskin5::unlock_data($sem);
168 ignore_user_abort(FALSE);
169 return (unrecerror());
172 $is_page_streaming = TRUE;
175 if ($user->trans_step != -1) {
176 log_rd2("TRANS USATO ".$user->trans_step);
177 $cur_step = $user->trans_step;
178 $user->trans_step = -1;
181 Briskin5::save_data($bri);
182 Briskin5::unlock_data($sem);
183 ignore_user_abort(FALSE);
186 log_rd2("TRANS NON ATTIVATO");
188 // ARRAY_POP DISABLED
189 // while (array_pop($user->comm) != NULL);
190 // // $user->step_inc(COMM_N + 1);
191 // Briskin5::save_data($bri);
193 Briskin5::unlock_data($sem);
194 ignore_user_abort(FALSE);
198 if ($cur_step == -1) {
199 log_rd2("PRE-NEWSTAT.");
206 if ($user->stat == "table") {
207 $ret = show_table(&$bri,&$user,$user->step,FALSE,FALSE);
209 log_rd2("SENDED TO THE STREAM: ".$ret);
211 log_rd2("NEWSTAT: ".$user->stat);
213 $new_stat = $user->stat;
214 $new_subst = $user->subst;
215 $new_step = $user->step;
218 ignore_user_abort(TRUE);
219 $sem = Briskin5::lock_data($table_idx);
220 if (($bri = &Briskin5::load_data($table_idx, $table_token)) == FALSE) {
221 Briskin5::unlock_data($sem);
222 ignore_user_abort(FALSE);
223 return (unrecerror());
225 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
226 Briskin5::unlock_data($sem);
227 ignore_user_abort(FALSE);
228 return (unrecerror());
230 if ($cur_step < $user->step) {
232 if ($cur_step + COMM_N < $user->step) {
233 if (($cur_stat != $user->stat)) {
234 $to_stat = $user->stat;
235 Briskin5::unlock_data($sem);
236 ignore_user_abort(FALSE);
237 return (page_sync($user->sess, $to_stat == "table" ? "index.php" : "../index.php"));
239 log_rd2("lost history, refresh from scratch");
243 for ($i = $cur_step ; $i < $user->step ; $i++) {
245 log_wr("TRY RET ".$i." COMM_N ".COMM_N." II ".$ii);
246 $ret .= $user->comm[$ii];
248 $new_stat = $user->stat;
249 $new_subst = $user->subst;
250 $new_step = $user->step;
253 if ($user->the_end == TRUE) {
254 log_rd2("LOGOUT BYE BYE!!");
255 log_auth($user->sess, "Explicit logout.");
256 $tmp_sess = $user->sess;
258 step_unproxy($tmp_sess);
261 $user->the_end = FALSE;
263 if ($user->subst == 'sitdown')
264 $bri->room_wakeup(&$user);
265 else if ($user->subst == 'standup')
266 $bri->room_outstandup(&$user);
268 log_rd2("LOGOUT FROM WHAT ???");
270 Briskin5::save_data($bri);
274 Briskin5::unlock_data($sem);
275 ignore_user_abort(FALSE);
293 $is_page_streaming = ((stristr($HTTP_USER_AGENT, "linux") &&
294 (stristr($HTTP_USER_AGENT, "firefox") || stristr($HTTP_USER_AGENT, "iceweasel"))) ? FALSE : TRUE);
297 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
298 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
304 log_rd2("FROM OUTSIDE - STAT: ".$stat." SUBST: ".$subst." STEP: ".$step." MYFROM: ".$myfrom. "IS_PAGE:" . $is_page_streaming."USER_AGENT:".$HTTP_USER_AGENT);
307 $endtime = time() + STREAM_TIMEOUT;
310 $old_step = $ext_step = $step;
312 for ($i = 0 ; time() < $endtime ; $i++) {
313 // log_rd("PRE MAIN ".$step);;
314 if (($ret = maincheck($sess, $old_stat, $old_subst, $old_step, &$stat, &$subst, &$step, $table_idx, $table_token)) != FALSE) {
316 // log_rd2(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));
319 log_send("EXT_STEP: ".$ext_step." ENDTIME: [".$endtime."] ".$ret);
321 if ($is_page_streaming)
327 // log_rd("POST MAIN ".$step);;
329 if (($i % 10) == 0) {
330 // log_rd2("TIME: ".time());