]> mop.ddnsfree.com - git repositories - brisk.git/commitdiff
whoever is displaced by another access goes back to the login
authorMatteo Nastasi <nastasi@alternativeoutput.it>
Sun, 13 Sep 2026 10:39:37 +0000 (12:39 +0200)
committerMatteo Nastasi <nastasi@alternativeoutput.it>
Sun, 13 Sep 2026 10:39:37 +0000 (12:39 +0200)
The farewell added a moment ago stopped the stream and showed a notice, the
same in every case. But the cases are two, and they want two different
answers.

If the two windows share the SAME session, it cannot be sent to the login:
the session cookie is shared between the tabs of the same browser, so
index.php would let it straight back in and the bouncing would start again.
It was checked that deleting the cookie from the displaced window would not
be enough either: the daemon reads the session ONLY from there (a stream with
sess in the url but no cookie is refused), so deleting it would disarm the
winning window as well, since the cookie is shared. For this case the notice
without a return to the login stays.

If instead the old stream belonged to another session - the "ghost swap" of
add_user(), that is a new access with the same name from another browser -
its session is orphaned by now and it must go back to the login: there
ghost_sess shows it "La tua sessione e' stata assegnata ad un altro browser"
and it does not come back in, because that session is no longer valid.

To tell them apart, the session the stream was opened with is recorded in
rd_sess, and when it is replaced that is compared with the one of the
newcomer.

Checked in both cases: same session -> xstm.stop() and the notice, no return
to the login; different session -> xstm.stop() and a return to index.php,
where the message really shows up. A complete game confirms it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014M1jiEq9cHdE5SE5j6vFuE

web/Obj/brisk.phh
web/Obj/user.phh
web/briskin5/Obj/briskin5.phh

index 71ed6156b1739b7f8023f774b3594e29ee404fde..08adf95a9fb72d0c7be15f41d66db834b0b966cf 100644 (file)
@@ -2839,8 +2839,26 @@ class Brisk
                      In the normal case - the same client reopening after having
                      given the connection up for lost - the message ends up on a
                      socket nobody reads any more, and does no harm. */
-                  $bye = $user->stream_bye('xstm.stop(); '
-                      .show_notify($mlang_brisk['sessmoved'][$G_lang], 0, "chiudi", 400, 120));
+                  if ($user->rd_sess !== NULL && $user->rd_sess != $cookie['sess']) {
+                      /* The old stream belonged to another session, which is
+                         now orphaned: this is the "ghost swap" of add_user(),
+                         that is a new access with the same name from another
+                         browser. There it can be sent back to the login, where
+                         ghost_sess explains that the session was assigned to
+                         another browser, and since its old session is no longer
+                         valid it does not come back in. */
+                      $bye = $user->stream_bye(sprintf('xstm.stop(); window.onbeforeunload = null; window.onunload = null; document.location.assign("%sindex.php");',
+                                                       User::base_get()));
+                  }
+                  else {
+                      /* Same session, two windows: it cannot be sent to the
+                         login, because the session cookie is shared between the
+                         tabs of the same browser and it would come straight back
+                         in, taking the stream again, from the top. It is stopped
+                         and told why. */
+                      $bye = $user->stream_bye('xstm.stop(); '
+                          .show_notify($mlang_brisk['sessmoved'][$G_lang], 0, "chiudi", 400, 120));
+                  }
                   if ($bye != "") {
                       @fwrite($prev, $bye, mb_strlen($bye, "ASCII"));
                   }
index 71f682b5849a0f4d1adec8f16a7c57f7fcb5ddbe..48556e6f75e63723ca1bec9cf8401325887a93d3 100644 (file)
@@ -130,6 +130,13 @@ class User {
   public $pend_async; // number of async check that must be returned
 
   public $rd_socket;  // socket handle of push stream
+  public $rd_sess;    // sessione con cui il flusso corrente e' stato aperto:
+                      // it tells apart the one displaced by another window on
+                      // the SAME session (which cannot go back to the login, the
+                      // cookie is shared and it would come back in) from the one
+                      // displaced by a new access with a different session
+                      // (which must go back to the login, and finds the
+                      // explanation there)
   public $rd_endtime; // end time for push stream
   public $rd_stat;    // actual status of push stream
   public $rd_subst;   // actual substatus of push stream
@@ -204,6 +211,7 @@ class User {
     $thiz->comm       = array();
 
     $thiz->rd_socket  = NULL;
+    $thiz->rd_sess    = NULL;
     $thiz->rd_endtime = -1;
     $thiz->rd_stat    = -1;
     $thiz->rd_subst   = "";
@@ -445,6 +453,10 @@ class User {
           }
       }
       $this->rd_socket = $sock;
+      /* the session the stream was opened with is recorded: when it gets
+         replaced, comparing it with the one of the newcomer tells whether it is
+         the same window-session or a different access */
+      $this->rd_sess = ($sock == NULL ? NULL : $this->sess);
   }
 
   function rd_kalive_get()
index 190c88dea0d5617b64cccc2bbf2b5b9574d8b2cb..b020ba151741af9f26b417cb4f8b72c2badda367 100644 (file)
@@ -1552,8 +1552,16 @@ class Bin5 {
                     /* as in the room: the stream being replaced is told what
                        happened to it, otherwise it reopens and displaces the
                        new one in turn, forever. */
-                    $bye = $user->stream_bye('xstm.stop(); '
-                        .show_notify($mlang_brisk['sessmoved'][$G_lang], 0, "chiudi", 400, 120));
+                    if ($user->rd_sess !== NULL && $user->rd_sess != $cookie['sess']) {
+                        /* as in the room: different session, the old one is
+                           orphaned and finds the explanation at the login */
+                        $bye = $user->stream_bye(sprintf('xstm.stop(); window.onbeforeunload = null; window.onunload = null; document.location.assign("%sindex.php");',
+                                                         Bin5_user::base_get()));
+                    }
+                    else {
+                        $bye = $user->stream_bye('xstm.stop(); '
+                            .show_notify($mlang_brisk['sessmoved'][$G_lang], 0, "chiudi", 400, 120));
+                    }
                     if ($bye != "") {
                         @fwrite($prev, $bye, mb_strlen($bye, "ASCII"));
                     }