Merge branch 'post-bold2' into avoid-domino avoid-domino
authorMatteo Nastasi <nastasi@alternativeoutput.it>
Tue, 21 Apr 2020 05:25:07 +0000 (07:25 +0200)
committerMatteo Nastasi <nastasi@alternativeoutput.it>
Tue, 21 Apr 2020 05:25:07 +0000 (07:25 +0200)
TODO.txt
web/Obj/brisk.phh
web/Obj/user.phh
web/index.php
web/xynt-streaming.js

index 9e88cb7..dd55942 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -1,6 +1,15 @@
  TODO |
 ------+
 
+page_id =>
+  - add page_id to both index.php pages (WIP)
+  DONE - add page_id to user class
+  DONE - pass page_id to transport (WIP)
+  - manage server-side page_id in transport channel
+  - manage index_rd
+  - manage page to stop transport retry
+
+
   BUGS |
  ------+
    - manage client answer (ping) on closing ws
index 5238b13..8397e2c 100644 (file)
@@ -2787,15 +2787,22 @@ class Brisk
           do {
               if (!isset($cookie['sess'])
                   || (($user = $this->get_user($cookie['sess'], $idx)) == FALSE)) {
-
-                  $content = User::stream_fini($transp, $s_a_p->rndstr, TRUE);
+               // || (($user = $this->get_user($cookie['sess'], $idx)) == FALSE)
+               // || $user->page_id != $get['page_id']) {
+                  $content = "";
+                  // if ($user->page_id != $get['page_id']) {
+                  //     $content .= "OLD_PAGE";
+                  // }
+                  printf("\ndiscarded here\n");
+                  printf("Is Cookie %s\n", (isset($cookie['sess']) ? TRUE : FALSE));
+                  $content .= User::stream_fini($transp, $s_a_p->rndstr, TRUE);
 
                   $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content);
                   return TRUE;
 
                   break;
-              }
-              $this->sess_cur_set($user->sess);
+          }
+          $this->sess_cur_set($user->sess);
               // close a previous opened index_read_ifra socket, if exists
               if (($prev = $user->rd_socket_get()) != NULL) {
                   $s_a_p->socks_unset($user->rd_socket_get());
index 32bb71e..6335832 100644 (file)
@@ -112,6 +112,7 @@ class User {
   var $code;       // authentication code
   var $name;       // name of the user
   var $sess;       // session of the user
+  var $page_id;    // id of the latest page connected with this session
   var $ip;         // ip of the user
   var $lacc;       // last access (for the cleanup)
   var $laccwr;     // last access (for the cleanup)
@@ -167,7 +168,7 @@ class User {
   function User() {
   }
 
-  static function create(&$brisk, $idx, $name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
+  static function create(&$brisk, $idx, $name, $sess, $page_id="", $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
     if (($thiz = new User()) == FALSE)
       return (FALSE);
 
@@ -177,6 +178,7 @@ class User {
     $thiz->code       = -1;
     $thiz->name       = $name;
     $thiz->sess       = $sess;
+    $thiz->page_id    = $page_id;
     $thiz->ip         = $ip;
     $thiz->lacc       = time();
     $thiz->laccwr     = time();
@@ -233,6 +235,7 @@ class User {
     $this->code       = $from->code;
     $this->name       = $from->name;
     $this->sess       = $from->sess;
+    $this->page_id    = $from->page_id;
     $this->ip         = $from->ip;
     $this->lacc       = $from->lacc;
     $this->laccwr     = $from->laccwr;
@@ -299,6 +302,7 @@ class User {
     $thiz->code       = $from->code;
     $thiz->name       = $from->name;
     $thiz->sess       = $from->sess;
+    $thiz->page_id    = $from->page_id;
     $thiz->ip         = $from->ip;
     $thiz->lacc       = $from->lacc;
     $thiz->laccwr     = $from->laccwr;
@@ -578,6 +582,7 @@ class User {
 
     $tmp_sess = $this->sess;
     $this->sess = "";
+    $this->page_id = "";
     self::unproxy_step($tmp_sess);
     $this->name = "";  // OK here
     while (array_pop($this->comm) != NULL);
index eb49939..553f10c 100644 (file)
@@ -512,6 +512,13 @@ function index_main(&$brisk, $transp_type, $header, &$header_out, $remote_addr_f
             }
         }
     }
+
+    if ($ACTION == "room") {
+        /* shutdown any previous transport socket */
+        $user->page_id = md5(microtime().$remote_addr_full);
+        // $brisk->abort_old_sockets($user);
+    }
+
     /* Rendering. */
 
     if ($BRISK_SHOWHTML == "debugtable") {
@@ -1224,6 +1231,7 @@ cookie_law(null);
    var $$ = jQuery.noConflict();
 
    var sess = "not_connected";
+   var page_id = "<? echo $user->page_id; ?>";
    var g_debug = 0;
    var g_lang = "<? echo $G_lang; ?>";
    var g_lng = "<? echo $G_lng; ?>";
@@ -1247,12 +1255,23 @@ cookie_law(null);
    var spo_slide, sup_slide;
 
    window.onload = function() {
-     g_brow = get_browser_agent();
+       if ('localStorage' in window) {
+           var v_name = cookiepath.replace(/\//g, '') + '_index_page_id';
+           var local_page_id = window.localStorage.getItem(v_name);
+           if (local_page_id == page_id) {
+               window.location.reload();
+           }
+           else {
+               window.localStorage.setItem(v_name, page_id);
+           }
+       }
+
+       g_brow = get_browser_agent();
 
-     g_prefs = new client_prefs(null);
+       g_prefs = new client_prefs(null);
 
-     spo_slide  = new sideslide($('spon_caro'), 80, 20);
-     sup_slide  = new sideslide($('supp_caro'), 80, 20);
+       spo_slide  = new sideslide($('spon_caro'), 80, 20);
+       sup_slide  = new sideslide($('supp_caro'), 80, 20);
 
 <?php
         if ($BRISK_SHOWHTML == "debugtable") {
@@ -1271,7 +1290,8 @@ cookie_law(null);
         sidebanners_init($G_sidebanner_idx);
 ?>
      sess = "<?php echo "$sess"; ?>";
-     xstm = new xynt_streaming(window, <?php printf("\"%s\", %d", $transp_type, $transp_port); ?>, 2, null /* console */, gst, 'index_php', 'sess', sess, $('sandbox'), 'index_rd.php', function(com){eval(com);});
+    xstm = new xynt_streaming(window, <?php printf("\"%s\", %d", $transp_type, $transp_port); ?>, 2, null /* console */, gst,
+                              'index_php', 'sess', sess, $('sandbox'), 'index_rd.php', page_id, function(com){eval(com);});
      xstm.hbit_set(heartbit);
      tra = new train($('room_tit'));
      window.onunload = onunload_cb;
index b9ef124..46bdb42 100644 (file)
@@ -566,7 +566,7 @@ transport_iframe.prototype = {
     }
 }
 
-function xynt_streaming(win, transp_type, transp_port, transp_fback, console, gst, from, cookiename, sess, sandbox, page, cmdproc)
+function xynt_streaming(win, transp_type, transp_port, transp_fback, console, gst, from, cookiename, sess, sandbox, page, page_id, cmdproc)
 {
     this.win = win;
     this.transp_type = transp_type;
@@ -579,6 +579,7 @@ function xynt_streaming(win, transp_type, transp_port, transp_fback, console, gs
     this.sess = sess;
     this.sandbox = sandbox;
     this.page = page;
+    this.page_id = page_id;
     this.cmdproc = cmdproc;
     // this.cmdproc = function(com){/* console.log("COM: "+com); */ eval(com);}
     this.doc = win.document;
@@ -607,6 +608,7 @@ xynt_streaming.prototype = {
     sess:              null,
     sandbox:           null,
     page:              null,
+    page_id:           null,
     cmdproc:           null,
 
     start_time:        0,
@@ -730,7 +732,7 @@ xynt_streaming.prototype = {
         }
         // stat, subst, this.gst.st
 
-        page = url_append_args(page, "sess", this.sess, "stat", stat, "subst", subst, "step", this.gst.st, "from", this.from);
+        page = url_append_args(page, "sess", this.sess, "page_id", this.page_id, "stat", stat, "subst", subst, "step", this.gst.st, "from", this.from);
         // this.log("the page:");
         // this.log(page);