From: Matteo Nastasi Date: Sun, 13 Sep 2026 10:39:37 +0000 (+0200) Subject: whoever is displaced by another access goes back to the login X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=commitdiff_plain;h=d13caa171f3c15dc82d7b9f3c3b7a5238b1a4a91;p=brisk.git whoever is displaced by another access goes back to the login 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) Claude-Session: https://claude.ai/code/session_014M1jiEq9cHdE5SE5j6vFuE --- diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index 71ed615..08adf95 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -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")); } diff --git a/web/Obj/user.phh b/web/Obj/user.phh index 71f682b..48556e6 100644 --- a/web/Obj/user.phh +++ b/web/Obj/user.phh @@ -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() diff --git a/web/briskin5/Obj/briskin5.phh b/web/briskin5/Obj/briskin5.phh index 190c88d..b020ba1 100644 --- a/web/briskin5/Obj/briskin5.phh +++ b/web/briskin5/Obj/briskin5.phh @@ -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")); }