fix: arch spirit placement field name, rules lock, and AI indicator

AiPlayerSession.ExecutePlacementAsync — NullReferenceException:
  Sent { Coord = ... } but GamePlaceArchSpiritRequest.Position is the
  field name. Changed to { Position = ... }.

GameUpdateLobbyRulesHandler — rules locked after adding AI:
  GuestReady=true is set when AI joins so the game auto-starts when
  host readies, but that flag was also blocking rule edits via
  CANNOT_CHANGE_RULES_WHILE_READY. Fix: inject IAiAccountRegistry
  (optional) and only block when a HUMAN guest is ready.

CustomLobby.gd — AI indicator not showing / rules reset on refresh:
  add_ai: populate ai_slots immediately from the game.ai.add ACK
  response so _refresh_display sees the AI before the push arrives.
  update_rules + lobby_updated push: keep lobby["rules"] in sync so
  _refresh_display() doesn't clobber _current_rules with stale data.

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-04-13 08:29:41 -04:00
co-authored by Claude Happy
parent 7eeb3acbf0
commit 23dc7925e2
3 changed files with 31 additions and 5 deletions
+1 -1
View File
@@ -168,7 +168,7 @@ internal sealed class AiPlayerSession : IAsyncDisposable
AiAccountId, coord.X, coord.Y);
await InvokeHandlerAsync("game.place_arch_spirit",
JsonSerializer.SerializeToUtf8Bytes(new { SessionId, Coord = new { coord.X, coord.Y } }),
JsonSerializer.SerializeToUtf8Bytes(new { SessionId, Position = new { coord.X, coord.Y } }),
ct);
}
@@ -5,6 +5,7 @@ using SOR.Database.Enums;
using SOR.Networking.Abstractions.Messaging;
using SOR.Networking.Abstractions.Push;
using SOR.Networking.Abstractions.Transport;
using SOR.Shared;
using SOR.Shared.Networking;
/// <summary>
@@ -18,15 +19,19 @@ internal sealed class GameUpdateLobbyRulesHandler : GameHandlerBase, IMessageHan
private readonly IMessageSerializer _serializer;
private readonly GameDbContext _gameDb;
private readonly IClientPush _clientPush;
// Optional: only present when SOR.Ai is loaded.
private readonly IAiAccountRegistry? _aiRegistry;
public GameUpdateLobbyRulesHandler(
IMessageSerializer serializer,
GameDbContext gameDb,
IClientPush clientPush)
IMessageSerializer serializer,
GameDbContext gameDb,
IClientPush clientPush,
IAiAccountRegistry? aiRegistry = null)
{
_serializer = serializer;
_gameDb = gameDb;
_clientPush = clientPush;
_aiRegistry = aiRegistry;
}
public string MessageType => "game.custom.update_rules";
@@ -48,7 +53,12 @@ internal sealed class GameUpdateLobbyRulesHandler : GameHandlerBase, IMessageHan
if (lobby.HostAccountId != accountId)
throw new GameException("HOST_ONLY");
if (lobby.HostReady || lobby.GuestReady)
// Allow rule changes as long as no HUMAN player has readied up.
// AI guests are auto-readied server-side; that flag must not block the host from editing.
bool humanGuestReady = lobby.GuestReady
&& lobby.GuestAccountId.HasValue
&& _aiRegistry?.IsAi(lobby.GuestAccountId.Value) != true;
if (lobby.HostReady || humanGuestReady)
throw new GameException("CANNOT_CHANGE_RULES_WHILE_READY");
// Apply all overrides (null = revert to default).