5 * Copyright (C) 2006-2011 Matteo Nastasi
6 * mailto: nastasi@alternativeoutput.it
7 * matteo.nastasi@milug.org
8 * web: http://www.alternativeoutput.it
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details. You should have received a
19 * copy of the GNU General Public License along with this program; if
20 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21 * Suite 330, Boston, MA 02111-1307, USA.
27 require_once("../Obj/brisk.phh");
28 // require_once("../Obj/proxyscan.phh");
29 require_once("Obj/briskin5.phh");
31 // Use of proxies isn't allowed.
37 log_load("LOAD: bin5/index_rd.php ".$QUERY_STRING);
42 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
43 echo "Debugging time!";
49 log_rd2("bin5 SHUTTA!".connection_status());
53 register_shutdown_function(shutta);
57 GLOBAL $is_page_streaming;
59 $is_page_streaming = TRUE;
60 log_rd2("UNREC_ERROR");
61 return (sprintf('the_end=true; window.onbeforeunload = null; window.onunload = null; document.location.assign("../index.php");'));
64 function page_sync($sess, $page)
66 GLOBAL $is_page_streaming;
68 $is_page_streaming = TRUE;
70 return (sprintf('the_end=true; window.onbeforeunload = null; window.onunload = null; document.location.assign("%s");', $page));
76 function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step, $table_idx, $table_token)
78 GLOBAL $is_page_streaming, $first_loop;
84 /* Sync check (read only without modifications */
85 ignore_user_abort(TRUE);
86 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
87 // Aggiorna l'expire time lato server
88 if ($first_loop == TRUE) {
91 // VERIFICARE TUTTE LE LOAD_DATA E PRENDERE CONTROMISURE NEL CASO FALLISCANO //
93 if (($bri = &Briskin5::load_data($table_idx, $table_token)) == FALSE) {
94 Briskin5::unlock_data($sem);
95 ignore_user_abort(FALSE);
96 return (unrecerror());
98 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
99 Briskin5::unlock_data($sem);
100 ignore_user_abort(FALSE);
101 return (unrecerror());
103 log_auth($sess, "bin5::update lacc");
104 $user->lacc = time();
106 $bri->garbage_manager(FALSE);
108 Briskin5::save_data($bri);
113 Briskin5::unlock_data($sem);
114 ignore_user_abort(FALSE);
120 if (($proxy_step = User::step_get($sess)) != FALSE) {
121 // log_rd2("Postget".$proxy_step."zizi");
123 if ($cur_step == $proxy_step['s']) {
137 ignore_user_abort(TRUE);
138 if (($sem = Briskin5::lock_data($table_idx)) == FALSE)
142 if (($bri = &Briskin5::load_data($table_idx, $table_token)) == FALSE)
147 Briskin5::unlock_data($sem);
149 ignore_user_abort(FALSE);
151 return (unrecerror());
154 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
155 return (unrecerror());
158 /* Nothing changed, return. */
159 if ($cur_step == $user->step)
162 log_rd2("do other ++".$cur_stat."++".$user->stat."++".$cur_step."++".$user->step);
164 if ($cur_step == -1) {
165 // FUNZIONE from_scratch DA QUI
166 ignore_user_abort(TRUE);
167 $sem = Briskin5::lock_data($table_idx);
168 $bri = &Briskin5::load_data($table_idx, $table_token);
169 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
170 Briskin5::unlock_data($sem);
171 ignore_user_abort(FALSE);
172 return (unrecerror());
175 $is_page_streaming = TRUE;
178 if ($user->trans_step != -1) {
179 log_rd2("TRANS USATO ".$user->trans_step);
180 $cur_step = $user->trans_step;
181 $user->trans_step = -1;
184 Briskin5::save_data($bri);
185 Briskin5::unlock_data($sem);
186 ignore_user_abort(FALSE);
189 log_rd2("TRANS NON ATTIVATO");
191 // ARRAY_POP DISABLED
192 // while (array_pop($user->comm) != NULL);
193 // // $user->step_inc(COMM_N + 1);
194 // Briskin5::save_data($bri);
196 Briskin5::unlock_data($sem);
197 ignore_user_abort(FALSE);
201 if ($cur_step == -1) {
202 log_rd2("PRE-NEWSTAT.");
209 if ($user->stat == "table") {
210 $ret = show_table(&$bri,&$user,$user->step,FALSE,FALSE);
212 log_rd2("SENDED TO THE STREAM: ".$ret);
214 log_rd2("NEWSTAT: ".$user->stat);
216 $new_stat = $user->stat;
217 $new_subst = $user->subst;
218 $new_step = $user->step;
221 ignore_user_abort(TRUE);
222 $sem = Briskin5::lock_data($table_idx);
223 if (($bri = &Briskin5::load_data($table_idx, $table_token)) == FALSE) {
224 Briskin5::unlock_data($sem);
225 ignore_user_abort(FALSE);
226 return (unrecerror());
228 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
229 Briskin5::unlock_data($sem);
230 ignore_user_abort(FALSE);
231 return (unrecerror());
233 if ($cur_step < $user->step) {
235 if ($cur_step + COMM_N < $user->step) {
236 if (($cur_stat != $user->stat)) {
237 $to_stat = $user->stat;
238 Briskin5::unlock_data($sem);
239 ignore_user_abort(FALSE);
240 return (page_sync($user->sess, $to_stat == "table" ? "index.php" : "../index.php"));
242 log_rd2("lost history, refresh from scratch");
246 for ($i = $cur_step ; $i < $user->step ; $i++) {
248 log_wr("TRY RET ".$i." COMM_N ".COMM_N." II ".$ii);
249 $ret .= $user->comm[$ii];
251 $new_stat = $user->stat;
252 $new_subst = $user->subst;
253 $new_step = $user->step;
256 log_mop($user->step, 'bin::index_rd.php: after ret set');
258 if ($user->the_end == TRUE) {
259 log_rd2("LOGOUT BYE BYE!!");
260 log_auth($user->sess, "Explicit logout.");
261 $tmp_sess = $user->sess;
263 step_unproxy($tmp_sess);
266 $user->the_end = FALSE;
268 if ($user->subst == 'sitdown')
269 $bri->room_wakeup(&$user);
270 else if ($user->subst == 'standup')
271 $bri->room_outstandup(&$user);
273 log_rd2("LOGOUT FROM WHAT ???");
275 Briskin5::save_data($bri);
279 Briskin5::unlock_data($sem);
280 ignore_user_abort(FALSE);
298 $is_page_streaming = (stristr($HTTP_USER_AGENT, "MSIE") || stristr($HTTP_USER_AGENT, "CHROME") ? TRUE : FALSE);
300 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
301 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
302 header('Content-type: application/xml; charset="utf-8"',true);
303 // header('Content-type: text/plain; charset="utf-8"',true);
304 // header('Content-type: text/html; charset="utf-8"',true);
310 log_rd2("FROM OUTSIDE - STAT: ".$stat." SUBST: ".$subst." STEP: ".$step." MYFROM: ".$myfrom. "IS_PAGE:" . $is_page_streaming."USER_AGENT:".$HTTP_USER_AGENT);
313 $endtime = time() + STREAM_TIMEOUT;
316 $old_step = $ext_step = $step;
318 for ($i = 0 ; time() < $endtime ; $i++) {
319 // log_rd("PRE MAIN ".$step);;
320 $pre_main = gettimeofday(TRUE);
321 if (($ret = maincheck($sess, $old_stat, $old_subst, $old_step, &$stat, &$subst, &$step, $table_idx, $table_token)) != FALSE) {
323 // 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));
326 log_send("EXT_STEP: ".$ext_step." ENDTIME: [".$endtime."] ".$ret);
328 log_mop(0, 'bin::index_rd.php: after flush (begin: '.sprintf("%f", $pre_main).')');
329 if ($is_page_streaming)
335 // log_rd("POST MAIN ".$step);;
337 if (($i % 10) == 0) {
338 // log_rd2("TIME: ".time());