Fix rules editor: allow Open state + update UI from ACK

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 <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-20 21:28:58 -04:00
co-authored by Claude Happy
parent 66e7f75155
commit a84a610964
2 changed files with 18 additions and 9 deletions
@@ -8,10 +8,10 @@ using SOR.Networking.Abstractions.Transport;
using SOR.Shared.Networking;
/// <summary>
/// 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.
/// </summary>
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<Task>
{
_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));