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("briskin5/Obj/briskin5.phh");
30 "GGZDGDRBXDWFXHGPYAAVDXEKFDUWSTEDTDVXBXQPMZAIFPNLRPTWMJAZRHXTIRNZ"
31 ."HTZXAUVJDCLXENDCLIZXSSEQQGUADYEKNNANJWEGRUFHPLUNSEROZQJSLMUYNUVG"
32 ."FPLQAGCMTTGIRRXZFBFQFTRBYPHTWFSXFKHKYBRDAOSOURCMEVGPVXJVUQAOCFPV"
33 ."OQSUBOYWOZLDGRPQQIBNOTHFUHTCRRZOBCUONAXIYUYCJBFTVNWIITVHBYLNMPWR"
34 ."LPMMIROZVRUNYXSJSMJINSXGACXDMJAEPNFFAERHVDJELXSPPJWKMNFGVGAPTIMR"
35 ."VMVMVCLWKMPOAJWZGPSPFEXVNQANXGLZIQSCBIYVFSTXZOODZYCXUVUZFCLFGHUJ"
36 ."TXZWFHSMFJQAZOQRANKZJAUJHFJIKHIIEQUSDXUBRPQBKMIAVTWYQEOIMYKKDTEV"
37 ."EYERPXKFJXWNIMJPOFFMWJCJSLFZKPNRNVXIDLUSRVBGLUCQZCUQCZNAORDXMRSS"
38 ."UBNMPXJDQXXLMQRCTOCCJJWHFSUWBNWXWZHPKWYYKPZIMBXTYAZXJJQS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."PYIFTUDCMWRQBZDROXTTVTAOOIQHIWOZESRHKPNGNCSHNAVEWUSGOTZCRNFSIXGF"
85 ."QJUMUFPEZBFPOVGZZDCGDKEODSWAPNDNHVJUQDYLCXWNXSCDFFFPBTDOIZIZLBBP"
86 ."ZXZYWTTPEUUCKXGBTXAJBAXYLMUVWWGWZYTXTKYVRXSOXOBHERLZJPRDXIQZRQLU"
87 ."TXCLIJNKIRWMVQEJTLHZIDTNGBOYSULGWUTSYTKGNMGZFWKXCCZXGOQGZNQFZJUK"
88 ."JMBQPQPZOPYTQMPEFTZUDLIIBZAZSZAPNILMIKMPKXJIRHRQMFSTJKAPIIQWOFYQ"
89 ."HGANJGJSUGDIENDVEQFEMUJBGMZBPHLOARCVGMUUCHLCDDNKSJSCKYSALUAGUZFN"
90 ."YVURVLREBESGXPANIDKGLPJZGXLKFKTPEQBQEINOYYZTBMPFBLBKIKVPAPFDKKRZ"
91 ."YMVUBYCYTRXCIICUPTXKGQOIJSVSWPYVALIROWGVXDXGNSRVZOLEJHNRSUKHNTRJ"
92 ."LQZQKBEFXYKIPXJRZMQMJKUGCNUKBZBWABPLHMAJJZVBCWOQYCLSGDUKJSTHTVXV"
93 ."OUGJVADGJWGVNBNXYRZDSNLOZDIQRKOQAKJJDKXRMMTXRVTLOMTETNROPDYNXAGR";
95 $S_load_stat = array( 'rU_heavy' => 0,
102 $mlang_indrd = array(
103 'btn_backtotab' => array('it' => ' torna ai tavoli ',
104 'en' => ' back to tables '),
105 'btn_btotabsup' => array('it' => ' grazie della donazione, torna ai tavoli ',
106 'en' => ' thank you for donation, back to tables ')
109 // Use of proxies isn't allowed.
114 log_load("index_rd.php");
116 // $first_loop = TRUE;
119 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
120 echo "Debugging time!";
124 function blocking_error($is_unrecoverable)
126 GLOBAL $is_page_streaming;
128 $is_page_streaming = TRUE;
129 log_crit("BLOCKING_ERROR UNREC: ".($is_unrecoverable ? "TRUE" : "FALSE"));
130 return (sprintf(($is_unrecoverable ? 'hstm.stop(); ' : '').'window.onbeforeunload = null; window.onunload = null; document.location.assign("index.php");'));
133 // FIXME TO SUPPORT iframe
134 function page_sync($sess, $page, $table_idx, $table_token)
136 GLOBAL $is_page_streaming;
138 log_rd2("page_sync:".var_export(debug_backtrace()));
140 $is_page_streaming = TRUE;
142 log_rd2("PAGE_SYNC");
143 return (sprintf('createCookie("table_idx", %d, 24*365, cookiepath); createCookie("table_token", "%s", 24*365, cookiepath); hstm.stop(); window.onunload = null; window.onbeforeunload = null; document.location.assign("%s");', $table_idx, $table_token, $page));
149 function maincheck(&$user, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step, $splashdate)
151 GLOBAL $G_lang, $mlang_indrd, $is_page_streaming;
152 // GLOBAL $first_loop;
153 GLOBAL $G_with_splash, $G_splash_content, $G_splash_interval, $G_splash_idx;
154 GLOBAL $G_splash_w, $G_splash_h, $G_splash_timeout;
155 $CO_splashdate = "CO_splashdate".$G_splash_idx;
156 $$CO_splashdate = $splashdate;
160 log_rd("maincheck begin");
163 // $user->room = FALSE;
167 // NOTE: qui forse si potrebbe fallback-are a una User::load_data
168 // anche se non ce ne dovrebbe essere mai la necessità
169 /* if (($proxy_step = User::load_step($sess)) == FALSE) { */
170 /* log_only2("R"); */
171 /* ignore_user_abort(FALSE); */
172 /* return (blocking_error(TRUE)); */
176 /* Sync check (read only without modifications */
177 ignore_user_abort(TRUE);
180 /* /\* shared locking to load info *\/ */
181 /* if (($sem = Room::lock_data(FALSE)) == FALSE) { */
182 /* // wait 20 secs, then restart the xhr */
183 /* ignore_user_abort(FALSE); */
184 /* return ("sleep(gst,20000);|hstm.xhr_abort();"); */
187 /* // Verifica l'expire time lato server */
188 /* if (($user = User::load_data($proxy_step['i'], $sess)) == FALSE) { */
189 /* Room::unlock_data($sem); */
190 /* ignore_user_abort(FALSE); */
191 /* return (blocking_error(TRUE)); */
193 /* if lacc time great than STREAM_TIMEOUT or the room garbage_time is expired
194 switch to exclusive locking and verify again the conditions */
195 if ((($curtime - $user->lacc) > STREAM_TIMEOUT) || Room::garbage_time_is_expired($curtime)) {
196 /* there is some info that require to change data, switch to exclusive locking */
197 // Room::unlock_data($sem);
198 /* if (($sem = Room::lock_data(TRUE)) == FALSE) { */
199 /* // wait 20 secs, then restart the xhr */
200 /* ignore_user_abort(FALSE); */
201 /* return ("sleep(gst,20000);|hstm.xhr_abort();"); */
203 $S_load_stat['lL_laccgarb']++;
205 // load again the data after locking
207 // Verifica l'expire time lato server
208 /* if (($user = User::load_data($proxy_step['i'], $sess)) == FALSE) { */
209 /* Room::unlock_data($sem); */
210 /* ignore_user_abort(FALSE); */
211 /* return (blocking_error(TRUE)); */
214 if (($curtime - $user->lacc) >= STREAM_TIMEOUT) {
215 $S_load_stat['wU_lacc_upd']++;
216 $user->lacc = $curtime;
217 // lacc field updated
218 /* User::save_data($user, $user->idx); */
221 if (Room::garbage_time_is_expired($curtime)) {
224 $S_load_stat['wR_garbage']++;
225 /* if (($user->room = Room::load_data()) == FALSE) { */
226 /* Room::unlock_data($sem); */
227 /* ignore_user_abort(FALSE); */
228 /* return (blocking_error(TRUE)); */
230 log_main("pre garbage_manager TRE");
231 $user->room->garbage_manager(FALSE);
232 /* Room::save_data($user->room); */
233 /* unset($user->room); */
236 log_main("infolock: U");
237 /* Room::unlock_data($sem); */
238 ignore_user_abort(FALSE);
242 // if ($first_loop == TRUE) {
243 // if (($sem = Room::lock_data(TRUE)) != FALSE) {
244 // // Aggiorna l'expire time lato server
245 // $S_load_stat['U_first_loop']++;
246 // if (($user = User::load_data($proxy_step['i'], $sess)) == FALSE) {
247 // Room::unlock_data($sem);
248 // ignore_user_abort(FALSE);
249 // return (blocking_error(TRUE));
251 // $user->lacc = $curtime;
252 // // lacc field updated
253 // User::save_data($user, $user->idx);
255 // if (Room::garbage_time_is_expired($curtime)) {
258 // $S_load_stat['R_garbage']++;
259 // if (($user->room = Room::load_data()) == FALSE) {
260 // Room::unlock_data($sem);
261 // ignore_user_abort(FALSE);
262 // return (blocking_error(TRUE));
264 // log_main("pre garbage_manager TRE");
265 // $user->room->garbage_manager(FALSE);
266 // Room::save_data($user->room);
267 // unset($user->room);
269 // log_main("infolock: U");
270 // Room::unlock_data($sem);
271 // ignore_user_abort(FALSE);
272 // } // if (($sem = Room::lock_data(TRUE)) != FALSE) {
274 // // wait 20 secs, then restart the xhr
275 // ignore_user_abort(FALSE);
277 // return ("sleep(gst,20000);|hstm.xhr_abort();");
279 // $first_loop = FALSE;
280 // } // if ($first_loop == TRUE) {
282 /* if ($cur_step == $proxy_step['s']) { */
283 /* log_main("infolock: P"); */
284 /* return (FALSE); */
287 /* log_only2("R"); */
290 $S_load_stat['rU_heavy']++;
291 /* if ($user == FALSE) { */
293 /* ignore_user_abort(TRUE); */
294 /* if (($sem = Room::lock_data(FALSE)) == FALSE) */
297 /* log_main("infolock: P"); */
298 /* if (($user = User::load_data($proxy_step['i'], $sess)) == FALSE) { */
303 /* if ($sem != FALSE) */
304 /* Room::unlock_data($sem); */
306 /* ignore_user_abort(FALSE); */
307 /* if ($user == FALSE) { */
308 /* return (blocking_error(TRUE)); */
312 /* Nothing changed, return. */
313 if ($cur_step == $user->step)
316 log_rd2("do other cur_stat[".$cur_stat."] user->stat[".$user->stat."] cur_step[".$cur_step."] user_step[".$user->step."]");
318 if ($cur_step == -1) {
320 * if $cur_step == -1 load the current state from the main struct
323 /* unset the $user var to reload it from main structure */
326 ignore_user_abort(TRUE);
327 /* $sem = Room::lock_data(TRUE); */
328 /* if (($user->room = Room::load_data()) == FALSE) { */
329 /* Room::unlock_data($sem); */
330 /* ignore_user_abort(FALSE); */
331 /* return (blocking_error(TRUE)); */
333 $S_load_stat['wR_minusone']++;
335 /* if (($user = $user->room->get_user($sess, $idx)) == FALSE) { */
336 /* Room::unlock_data($sem); */
337 /* ignore_user_abort(FALSE); */
338 /* return (blocking_error(TRUE)); */
341 if ($user->the_end == TRUE) {
342 log_rd2("main_check: the end".var_export(debug_backtrace()));
343 $is_page_streaming = TRUE;
346 if ($user->trans_step != -1) {
347 log_rd2("TRANS USATO ".$user->trans_step);
348 $cur_step = $user->trans_step;
349 $user->trans_step = -1;
351 /* Room::save_data($user->room); */
352 /* Room::unlock_data($sem); */
353 ignore_user_abort(FALSE);
356 log_rd2("TRANS NON ATTIVATO");
357 // ARRAY_POP DISABLED
358 // log_rd2("TRANS NON ATTIVATO, clean del comm array");
359 // while (($el = array_pop($user->comm)) != NULL) {
360 // log_rd2("clean element [".$el."]");
362 // // $user->step_inc(COMM_N + 1);
363 // Room::save_data($user->room);
364 // // $new_step = $user->step;
366 /* Room::unlock_data($sem); */
367 ignore_user_abort(FALSE);
372 /* this part I suppose is read only on $user->room structure */
373 if ($cur_step == -1) {
374 log_rd2("PRE-NEWSTAT: ".$user->stat);
376 if ($user->stat == 'room') {
377 log_rd("roomma ".$user->step);
380 if ($G_with_splash &&
381 ($$CO_splashdate < $curtime - $G_splash_interval ||
382 $$CO_splashdate > $curtime)) {
383 $is_super = $user->flags & USER_FLAG_TY_SUPER;
384 $ret .= show_notify_ex(str_replace("\n", " ", $G_splash_content[$G_lang]),
385 ($is_super ? 0 : $G_splash_timeout),
386 $mlang_indrd[($is_super ? 'btn_btotabsup' : 'btn_backtotab')][$G_lang],
387 $G_splash_w, $G_splash_h, true,
388 ($is_super ? 0 : $G_splash_timeout));
389 $ret .= sprintf('|createCookie("CO_splashdate%d", %d, 24*365, cookiepath);', $G_splash_idx, $curtime);
391 $ret .= $user->room->show_room($user->step, $user);
393 // TODO uncomment and test
394 /* NOTE the sets went common */
395 $new_stat = $user->stat;
396 $new_subst = $user->subst;
397 $new_step = $user->step;
404 else if ($user->stat == 'table') {
406 return (page_sync($user->sess, "briskin5/index.php", $user->table, $user->table_token));
408 log_rd2("NEWSTAT: ".$user->stat);
409 } /* if ($cur_step == -1) { */
411 ignore_user_abort(TRUE);
412 /* $sem = Room::lock_data(FALSE); */
413 $S_load_stat['rU_heavy']++;
414 /* if (($user = User::load_data($proxy_step['i'], $sess)) == FALSE) { */
415 /* Room::unlock_data($sem); */
416 /* ignore_user_abort(FALSE); */
417 /* return (blocking_error(TRUE)); */
420 if ($cur_step < $user->step) {
422 if ($cur_step + COMM_N < $user->step) {
423 if (($cur_stat != $user->stat)) {
424 $to_stat = $user->stat;
425 /* Room::unlock_data($sem); */
426 ignore_user_abort(FALSE);
428 return (page_sync($user->sess, ($to_stat == "table" ? "briskin5/index.php" : "index.php"), $user->table, $user->table_token));
430 log_rd2("lost history, refresh from scratch");
434 for ($i = $cur_step ; $i < $user->step ; $i++) {
436 log_rd2("ADDED TO THE STREAM: ".$user->comm[$ii]);
437 $ret .= $user->comm[$ii];
439 $new_stat = $user->stat;
440 $new_subst = $user->subst;
441 $new_step = $user->step;
444 log_rd2($user->step, 'index_rd.php: after ret set');
446 if ($user->the_end == TRUE) {
447 /* Room::unlock_data($sem); */
449 /* Switch to exclusive locking */
450 /* $sem = Room::lock_data(TRUE); */
454 $S_load_stat['wR_the_end']++;
455 /* if (($user->room = Room::load_data()) == FALSE) { */
456 /* Room::unlock_data($sem); */
457 /* ignore_user_abort(FALSE); */
458 /* return (blocking_error(TRUE)); */
461 /* if (($user = $user->room->get_user($sess, $idx)) == FALSE) { */
462 /* Room::unlock_data($sem); */
463 /* ignore_user_abort(FALSE); */
464 /* return (blocking_error(TRUE)); */
467 log_rd2("LOGOUT BYE BYE!!");
468 log_auth($user->sess, "Explicit logout.");
470 if ($user->the_end == TRUE) {
473 if ($user->subst == 'sitdown') {
474 log_load("ROOM WAKEUP");
475 $user->room->room_wakeup($user);
477 else if ($user->subst == 'standup')
478 $user->room->room_outstandup($user);
480 log_rd2("LOGOUT FROM WHAT ???");
482 /* Room::save_data($user->room); */
483 } /* if ($user->the_end == TRUE) { ... */
484 } /* if ($user->the_end == TRUE) { ... */
485 } /* if ($cur_step < $user->step) { */
487 /* Room::unlock_data($sem); */
488 ignore_user_abort(FALSE);
489 } /* else of if ($cur_step == -1) { */
495 function index_rd_ifra_fini($is_unrecoverable)
497 GLOBAL $G_four_rnd_string;
501 $body .= sprintf("<html>
503 <script type=\"text/javascript\" src=\"commons.js\"></script>
504 <script type=\"text/javascript\" src=\"xynt-http-streaming-ifra.js\"></script>
505 <script type=\"text/javascript\">
506 var http_streaming = \"ready\";");
508 window.onload = function () { if (http_streaming != \"ready\") { http_streaming.reload(); } };
512 $body .= sprintf("<!-- \n%s -->\n", $G_four_rnd_string);
513 $body .= sprintf("<script id='hs%d' type='text/javascript'><!--
516 </script>", 0, escpush(blocking_error($is_unrecoverable)) );
518 // return (blocking_error($is_unrecoverable));
532 function index_rd_ifra_init(&$user, &$header_out, &$body, $get, $post, $cookie)
534 GLOBAL $G_four_rnd_string;
538 $is_page_streaming = FALSE; // (webservers_exceeded() || stristr($HTTP_USER_AGENT, "Mozilla/5.0 (Windows NT 6.1; rv:5.0)") || stristr($HTTP_USER_AGENT, "MSIE") || stristr($HTTP_USER_AGENT, "CHROME") ? TRUE : FALSE);
540 $header_out['Cache-Control'] = 'no-cache, must-revalidate'; // HTTP/1.1
541 $header_out['Expires'] = 'Mon, 26 Jul 1997 05:00:00 GMT'; // Date in the past
542 $header_out['Content-type'] = 'text/html; charset="utf-8"';
544 log_load("index_rd_ifra_init.php");
546 if (($from = gpcs_var('from', $get, $post, $cookie)) === FALSE)
548 if (($stat = gpcs_var('stat', $get, $post, $cookie)) === FALSE)
550 if (($subst = gpcs_var('subst', $get, $post, $cookie)) === FALSE)
552 if (($step = gpcs_var('step', $get, $post, $cookie)) === FALSE)
555 $user->rd_data_set($curtime, $stat, $subst, $step, $from);
557 $body .= sprintf("<html>
559 <script type=\"text/javascript\" src=\"commons.js\"></script>
560 <script type=\"text/javascript\" src=\"xynt-http-streaming-ifra.js\"></script>
561 <script type=\"text/javascript\">
562 var http_streaming = \"ready\";");
563 if ($user->rd_scristp > 0)
564 $body .= sprintf("last_clean = %d;\n", ($user->rd_scristp-1));
566 window.onload = function () { if (http_streaming != \"ready\") { http_streaming.reload(); } };
570 $body .= sprintf("<!-- \n%s -->\n", $G_four_rnd_string);
575 function index_rd_ifra_main(&$user, &$body, $get, $post, $cookie)
577 GLOBAL $is_page_streaming, $G_splash_idx;
578 // FIXME: only to test fwrite
579 // GLOBAL $G_four_rnd_string;
581 $CO_splashdate = "CO_splashdate".$G_splash_idx;
582 if (($splashdate = gpcs_var("$CO_splashdate", $get, $post, $cookie)) === FALSE)
585 $is_page_streaming = FALSE;
586 log_rd2("FROM OUTSIDE - STAT: ".$user->rd_stat." SUBST: ".$user->rd_subst." STEP: ".$user->rd_step." FROM: ".$user->rd_from. "IS_PAGE:" . $is_page_streaming);
590 // for ($i = 0, $script_step = 0 ; time() < $endtime ; $i++) {
591 // log_rd("PRE MAIN ".$step);;
593 $pre_main = gettimeofday(TRUE);
595 $old_stat = $user->rd_stat;
596 $old_subst = $user->rd_subst;
597 $old_step = $user->rd_step;
598 if (($ret = maincheck($user, $old_stat, $old_subst, $old_step, $user->rd_stat, $user->rd_subst, $user->rd_step, $splashdate)) != FALSE) {
602 // 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));
607 // FIXME only to test fwrite
608 // for ($u = 0 ; $u < 10 ; $u++) {
609 // $body .= sprintf("<!-- \n%s -->\n", $G_four_rnd_string);
611 $body .= sprintf("<script id='hs%d' type='text/javascript'><!--
614 </script>", $user->rd_scristp++, escpush($ret) );
616 // log_send("IS_PAGE: ".($is_page_streaming == TRUE ? "TRUE" : "FALSE")." ENDTIME: [".$endtime."] ".$ret);
618 log_rd2(0, 'index_rd.php: after mop_flush (begin: '.sprintf("%f", $pre_main).')');
619 if ($is_page_streaming)
622 /* $old_stat = $stat; */
623 /* $old_subst = $subst; */
624 /* $old_step = $step; */
625 // log_rd("POST MAIN ".$step);;
627 /* if (($i % 10) == 0 && 1 == 0) { // TODO: reenable push(null); */
628 /* if ($no_data == TRUE) { */
629 /* // log_rd2("TIME: ".time()); */
630 /* printf("<script id='hs%d' type='text/javascript'><!-- */
633 /* alert(\"de che\"); */
634 /* </script>", $script_step++); */
635 /* // mop_flush(); */
636 /* log_crit("flush"); */
638 /* $no_data = TRUE; */
645 /* foreach ($S_load_stat as $key => $value) { */
646 /* $s .= sprintf("%s: %d - ", $key, $value); */
647 /* if (substr($key, 0, 1) == "w") */
649 /* else if (substr($key, 0, 1) == "r") */
652 /* $s = sprintf("index_rd.php stats: R: %d W: %d - %s", $tr, $tw, $s); */
658 function index_rd_ifra_keepalive(&$user)
660 return (sprintf("<script id='hs%d' type='text/javascript'><!--
663 </script>", $user->rd_scristp++));