5 * Copyright (C) 2006-2009 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("briskin5/Obj/briskin5.phh");
33 'btn_backtotab' => array('it' => 'torna ai tavoli',
34 'en' => 'back to tables')
37 // Use of proxies isn't allowed.
42 log_load("index_rd.php");
47 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
48 echo "Debugging time!";
54 log_rd2("SHUTTA!".connection_status());
58 register_shutdown_function(shutta);
62 GLOBAL $is_page_streaming;
64 $is_page_streaming = TRUE;
65 log_rd2("UNREC_ERROR:".var_export(debug_backtrace()));
66 return (sprintf('the_end=true; window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");'));
69 function page_sync($sess, $page, $table_idx, $table_token)
71 GLOBAL $is_page_streaming;
73 log_rd2("page_sync:".var_export(debug_backtrace()));
75 $is_page_streaming = TRUE;
78 return (sprintf('createCookie("table_idx", %d, 24*365, cookiepath); createCookie("table_token", "%s", 24*365, cookiepath); the_end=true; window.onunload = null; window.onbeforeunload = null; document.location.assign("%s");', $table_idx, $table_token, $page));
84 function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step)
86 GLOBAL $G_lang, $mlang_indrd, $is_page_streaming, $first_loop;
87 GLOBAL $G_with_splash, $G_splash_content, $G_splash_interval, $G_splash_idx;
88 GLOBAL $G_splash_w, $G_splash_h, $G_splash_timeout;
89 $CO_splashdate = "CO_splashdate".$G_splash_idx;
90 GLOBAL $$CO_splashdate;
96 /* Sync check (read only without modifications */
97 ignore_user_abort(TRUE);
98 if (($sem = Room::lock_data()) != FALSE) {
99 // Aggiorna l'expire time lato server
100 if ($first_loop == TRUE) {
102 $room = &Room::load_data();
103 if (($user = &$room->get_user($sess, $idx)) == FALSE) {
104 Room::unlock_data($sem);
105 ignore_user_abort(FALSE);
106 return (unrecerror());
108 log_auth($sess, "update lacc");
109 $user->lacc = time();
111 log_main("pre garbage_manager TRE");
112 $room->garbage_manager(FALSE);
114 Room::save_data($room);
119 Room::unlock_data($sem);
120 ignore_user_abort(FALSE);
123 // wait 20 secs, then restart the xhr
124 ignore_user_abort(FALSE);
126 return ("sleep(gst,20000);|xhr_rd_abort(xhr_rd);");
128 ignore_user_abort(FALSE);
133 if (($proxy_step = step_get($sess)) != FALSE) {
134 // log_rd2("Postget".$proxy_step."zizi");
136 if ($cur_step == $proxy_step) {
148 if ($room == FALSE) {
150 ignore_user_abort(TRUE);
151 if (($sem = Room::lock_data()) == FALSE)
155 if (($room = &Room::load_data()) == FALSE)
160 Room::unlock_data($sem);
162 ignore_user_abort(FALSE);
167 if (($user = &$room->get_user($sess, $idx)) == FALSE) {
168 return (unrecerror());
171 /* Nothing changed, return. */
172 if ($cur_step == $user->step)
175 log_rd2("do other ++".$cur_stat."++".$user->stat."++".$cur_step."++".$user->step);
177 if ($cur_step == -1) {
178 // FUNZIONE from_scratch DA QUI
179 ignore_user_abort(TRUE);
180 $sem = Room::lock_data();
181 $room = &Room::load_data();
182 if (($user = &$room->get_user($sess, $idx)) == FALSE) {
183 Room::unlock_data($sem);
184 ignore_user_abort(FALSE);
185 return (unrecerror());
187 if ($user->the_end) {
188 log_rd2("main_check: the end".var_export(debug_backtrace()));
189 $is_page_streaming = TRUE;
192 if ($user->trans_step != -1) {
193 log_rd2("TRANS USATO ".$user->trans_step);
194 $cur_step = $user->trans_step;
195 $user->trans_step = -1;
198 Room::save_data($room);
199 Room::unlock_data($sem);
200 ignore_user_abort(FALSE);
203 log_rd2("TRANS NON ATTIVATO");
204 // ARRAY_POP DISABLED
205 // log_rd2("TRANS NON ATTIVATO, clean del comm array");
206 // while (($el = array_pop($user->comm)) != NULL) {
207 // log_rd2("clean element [".$el."]");
209 // // $user->step_inc(COMM_N + 1);
210 // Room::save_data($room);
211 // // $new_step = $user->step;
213 Room::unlock_data($sem);
214 ignore_user_abort(FALSE);
218 if ($cur_step == -1) {
219 log_rd2("PRE-NEWSTAT: ".$user->stat);
221 if ($user->stat == 'room') {
222 log_rd("roomma ".$user->step);
225 if ($G_with_splash &&
226 ($$CO_splashdate < $curtime - $G_splash_interval ||
227 $$CO_splashdate > $curtime)) {
228 $ret .= show_notify_ex(str_replace("\n", " ", $G_splash_content[$G_lang]), $G_splash_timeout, $mlang_indrd['btn_backtotab'][$G_lang], $G_splash_w, $G_splash_h, true, $G_splash_timeout);
229 $ret .= sprintf('|createCookie("CO_splashdate%d", %d, 24*365, cookiepath);', $G_splash_idx, $curtime);
231 $ret .= $room->show_room($user->step, &$user);
233 // TODO uncomment and test
234 /* NOTE the sets went common */
235 $new_stat = $user->stat;
236 $new_subst = $user->subst;
237 $new_step = $user->step;
244 else if ($user->stat == 'table') {
246 return (page_sync($user->sess, "briskin5/index.php", $user->table, $user->table_token));
248 log_rd2("NEWSTAT: ".$user->stat);
251 ignore_user_abort(TRUE);
252 $sem = Room::lock_data();
253 $room = &Room::load_data();
254 if (($user = &$room->get_user($sess, $idx)) == FALSE) {
255 Room::unlock_data($sem);
256 ignore_user_abort(FALSE);
257 return (unrecerror());
259 if ($cur_step < $user->step) {
261 if ($cur_step + COMM_N < $user->step) {
262 if (($cur_stat != $user->stat)) {
263 $to_stat = $user->stat;
264 Room::unlock_data($sem);
265 ignore_user_abort(FALSE);
267 return (page_sync($user->sess, ($to_stat == "table" ? "briskin5/index.php" : "index.php"), $user->table, $user->table_token));
269 log_rd2("lost history, refresh from scratch");
273 for ($i = $cur_step ; $i < $user->step ; $i++) {
274 log_rd2("ADDED TO THE STREAM: ".$user->comm[$i % COMM_N]);
275 $ret .= $user->comm[$i % COMM_N];
277 $new_stat = $user->stat;
278 $new_subst = $user->subst;
279 $new_step = $user->step;
282 if ($user->the_end == TRUE) {
283 log_rd2("LOGOUT BYE BYE!!");
284 log_auth($user->sess, "Explicit logout.");
288 if ($user->subst == 'sitdown') {
289 log_load("ROOM WAKEUP");
290 $room->room_wakeup(&$user);
292 else if ($user->subst == 'standup')
293 $room->room_outstandup(&$user);
295 log_rd2("LOGOUT FROM WHAT ???");
297 Room::save_data($room);
301 Room::unlock_data($sem);
302 ignore_user_abort(FALSE);
320 $is_page_streaming = ((stristr($HTTP_USER_AGENT, "linux") &&
321 (stristr($HTTP_USER_AGENT, "firefox") || stristr($HTTP_USER_AGENT, "iceweasel"))) ? FALSE : TRUE);
324 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
325 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
326 header('Content-type: application/xml; charset="utf-8"',true);
327 // header('Content-type: text/plain; charset="utf-8"',true);
328 // header('Content-type: text/html; charset="utf-8"',true);
334 log_rd2("FROM OUTSIDE - STAT: ".$stat." SUBST: ".$subst." STEP: ".$step." MYFROM: ".$myfrom. "IS_PAGE:" . $is_page_streaming);
337 $endtime = time() + STREAM_TIMEOUT;
340 $old_step = $ext_step = $step;
342 for ($i = 0 ; time() < $endtime ; $i++) {
343 // log_rd("PRE MAIN ".$step);;
344 if (($ret = maincheck($sess, $old_stat, $old_subst, $old_step, &$stat, &$subst, &$step)) != FALSE) {
346 // 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));
349 log_send("IS_PAGE: ".($is_page_streaming == TRUE ? "TRUE" : "FALSE")."EXT_STEP: ".$ext_step." ENDTIME: [".$endtime."] ".$ret);
351 if ($is_page_streaming)
357 // log_rd("POST MAIN ".$step);;
360 // log_rd2("TIME: ".time());