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.
25 require_once("../Obj/brisk.phh");
26 // require_once("../Obj/proxyscan.phh");
27 require_once("Obj/briskin5.phh");
29 // Use of proxies isn't allowed.
35 log_load("LOAD: bin5/index_rd.php ".$QUERY_STRING);
40 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
41 echo "Debugging time!";
47 log_rd2("bin5 SHUTTA!".connection_status());
51 register_shutdown_function(shutta);
55 GLOBAL $is_page_streaming;
57 $is_page_streaming = TRUE;
58 log_rd2("UNREC_ERROR");
59 return (sprintf('the_end=true; window.onbeforeunload = null; window.onunload = null; document.location.assign("../index.php");'));
62 function page_sync($sess, $page)
64 GLOBAL $is_page_streaming;
66 $is_page_streaming = TRUE;
68 return (sprintf('the_end=true; window.onbeforeunload = null; window.onunload = null; document.location.assign("%s");', $page));
74 function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step, $table_idx, $table_token)
76 GLOBAL $is_page_streaming, $first_loop;
82 /* Sync check (read only without modifications */
83 ignore_user_abort(TRUE);
84 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
85 // Aggiorna l'expire time lato server
86 if ($first_loop == TRUE) {
89 // VERIFICARE TUTTE LE LOAD_DATA E PRENDERE CONTROMISURE NEL CASO FALLISCANO //
91 if (($bri = &Briskin5::load_data($table_idx, $table_token)) == FALSE) {
92 Briskin5::unlock_data($sem);
93 ignore_user_abort(FALSE);
94 return (unrecerror());
96 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
97 Briskin5::unlock_data($sem);
98 ignore_user_abort(FALSE);
99 return (unrecerror());
101 log_auth($sess, "bin5::update lacc");
102 $user->lacc = time();
104 $bri->garbage_manager(FALSE);
106 Briskin5::save_data($bri);
111 Briskin5::unlock_data($sem);
112 ignore_user_abort(FALSE);
118 if (($proxy_step = step_get($sess)) != FALSE) {
119 // log_rd2("Postget".$proxy_step."zizi");
121 if ($cur_step == $proxy_step) {
135 ignore_user_abort(TRUE);
136 if (($sem = Briskin5::lock_data($table_idx)) == FALSE)
140 if (($bri = &Briskin5::load_data($table_idx, $table_token)) == FALSE)
145 Briskin5::unlock_data($sem);
147 ignore_user_abort(FALSE);
149 return (unrecerror());
152 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
153 return (unrecerror());
156 /* Nothing changed, return. */
157 if ($cur_step == $user->step)
160 log_rd2("do other ++".$cur_stat."++".$user->stat."++".$cur_step."++".$user->step);
162 if ($cur_step == -1) {
163 // FUNZIONE from_scratch DA QUI
164 ignore_user_abort(TRUE);
165 $sem = Briskin5::lock_data($table_idx);
166 $bri = &Briskin5::load_data($table_idx, $table_token);
167 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
168 Briskin5::unlock_data($sem);
169 ignore_user_abort(FALSE);
170 return (unrecerror());
173 $is_page_streaming = TRUE;
176 if ($user->trans_step != -1) {
177 log_rd2("TRANS USATO ".$user->trans_step);
178 $cur_step = $user->trans_step;
179 $user->trans_step = -1;
182 Briskin5::save_data($bri);
183 Briskin5::unlock_data($sem);
184 ignore_user_abort(FALSE);
187 log_rd2("TRANS NON ATTIVATO");
189 // ARRAY_POP DISABLED
190 // while (array_pop($user->comm) != NULL);
191 // // $user->step_inc(COMM_N + 1);
192 // Briskin5::save_data($bri);
194 Briskin5::unlock_data($sem);
195 ignore_user_abort(FALSE);
199 if ($cur_step == -1) {
200 log_rd2("PRE-NEWSTAT.");
207 if ($user->stat == "table") {
208 $ret = show_table(&$bri,&$user,$user->step,FALSE,FALSE);
210 log_rd2("SENDED TO THE STREAM: ".$ret);
212 log_rd2("NEWSTAT: ".$user->stat);
214 $new_stat = $user->stat;
215 $new_subst = $user->subst;
216 $new_step = $user->step;
219 ignore_user_abort(TRUE);
220 $sem = Briskin5::lock_data($table_idx);
221 if (($bri = &Briskin5::load_data($table_idx, $table_token)) == FALSE) {
222 Briskin5::unlock_data($sem);
223 ignore_user_abort(FALSE);
224 return (unrecerror());
226 if (($user = &$bri->get_user($sess, $idx)) == FALSE) {
227 Briskin5::unlock_data($sem);
228 ignore_user_abort(FALSE);
229 return (unrecerror());
231 if ($cur_step < $user->step) {
233 if ($cur_step + COMM_N < $user->step) {
234 if (($cur_stat != $user->stat)) {
235 $to_stat = $user->stat;
236 Briskin5::unlock_data($sem);
237 ignore_user_abort(FALSE);
238 return (page_sync($user->sess, $to_stat == "table" ? "index.php" : "../index.php"));
240 log_rd2("lost history, refresh from scratch");
244 for ($i = $cur_step ; $i < $user->step ; $i++) {
246 log_wr("TRY RET ".$i." COMM_N ".COMM_N." II ".$ii);
247 $ret .= $user->comm[$ii];
249 $new_stat = $user->stat;
250 $new_subst = $user->subst;
251 $new_step = $user->step;
254 log_mop($user->step, 'bin::index_rd.php: after ret set');
256 if ($user->the_end == TRUE) {
257 log_rd2("LOGOUT BYE BYE!!");
258 log_auth($user->sess, "Explicit logout.");
259 $tmp_sess = $user->sess;
261 step_unproxy($tmp_sess);
264 $user->the_end = FALSE;
266 if ($user->subst == 'sitdown')
267 $bri->room_wakeup(&$user);
268 else if ($user->subst == 'standup')
269 $bri->room_outstandup(&$user);
271 log_rd2("LOGOUT FROM WHAT ???");
273 Briskin5::save_data($bri);
277 Briskin5::unlock_data($sem);
278 ignore_user_abort(FALSE);
296 $is_page_streaming = (stristr($HTTP_USER_AGENT, "MSIE") || stristr($HTTP_USER_AGENT, "CHROME") ? TRUE : FALSE);
298 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
299 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
300 header('Content-type: application/xml; charset="utf-8"',true);
301 // header('Content-type: text/plain; charset="utf-8"',true);
302 // header('Content-type: text/html; charset="utf-8"',true);
308 log_rd2("FROM OUTSIDE - STAT: ".$stat." SUBST: ".$subst." STEP: ".$step." MYFROM: ".$myfrom. "IS_PAGE:" . $is_page_streaming."USER_AGENT:".$HTTP_USER_AGENT);
311 $endtime = time() + STREAM_TIMEOUT;
314 $old_step = $ext_step = $step;
316 for ($i = 0 ; time() < $endtime ; $i++) {
317 // log_rd("PRE MAIN ".$step);;
318 $pre_main = gettimeofday(TRUE);
319 if (($ret = maincheck($sess, $old_stat, $old_subst, $old_step, &$stat, &$subst, &$step, $table_idx, $table_token)) != FALSE) {
321 // 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));
324 log_send("EXT_STEP: ".$ext_step." ENDTIME: [".$endtime."] ".$ret);
326 log_mop(0, 'bin::index_rd.php: after flush (begin: '.sprintf("%f", $pre_main).')');
327 if ($is_page_streaming)
333 // log_rd("POST MAIN ".$step);;
335 if (($i % 10) == 0) {
336 // log_rd2("TIME: ".time());