typo fixed
[brisk.git] / web / Obj / user.phh
1 <?php
2 /*
3  *  brisk - Obj/user.phh
4  *
5  *  Copyright (C) 2012 Matteo Nastasi
6  *                          mailto: nastasi@alternativeoutput.it 
7  *                                  matteo.nastasi@milug.org
8  *                          web: http://www.alternativeoutput.it
9  *
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.
14  *
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.
22  */
23
24 require_once("${G_base}Obj/transports.phh");
25
26
27 // User flags
28 define('USER_FLAG_AUTH',     0x02);
29
30 define('USER_FLAG_MAP_AUTH', 0x0c);
31 define('USER_FLAG_LISTAUTH', 0x04);
32 define('USER_FLAG_ISOLAUTH', 0x08);
33
34 define('USER_FLAG_DBFAILED', 0x10);
35
36 //   user status
37 define('USER_FLAG_S_NORM',  0x000); // done
38 define('USER_FLAG_S_PAU',   0x100); // done
39 define('USER_FLAG_S_OUT',   0x200); // done
40 define('USER_FLAG_S_DOG',   0x300); // done
41 define('USER_FLAG_S_EAT',   0x400); // done
42 define('USER_FLAG_S_WRK',   0x500); // done
43 define('USER_FLAG_S_SMK',   0x600); // done
44 define('USER_FLAG_S_EYE',   0x700); // done
45 define('USER_FLAG_S_RABB',  0x800); // done
46 define('USER_FLAG_S_SOCC',  0x900); // done
47 define('USER_FLAG_S_BABY',  0xa00); // done
48 define('USER_FLAG_S_MOP',   0xb00); // done
49
50 define('USER_FLAG_S_ALL',   0xf00); // done
51
52 /* type of user normal, supporter etc ... */
53 define('USER_FLAG_TY_ALL',     0xff0000); // done
54 define('USER_FLAG_TY_NORM',    0x010000); // done
55 define('USER_FLAG_TY_SUPER',   0x020000); // done
56 //  ... other usefull status ...
57 define('USER_FLAG_TY_SUSPEND', 0x400000); // done
58 define('USER_FLAG_TY_DISABLE', 0x800000); // done
59
60 // 240 is the right value, 600 is for fwrite error test
61 define('RD_ENDTIME_DELTA',  240);
62 define('RD_KEEPALIVE_TOUT',   4);
63
64 $S_load_stat = array( 'rU_heavy'      => 0,
65                       'lL_laccgarb'   => 0,
66                       'wU_lacc_upd'   => 0,
67                       'wR_garbage'    => 0,
68                       'wR_minusone'   => 0,
69                       'wR_the_end'    => 0 );
70
71 $mlang_indrd = array( 
72                      'btn_backtotab'  => array('it' => ' torna ai tavoli ',
73                                                'en' => ' back to tables '),
74                      'btn_btotabsup'  => array('it' => ' grazie della donazione, torna ai tavoli ',
75                                                'en' => ' thank you for donation, back to tables ') 
76                      );
77
78 class User {
79   var $room;       // reference to the room where the user is registered
80   var $idx;        // index in the users array when you are in game
81   var $idx_orig;   // index in the users array when you aren't in game
82   var $code;       // authentication code
83   var $name;       // name of the user
84   var $sess;       // session of the user
85   var $ip;         // ip of the user
86   var $lacc;       // last access (for the cleanup)
87   var $laccwr;     // last access (for the cleanup)
88   var $bantime;    // timeout to temporary ban
89   var $stat;       // status (outdoor, room, table, game, ...)
90   var $subst;      // substatus for each status   
91   var $step;       // step of the current status
92   var $trans_step; // step to enable transition between pages (disable == -1)
93
94   var $rd_socket;  // socket handle of push stream
95   var $rd_endtime; // end time for push stream
96   var $rd_stat;    // actual status of push stream
97   var $rd_subst;   // actual substatus of push stream
98   var $rd_step;    // actual step of push stream
99   var $rd_from;    // referer
100   var $rd_scristp; // current script step (for each session) 
101   var $rd_kalive;  // if no message are sent after RD_KEEPALIVE_TOUT secs we send a keepalive from server
102   var $rd_cache;   // place where store failed fwrite data
103   var $rd_zls;     // zlibstream object handle if compressed stream, else FALSE
104   var $rd_transp;  // class that define stream encapsulation type (iframe, xhr, ...)
105
106   var $comm;       // commands array
107   // var $asta_card;  // 
108   // var $asta_pnt;   //
109   // var $handpt;     // Total card points at the beginning of the current hand.
110   // var $exitislock; // Player can exit from the table ?
111
112   // FIXME: the table_orig field must be removed after table field verify of index management (in spawned table
113   //        it is allways ZERO
114   var $table;      // id of the current table when you are in game
115   var $table_orig; // id of the current table when you aren't in game
116   var $table_pos;  // idx on the table
117   var $table_token;// token that identify a game on a table
118   var $flags;      // Bitfield with: AUTHENTICATE: 0x02 
119   var $the_end;    // Flag to change the end of the session
120
121   var $chat_lst;      // Last chat line
122   var $chattime;      // Array of chat times
123   var $chat_cur;      // Current chat line number
124   var $chat_ban;      // Time for ban chat
125   var $chat_dlt;      // Delta t for ban
126   var $shm_sz;
127
128   const BASE = "";    // basepath for absolute web references
129
130   function User() {
131   }
132
133   function create(&$room, $idx, $name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
134     if (($thiz = new User()) == FALSE)
135       return (FALSE);
136
137     $thiz->room       = &$room;
138     $thiz->idx        = $idx;
139     $thiz->idx_orig   = $idx;
140     $thiz->code       = -1;
141     $thiz->name       = $name;
142     $thiz->sess       = $sess;
143     $thiz->ip         = $ip;
144     $thiz->lacc       = time();
145     $thiz->laccwr     = time();
146     $thiz->bantime    = 0;
147     $thiz->stat       = $stat;
148     $thiz->subst      = $subst;
149     $thiz->step       = 1;
150     $thiz->trans_step = -1;
151     $thiz->comm       = array();
152
153     $thiz->rd_socket  = NULL;
154     $thiz->rd_endtime = -1;
155     $thiz->rd_stat    = -1;
156     $thiz->rd_subst   = "";
157     $thiz->rd_step    = -1;
158     $thiz->rd_from    = "";
159     $thiz->rd_scristp = -1;
160     $thiz->rd_kalive  = -1;
161     $thiz->rd_cache   = "";
162     $thiz->rd_zls     = FALSE;
163     $thiz->rd_transp  = NULL;
164
165     $thiz->asta_card  = -2;
166     $thiz->asta_pnt   = -1;
167     $thiz->handpt     = -1;
168     $thiz->exitislock = TRUE;
169
170     $thiz->flags      = 0x00;
171     
172     $thiz->chattime   = array_fill(0, CHAT_N, 0);
173     $thiz->chat_cur   = 0;
174     $thiz->chat_lst   = "";
175     $thiz->chat_ban   = 0;
176     $thiz->chat_dlt   = 0;
177
178     $thiz->table_orig = $table;
179     $thiz->table      = $table;
180     $thiz->table_pos  = -1;
181     $thiz->table_token= "";
182     $thiz->shm_sz = SHM_DIMS_U_MIN;
183     return ($thiz);
184   }
185
186   function copy($from)
187   {
188     $this->idx        = $from->idx;
189     $this->idx_orig   = $from->idx;
190     $this->code       = $from->code;
191     $this->name       = $from->name;
192     $this->sess       = $from->sess;
193     $this->ip         = $from->ip;
194     $this->lacc       = $from->lacc;
195     $this->laccwr     = $from->laccwr;
196     $this->bantime    = $from->bantime;
197     $this->stat       = $from->stat;
198     $this->subst      = $from->subst;
199     $this->step       = $from->step;
200     $this->trans_step = $from->trans_step;
201     $this->comm       = array();
202
203     $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N)); 
204     for ($i = $i_start ; $i < $from->step ; $i++) {
205         $ii = $i % COMM_N;
206         if (isset($from->comm[$ii])) {
207             $this->comm[$ii] = $from->comm[$ii];
208         }
209     }
210     $this->asta_card  = $from->asta_card;
211     $this->asta_pnt   = $from->asta_pnt;
212     $this->handpt     = $from->handpt;
213     $this->exitislock = $from->exitislock;
214
215     $this->flags      = $from->flags;
216
217     $this->chattime   = array();
218     for ($i = 0 ; $i < CHAT_N ; $i++)
219       $this->chattime[$i] = $from->chattime[$i];
220     $this->chat_cur   = $from->chat_cur;
221     $this->chat_lst   = $from->chat_lst;
222     $this->chat_ban   = $from->chat_ban;
223     $this->chat_dlt   = $from->chat_dlt;
224
225     $this->table_orig = $from->table_orig;
226     $this->table      = $from->table;
227     $this->table_pos  = $from->table_pos;
228     $this->table_token = $from->table_token;
229     $this->the_end    = $from->the_end;
230     $this->shm_sz     = $from->shm_sz;
231     return (TRUE);
232   }
233
234
235   function myclone($from)
236   {
237     if (($thiz = new User()) == FALSE)
238       return (FALSE);
239     
240     $thiz->copy($from);
241
242     return ($thiz);
243   }
244   
245   function spawn($from, $table, $table_pos)
246   {
247     if (($thiz = new User()) == FALSE)
248       return (FALSE);
249     
250     $thiz->idx        = $from->idx;
251     $thiz->idx_orig   = $from->idx;
252     $thiz->code       = $from->code;
253     $thiz->name       = $from->name;
254     $thiz->sess       = $from->sess;
255     $thiz->ip         = $from->ip;
256     $thiz->lacc       = $from->lacc;
257     $thiz->laccwr     = $from->laccwr;
258     $thiz->bantime    = $from->bantime;
259     $thiz->stat       = $from->stat;
260     $thiz->subst      = $from->subst;
261     $thiz->step       = $from->step;
262     $thiz->trans_step = $from->trans_step;
263     $thiz->comm       = array();
264
265     /*
266     $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N)); 
267     for ($i = $i_start ; $i < $from->step ; $i++) {
268       log_wr("TRY PUSH:".$i);
269       $ii = $i % COMM_N;
270       $thiz->comm[$ii]   = $from->comm[$ii];
271     }
272     */
273     $thiz->asta_card  = $from->asta_card;
274     $thiz->asta_pnt   = $from->asta_pnt;
275     $thiz->handpt     = $from->handpt;
276     $thiz->exitislock = $from->exitislock;
277     $thiz->the_end    = $from->the_end;
278
279     $thiz->flags      = $from->flags;
280
281     $thiz->chattime   = array_fill(0, CHAT_N, 0);
282     $thiz->chat_cur   = 0;
283     $thiz->chat_lst   = "";
284     $thiz->chat_ban   = 0;
285     $thiz->chat_dlt   = 0;
286
287
288     $thiz->table_orig = $table;
289     $thiz->table      = 0;
290     $thiz->table_pos  = $table_pos;
291     $thiz->table_token = $from->table_token;
292     $thiz->shm_sz      = $from->shm_sz;
293
294     return ($thiz);
295   }
296
297   function rd_data_set($curtime, $enc, $stat, $subst, $step, $from)
298   {
299       $this->rd_endtime = $curtime + RD_ENDTIME_DELTA;
300       $this->rd_stat    = $stat;
301       $this->rd_subst   = $subst;
302       $this->rd_step    = $step;
303       $this->rd_from    = $from;
304       $this->rd_scristp = 0;
305       $this->rd_kalive  = $curtime + RD_KEEPALIVE_TOUT;
306       $this->rd_zls     = ZLibStream::create($enc);
307       $this->rd_transp  = new Transport_iframe();
308   }
309
310   function rd_socket_get() {
311       return ($this->rd_socket);
312   }
313
314   function rd_socket_set($sock) {
315       if ($sock == NULL) {
316           if ($this->rd_zls) {
317               $this->rd_zls->destroy();
318               $this->rd_zls = FALSE;
319           }
320       }
321       $this->rd_socket = $sock;
322   }
323
324   function rd_kalive_get()
325   {
326       return ($this->rd_kalive);
327   }
328
329   function rd_kalive_set($tm)
330   {
331       $this->rd_kalive = $tm;
332   }
333
334   function rd_kalive_is_expired($tm)
335   {
336       // printf("rd_kalive %d tm %d\n", $this->rd_kalive, $tm);
337       return ($this->rd_kalive < $tm);
338   }
339
340   function rd_endtime_is_expired($tm)
341   {
342       // printf("rd_endtime %d tm %d\n", $this->rd_kalive, $tm);
343       return ($this->rd_endtime < $tm);
344   }
345
346   function rd_kalive_reset($tm)
347   {
348       $this->rd_kalive = $tm + RD_KEEPALIVE_TOUT;
349   }
350
351   function rd_cache_get()
352   {
353       return ($this->rd_cache);
354   }
355
356   function rd_cache_set($cache)
357   {
358       $this->rd_cache = $cache;
359   }
360
361   function rd_zls_get()
362   {
363       return ($this->rd_zls);
364   }
365
366   function idx_get() {
367       return ($this->idx);
368   }
369
370   function code_get() {
371       return ($this->code);
372   }
373   
374   function stat_set($stat) {
375     log_main("sess: [".$this->sess. "] NEW STAT: [".$stat."]"); 
376     $this->stat = "$stat";
377     
378     /*
379     if (validate_sess($this->sess)) {
380       if (file_exists(PROXY_PATH) == FALSE)
381         mkdir(PROXY_PATH, 0775, TRUE);
382       $fp = @fopen(PROXY_PATH."/".$this->sess.".stat", 'w');
383       fwrite($fp, sprintf("%s\n",$this->stat));
384       fclose($fp);
385     }
386     */
387   }
388
389   function step_set($step) 
390   {
391       $this->step = $step & 0x7fffffff;
392       
393       return (TRUE);
394   }
395
396   function step_inc($delta = 1) {
397       $this->step += $delta;
398       /* modularization because unpack() not manage unsigned 32bit int correctly */
399       $this->step &= 0x7fffffff;
400       
401       return TRUE;
402   }
403
404
405   function save_step() 
406   {
407       do {
408           if (validate_sess($this->sess) == FALSE)
409               break;
410           if (file_exists(PROXY_PATH) == FALSE)
411               mkdir(PROXY_PATH, 0775, TRUE);
412           if (($fp = @fopen(PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
413               break;
414           fwrite($fp, pack("LL",$this->step, $this->idx));
415           fclose($fp);
416           
417           log_main("step_set [".$this->sess. "] [".$this->step."]"); 
418           
419           return (TRUE);
420       } while (0);
421       
422       return (FALSE);
423   }
424   
425   static function load_step($sess) 
426   {
427       $fp = FALSE;
428       do {
429           if (validate_sess($sess) == FALSE)
430               break;
431           
432           if (file_exists(PROXY_PATH) == FALSE)
433               mkdir(PROXY_PATH, 0775, TRUE);
434           if (($fp = @fopen(PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
435               break;
436           if (($s = fread($fp, 8)) == FALSE)
437               break;
438           if (mb_strlen($s, "ASCII") != 8)
439               break;
440           $arr = unpack('Ls/Li', $s);
441           fclose($fp);
442           
443           // log_rd2("A0: ".$arr[0]."  A1: ".$arr[1]);
444           return ($arr);
445       } while (0);
446       
447       if ($fp != FALSE)
448           fclose($fp);
449       
450       log_rd2("STEP_GET [".$sess."]: return false ");
451       
452       return (FALSE);
453   }
454
455   static function unproxy_step($sess) {
456       log_rd2("UNPROXY: ".PROXY_PATH."/".$sess.".step");
457       if (file_exists(PROXY_PATH) == FALSE)
458           return;
459       @unlink(PROXY_PATH."/".$sess.".step");
460   }
461
462   function reset() {
463     $curtime = time();
464     log_legal($curtime, 'xxx', $this, "STAT:LOGOUT", '');
465
466     $tmp_sess = $this->sess;
467     $this->sess = "";
468     self::unproxy_step($tmp_sess);
469     $this->name = "";  // OK here
470     while (array_pop($this->comm) != NULL);
471     $this->step = 0;
472     $this->chattime = array_fill(0, CHAT_N, 0);
473     $this->chat_cur = 0;
474     $this->chat_lst = "";
475     $this->chat_ban = 0;
476     $this->chat_dlt = 0;
477     $this->the_end = FALSE;
478   }
479
480   function myname_innerHTML()
481   {
482       $class_id = ($this->flags & USER_FLAG_AUTH) + 1;
483       
484       return (sprintf('$("myname").innerHTML = "<span class=\"au%d\">%s</span>";', $class_id, 
485                       xcape($this->name,ENT_COMPAT,"UTF-8")));
486   }
487
488   /* INDEX_RD_IFRA PORT */
489
490   static function blocking_error($is_unrecoverable)
491   {
492       log_crit("BLOCKING_ERROR UNREC: ".($is_unrecoverable ? "TRUE" : "FALSE"));
493       return (sprintf(($is_unrecoverable ? 'xstm.stop(); ' : '').'window.onbeforeunload = null; window.onunload = null; document.location.assign("index.php");'));
494   }
495   
496   // FIXME TO SUPPORT iframe
497   protected function page_sync($sess, $page, $table_idx, $table_token)
498   {
499       // log_rd2("page_sync:".var_export(debug_backtrace()));
500       
501       log_rd2("PAGE_SYNC");
502       printf("xXx USER::PAGE_SYNC [%s]\n", get_class($this));
503       return (sprintf('createCookie("table_idx", %d, 24*365, cookiepath); createCookie("table_token", "%s", 24*365, cookiepath); xstm.stop(); window.onunload = null; window.onbeforeunload = null; document.location.assign("%s");', $table_idx, $table_token, $page));
504   }
505
506
507
508
509   protected function maincheck($cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step, $splashdate, $table_idx, $table_token)
510   {
511       GLOBAL $G_lang, $mlang_indrd;
512       // GLOBAL $first_loop;
513       GLOBAL $G_with_splash, $G_splash_content, $G_splash_interval, $G_splash_idx;
514       GLOBAL $G_splash_w, $G_splash_h, $G_splash_timeout;
515       $CO_splashdate = "CO_splashdate".$G_splash_idx;
516       $$CO_splashdate = $splashdate;
517       
518       GLOBAL $S_load_stat;
519       
520       log_rd("maincheck begin");
521       
522       $ret = FALSE;
523       $curtime = time();
524       
525       /* Nothing changed, return. */
526       if ($cur_step == $this->step) 
527           return (FALSE);
528       
529       log_rd2("do other cur_stat[".$cur_stat."] user->stat[".$this->stat."] cur_step[".$cur_step."] user_step[".$this->step."]");
530       
531       if ($cur_step == -1) {
532           /*
533            *  if $cur_step == -1 load the current state from the main struct
534            */
535           
536           $S_load_stat['wR_minusone']++;
537           
538           // if ($this->the_end == TRUE) {
539           // log_rd2("main_check: the end".var_export(debug_backtrace()));
540           // }
541           
542           if ($this->trans_step != -1) {
543               log_rd2("TRANS USATO ".$this->trans_step);
544               $cur_step = $this->trans_step;
545               $this->trans_step = -1;
546           }
547           else {
548               log_rd2("TRANS NON ATTIVATO");
549           }
550       }
551       
552       
553       /* this part I suppose is read only on $this->room structure */
554       if ($cur_step == -1) {
555           log_rd2("PRE-NEWSTAT: ".$this->stat);
556           
557           if ($this->stat == 'room') {
558               log_rd("roomma ".$this->step);
559               $curtime = time();
560               
561               if ($G_with_splash &&
562                   ($$CO_splashdate < $curtime - $G_splash_interval ||
563                    $$CO_splashdate > $curtime)) {
564                   $is_super = $this->flags & USER_FLAG_TY_SUPER;
565                   $ret .=  show_notify_ex(str_replace("\n", " ", $G_splash_content[$G_lang]), 
566                                           ($is_super ? 0 : $G_splash_timeout), 
567                                           $mlang_indrd[($is_super ? 'btn_btotabsup' : 'btn_backtotab')][$G_lang], 
568                                           $G_splash_w, $G_splash_h, true, 
569                                           ($is_super ? 0 : $G_splash_timeout));
570                   $ret .= sprintf('|createCookie("CO_splashdate%d", %d, 24*365, cookiepath);', $G_splash_idx, $curtime);
571               }
572               $ret .= $this->room->show_room($this->step, $this);
573               
574               // TODO uncomment and test
575               /* NOTE the sets went common */
576               $new_stat =  $this->stat;
577               $new_subst = $this->subst;
578               $new_step =  $this->step;
579           }
580           /***************
581            *             *
582            *    TABLE    *
583            *             *
584            ***************/
585           else if ($this->stat == 'table') {
586               log_load("RESYNC");
587               printf("xXx USER::MAINCHECK1 [%s]\n", get_class($this));
588
589               return ($this->page_sync($this->sess, "briskin5/index.php", $this->table, $this->table_token));
590           }
591           log_rd2("NEWSTAT: ".$this->stat);
592       } /* if ($cur_step == -1) { */
593       else {
594           /* $sem = Room::lock_data(FALSE); */
595           $S_load_stat['rU_heavy']++;
596           
597           if ($cur_step < $this->step) {
598               do {
599                   if ($cur_step + COMM_N < $this->step) {
600                       if (($cur_stat != $this->stat)) {
601                           $to_stat = $this->stat;
602                           /* Room::unlock_data($sem); */
603                           log_load("RESYNC");
604                           printf("xXx USER::MAINCHECK2 [%s]\n", get_class($this));
605                           return ($this->page_sync($this->sess, ($to_stat == "table" ? "briskin5/index.php" : "index.php"), $this->table, $this->table_token));
606                       }
607                       log_rd2("lost history, refresh from scratch");
608                       $new_step = -1;
609                       break;
610                   } 
611                   for ($i = $cur_step ; $i < $this->step ; $i++) {
612                       $ii = $i % COMM_N;
613                       log_rd2("ADDED TO THE STREAM: ".$this->comm[$ii]);
614                       $ret .= $this->comm[$ii];
615                   }
616                   $new_stat =  $this->stat;
617                   $new_subst = $this->subst;
618                   $new_step =  $this->step;
619               } while (0);
620               
621               log_rd2($this->step, 'index_rd.php: after ret set');
622               
623               if ($this->the_end == TRUE) {
624                   log_rd2("LOGOUT BYE BYE!!");
625                   log_auth($this->sess, "Explicit logout.");
626                   
627                   if ($this->the_end == TRUE) {
628                       $this->reset();
629                       
630                       if ($this->subst == 'sitdown') {
631                           log_load("ROOM WAKEUP");
632                           $this->room->room_wakeup($this);
633                       }
634                       else if ($this->subst == 'standup')
635                           $this->room->room_outstandup($this);
636                       else
637                           log_rd2("LOGOUT FROM WHAT ???");
638                       
639                   } /* if ($this->the_end == TRUE) { ... */
640               } /* if ($this->the_end == TRUE) { ... */
641           } /* if ($cur_step < $this->step) { */
642           
643           /* Room::unlock_data($sem); */
644       }  /* else of if ($cur_step == -1) { */
645       
646     
647       return ($ret);
648   }  //   function maincheck (...
649
650   public static function stream_fini($init_string, $is_unrecoverable)
651 {
652     printf("xXx user::stream_fini\n");
653
654     // FIXME: dynamic "Transport_" type
655     $tans_class = "Transport_iframe";
656     $body = $tans_class::fini($init_string, static::blocking_error($is_unrecoverable));
657
658     // ELSE IF XHR THEN:
659     // return (static::blocking_error($is_unrecoverable));
660     return ($body);
661 }
662
663 /*
664  *  MAIN
665  */
666
667 /*
668    FROM THE EXTERN 
669    sess
670    stat
671    step
672 */
673 function stream_init($init_string, $enc, &$header_out, &$body, $get, $post, $cookie)
674 {
675     $curtime = time();
676     
677     printf("CLASS: [%s] base: [%s]\n", get_class($this), self::base_get());
678     
679     // (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);
680
681     log_load("index_rd_ifra_init.php");
682     
683     if (($from  = gpcs_var('from', $get, $post, $cookie)) === FALSE)
684         $from = "";
685     if (($stat  = gpcs_var('stat', $get, $post, $cookie)) === FALSE) 
686         $stat = "";
687     if (($subst = gpcs_var('subst', $get, $post, $cookie)) === FALSE) 
688         $subst = "";
689     if (($step  = gpcs_var('step', $get, $post, $cookie)) === FALSE) 
690         unset($step);
691     
692     $this->rd_data_set($curtime, $enc, $stat, $subst, $step, $from);
693     
694     $body .= $this->rd_transp->init($enc, &$header_out, $init_string, self::base_get(), $this->rd_scristp);
695
696     return TRUE;
697   }
698
699 function stream_main(&$body, $get, $post, $cookie)
700 {
701     GLOBAL $G_splash_idx;
702
703     $CO_splashdate = "CO_splashdate".$G_splash_idx;
704     if (($splashdate = gpcs_var("$CO_splashdate", $get, $post, $cookie)) === FALSE)
705         $splashdate = ""; 
706     if (($table_idx = gpcs_var("table_idx", $get, $post, $cookie)) === FALSE)
707         $table_idx = ""; 
708     if (($table_token = gpcs_var("table_token", $get, $post, $cookie)) === FALSE)
709         $table_token = ""; 
710
711     log_rd2("FROM OUTSIDE - STAT: ".$this->rd_stat." SUBST: ".$this->rd_subst." STEP: ".$this->rd_step." FROM: ".$this->rd_from);
712     
713     
714     $pre_main = gettimeofday(TRUE);
715     
716     $old_stat  = $this->rd_stat;
717     $old_subst = $this->rd_subst;
718     $old_step  = $this->rd_step;
719     printf("xXx PRE : rd_step %d\n", $this->rd_step);
720     if (($ret = $this->maincheck($old_stat, $old_subst, $old_step, $this->rd_stat, $this->rd_subst, $this->rd_step, $splashdate, $table_idx, $table_token)) != FALSE) {
721         $body .= $this->rd_transp->chunk( $this->rd_scristp++, $ret);
722         log_rd2(0, 'index_rd.php: after mop_flush (begin: '.sprintf("%f", $pre_main).')');
723     }
724     printf("xXx POST: rd_step %d\n", $this->rd_step);
725
726     return TRUE;
727 }
728
729 function stream_keepalive($with_ping)
730 {
731     return ($this->rd_transp->chunk( $this->rd_scristp++, ($with_ping ? "act_ping();" : NULL)));
732 }
733
734 static function base_get()
735 {
736     $c = get_called_class();
737     printf("CALLED_CLASS: [%s]\n", $c);
738     return $c::BASE;
739 }
740
741 } // end class User
742
743
744 ?>