Fix AI opponents in FreePlay 3+ player lobbies

- Remove max_players == 2 gate; use per-seat Add AI buttons in the
  additional players panel instead of the guest-slot button
- Fix seat-indexed panel rendering: unified loop over all additional
  seats detects AI slots, human players, and empty seats correctly
- Add _ai_adding guard to prevent concurrent add-AI requests that
  caused the server race (second request overwrote first AI slot)
- Fix push handler reading wrong key ("slots" → "currentAiSlots")
  which wiped ai_slots on every push, leaving only the newest AI
- Fix ACK handler reading wrong keys ("aiId"/"displayName" →
  "aiAccountId"/"aiDisplayName")
- Server: fix all-ready check that required GuestAccountId.HasValue,
  blocking start for no-guest lobbies filled via AdditionalPlayersJson
- Server: fix StartGameAsync null-deref on GuestAccountId and add
  no-guest branch (host=P1, first additional=P2, rest=seats 2+)

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-05-26 16:51:01 -04:00
co-authored by Claude Happy
parent 32693d303b
commit dfccd091fd
5 changed files with 137 additions and 75 deletions
@@ -342,8 +342,8 @@ func add_ai(difficulty: int, strategy: String,
ai_slots = ai_slots.filter(func(s: Dictionary) -> bool:
return int(s.get("seatIndex", -1)) != seat)
ai_slots.append({
"accountId": str(d.get("aiId", "")),
"displayName": str(d.get("displayName", "AI")),
"accountId": str(d.get("aiAccountId", "")),
"displayName": str(d.get("aiDisplayName", "AI")),
"difficulty": difficulty,
"strategy": strategy,
"seatIndex": seat,
@@ -451,7 +451,7 @@ func _on_server_push(type: String, payload: Variant) -> void:
"game.ai.slots_changed":
var d := payload as Dictionary
ai_slots = d.get("slots", []) as Array
ai_slots = d.get("currentAiSlots", []) as Array
ai_slots_changed.emit(ai_slots)
"game.custom.lobby.team_reassigned":