Add persistent AFK reserves, gameplay rewards, and atomic bank-to-time purchases #151

Open
opened 2026-10-12 19:59:54 -04:00 by goddard · 0 comments
Collaborator

Provide the persistent AFK reserve, machine API, and reporting needed by tws-zombies-scripts #12. Players receive free break time, earn additional time through gameplay, and optionally convert bank points into protected AFK time shared across T5 and T6.

Build on EC #146 for bank identity, server authentication, and ledger guarantees; do not implement a second points bank. The game scripts own command handling, purchase confirmation, the center-screen countdown, and protection changes. EC owns persistent balances, policy validation, transactions, and reporting.

Approved behavior and initial configurable rates

Source Reward
Free allowance 30 minutes per rolling 24 hours
Active play 1 minute per 5 active minutes
Round completion with meaningful participation 15 seconds
Every 100 kills 30 seconds
Every 25 headshot kills 15 seconds
Every successful teammate revive 30 seconds
Optional bank purchase 10,000 points for 10 minutes
  • Free allowance is separate, non-accumulating across unused days, and consumed before saved time. Reconnecting, changing maps, or moving between servers/games must not replenish it.
  • Earned and purchased time persists without expiration, with an initial combined reserve capacity of six hours.
  • Round, kill, and headshot bonuses share a cap of eight minutes per active hour. Active-play rewards are separate; headshot and kill rewards may stack within that cap.
  • Every legitimate revive earns time, including repeated revives of the same teammate. Revives have no per-teammate, per-match, or hourly reward limit and are excluded from the performance-bonus cap. Only the overall reserve capacity applies. Repeatedly helping a teammate who goes down is intended behavior.
  • No rewards for time spent AFK, spectating, or merely connected. Round rewards require participation. Do not use raw score or score_total increases as a substitute for contribution events.
  • Consume actual elapsed AFK seconds, stopping on manual return, disconnect, death, or match end. Repeated .afk commands do not reset allowances or spend twice.
  • At zero available time, the scripts immediately end AFK protection and restore normal vulnerability and controls. The central countdown must match the authorized remaining time. There is no automatic purchase, spectator transition, or expiration grace period. Preserve the separate manual .back behavior.

Fix

  • Add a persistent AFK account per player GUID, shared across T5/T6, with separate free allowance and saved reserve, recorded in seconds. Keep balances and audit history independent of match retention and server deletion.
  • Implement configurable rates, reserve capacity, free-allowance replenishment, and the limited round/kill/headshot bonus budget. Define rolling-window and partial-progress accounting precisely, persist it across reconnects, and enforce the unlimited-revive rule above.
  • Add server-authenticated machine operations to read available time, submit verified gameplay contribution events, purchase time, reserve time for an AFK session, and reconcile consumption/release. Publish the exact request/response schemas and ownership split with scripts #12.
  • Reuse the server-scoped authentication and GUID/active-match validation from #146. Validate session ownership and bind events to the originating server, player, and match; allow legitimate delayed session settlement after a player leaves without requiring them to remain in the current active match.
  • Accept actual successful revives and accepted AFK transitions from the scripts. Deduplicate retries by stable operation/event IDs without suppressing separate legitimate repeated revives. Prevent replays of round, kill, headshot, or active-time progress from awarding twice.
  • Convert bank points into AFK reserve atomically: either debit points and grant time together or change neither. Reject insufficient funds, invalid amounts, and purchases exceeding capacity. Never spend points automatically; the scripts obtain explicit player confirmation before submitting the purchase.
  • Make reservations and purchases safe across concurrent requests and servers. A player cannot reserve or spend the same free allowance or saved time twice. Return the original result for a retry, and reject reuse of an operation ID with different parameters.
  • Return enough information for the scripts to run an accurate local countdown from authorized time. An EC outage must not prematurely remove already-authorized protection; the countdown still ends at zero. Define start acknowledgement, consumption, unused-time release, and crash recovery so unused reservations can be reconciled without refunding time that another server can still consume. Reconciliation must not depend on an absent heartbeat being proof that protection ended.
  • Record accepted AFK session starts, ends, end reasons, and consumption. Handle delayed, duplicate, and out-of-order reports without reopening completed sessions or double charging. Distinguish confirmed durations from unresolved sessions rather than fabricating exact times after a crash.
  • Keep an auditable ledger of free grants, gameplay rewards, purchases, consumption, releases, and corrections, including GUID, server, match when known, operation/session ID, event time, and resulting balances. Link point debits to the corresponding AFK grants.
  • Expose the balance and recent time-ledger entries alongside bank information on the player profile, respecting existing access controls. Provide AFK duration, active playtime, expiration, purchase, and return-to-play data for evaluating repeat visits and actual usage; keep AFK time separate from active playtime.
  • Document configuration, endpoint authentication, retry/reordering behavior, outage recovery, and the integration contract in docs/guides/. Coordinate activation with scripts #12; the game scripts own countdown rendering, activation safeguards, and all-player-AFK/match-ending behavior.

Verification

  • Tests cover shared T5/T6 identity, free-allowance replenishment and non-accumulation, cross-server/reconnect persistence, reserve capacity, partial reward progress, and bonus caps that never apply to revives.
  • Repeated legitimate revives of the same teammate each earn time; retries of one revive earn only once. AFK/spectator activity and passive score changes do not earn time.
  • Atomic purchases, concurrent spending/reservations, insufficient funds, over-capacity purchases, invalid amounts, and repeated/mismatched operation IDs behave as specified without losing points or creating time.
  • Unauthorized server/player requests are rejected, including the shared telemetry token. Legitimate delayed settlement remains possible after disconnect or match completion.
  • Retry, out-of-order delivery, disconnect, process restart, match end, and backend outage scenarios preserve balances and reconcile sessions correctly.
  • Joint T5/T6 integration validation confirms the center-screen countdown matches authorized time, manual return stops charging, and reaching zero removes protection immediately without leaving controls or weapons locked.
Provide the persistent AFK reserve, machine API, and reporting needed by [tws-zombies-scripts #12](https://gitea.thewrightserver.net/josh/tws-zombies-scripts/issues/12). Players receive free break time, earn additional time through gameplay, and optionally convert bank points into protected AFK time shared across T5 and T6. Build on [EC #146](https://gitea.thewrightserver.net/josh/electric-cherry/issues/146) for bank identity, server authentication, and ledger guarantees; do not implement a second points bank. The game scripts own command handling, purchase confirmation, the center-screen countdown, and protection changes. EC owns persistent balances, policy validation, transactions, and reporting. **Approved behavior and initial configurable rates** | Source | Reward | |---|---:| | Free allowance | 30 minutes per rolling 24 hours | | Active play | 1 minute per 5 active minutes | | Round completion with meaningful participation | 15 seconds | | Every 100 kills | 30 seconds | | Every 25 headshot kills | 15 seconds | | Every successful teammate revive | 30 seconds | | Optional bank purchase | 10,000 points for 10 minutes | - Free allowance is separate, non-accumulating across unused days, and consumed before saved time. Reconnecting, changing maps, or moving between servers/games must not replenish it. - Earned and purchased time persists without expiration, with an initial combined reserve capacity of six hours. - Round, kill, and headshot bonuses share a cap of eight minutes per active hour. Active-play rewards are separate; headshot and kill rewards may stack within that cap. - **Every legitimate revive earns time, including repeated revives of the same teammate. Revives have no per-teammate, per-match, or hourly reward limit and are excluded from the performance-bonus cap.** Only the overall reserve capacity applies. Repeatedly helping a teammate who goes down is intended behavior. - No rewards for time spent AFK, spectating, or merely connected. Round rewards require participation. Do not use raw score or score_total increases as a substitute for contribution events. - Consume actual elapsed AFK seconds, stopping on manual return, disconnect, death, or match end. Repeated `.afk` commands do not reset allowances or spend twice. - **At zero available time, the scripts immediately end AFK protection and restore normal vulnerability and controls.** The central countdown must match the authorized remaining time. There is no automatic purchase, spectator transition, or expiration grace period. Preserve the separate manual `.back` behavior. **Fix** - [ ] Add a persistent AFK account per player GUID, shared across T5/T6, with separate free allowance and saved reserve, recorded in seconds. Keep balances and audit history independent of match retention and server deletion. - [ ] Implement configurable rates, reserve capacity, free-allowance replenishment, and the limited round/kill/headshot bonus budget. Define rolling-window and partial-progress accounting precisely, persist it across reconnects, and enforce the unlimited-revive rule above. - [ ] Add server-authenticated machine operations to read available time, submit verified gameplay contribution events, purchase time, reserve time for an AFK session, and reconcile consumption/release. Publish the exact request/response schemas and ownership split with scripts #12. - [ ] Reuse the server-scoped authentication and GUID/active-match validation from #146. Validate session ownership and bind events to the originating server, player, and match; allow legitimate delayed session settlement after a player leaves without requiring them to remain in the current active match. - [ ] Accept actual successful revives and accepted AFK transitions from the scripts. Deduplicate retries by stable operation/event IDs without suppressing separate legitimate repeated revives. Prevent replays of round, kill, headshot, or active-time progress from awarding twice. - [ ] Convert bank points into AFK reserve atomically: either debit points and grant time together or change neither. Reject insufficient funds, invalid amounts, and purchases exceeding capacity. Never spend points automatically; the scripts obtain explicit player confirmation before submitting the purchase. - [ ] Make reservations and purchases safe across concurrent requests and servers. A player cannot reserve or spend the same free allowance or saved time twice. Return the original result for a retry, and reject reuse of an operation ID with different parameters. - [ ] Return enough information for the scripts to run an accurate local countdown from authorized time. An EC outage must not prematurely remove already-authorized protection; the countdown still ends at zero. Define start acknowledgement, consumption, unused-time release, and crash recovery so unused reservations can be reconciled without refunding time that another server can still consume. Reconciliation must not depend on an absent heartbeat being proof that protection ended. - [ ] Record accepted AFK session starts, ends, end reasons, and consumption. Handle delayed, duplicate, and out-of-order reports without reopening completed sessions or double charging. Distinguish confirmed durations from unresolved sessions rather than fabricating exact times after a crash. - [ ] Keep an auditable ledger of free grants, gameplay rewards, purchases, consumption, releases, and corrections, including GUID, server, match when known, operation/session ID, event time, and resulting balances. Link point debits to the corresponding AFK grants. - [ ] Expose the balance and recent time-ledger entries alongside bank information on the player profile, respecting existing access controls. Provide AFK duration, active playtime, expiration, purchase, and return-to-play data for evaluating repeat visits and actual usage; keep AFK time separate from active playtime. - [ ] Document configuration, endpoint authentication, retry/reordering behavior, outage recovery, and the integration contract in `docs/guides/`. Coordinate activation with scripts #12; the game scripts own countdown rendering, activation safeguards, and all-player-AFK/match-ending behavior. **Verification** - [ ] Tests cover shared T5/T6 identity, free-allowance replenishment and non-accumulation, cross-server/reconnect persistence, reserve capacity, partial reward progress, and bonus caps that never apply to revives. - [ ] Repeated legitimate revives of the same teammate each earn time; retries of one revive earn only once. AFK/spectator activity and passive score changes do not earn time. - [ ] Atomic purchases, concurrent spending/reservations, insufficient funds, over-capacity purchases, invalid amounts, and repeated/mismatched operation IDs behave as specified without losing points or creating time. - [ ] Unauthorized server/player requests are rejected, including the shared telemetry token. Legitimate delayed settlement remains possible after disconnect or match completion. - [ ] Retry, out-of-order delivery, disconnect, process restart, match end, and backend outage scenarios preserve balances and reconcile sessions correctly. - [ ] Joint T5/T6 integration validation confirms the center-screen countdown matches authorized time, manual return stops charging, and reaching zero removes protection immediately without leaving controls or weapons locked.
goddard added the
priority
medium
type/hardeningtype/maintainability
labels 2026-10-12 19:59:54 -04:00
josh was assigned by goddard 2026-10-12 19:59:54 -04:00
Sign in to join this conversation.