ctm / mb2-doc

Mb2, poker software
https://devctm.com
7 stars 2 forks source link

Fix so demo can be used after a demo account is logged out via a restart #1436

Closed ctm closed 1 month ago

ctm commented 1 month ago

Fix so that if a user has created, but not started a demo and the server is restarted, the user can then create and start a new demo.

This is a regression that I introduced when I disallowed demos created before a restart to be started after a restart (#1434). I think that's an acceptable policy, but unbeknownst to me, my fix made it so the "demo" button couldn't be used after the demo user was logged out due to a restart. I documented that problem in a comment and reopened #1434, but now that I have a fix, I'd prefer a separate issue for it so that I can refer to this issue, rather than #1434, since the (one line!) fix is a hack and has a bunch of comments explaining what's going on.

Ugh.

ctm commented 1 month ago

Deploying now. Here's the embarrassing fix:

diff --git a/front-ends/web/src/lobby.rs b/front-ends/web/src/lobby.rs
index 69cef7b7..32b16a9d 100644
--- a/front-ends/web/src/lobby.rs
+++ b/front-ends/web/src/lobby.rs
@@ -1428,6 +1428,25 @@ impl Lobby {
             self.demo = true;
             let request = if extended {
                 self.show_creation_modal = true;
+
+                // Setting structure_names to None here is a hack to
+                // fix #1436.
+                //
+                // If structure_names is set, but we're here, that
+                // suggests that we've reconnected and had our session
+                // invalidated.  That means extended_demo_creation
+                // produced empty output and needs to run again.  The
+                // easiest way to make that happen is to "start over".
+                //
+                // FWIW, I have a branch where we no longer use
+                // extended_demo_creation and instead use the generic
+                // modal facility to bring up the demo creation modal,
+                // which is a bit cleaner in general and gets rid of
+                // the need for this hack.  Since I assume I'll merge
+                // that branch before "too long", I'm OK with this
+                // hack "for now".
+                self.structure_names = None;
+
                 FirstRequest::StructureNames
             } else {
                 FirstRequest::Demo(Default::default())