add index_rd_ifra user data server side. rd keepalive and endtime management
[brisk.git] / web / Obj / brisk.phh
index 58f1e85..95ec8ab 100644 (file)
@@ -275,7 +275,7 @@ $G_room_about = array( 'it' => '<br>
   briscola chiamata in salsa ajax
 </div>
 <br><b>version '.$G_brisk_version.'</b><br><br>
-Copyright 2006-2009 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>',
+Copyright 2006-2012 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>',
                       'en' => '<br>
 <div id=\\"header\\" class=\\"header\\">
   <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
@@ -690,6 +690,8 @@ define('USER_FLAG_TY_SUPER',   0x020000); // done
 define('USER_FLAG_TY_SUSPEND', 0x400000); // done
 define('USER_FLAG_TY_DISABLE', 0x800000); // done
 
+define('RD_STREAM_TIMEOUT', 4);
+
 class User {
   var $idx;        // index in the users array when you are in game
   var $idx_orig;   // index in the users array when you aren't in game
@@ -712,6 +714,8 @@ class User {
   var $rd_step;    // actual step of push stream
   var $rd_from;    // referer
   var $rd_scristp; // current script step (for each session) 
+  var $rd_tout;    // if no message are sent after RD_STREAM_TIMEOUT secs we send a keepalive from server
+
   var $comm;       // commands array
   // var $asta_card;  // 
   // var $asta_pnt;   //
@@ -763,6 +767,7 @@ class User {
     $thiz->rd_step    = -1;
     $thiz->rd_from    = "";
     $thiz->rd_scristp = -1;
+    $thiz->rd_tout    = -1;
 
     $thiz->asta_card  = -2;
     $thiz->asta_pnt   = -1;
@@ -896,6 +901,17 @@ class User {
     return ($thiz);
   }
 
+  function rd_data_set($curtime, $stat, $subst, $step, $from)
+  {
+      $this->rd_endtime = $curtime + STREAM_TIMEOUT;
+      $this->rd_stat    = $stat;
+      $this->rd_subst   = $subst;
+      $this->rd_step    = $step;
+      $this->rd_from    = $from;
+      $this->rd_scristp = 0;
+      $this->rd_tout    = $curtime + RD_STREAM_TIMEOUT;
+  }
+
   function rd_socket_get() {
       return ($this->rd_socket);
   }
@@ -904,6 +920,33 @@ class User {
       $this->rd_socket = $sock;
   }
 
+  function rd_tout_get()
+  {
+      return ($this->rd_tout);
+  }
+
+  function rd_tout_set($tm)
+  {
+      $this->rd_tout = $tm;
+  }
+
+  function rd_tout_is_expired($tm)
+  {
+      // printf("rd_tout %d tm %d\n", $this->rd_tout, $tm);
+      return ($this->rd_tout < $tm);
+  }
+
+  function rd_endtime_is_expired($tm)
+  {
+      // printf("rd_endtime %d tm %d\n", $this->rd_tout, $tm);
+      return ($this->rd_endtime < $tm);
+  }
+
+  function rd_tout_reset($tm)
+  {
+      $this->rd_tout = $tm + RD_STREAM_TIMEOUT;
+  }
+
   function idx_get() {
       return ($this->idx);
   }
@@ -942,16 +985,6 @@ class User {
       return TRUE;
   }
 
-  function rd_data_set($endtime, $stat, $subst, $step, $from)
-  {
-      $this->rd_endtime = $endtime;
-      $this->rd_stat    = $stat;
-      $this->rd_subst   = $subst;
-      $this->rd_step    = $step;
-      $this->rd_from    = $from;
-      $this->rd_scristp = 0;
-  }
-
 
   function save_step() 
   {