From a84a610964e64768b7a3b1e785990e1fb921054a Mon Sep 17 00:00:00 2001 From: dingo Date: Fri, 20 Mar 2026 21:28:58 -0400 Subject: [PATCH] Fix rules editor: allow Open state + update UI from ACK MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Server (GameUpdateLobbyRulesHandler): - Allow update_rules in both Open (solo) and Full lobby states, not just Full — was silently failing when no guest had joined yet - Push to guest only when GuestAccountId is present (was crashing with null deref in Open state if status check had been bypassed) Client (CustomLobby.gd): - update_rules ACK callback now emits lobby_rules_updated immediately from the ACK payload instead of relying solely on the lobby_updated push Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- Client/origin-client/autoloads/CustomLobby.gd | 9 +++++++-- .../Handlers/GameUpdateLobbyRulesHandler.cs | 18 +++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Client/origin-client/autoloads/CustomLobby.gd b/Client/origin-client/autoloads/CustomLobby.gd index f4912e3..406ebd7 100644 --- a/Client/origin-client/autoloads/CustomLobby.gd +++ b/Client/origin-client/autoloads/CustomLobby.gd @@ -171,11 +171,16 @@ func change_deck(deck_id: String) -> void: print("[CustomLobby] ERR change_deck ", code, " ", msg)) -## Host-only: update lobby rule overrides (only when neither player is ready). +## Host-only: update lobby rule overrides (open or full lobby, neither player ready). func update_rules(rules_override: Dictionary) -> void: Network.request("game.custom.update_rules", { "lobbyId": lobby_id, "rules": rules_override }, - func(_t: String, _p: Variant) -> void: pass, + func(_t: String, p: Variant) -> void: + # Apply new rules immediately from the ACK (don't wait for the push). + var d := p as Dictionary + var rules := d.get("rules", {}) as Dictionary + if not rules.is_empty(): + lobby_rules_updated.emit(rules), func(code: String, msg: String) -> void: print("[CustomLobby] ERR update_rules ", code, " ", msg)) diff --git a/Server/src/SOR.Game/Handlers/GameUpdateLobbyRulesHandler.cs b/Server/src/SOR.Game/Handlers/GameUpdateLobbyRulesHandler.cs index 2e5339e..0342aba 100644 --- a/Server/src/SOR.Game/Handlers/GameUpdateLobbyRulesHandler.cs +++ b/Server/src/SOR.Game/Handlers/GameUpdateLobbyRulesHandler.cs @@ -8,10 +8,10 @@ using SOR.Networking.Abstractions.Transport; using SOR.Shared.Networking; /// -/// game.custom.update_rules — host updates lobby rule overrides while in Full state. +/// game.custom.update_rules — host updates lobby rule overrides while in Open or Full state. /// -/// Only allowed when the lobby is Full and neither player is ready. -/// A LobbyUpdatedPush with the new effective rules is sent to both participants. +/// Allowed when the lobby is Open (waiting for guest) or Full (neither player ready). +/// A LobbyUpdatedPush is sent to both participants when in Full state; host only when Open. /// internal sealed class GameUpdateLobbyRulesHandler : GameHandlerBase, IMessageHandler { @@ -42,8 +42,8 @@ internal sealed class GameUpdateLobbyRulesHandler : GameHandlerBase, IMessageHan var lobby = await _gameDb.CustomLobbies.FindAsync([req.LobbyId], ct) ?? throw new GameException("LOBBY_NOT_FOUND"); - if (lobby.Status != CustomLobbyStatus.Full) - throw new GameException("LOBBY_NOT_FULL"); + if (lobby.Status != CustomLobbyStatus.Open && lobby.Status != CustomLobbyStatus.Full) + throw new GameException("LOBBY_NOT_OPEN_OR_FULL"); if (lobby.HostAccountId != accountId) throw new GameException("HOST_ONLY"); @@ -99,9 +99,13 @@ internal sealed class GameUpdateLobbyRulesHandler : GameHandlerBase, IMessageHan var updatedPush = ServerMessage.Push("game.custom.lobby_updated", new LobbyUpdatedPush(lobby.Id, effective)); - await Task.WhenAll( + var pushTasks = new List + { _clientPush.PushAsync(lobby.HostAccountId.ToString(), updatedPush, ct), - _clientPush.PushAsync(lobby.GuestAccountId!.Value.ToString(), updatedPush, ct)); + }; + if (lobby.GuestAccountId.HasValue) + pushTasks.Add(_clientPush.PushAsync(lobby.GuestAccountId.Value.ToString(), updatedPush, ct)); + await Task.WhenAll(pushTasks); return ServerMessage.Reply("game.custom.update_rules.ack", message.Seq, new UpdateLobbyRulesResponse(LobbyId: lobby.Id, Rules: effective));