feat(ui): per-kind active-game limit lock on the New Game screen
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 12s
CI / integration (pull_request) Successful in 28s
CI / ui (pull_request) Successful in 1m11s
CI / conformance (pull_request) Successful in 10s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m46s
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 12s
CI / integration (pull_request) Successful in 28s
CI / ui (pull_request) Successful in 1m11s
CI / conformance (pull_request) Successful in 10s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m46s
Carry the caller's per-tier active-game caps and each game's kind on the wire (Profile.game_limits + GameView.kind, additive FBS + gateway transcode + client codec, committed regen). The New Game screen counts the player's active games per kind from the lobby and locks a capped start: an outline button with a lock that opens a funnel modal instead of a game -- a sign-in prompt for a guest, a "finish a current game first" notice for a signed-in account (native Telegram popup, in-app modal elsewhere). The lock lifts via the existing profile refetch after a guest->durable upgrade. Remove the lobby's old at_game_limit New-Game tab disable + notice: the flag (now the random-kind cap) conflicted with the per-kind lock -- it hid the screen where the lock lives and wrongly blocked an unfulfilled kind. The New Game tab is always enabled; the per-kind start lock is the only gate. The at_game_limit wire field stays (unused by the client) for a later cleanup. Tests: client lock logic + codec kind/game_limits roundtrip + gateway transcode encode + native popup builders (unit); a mock e2e for the lock badge and the modal.
This commit is contained in:
@@ -72,6 +72,7 @@ func (s *Server) profileResponse(ctx context.Context, acc account.Account) profi
|
||||
}
|
||||
r.Banner = s.bannerFor(ctx, acc, cxt, present)
|
||||
r.Ads = s.adsFor(ctx, acc, cxt, present)
|
||||
r.GameLimits = s.gameLimitsDTOFor(acc.IsGuest)
|
||||
s.fillLinkedIdentities(ctx, &r, acc.ID)
|
||||
r.DictVersions = s.currentDictVersions()
|
||||
return r
|
||||
|
||||
@@ -78,6 +78,18 @@ type profileResponse struct {
|
||||
// Filled outside the pure projection (it reads the dictionary registry), so it is empty
|
||||
// for callers that build the DTO without a Server. See Server.profileResponse.
|
||||
DictVersions []dictVersion `json:"dict_versions,omitempty"`
|
||||
// GameLimits carries the caller's tier active-game caps per kind (-1 = unlimited); the client
|
||||
// counts its active games per kind from the lobby and locks a capped New-Game start. Filled
|
||||
// outside the pure projection (it reads the limits config). See Server.profileResponse.
|
||||
GameLimits *gameLimitsDTO `json:"game_limits,omitempty"`
|
||||
}
|
||||
|
||||
// gameLimitsDTO is the caller's tier active-game caps per kind (-1 = unlimited), for the client's
|
||||
// per-kind New-Game lock. profileResponse.GameLimits carries it.
|
||||
type gameLimitsDTO struct {
|
||||
VsAI int `json:"vs_ai"`
|
||||
Random int `json:"random"`
|
||||
Friends int `json:"friends"`
|
||||
}
|
||||
|
||||
// dictVersion pairs a game variant's stable label (engine.Variant.String) with its current
|
||||
@@ -134,7 +146,11 @@ type gameDTO struct {
|
||||
MultipleWordsPerTurn bool `json:"multiple_words_per_turn"`
|
||||
// VsAI marks an honest-AI game: the opponent is shown as 🤖 and chat/nudge/add-friend
|
||||
// are suppressed in the client.
|
||||
VsAI bool `json:"vs_ai"`
|
||||
VsAI bool `json:"vs_ai"`
|
||||
// Kind is the game's origin for the active-game limits (game.Kind): 0 unknown (a pre-existing
|
||||
// game), 1 vs_ai, 2 random, 3 friends. The lobby counts active games per kind to lock a capped
|
||||
// New-Game start.
|
||||
Kind int `json:"kind"`
|
||||
MoveCount int `json:"move_count"`
|
||||
EndReason string `json:"end_reason"`
|
||||
// LastActivityUnix is the lobby sort key: the current turn's start for an active
|
||||
@@ -277,6 +293,7 @@ func gameDTOFromGame(g game.Game) gameDTO {
|
||||
TurnTimeoutSecs: int(g.TurnTimeout.Seconds()),
|
||||
MultipleWordsPerTurn: g.MultipleWordsPerTurn,
|
||||
VsAI: g.VsAI,
|
||||
Kind: int(g.Kind),
|
||||
MoveCount: g.MoveCount,
|
||||
EndReason: g.EndReason,
|
||||
LastActivityUnix: last.Unix(),
|
||||
|
||||
@@ -9,6 +9,16 @@ import (
|
||||
"scrabble/backend/internal/gamelimits"
|
||||
)
|
||||
|
||||
// gameLimitsDTOFor resolves the caller's tier active-game caps into the profile DTO, so the client
|
||||
// can lock a capped New-Game start per kind. It returns nil when the limits config is not wired.
|
||||
func (s *Server) gameLimitsDTOFor(isGuest bool) *gameLimitsDTO {
|
||||
if s.gamelimits == nil {
|
||||
return nil
|
||||
}
|
||||
l := s.gamelimits.LimitsFor(isGuest)
|
||||
return &gameLimitsDTO{VsAI: l.VsAI, Random: l.Random, Friends: l.Friends}
|
||||
}
|
||||
|
||||
// consoleLimits renders the per-tier, per-kind active-game limit form (backend.config), read from
|
||||
// the in-memory cache.
|
||||
func (s *Server) consoleLimits(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user