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("briskin5/Obj/briskin5.phh");
27 log_load("index_rd.php");
32 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
33 echo "Debugging time!";
39 log_rd2("SHUTTA!".connection_status());
43 register_shutdown_function(shutta);
47 GLOBAL $is_page_streaming;
49 $is_page_streaming = TRUE;
50 log_rd2("UNREC_ERROR:".var_export(debug_backtrace()));
51 return (sprintf('the_end=true; window.onunload = null; document.location.assign("index.php");'));
54 function page_sync($sess, $page)
56 GLOBAL $is_page_streaming;
58 log_rd2("page_sync:".var_export(debug_backtrace()));
60 $is_page_streaming = TRUE;
62 return (sprintf('the_end=true; window.onunload = null; document.location.assign("%s");', $page));
68 function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step)
70 GLOBAL $is_page_streaming, $first_loop;
76 /* Sync check (read only without modifications */
77 ignore_user_abort(TRUE);
78 if (($sem = Room::lock_data()) != FALSE) {
79 // Aggiorna l'expire time lato server
80 if ($first_loop == TRUE) {
82 $room = &Room::load_data();
83 if (($user = &$room->get_user($sess, $idx)) == FALSE) {
84 Room::unlock_data($sem);
85 ignore_user_abort(FALSE);
86 return (unrecerror());
88 log_auth($sess, "update lacc");
91 $room->garbage_manager(FALSE);
93 Room::save_data($room);
98 Room::unlock_data($sem);
99 ignore_user_abort(FALSE);
105 if (($proxy_step = step_get($sess)) != FALSE) {
106 // log_rd2("Postget".$proxy_step."zizi");
108 if ($cur_step == $proxy_step) {
120 if ($room == FALSE) {
122 ignore_user_abort(TRUE);
123 if (($sem = Room::lock_data()) == FALSE)
127 if (($room = &Room::load_data()) == FALSE)
132 Room::unlock_data($sem);
134 ignore_user_abort(FALSE);
139 if (($user = &$room->get_user($sess, $idx)) == FALSE) {
140 return (unrecerror());
143 /* Nothing changed, return. */
144 if ($cur_step == $user->step)
147 log_rd2("do other ++".$cur_stat."++".$user->stat."++".$cur_step."++".$user->step);
149 if ($cur_step == -1) {
150 // FUNZIONE from_scratch DA QUI
151 ignore_user_abort(TRUE);
152 $sem = Room::lock_data();
153 $room = &Room::load_data();
154 if (($user = &$room->get_user($sess, $idx)) == FALSE) {
155 Room::unlock_data($sem);
156 ignore_user_abort(FALSE);
157 return (unrecerror());
159 if ($user->the_end) {
160 log_rd2("main_check: the end".var_export(debug_backtrace()));
161 $is_page_streaming = TRUE;
164 if ($user->trans_step != -1) {
165 log_rd2("TRANS USATO ".$user->trans_step);
166 $cur_step = $user->trans_step;
167 $user->trans_step = -1;
170 Room::save_data($room);
171 Room::unlock_data($sem);
172 ignore_user_abort(FALSE);
175 log_rd2("TRANS NON ATTIVATO");
176 Room::unlock_data($sem);
177 ignore_user_abort(FALSE);
181 if ($cur_step == -1) {
182 log_rd2("PRE-NEWSTAT: ".$user->stat);
184 if ($user->stat == 'room') {
186 $ret .= show_room(&$room, &$user);
188 /* NOTE the sets went common */
189 $new_stat = $user->stat;
190 $new_subst = $user->subst;
191 $new_step = $user->step;
198 else if ($user->stat == 'table') {
199 /* FIXME we need to decide what do in this case
201 if ($user->subst != "shutdowned" && $user->subst != "shutdowner")
202 $ret = show_table(&$room,&$user,$user->step,FALSE,FALSE);
204 log_rd2("SENDED TO THE STREAM: ".$ret);
207 $new_stat = $user->stat;
208 $new_subst = $user->subst;
209 $new_step = $user->step;
211 log_rd2("ALL COMMENTED: ".$ret);
215 log_rd2("NEWSTAT: ".$user->stat);
219 ignore_user_abort(TRUE);
220 $sem = Room::lock_data();
221 $room = &Room::load_data();
222 if (($user = &$room->get_user($sess, $idx)) == FALSE) {
223 Room::unlock_data($sem);
224 ignore_user_abort(FALSE);
225 return (unrecerror());
227 if ($cur_step < $user->step) {
229 if ($cur_step + COMM_N < $user->step) {
230 if (($cur_stat != $user->stat)) {
231 $to_stat = $user->stat;
232 Room::unlock_data($sem);
233 ignore_user_abort(FALSE);
235 return (page_sync($user->sess, $to_stat == "table" ? "table.php" : "index.php"));
237 log_rd2("lost history, refresh from scratch");
241 for ($i = $cur_step ; $i < $user->step ; $i++) {
242 log_rd2("ADDED TO THE STREAM: ".$user->comm[$i % COMM_N]);
243 $ret .= $user->comm[$i % COMM_N];
245 $new_stat = $user->stat;
246 $new_subst = $user->subst;
247 $new_step = $user->step;
250 if ($user->the_end == TRUE) {
251 log_rd2("LOGOUT BYE BYE!!");
252 log_auth($user->sess, "Explicit logout.");
253 $tmp_sess = $user->sess;
255 step_unproxy($tmp_sess);
258 $user->the_end = FALSE;
260 if ($user->subst == 'sitdown') {
261 log_load("ROOM WAKEUP");
262 $room->room_wakeup(&$user);
264 else if ($user->subst == 'standup')
265 $room->room_outstandup(&$user);
267 log_rd2("LOGOUT FROM WHAT ???");
269 Room::save_data($room);
273 Room::unlock_data($sem);
274 ignore_user_abort(FALSE);
292 $is_page_streaming = ((stristr($HTTP_USER_AGENT, "linux") &&
293 (stristr($HTTP_USER_AGENT, "firefox") || stristr($HTTP_USER_AGENT, "iceweasel"))) ? FALSE : TRUE);
296 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
297 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
303 log_rd2("FROM OUTSIDE - STAT: ".$stat." SUBST: ".$subst." STEP: ".$step." MYFROM: ".$myfrom. "IS_PAGE:" . $is_page_streaming);
306 $endtime = time() + STREAM_TIMEOUT;
309 $old_step = $ext_step = $step;
311 for ($i = 0 ; time() < $endtime ; $i++) {
312 // log_rd("PRE MAIN ".$step);;
313 if (($ret = maincheck($sess, $old_stat, $old_subst, $old_step, &$stat, &$subst, &$step)) != FALSE) {
315 // 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));
318 log_send("IS_PAGE: ".($is_page_streaming == TRUE ? "TRUE" : "FALSE")."EXT_STEP: ".$ext_step." ENDTIME: [".$endtime."] ".$ret);
320 if ($is_page_streaming)
326 // log_rd("POST MAIN ".$step);;
329 // log_rd2("TIME: ".time());