5 * Copyright (C) 2012 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 define('USER_FLAG_AUTH', 0x02);
27 define('USER_FLAG_MAP_AUTH', 0x0c);
28 define('USER_FLAG_LISTAUTH', 0x04);
29 define('USER_FLAG_ISOLAUTH', 0x08);
31 define('USER_FLAG_DBFAILED', 0x10);
34 define('USER_FLAG_S_NORM', 0x000); // done
35 define('USER_FLAG_S_PAU', 0x100); // done
36 define('USER_FLAG_S_OUT', 0x200); // done
37 define('USER_FLAG_S_DOG', 0x300); // done
38 define('USER_FLAG_S_EAT', 0x400); // done
39 define('USER_FLAG_S_WRK', 0x500); // done
40 define('USER_FLAG_S_SMK', 0x600); // done
41 define('USER_FLAG_S_EYE', 0x700); // done
42 define('USER_FLAG_S_RABB', 0x800); // done
43 define('USER_FLAG_S_SOCC', 0x900); // done
44 define('USER_FLAG_S_BABY', 0xa00); // done
45 define('USER_FLAG_S_MOP', 0xb00); // done
47 define('USER_FLAG_S_ALL', 0xf00); // done
49 /* type of user normal, supporter etc ... */
50 define('USER_FLAG_TY_ALL', 0xff0000); // done
51 define('USER_FLAG_TY_NORM', 0x010000); // done
52 define('USER_FLAG_TY_SUPER', 0x020000); // done
53 // ... other usefull status ...
54 define('USER_FLAG_TY_SUSPEND', 0x400000); // done
55 define('USER_FLAG_TY_DISABLE', 0x800000); // done
57 // 240 is the right value, 600 is for fwrite error test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ZBPHLOARCVGMUUCHLCDDNKSJSCKYSALUAGUZFN"
122 ."YVURVLREBESGXPANIDKGLPJZGXLKFKTPEQBQEINOYYZTBMPFBLBKIKVPAPFDKKRZ"
123 ."YMVUBYCYTRXCIICUPTXKGQOIJSVSWPYVALIROWGVXDXGNSRVZOLEJHNRSUKHNTRJ"
124 ."LQZQKBEFXYKIPXJRZMQMJKUGCNUKBZBWABPLHMAJJZVBCWOQYCLSGDUKJSTHTVXV"
125 ."OUGJVADGJWGVNBNXYRZDSNLOZDIQRKOQAKJJDKXRMMTXRVTLOMTETNROPDYNXAGR";
127 $S_load_stat = array( 'rU_heavy' => 0,
134 $mlang_indrd = array(
135 'btn_backtotab' => array('it' => ' torna ai tavoli ',
136 'en' => ' back to tables '),
137 'btn_btotabsup' => array('it' => ' grazie della donazione, torna ai tavoli ',
138 'en' => ' thank you for donation, back to tables ')
142 var $room; // reference to the room where the user is registered
143 var $idx; // index in the users array when you are in game
144 var $idx_orig; // index in the users array when you aren't in game
145 var $code; // authentication code
146 var $name; // name of the user
147 var $sess; // session of the user
148 var $ip; // ip of the user
149 var $lacc; // last access (for the cleanup)
150 var $laccwr; // last access (for the cleanup)
151 var $bantime; // timeout to temporary ban
152 var $stat; // status (outdoor, room, table, game, ...)
153 var $subst; // substatus for each status
154 var $step; // step of the current status
155 var $trans_step; // step to enable transition between pages (disable == -1)
157 var $rd_socket; // socket handle of push stream
158 var $rd_endtime; // end time for push stream
159 var $rd_stat; // actual status of push stream
160 var $rd_subst; // actual substatus of push stream
161 var $rd_step; // actual step of push stream
162 var $rd_from; // referer
163 var $rd_scristp; // current script step (for each session)
164 var $rd_kalive; // if no message are sent after RD_KEEPALIVE_TOUT secs we send a keepalive from server
165 var $rd_cache; // place where store failed fwrite data
167 var $comm; // commands array
168 // var $asta_card; //
170 // var $handpt; // Total card points at the beginning of the current hand.
171 // var $exitislock; // Player can exit from the table ?
173 // FIXME: the table_orig field must be removed after table field verify of index management (in spawned table
174 // it is allways ZERO
175 var $table; // id of the current table when you are in game
176 var $table_orig; // id of the current table when you aren't in game
177 var $table_pos; // idx on the table
178 var $table_token;// token that identify a game on a table
179 var $flags; // Bitfield with: AUTHENTICATE: 0x02
180 var $the_end; // Flag to change the end of the session
182 var $chat_lst; // Last chat line
183 var $chattime; // Array of chat times
184 var $chat_cur; // Current chat line number
185 var $chat_ban; // Time for ban chat
186 var $chat_dlt; // Delta t for ban
189 const BASE = ""; // basepath for absolute web references
194 function create(&$room, $idx, $name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
195 if (($thiz = new User()) == FALSE)
198 $thiz->room = &$room;
200 $thiz->idx_orig = $idx;
205 $thiz->lacc = time();
206 $thiz->laccwr = time();
209 $thiz->subst = $subst;
211 $thiz->trans_step = -1;
212 $thiz->comm = array();
214 $thiz->rd_socket = NULL;
215 $thiz->rd_endtime = -1;
217 $thiz->rd_subst = "";
220 $thiz->rd_scristp = -1;
221 $thiz->rd_kalive = -1;
222 $thiz->rd_cache = "";
224 $thiz->asta_card = -2;
225 $thiz->asta_pnt = -1;
227 $thiz->exitislock = TRUE;
231 $thiz->chattime = array_fill(0, CHAT_N, 0);
233 $thiz->chat_lst = "";
237 $thiz->table_orig = $table;
238 $thiz->table = $table;
239 $thiz->table_pos = -1;
240 $thiz->table_token= "";
241 $thiz->shm_sz = SHM_DIMS_U_MIN;
247 $this->idx = $from->idx;
248 $this->idx_orig = $from->idx;
249 $this->code = $from->code;
250 $this->name = $from->name;
251 $this->sess = $from->sess;
252 $this->ip = $from->ip;
253 $this->lacc = $from->lacc;
254 $this->laccwr = $from->laccwr;
255 $this->bantime = $from->bantime;
256 $this->stat = $from->stat;
257 $this->subst = $from->subst;
258 $this->step = $from->step;
259 $this->trans_step = $from->trans_step;
260 $this->comm = array();
262 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
263 for ($i = $i_start ; $i < $from->step ; $i++) {
265 if (isset($from->comm[$ii])) {
266 $this->comm[$ii] = $from->comm[$ii];
269 $this->asta_card = $from->asta_card;
270 $this->asta_pnt = $from->asta_pnt;
271 $this->handpt = $from->handpt;
272 $this->exitislock = $from->exitislock;
274 $this->flags = $from->flags;
276 $this->chattime = array();
277 for ($i = 0 ; $i < CHAT_N ; $i++)
278 $this->chattime[$i] = $from->chattime[$i];
279 $this->chat_cur = $from->chat_cur;
280 $this->chat_lst = $from->chat_lst;
281 $this->chat_ban = $from->chat_ban;
282 $this->chat_dlt = $from->chat_dlt;
284 $this->table_orig = $from->table_orig;
285 $this->table = $from->table;
286 $this->table_pos = $from->table_pos;
287 $this->table_token = $from->table_token;
288 $this->the_end = $from->the_end;
289 $this->shm_sz = $from->shm_sz;
294 function myclone($from)
296 if (($thiz = new User()) == FALSE)
304 function spawn($from, $table, $table_pos)
306 if (($thiz = new User()) == FALSE)
309 $thiz->idx = $from->idx;
310 $thiz->idx_orig = $from->idx;
311 $thiz->code = $from->code;
312 $thiz->name = $from->name;
313 $thiz->sess = $from->sess;
314 $thiz->ip = $from->ip;
315 $thiz->lacc = $from->lacc;
316 $thiz->laccwr = $from->laccwr;
317 $thiz->bantime = $from->bantime;
318 $thiz->stat = $from->stat;
319 $thiz->subst = $from->subst;
320 $thiz->step = $from->step;
321 $thiz->trans_step = $from->trans_step;
322 $thiz->comm = array();
325 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
326 for ($i = $i_start ; $i < $from->step ; $i++) {
327 log_wr("TRY PUSH:".$i);
329 $thiz->comm[$ii] = $from->comm[$ii];
332 $thiz->asta_card = $from->asta_card;
333 $thiz->asta_pnt = $from->asta_pnt;
334 $thiz->handpt = $from->handpt;
335 $thiz->exitislock = $from->exitislock;
336 $thiz->the_end = $from->the_end;
338 $thiz->flags = $from->flags;
340 $thiz->chattime = array_fill(0, CHAT_N, 0);
342 $thiz->chat_lst = "";
347 $thiz->table_orig = $table;
349 $thiz->table_pos = $table_pos;
350 $thiz->table_token = $from->table_token;
351 $thiz->shm_sz = $from->shm_sz;
356 function rd_data_set($curtime, $stat, $subst, $step, $from)
358 $this->rd_endtime = $curtime + RD_ENDTIME_DELTA;
359 $this->rd_stat = $stat;
360 $this->rd_subst = $subst;
361 $this->rd_step = $step;
362 $this->rd_from = $from;
363 $this->rd_scristp = 0;
364 $this->rd_kalive = $curtime + RD_KEEPALIVE_TOUT;
367 function rd_socket_get() {
368 return ($this->rd_socket);
371 function rd_socket_set($sock) {
372 $this->rd_socket = $sock;
375 function rd_kalive_get()
377 return ($this->rd_kalive);
380 function rd_kalive_set($tm)
382 $this->rd_kalive = $tm;
385 function rd_kalive_is_expired($tm)
387 // printf("rd_kalive %d tm %d\n", $this->rd_kalive, $tm);
388 return ($this->rd_kalive < $tm);
391 function rd_endtime_is_expired($tm)
393 // printf("rd_endtime %d tm %d\n", $this->rd_kalive, $tm);
394 return ($this->rd_endtime < $tm);
397 function rd_kalive_reset($tm)
399 $this->rd_kalive = $tm + RD_KEEPALIVE_TOUT;
402 function rd_cache_get()
404 return ($this->rd_cache);
407 function rd_cache_set($cache)
409 $this->rd_cache = $cache;
416 function code_get() {
417 return ($this->code);
420 function stat_set($stat) {
421 log_main("sess: [".$this->sess. "] NEW STAT: [".$stat."]");
422 $this->stat = "$stat";
425 if (validate_sess($this->sess)) {
426 if (file_exists(PROXY_PATH) == FALSE)
427 mkdir(PROXY_PATH, 0775, TRUE);
428 $fp = @fopen(PROXY_PATH."/".$this->sess.".stat", 'w');
429 fwrite($fp, sprintf("%s\n",$this->stat));
435 function step_set($step)
437 $this->step = $step & 0x7fffffff;
442 function step_inc($delta = 1) {
443 $this->step += $delta;
444 /* modularization because unpack() not manage unsigned 32bit int correctly */
445 $this->step &= 0x7fffffff;
454 if (validate_sess($this->sess) == FALSE)
456 if (file_exists(PROXY_PATH) == FALSE)
457 mkdir(PROXY_PATH, 0775, TRUE);
458 if (($fp = @fopen(PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
460 fwrite($fp, pack("LL",$this->step, $this->idx));
463 log_main("step_set [".$this->sess. "] [".$this->step."]");
471 static function load_step($sess)
475 if (validate_sess($sess) == FALSE)
478 if (file_exists(PROXY_PATH) == FALSE)
479 mkdir(PROXY_PATH, 0775, TRUE);
480 if (($fp = @fopen(PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
482 if (($s = fread($fp, 8)) == FALSE)
484 if (mb_strlen($s, "ASCII") != 8)
486 $arr = unpack('Ls/Li', $s);
489 // log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
496 log_rd2("STEP_GET [".$sess."]: return false ");
501 static function unproxy_step($sess) {
502 log_rd2("UNPROXY: ".PROXY_PATH."/".$sess.".step");
503 if (file_exists(PROXY_PATH) == FALSE)
505 @unlink(PROXY_PATH."/".$sess.".step");
510 log_legal($curtime, 'xxx', $this, "STAT:LOGOUT", '');
512 $tmp_sess = $this->sess;
514 self::unproxy_step($tmp_sess);
515 $this->name = ""; // OK here
516 while (array_pop($this->comm) != NULL);
518 $this->chattime = array_fill(0, CHAT_N, 0);
520 $this->chat_lst = "";
523 $this->the_end = FALSE;
526 static function load_data($id, $sess)
528 log_main("load_data: id [".$id."] sess [".($sess == FALSE ? "FALSE" : $sess)."] ");
531 if (($tok = @ftok(FTOK_PATH."/user".$id, "B")) == -1) {
532 log_main("ftok failed");
536 if (($shm_sz = sharedmem_sz($tok)) == -1) {
537 log_main("shmop_open failed");
541 $shm_sz = SHM_DIMS_U_MIN;
543 if ($shm = shm_attach($tok, $shm_sz)) {
544 if (($user = @shm_get_var($shm, $tok)) == FALSE) {
547 if ($sess != FALSE && $user->sess != $sess) {
550 log_only("user == ".($user == FALSE ? "FALSE" : "TRUE")." user === ".($user === FALSE ? "FALSE" : "TRUE")." user isset ".(isset($user) ? "TRUE" : "FALSE"));
552 if ($user == FALSE) {
553 log_only("INIT MAIN DATA");
555 // SHSPLIT FIXME: init_data for User class ??
556 $user = self::create($id, "", "");
557 if (@shm_put_var($shm, $tok, $user) == FALSE) {
558 log_only("PUT_VAR FALLITA ".strlen(serialize($user)));
559 log_only(serialize($user));
561 log_shme("User::save_data2");
564 if ($sess != FALSE) {
566 * NOTE: this part is for check only, theoretically
567 * user->step anch proxy_step are set allways at the same value
569 $old_step = $user->step;
570 $arr = self::load_step($sess);
571 $user->step = $arr['s'];
572 if ($old_step != $user->step) {
573 log_crit("steps are diffetents User->step ".$user->step." Old_step: ".$old_step);
577 $user->shm_sz = $shm_sz;
583 // SHSPLIT: load users from the shared memory
592 static function save_data($user, $id)
598 if (($tok = @ftok(FTOK_PATH."/user".$id, "B")) == -1) {
601 while ($user->shm_sz < SHM_DIMS_U_MAX) {
602 if (($shm = shm_attach($tok, $user->shm_sz)) == FALSE)
605 // log_only("PUT_VAR DI ".strlen(serialize($user)));
606 if (@shm_put_var($shm, $tok, $user) != FALSE) {
608 if ($user->sess != "")
611 log_shme("User::save_data");
613 log_main("User[".$id."] saved.");
616 if (shm_remove($shm) === FALSE) {
617 log_only("REMOVE FALLITA");
621 $user->shm_sz += SHM_DIMS_U_DLT;
630 function myname_innerHTML()
632 $class_id = ($this->flags & USER_FLAG_AUTH) + 1;
634 return (sprintf('$("myname").innerHTML = "<span class=\"au%d\">%s</span>";', $class_id,
635 xcape($this->name,ENT_COMPAT,"UTF-8")));
638 /* INDEX_RD_IFRA PORT */
640 static function blocking_error($is_unrecoverable)
642 GLOBAL $is_page_streaming;
644 $is_page_streaming = TRUE;
645 log_crit("BLOCKING_ERROR UNREC: ".($is_unrecoverable ? "TRUE" : "FALSE"));
646 return (sprintf(($is_unrecoverable ? 'hstm.stop(); ' : '').'window.onbeforeunload = null; window.onunload = null; document.location.assign("index.php");'));
649 // FIXME TO SUPPORT iframe
650 static function page_sync($sess, $page, $table_idx, $table_token)
652 GLOBAL $is_page_streaming;
654 log_rd2("page_sync:".var_export(debug_backtrace()));
656 $is_page_streaming = TRUE;
658 log_rd2("PAGE_SYNC");
659 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));
665 function maincheck($cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step, $splashdate)
667 GLOBAL $G_lang, $mlang_indrd, $is_page_streaming;
668 // GLOBAL $first_loop;
669 GLOBAL $G_with_splash, $G_splash_content, $G_splash_interval, $G_splash_idx;
670 GLOBAL $G_splash_w, $G_splash_h, $G_splash_timeout;
671 $CO_splashdate = "CO_splashdate".$G_splash_idx;
672 $$CO_splashdate = $splashdate;
676 log_rd("maincheck begin");
681 /* if ((($curtime - $this->lacc) > STREAM_TIMEOUT) || Room::garbage_time_is_expired($curtime)) { */
682 /* $S_load_stat['lL_laccgarb']++; */
684 /* if (($curtime - $this->lacc) >= STREAM_TIMEOUT) { */
685 /* $S_load_stat['wU_lacc_upd']++; */
686 /* $this->lacc = $curtime; */
689 /* if (Room::garbage_time_is_expired($curtime)) { */
692 /* $S_load_stat['wR_garbage']++; */
693 /* log_main("pre garbage_manager TRE"); */
694 /* $this->room->garbage_manager(FALSE); */
698 /* Nothing changed, return. */
699 if ($cur_step == $this->step)
702 log_rd2("do other cur_stat[".$cur_stat."] user->stat[".$this->stat."] cur_step[".$cur_step."] user_step[".$this->step."]");
704 if ($cur_step == -1) {
706 * if $cur_step == -1 load the current state from the main struct
709 $S_load_stat['wR_minusone']++;
711 if ($this->the_end == TRUE) {
712 log_rd2("main_check: the end".var_export(debug_backtrace()));
713 $is_page_streaming = TRUE;
716 if ($this->trans_step != -1) {
717 log_rd2("TRANS USATO ".$this->trans_step);
718 $cur_step = $this->trans_step;
719 $this->trans_step = -1;
722 log_rd2("TRANS NON ATTIVATO");
727 /* this part I suppose is read only on $this->room structure */
728 if ($cur_step == -1) {
729 log_rd2("PRE-NEWSTAT: ".$this->stat);
731 if ($this->stat == 'room') {
732 log_rd("roomma ".$this->step);
735 if ($G_with_splash &&
736 ($$CO_splashdate < $curtime - $G_splash_interval ||
737 $$CO_splashdate > $curtime)) {
738 $is_super = $this->flags & USER_FLAG_TY_SUPER;
739 $ret .= show_notify_ex(str_replace("\n", " ", $G_splash_content[$G_lang]),
740 ($is_super ? 0 : $G_splash_timeout),
741 $mlang_indrd[($is_super ? 'btn_btotabsup' : 'btn_backtotab')][$G_lang],
742 $G_splash_w, $G_splash_h, true,
743 ($is_super ? 0 : $G_splash_timeout));
744 $ret .= sprintf('|createCookie("CO_splashdate%d", %d, 24*365, cookiepath);', $G_splash_idx, $curtime);
746 $ret .= $this->room->show_room($this->step, $this);
748 // TODO uncomment and test
749 /* NOTE the sets went common */
750 $new_stat = $this->stat;
751 $new_subst = $this->subst;
752 $new_step = $this->step;
759 else if ($this->stat == 'table') {
761 return (self::page_sync($this->sess, "briskin5/index.php", $this->table, $this->table_token));
763 log_rd2("NEWSTAT: ".$this->stat);
764 } /* if ($cur_step == -1) { */
766 /* $sem = Room::lock_data(FALSE); */
767 $S_load_stat['rU_heavy']++;
769 if ($cur_step < $this->step) {
771 if ($cur_step + COMM_N < $this->step) {
772 if (($cur_stat != $this->stat)) {
773 $to_stat = $this->stat;
774 /* Room::unlock_data($sem); */
776 return (self::page_sync($this->sess, ($to_stat == "table" ? "briskin5/index.php" : "index.php"), $this->table, $this->table_token));
778 log_rd2("lost history, refresh from scratch");
782 for ($i = $cur_step ; $i < $this->step ; $i++) {
784 log_rd2("ADDED TO THE STREAM: ".$this->comm[$ii]);
785 $ret .= $this->comm[$ii];
787 $new_stat = $this->stat;
788 $new_subst = $this->subst;
789 $new_step = $this->step;
792 log_rd2($this->step, 'index_rd.php: after ret set');
794 if ($this->the_end == TRUE) {
795 log_rd2("LOGOUT BYE BYE!!");
796 log_auth($this->sess, "Explicit logout.");
798 if ($this->the_end == TRUE) {
801 if ($this->subst == 'sitdown') {
802 log_load("ROOM WAKEUP");
803 $this->room->room_wakeup($this);
805 else if ($this->subst == 'standup')
806 $this->room->room_outstandup($this);
808 log_rd2("LOGOUT FROM WHAT ???");
810 } /* if ($this->the_end == TRUE) { ... */
811 } /* if ($this->the_end == TRUE) { ... */
812 } /* if ($cur_step < $this->step) { */
814 /* Room::unlock_data($sem); */
815 } /* else of if ($cur_step == -1) { */
819 } // function maincheck (...
821 static function stream_fini($is_unrecoverable)
823 GLOBAL $G_four_rnd_string;
827 $body .= sprintf("<html>
829 <script type=\"text/javascript\" src=\"%scommons.js\"></script>
830 <script type=\"text/javascript\" src=\"%sxynt-http-streaming-ifra.js\"></script>
831 <script type=\"text/javascript\">
832 var http_streaming = \"ready\";", self::base_get(), self::base_get());
834 window.onload = function () { if (http_streaming != \"ready\") { http_streaming.reload(); } };
838 $body .= sprintf("<!-- \n%s -->\n", $G_four_rnd_string);
839 $body .= sprintf("<script id='hs%d' type='text/javascript'><!--
842 </script>", 0, escpush(self::blocking_error($is_unrecoverable)) );
844 // return (self::blocking_error($is_unrecoverable));
858 function stream_init(&$header_out, &$body, $get, $post, $cookie)
860 GLOBAL $G_four_rnd_string;
864 printf("CLASS: [%s] base: [%s]\n", get_class($this), self::base_get());
866 $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);
868 $header_out['Cache-Control'] = 'no-cache, must-revalidate'; // HTTP/1.1
869 $header_out['Expires'] = 'Mon, 26 Jul 1997 05:00:00 GMT'; // Date in the past
870 $header_out['Content-type'] = 'text/html; charset="utf-8"';
872 log_load("index_rd_ifra_init.php");
874 if (($from = gpcs_var('from', $get, $post, $cookie)) === FALSE)
876 if (($stat = gpcs_var('stat', $get, $post, $cookie)) === FALSE)
878 if (($subst = gpcs_var('subst', $get, $post, $cookie)) === FALSE)
880 if (($step = gpcs_var('step', $get, $post, $cookie)) === FALSE)
883 $this->rd_data_set($curtime, $stat, $subst, $step, $from);
884 $cc = get_called_class();
886 $body .= sprintf("<html>
888 <script type=\"text/javascript\" src=\"%scommons.js\"></script>
889 <script type=\"text/javascript\" src=\"%sxynt-http-streaming-ifra.js\"></script>
890 <script type=\"text/javascript\">
891 var http_streaming = \"ready\";", self::base_get(), self::base_get());
892 if ($this->rd_scristp > 0)
893 $body .= sprintf("last_clean = %d;\n", ($this->rd_scristp-1));
895 window.onload = function () { if (http_streaming != \"ready\") { http_streaming.reload(); } };
899 $body .= sprintf("<!-- \n%s -->\n", $G_four_rnd_string);
904 function stream_main(&$body, $get, $post, $cookie)
906 GLOBAL $is_page_streaming, $G_splash_idx;
907 // FIXME: only to test fwrite
908 // GLOBAL $G_four_rnd_string;
910 $CO_splashdate = "CO_splashdate".$G_splash_idx;
911 if (($splashdate = gpcs_var("$CO_splashdate", $get, $post, $cookie)) === FALSE)
914 $is_page_streaming = FALSE;
915 log_rd2("FROM OUTSIDE - STAT: ".$this->rd_stat." SUBST: ".$this->rd_subst." STEP: ".$this->rd_step." FROM: ".$this->rd_from. "IS_PAGE:" . $is_page_streaming);
918 $pre_main = gettimeofday(TRUE);
920 $old_stat = $this->rd_stat;
921 $old_subst = $this->rd_subst;
922 $old_step = $this->rd_step;
923 if (($ret = $this->maincheck($old_stat, $old_subst, $old_step, $this->rd_stat, $this->rd_subst, $this->rd_step, $splashdate)) != FALSE) {
924 $body .= sprintf("<script id='hs%d' type='text/javascript'><!--
927 </script>", $this->rd_scristp++, escpush($ret) );
929 log_rd2(0, 'index_rd.php: after mop_flush (begin: '.sprintf("%f", $pre_main).')');
930 if ($is_page_streaming)
937 function stream_keepalive()
939 return (sprintf("<script id='hs%d' type='text/javascript'><!--
942 </script>", $this->rd_scristp++));
946 function stream_ping()
948 return (sprintf("<script id='hs%d' type='text/javascript'><!--
949 push(\"act_ping();\");
951 </script>", $this->rd_scristp++));
955 static function base_get()
957 $c = get_called_class();
958 printf("CALLED_CLASS: [%s]\n", $c);