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("LOAD: bin5/index_rd.php ".$QUERY_STRING);
32 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
33 echo "Debugging time!";
39 log_rd2("bin5 SHUTTA!".connection_status());
43 register_shutdown_function(shutta);
47 GLOBAL $is_page_streaming;
49 $is_page_streaming = TRUE;
50 log_rd2("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;
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, $table_token)
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) {
81 // VERIFICARE TUTTE LE LOAD_DATA E PRENDERE CONTROMISURE NEL CASO FALLISCANO //
83 if (($bri = &Briskin5::load_data($table_idx, $table_token)) == FALSE) {
84 Briskin5::unlock_data($sem);
85 ignore_user_abort(FALSE);
86 return (unrecerror());
88 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
89 Briskin5::unlock_data($sem);
90 ignore_user_abort(FALSE);
91 return (unrecerror());
93 log_auth($sess, "bin5::update lacc");
96 $bri->garbage_manager(FALSE);
98 Briskin5::save_data($bri);
103 Briskin5::unlock_data($sem);
104 ignore_user_abort(FALSE);
110 if (($proxy_step = step_get($sess)) != FALSE) {
111 // log_rd2("Postget".$proxy_step."zizi");
113 if ($cur_step == $proxy_step) {
127 ignore_user_abort(TRUE);
128 if (($sem = Briskin5::lock_data($table_idx)) == FALSE)
132 if (($bri = &Briskin5::load_data($table_idx, $table_token)) == FALSE)
137 Briskin5::unlock_data($sem);
139 ignore_user_abort(FALSE);
141 return (unrecerror());
144 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
145 return (unrecerror());
148 /* Nothing changed, return. */
149 if ($cur_step == $user->step)
152 log_rd2("do other ++".$cur_stat."++".$user->stat."++".$cur_step."++".$user->step);
154 if ($cur_step == -1) {
155 // FUNZIONE from_scratch DA QUI
156 ignore_user_abort(TRUE);
157 $sem = Briskin5::lock_data($table_idx);
158 $bri = &Briskin5::load_data($table_idx, $table_token);
159 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
160 Briskin5::unlock_data($sem);
161 ignore_user_abort(FALSE);
162 return (unrecerror());
165 $is_page_streaming = TRUE;
168 if ($user->trans_step != -1) {
169 log_rd2("TRANS USATO ".$user->trans_step);
170 $cur_step = $user->trans_step;
171 $user->trans_step = -1;
174 Briskin5::save_data($bri);
175 Briskin5::unlock_data($sem);
176 ignore_user_abort(FALSE);
179 log_rd2("TRANS NON ATTIVATO");
180 while (array_pop($user->comm) != NULL);
181 // $user->step_inc(COMM_N + 1);
183 Briskin5::save_data($bri);
184 Briskin5::unlock_data($sem);
185 ignore_user_abort(FALSE);
189 if ($cur_step == -1) {
190 log_rd2("PRE-NEWSTAT.");
197 if ($user->stat == "table") {
198 $ret = show_table(&$bri,&$user,$user->step,FALSE,FALSE);
200 log_rd2("SENDED TO THE STREAM: ".$ret);
202 log_rd2("NEWSTAT: ".$user->stat);
204 $new_stat = $user->stat;
205 $new_subst = $user->subst;
206 $new_step = $user->step;
209 ignore_user_abort(TRUE);
210 $sem = Briskin5::lock_data($table_idx);
211 if (($bri = &Briskin5::load_data($table_idx, $table_token)) == FALSE) {
212 Briskin5::unlock_data($sem);
213 ignore_user_abort(FALSE);
214 return (unrecerror());
216 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
217 Briskin5::unlock_data($sem);
218 ignore_user_abort(FALSE);
219 return (unrecerror());
221 if ($cur_step < $user->step) {
223 if ($cur_step + COMM_N < $user->step) {
224 if (($cur_stat != $user->stat)) {
225 $to_stat = $user->stat;
226 Briskin5::unlock_data($sem);
227 ignore_user_abort(FALSE);
228 return (page_sync($user->sess, $to_stat == "table" ? "index.php" : "../index.php"));
230 log_rd2("lost history, refresh from scratch");
234 for ($i = $cur_step ; $i < $user->step ; $i++) {
236 log_wr("TRY RET ".$i." COMM_N ".COMM_N." II ".$ii);
237 $ret .= $user->comm[$ii];
239 $new_stat = $user->stat;
240 $new_subst = $user->subst;
241 $new_step = $user->step;
244 if ($user->the_end == TRUE) {
245 log_rd2("LOGOUT BYE BYE!!");
246 log_auth($user->sess, "Explicit logout.");
247 $tmp_sess = $user->sess;
249 step_unproxy($tmp_sess);
252 $user->the_end = FALSE;
254 if ($user->subst == 'sitdown')
255 $bri->room_wakeup(&$user);
256 else if ($user->subst == 'standup')
257 $bri->room_outstandup(&$user);
259 log_rd2("LOGOUT FROM WHAT ???");
261 Briskin5::save_data($bri);
265 Briskin5::unlock_data($sem);
266 ignore_user_abort(FALSE);
284 $is_page_streaming = ((stristr($HTTP_USER_AGENT, "linux") &&
285 (stristr($HTTP_USER_AGENT, "firefox") || stristr($HTTP_USER_AGENT, "iceweasel"))) ? FALSE : TRUE);
288 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
289 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
295 log_rd2("FROM OUTSIDE - STAT: ".$stat." SUBST: ".$subst." STEP: ".$step." MYFROM: ".$myfrom. "IS_PAGE:" . $is_page_streaming."USER_AGENT:".$HTTP_USER_AGENT);
298 $endtime = time() + STREAM_TIMEOUT;
301 $old_step = $ext_step = $step;
303 for ($i = 0 ; time() < $endtime ; $i++) {
304 // log_rd("PRE MAIN ".$step);;
305 if (($ret = maincheck($sess, $old_stat, $old_subst, $old_step, &$stat, &$subst, &$step, $table_idx, $table_token)) != FALSE) {
307 // 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));
310 log_send("EXT_STEP: ".$ext_step." ENDTIME: [".$endtime."] ".$ret);
312 if ($is_page_streaming)
318 // log_rd("POST MAIN ".$step);;
321 // log_rd2("TIME: ".time());