Zeal accounts and required Ranked admission
==========================================

Player flow
-----------
Register appears between Options and Quit. The client signs a fresh challenge
using its existing IW4x GUID key, then opens https://zeal.family with a one-use
registration link. Players choose one unique username (3-15 ASCII characters;
letters, digits, spaces, dots, dashes and underscores, alphanumeric ends).
Names are unique without regard to case. The browser never asks for a GUID,
password, email address or Discord login. Registration does not change ratings.

Ranked proves identity again for each new lobby. Only an account with a valid
proof receives an admission ticket. The registered name replaces the local
nickname in the party roster, voice roster and dedicated-server player name.
Invited friends must register too. Duos, eight-player starts and all existing
matchmaking, maps, loadout, voice and Elo rules continue to apply.

Identity and recovery
---------------------
IW4x uses an ECDSA P-521 key. Its GUID is the first eight SHA-1 bytes of its raw
X9.63 public key interpreted little-endian. The account service stores both the
GUID and full public key, and verifies domain-separated ECDSA/SHA-512 proofs.
The private key never leaves the game or enters website storage.

Keep the existing IW4x identity/profile when updating or reinstalling. A new
GUID is a new key; link it to the account with a link code (next section)
instead of copying the private key between PCs. Username ownership cannot be
recovered with just the public GUID. Username changes and merging two
registered accounts are not implemented. Never ask players to send their
private GUID key.

Playing from more than one PC (linked keys, release 1.32)
---------------------------------------------------------
Each PC has its own IW4x key and therefore its own GUID. An account may own
up to five keys. The original key's GUID stays the account GUID; linked keys
map to it in account_keys. Username, friends, blocks, privacy, staff role,
restrictions, kicks, ratings, placements, results, leaderboard rows and device
evidence are all keyed by the account GUID. Tickets, lobby seats, membership
files, admissions and game-server reports keep the connecting key's GUID, which
is what the dedicated server, voice peers and the native client see. Nothing in
the client, GSC scripts or bridges changes; the lobby and rating services
translate the connecting GUID to the account.

Linking is self-service and never moves a private key:
  1. On the registered PC open Options > "Link another PC" in the game. The
     client signs a proof with purpose "link"; the service answers with a
     one-use 8-character code (XXXX-XXXX, no 0/O/1/I) shown in-game. It
     expires after 15 minutes; a new request replaces the previous code. The
     same button exists on zeal.family under "Your PCs" after Register.
  2. On the new PC select Register. The site first asks whether this is the
     player's first account; "I already play on another PC" opens the code
     entry. Claiming a username that is already registered redirects there
     too. Enter the code and an optional PC name. The browser session of the
     new key (the usual signed registration proof) is bound to the account
     and the game's registration poll picks up the username.
  3. Admin/owner staff can issue the same code from the dashboard ("Issue PC
     link code") when the player cannot reach their original PC. The code is
     shown once and audited; it is never stored in clear.

Links are permanent by policy: a key that already belongs to an account (its
own or a linked one) can never be moved, merged or unlinked, by the player or
by staff, so identity, rating history and ban evidence always stay together.
Only a never-registered key can be linked. Registered players see their PCs
on zeal.family. The site asks a fresh PC first whether this is the player's
first account; claiming a name that is already registered redirects to the
link code entry instead of creating a second account.

One account holds one Ranked seat: opening Ranked on a second PC while the
first is still live returns account_already_connected, and an idle session is
replaced after a few seconds. Both PCs of one account can never be in one
rated roster (duplicate_account). Resume Match stays bound to the connecting
GUID of the crashed session. The rating service stores players, leases and
results by account GUID; begin/finish replies and the snapshot carry the
connecting GUIDs (linked keys mirror the account's row) so the game's Elo
caches and display keep working.

Device evidence (DEVICE-ENFORCEMENT.txt) is recorded under the account for
whichever PC signs. A permanent Ranked restriction therefore freezes the
hardware of every linked PC, which closes the "clean second PC" route for
ban evasion rather than opening it. Evidence a key reported while it was
still unregistered moves to the account when it links.

Rollout: restart accounts first (creates account_keys/link_codes, backfills
existing accounts as their own primary key, and recreates the ephemeral
ranked_admissions table without its old foreign key), then lobby and rating
when no match is active. Older read-only consumers that see no account_keys
table behave as before (every key is its own account).

Short-lived capabilities
-----------------------
Challenges expire after 120 seconds and are consumed after a valid signature.
Browser links expire after 15 minutes, use URL fragments (not HTTP query logs),
and exchange once for a Secure/HttpOnly/SameSite=Strict cookie. The fragment is
removed immediately. Browser writes require the configured Origin and a CSRF
proof; native polling uses a separate capability. Only hashes of browser,
polling, cookie, CSRF and admission capabilities are stored in SQLite.

Ranked tickets last 90 seconds, are one-use, and bind to a specific GUID, full
key and lobby session. A private per-session proof additionally authenticates
lobby requests; the public token carried in game userinfo is insufficient.
Only one active lobby per GUID is allowed. A disconnected lobby expires after
two minutes; returning players can retry then. Tickets never appear in logs,
dvars or the game server's public userinfo.

The game server trusts only fresh bridge-issued membership files containing
the actual connection GUID, session token, party and registered username. New
connections without a valid reservation are kicked after a 15-second bridge
grace period. They cannot enter a rated roster. An already admitted player's
live match is not interrupted solely by a temporary bridge outage.

Deployment
----------
Install zeal_accounts/requirements.txt in the service/lobby Python environment.
Copy zeal_accounts/service.example.json to private storage, set database and
origin, and run:

  python3 -m zeal_accounts.service --config /private/accounts.json

The production origin is https://zeal.family. Bind to loopback behind a local
Cloudflare Tunnel; route only zeal.family to this service. Forwarded client IPs
are accepted only from trusted_proxies, which should contain the local tunnel
connector, never arbitrary LAN/public peers. The service limits request sizes,
parallel workers, pending capabilities and per-IP requests. It exposes only
fixed static paths and the registration API. No permissive CORS is enabled.

Set the lobby config's registration.database to the SAME local SQLite path.
Keep the account and lobby services together; per-game VPS bridges use their
authenticated central lobby API. No account database belongs on player systems
or game VPSs. The native DLL, menu, backend and ranked_system.gsc must be
deployed together. Start the account service before the lobby service.

MS-02 deployment (Incus iw4x-qa)
------------------------------
Site/code: /opt/zeal-registration/zeal_accounts
Python environment: /opt/zeal-registration/venv
Service config: /etc/zeal/accounts.json
Account database: /var/lib/zeal/accounts.sqlite3 (owned by zealweb, private)
Public service: zeal-accounts.service, loopback TCP 8792
Tunnel service: zeal-tunnel.service, /etc/zeal/cloudflared.yml
Tunnel credentials: /etc/zeal/tunnel-credentials.json (private, never package)
Tunnel name: zeal-family-ms02

Back up the account database using SQLite's online backup API, for example:

  python3 -c 'import sqlite3; s=sqlite3.connect("/var/lib/zeal/accounts.sqlite3"); d=sqlite3.connect("/private/backup/accounts.sqlite3"); s.backup(d); d.close(); s.close()'

Keep backups private and off the service host. Do not copy only the main live
SQLite file while WAL writes are active. Existing rating data stays in its own
database and must be backed up independently.

QA exception
------------
Production client_menu/servers.json uses account_url=https://zeal.family and
account_allow_insecure_lan=false. An explicit private-IP HTTP endpoint is
supported only for isolated LAN QA. Tests use a separate accounts-qa.sqlite3,
not the real registration database. Never distribute the QA menu/config.
The website and central APIs now use public HTTPS. The game and voice UDP
endpoints remain LAN-only until Psychz setup; see CENTRAL-OPERATIONS.txt.

Friends and invitations (installer 1.25)
----------------------------------------
Party lobby Invite opens the saved Zeal friends list. Add by registered
username, accept incoming requests, cancel/decline requests, or remove friends.
Friendships and requests are stored in the central account database, never
in the client profile. Accounts are limited to 200 friends and 50 pending
requests in each direction; repeated additions and invites are rate limited.
Both players must have Ranked open to receive a duo invite. Invitations are
private to the authenticated recipient, expire after 60 seconds, and become
invalid if either party searches, leaves, fills, or removes the friendship.
Accept is atomic and cannot create a third party member. Lobby codes remain
available. Steam and Discord are not required for Zeal friend invitations.

Leaderboard and results
-----------------------
Leaderboard appears below Invite in the party lobby. It displays the Top 50
registered players who completed five placements, ordered by committed Elo;
ties use the stable account GUID internally. Public rows expose names, ranks
and Elo, not GUIDs. The shared cache refreshes within 20 seconds. All names
come from the account database, including older imported rating records.
The party panel shows the last committed match Elo gain/loss. A transactional
latest-result record is updated with match settlement, survives restarts, and
is backfilled from existing completed-match audit records once. Retries,
warmups, invitations and cancelled matches never change this result. Existing
post-match Elo screens and all 15 distinct Obsidian division badges remain.
Voice settings are under Options > Voice on both the main menu and the party
lobby. Closing Options returns to the existing party. F7 remains available.
The main-menu status says voice is ready and connects after entering Ranked.
Party rows have speaker icons: dim while connecting, white when connected,
green while speaking, red for the local microphone mute/deafen/disable state
or a peer muted locally. A peer's private microphone switch is not broadcast.

Central moderation and monitoring
----------------------------------
Register also signs an existing account into the website. Staff assigned by
the owner can open /admin to monitor instances, drain servers, review reports,
apply/lift ranked/voice/social restrictions, remove sessions and review the
audit. Owners (Cynic, Ynzie, xDLJ) can assign/revoke moderator/admin roles. Every action requires
an authenticated browser session and CSRF token; a client/server cannot grant
its own role. Blocks persist and stop requests, invitations and voice between
the two players. Enforcement also reaches dedicated-server admission and the
encrypted relay, independently of a cooperative client. Detailed scope, limits,
staff hierarchy and local recovery are in CENTRAL-OPERATIONS.txt.
