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/proxyscan.phh");
26 require_once("briskin5/Obj/briskin5.phh");
28 // Use of proxies isn't allowed.
33 log_load("index_rd.php");
38 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
39 echo "Debugging time!";
45 log_rd2("SHUTTA!".connection_status());
49 register_shutdown_function(shutta);
53 GLOBAL $is_page_streaming;
55 $is_page_streaming = TRUE;
56 log_rd2("UNREC_ERROR:".var_export(debug_backtrace()));
57 return (sprintf('the_end=true; window.onunload = null; document.location.assign("index.php");'));
60 function page_sync($sess, $page, $table_idx, $table_token)
62 GLOBAL $is_page_streaming;
64 log_rd2("page_sync:".var_export(debug_backtrace()));
66 $is_page_streaming = TRUE;
69 return (sprintf('createCookie("table_idx", %d, 24*365, cookiepath); createCookie("table_token", "%s", 24*365, cookiepath); the_end=true; window.onunload = null; document.location.assign("%s");', $table_idx, $table_token, $page));
75 function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step)
77 GLOBAL $is_page_streaming, $first_loop;
83 /* Sync check (read only without modifications */
84 ignore_user_abort(TRUE);
85 if (($sem = Room::lock_data()) != FALSE) {
86 // Aggiorna l'expire time lato server
87 if ($first_loop == TRUE) {
89 $room = &Room::load_data();
90 if (($user = &$room->get_user($sess, $idx)) == FALSE) {
91 Room::unlock_data($sem);
92 ignore_user_abort(FALSE);
93 return (unrecerror());
95 log_auth($sess, "update lacc");
98 log_main("pre garbage_manager TRE");
99 $room->garbage_manager(FALSE);
101 Room::save_data($room);
106 Room::unlock_data($sem);
107 ignore_user_abort(FALSE);
113 if (($proxy_step = step_get($sess)) != FALSE) {
114 // log_rd2("Postget".$proxy_step."zizi");
116 if ($cur_step == $proxy_step) {
128 if ($room == FALSE) {
130 ignore_user_abort(TRUE);
131 if (($sem = Room::lock_data()) == FALSE)
135 if (($room = &Room::load_data()) == FALSE)
140 Room::unlock_data($sem);
142 ignore_user_abort(FALSE);
147 if (($user = &$room->get_user($sess, $idx)) == FALSE) {
148 return (unrecerror());
151 /* Nothing changed, return. */
152 if ($cur_step == $user->step)
155 log_rd2("do other ++".$cur_stat."++".$user->stat."++".$cur_step."++".$user->step);
157 if ($cur_step == -1) {
158 // FUNZIONE from_scratch DA QUI
159 ignore_user_abort(TRUE);
160 $sem = Room::lock_data();
161 $room = &Room::load_data();
162 if (($user = &$room->get_user($sess, $idx)) == FALSE) {
163 Room::unlock_data($sem);
164 ignore_user_abort(FALSE);
165 return (unrecerror());
167 if ($user->the_end) {
168 log_rd2("main_check: the end".var_export(debug_backtrace()));
169 $is_page_streaming = TRUE;
172 if ($user->trans_step != -1) {
173 log_rd2("TRANS USATO ".$user->trans_step);
174 $cur_step = $user->trans_step;
175 $user->trans_step = -1;
178 Room::save_data($room);
179 Room::unlock_data($sem);
180 ignore_user_abort(FALSE);
183 log_rd2("TRANS NON ATTIVATO");
184 // ARRAY_POP DISABLED
185 // log_rd2("TRANS NON ATTIVATO, clean del comm array");
186 // while (($el = array_pop($user->comm)) != NULL) {
187 // log_rd2("clean element [".$el."]");
189 // // $user->step_inc(COMM_N + 1);
190 // Room::save_data($room);
191 // // $new_step = $user->step;
193 Room::unlock_data($sem);
194 ignore_user_abort(FALSE);
198 if ($cur_step == -1) {
199 log_rd2("PRE-NEWSTAT: ".$user->stat);
201 if ($user->stat == 'room') {
202 log_rd("roomma ".$user->step);
203 $ret .= show_room(&$room, $user->step, &$user);
205 // TODO uncomment and test
206 /* NOTE the sets went common */
207 $new_stat = $user->stat;
208 $new_subst = $user->subst;
209 $new_step = $user->step;
216 else if ($user->stat == 'table') {
218 return (page_sync($user->sess, "briskin5/index.php", $user->table, $user->table_token));
220 log_rd2("NEWSTAT: ".$user->stat);
223 ignore_user_abort(TRUE);
224 $sem = Room::lock_data();
225 $room = &Room::load_data();
226 if (($user = &$room->get_user($sess, $idx)) == FALSE) {
227 Room::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 Room::unlock_data($sem);
237 ignore_user_abort(FALSE);
239 return (page_sync($user->sess, ($to_stat == "table" ? "briskin5/index.php" : "index.php"), $user->table, $user->table_token));
241 log_rd2("lost history, refresh from scratch");
245 for ($i = $cur_step ; $i < $user->step ; $i++) {
246 log_rd2("ADDED TO THE STREAM: ".$user->comm[$i % COMM_N]);
247 $ret .= $user->comm[$i % COMM_N];
249 $new_stat = $user->stat;
250 $new_subst = $user->subst;
251 $new_step = $user->step;
254 if ($user->the_end == TRUE) {
255 log_rd2("LOGOUT BYE BYE!!");
256 log_auth($user->sess, "Explicit logout.");
259 /* factorized with ->reset()
260 $tmp_sess = $user->sess;
262 step_unproxy($tmp_sess);
264 while (array_pop($user->comm) != NULL);
266 $user->the_end = FALSE;
269 if ($user->subst == 'sitdown') {
270 log_load("ROOM WAKEUP");
271 $room->room_wakeup(&$user);
273 else if ($user->subst == 'standup')
274 $room->room_outstandup(&$user);
276 log_rd2("LOGOUT FROM WHAT ???");
278 Room::save_data($room);
282 Room::unlock_data($sem);
283 ignore_user_abort(FALSE);
301 $is_page_streaming = ((stristr($HTTP_USER_AGENT, "linux") &&
302 (stristr($HTTP_USER_AGENT, "firefox") || stristr($HTTP_USER_AGENT, "iceweasel"))) ? FALSE : TRUE);
305 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
306 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
312 log_rd2("FROM OUTSIDE - STAT: ".$stat." SUBST: ".$subst." STEP: ".$step." MYFROM: ".$myfrom. "IS_PAGE:" . $is_page_streaming);
315 $endtime = time() + STREAM_TIMEOUT;
318 $old_step = $ext_step = $step;
320 for ($i = 0 ; time() < $endtime ; $i++) {
321 // log_rd("PRE MAIN ".$step);;
322 if (($ret = maincheck($sess, $old_stat, $old_subst, $old_step, &$stat, &$subst, &$step)) != FALSE) {
324 // 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));
327 log_send("IS_PAGE: ".($is_page_streaming == TRUE ? "TRUE" : "FALSE")."EXT_STEP: ".$ext_step." ENDTIME: [".$endtime."] ".$ret);
329 if ($is_page_streaming)
335 // log_rd("POST MAIN ".$step);;
337 if (($i % 10) == 0) {
338 // log_rd2("TIME: ".time());