[PR #1185] [MERGED] Live player count: an anonymous "I'm playing" ping and "N playing now" in the launcher #3399

Closed
opened 2026-11-03 04:09:15 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1185
Author: @ludovic111
Created: 10/22/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @ludovic111

Base: main ← Head: feat/live-player-count


📝 Commits (3)

  • 8f738d3 Live player count: an anonymous "I'm playing" ping and "N playing now"
  • 9054acf Launcher: the ping notice keeps its height; status lists the ping
  • 388f59a Game: the ping's LAN flag follows is_published, every frame

📊 Changes

21 files changed (+1064 additions, -46 deletions)

View changed files

📝 crates/horizon-client/Cargo.toml (+3 -2)
📝 crates/horizon-client/src/game.rs (+12 -0)
➕ crates/horizon-client/src/heartbeat.rs (+74 -0)
📝 crates/horizon-client/src/lib.rs (+1 -0)
📝 crates/horizon-client/src/telemetry.rs (+2 -1)
📝 crates/horizon-telemetry-server/README.md (+8 -1)
📝 crates/horizon-telemetry-server/src/lib.rs (+131 -26)
➕ crates/horizon-telemetry-server/src/live.rs (+201 -0)
➕ crates/horizon-telemetry-server/tests/live.rs (+190 -0)
📝 crates/horizon-telemetry/Cargo.toml (+4 -2)
📝 crates/horizon-telemetry/src/lib.rs (+7 -2)
➕ crates/horizon-telemetry/src/live.rs (+215 -0)
📝 docs/play-with-friends.md (+2 -1)
📝 docs/telemetry.md (+25 -0)
📝 launcher/src/backend.rs (+6 -0)
📝 launcher/src/collection.rs (+59 -4)
📝 launcher/src/main.rs (+83 -1)
📝 launcher/src/telemetry.rs (+30 -0)
📝 website/docs/faq.md (+1 -1)
📝 website/docs/troubleshooting.md (+1 -1)

...and 1 more files

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

What

FEATURES.md item 14: "how many people are playing Horizon right now", as Ludovic decided on 2026-10-22. Every player is counted, with or without data collection consent, and the launcher tells them.

  • Game (crates/horizon-client/src/heartbeat.rs): while the game runs, a thread of its own sends POST /v1/live once a minute: {"session","version","platform","lan"}. It sends at once when a world opens to or closes from LAN or friends (is_published, so server-thread single player counts too). The session ID is 128 random bits made at start and kept only in memory; it is not the install ID. There is no ping from a dedicated server, --benchmark, --offscreen or a --frames/--world-frames run, or with HORIZON_NO_HEARTBEAT=1. After a failure it waits twice as long, up to 10 minutes, and logs it once.

  • Shared types (crates/horizon-telemetry/src/live.rs): Ping (checked field by field, unknown fields refused), Count, round (exact under 10, then to 5 / 10 / 100), send/fetch behind a new live feature. The game takes only live, not upload.

  • Server (crates/horizon-telemetry-server/src/live.rs): an in-memory table (session → last seen, version, platform, LAN), never on disk, never with an address. A session counts while its last ping is under 2 minutes old. GET /v1/live returns {"playing","lan","versions","platforms"}, all rounded. It shows the 12 biggest versions and sums the rest under other. It is cached for 15 s and sends the website's CORS origin. Abuse limits: a separate token bucket per address for pings and reads (600/h, bursts of 60, so ten players can share one address), 512-byte bodies, and at most 200 000 sessions (503 past that). The upkeep tick forgets expired sessions.

  • Launcher: "N PLAYING NOW" in the Play page's status line when the server answers, read at start and every minute. Nothing shows when the server can't be reached. Players are told about the ping in three places:

    • an "Always on" row in the first-run question;
    • the same row in Settings → Data collection;
    • a one-time notice on the Play page ("Got it") for players who answered the question before the ping existed (ping_notice_seen in settings.json).

    data status / MCP also return the text.

  • Docs: docs/telemetry.md has a new section on the ping, and the server README covers its endpoints, settings and memory. The website gets a new section on privacy.html and new lines in the FAQ and troubleshooting pages. docs/play-with-friends.md now mentions the LAN flag.

Like the rest of telemetry, DEFAULT_ENDPOINT stays None: until HORIZON_TELEMETRY_URL is set, or a server is put in DEFAULT_ENDPOINT, the game pings nothing and the launcher shows no count. No Railway service, domain or variable was created or changed.

Screenshots (Mac mini, scratch launcher/game homes, local server)

First-run question, with the ping row:
consent

Play page, a player who answered before: one-time notice, and "1 PLAYING NOW":
play notice

After "Got it":
play count

Server unreachable: no count:
unreachable

Settings → Data collection:
settings

How tested

End to end on the Mac mini: the release horizon-telemetry-server (default 120 s window) ran locally, and two real games (fast build, horizon-ctl launch) used HORIZON_TELEMETRY_URL=http://127.0.0.1:18317:

10:27:05 before:          {"playing":0,"lan":0,"versions":{},"platforms":{}}
10:27:15 two games:       {"playing":2,"lan":0,"versions":{"dev 0.1.0":2},"platforms":{"macos":2}}
10:27:30 A /publish:      {"playing":2,"lan":1,"versions":{"dev 0.1.0":2},"platforms":{"macos":2}}
10:27:37 B quit:          {"playing":2,"lan":1,"versions":{"dev 0.1.0":2},"platforms":{"macos":2}}
10:29:24 after expiry:    {"playing":1,"lan":1,"versions":{"dev 0.1.0":1},"platforms":{"macos":1}}

Self-check:

cargo fmt --check (workspace, launcher, server), clippy --all-targets -D warnings with pipefail:
fmt workspace ok
fmt launcher ok
fmt server ok
clippy workspace exit 0 errors 0
clippy launcher exit 0 errors 0
clippy server exit 0 errors 0
horizon-telemetry: 36 passed, 0 failed
horizon-client --lib: test result: ok. 984 passed; 0 failed; 15 ignored; 0 measured; 0 filtered out; finished in 60.76s
horizon-telemetry-server: 16 passed, 0 failed
horizon-launcher: 109 passed, 0 failed
Building probes...
Probes built in 386s.
Running 3 harnesses, 3 at a time here...
PASS world_reopen 152s
PASS world_options 301s
PASS toggle_keys 307s

3 passed, 0 failed in 5.1 min.
parity: PASS world_reopen 152s
parity: PASS world_options 301s
parity: PASS toggle_keys 307s
parity: 3 passed, 0 failed in 5.1 min.

The game.rs change is two calls: heartbeat::start() in run(), which does nothing without a server URL, and one atomic store a frame. tools/parity.py --changed origin/main picks 102 harnesses because it matches on game.rs. I ran the three that cover startup and the run loop (above) rather than all 102.

New tests: horizon-telemetry live (ping fields, checks, rounding), server live unit tests (expiry, cap, rare versions) and tests/live.rs (HTTP: count and expiry, bad pings, rate limit, full table, and the game's send + the launcher's fetch end to end), and the launcher's thousands separator.

Not covered: the Linux launcher (Wayland/X11) needs vscreen on the desktop; the layout is the same GPUI code.

Needs Ludovic (to switch it on)

Nothing goes live with this PR. To switch it on, once Ludovic says go:

  1. Host horizon-telemetry-server with its Dockerfile, as crates/horizon-telemetry-server/README.md says. That is the same service the opt-in collection needs (about $0.35 a month). The live count only adds RAM: about 100 bytes a player, 20 MB at the 200 000 cap. Set HORIZON_TELEMETRY_TRUST_PROXY=1 behind Railway's proxy. The HORIZON_TELEMETRY_LIVE_* settings can stay at their defaults.
  2. Point the clients at it: set DEFAULT_ENDPOINT in crates/horizon-telemetry/src/lib.rs to the server's HTTPS URL, in a small PR. That switches on both the opt-in uploads and the ping. A release then ships it.
  3. Optional: the website could read GET /v1/live (CORS is set for playhorizon.dev).
  4. Agents' automated game runs should export HORIZON_NO_HEARTBEAT=1 (for example in horizon-parity/env.sh) so they stay out of the count.

Legal wording: the privacy page now says the ping holds no personal data, and that the sending address is used only in memory for rate limiting. Ludovic may want to check that this matches what he wants to promise.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/1185 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/live-player-count` --- ### 📝 Commits (3) - [`8f738d3`](https://github.com/horizon-rust/horizon/commit/8f738d35ecb23af1d6b743c5acd0f25238f0023d) Live player count: an anonymous "I'm playing" ping and "N playing now" - [`9054acf`](https://github.com/horizon-rust/horizon/commit/9054acfed290cfc4c6c93de0e692b336941857f0) Launcher: the ping notice keeps its height; status lists the ping - [`388f59a`](https://github.com/horizon-rust/horizon/commit/388f59aff4a4c5affdbc128e0c1a3b272aebbea3) Game: the ping's LAN flag follows is_published, every frame ### 📊 Changes **21 files changed** (+1064 additions, -46 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/Cargo.toml` (+3 -2) 📝 `crates/horizon-client/src/game.rs` (+12 -0) ➕ `crates/horizon-client/src/heartbeat.rs` (+74 -0) 📝 `crates/horizon-client/src/lib.rs` (+1 -0) 📝 `crates/horizon-client/src/telemetry.rs` (+2 -1) 📝 `crates/horizon-telemetry-server/README.md` (+8 -1) 📝 `crates/horizon-telemetry-server/src/lib.rs` (+131 -26) ➕ `crates/horizon-telemetry-server/src/live.rs` (+201 -0) ➕ `crates/horizon-telemetry-server/tests/live.rs` (+190 -0) 📝 `crates/horizon-telemetry/Cargo.toml` (+4 -2) 📝 `crates/horizon-telemetry/src/lib.rs` (+7 -2) ➕ `crates/horizon-telemetry/src/live.rs` (+215 -0) 📝 `docs/play-with-friends.md` (+2 -1) 📝 `docs/telemetry.md` (+25 -0) 📝 `launcher/src/backend.rs` (+6 -0) 📝 `launcher/src/collection.rs` (+59 -4) 📝 `launcher/src/main.rs` (+83 -1) 📝 `launcher/src/telemetry.rs` (+30 -0) 📝 `website/docs/faq.md` (+1 -1) 📝 `website/docs/troubleshooting.md` (+1 -1) _...and 1 more files_ </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What FEATURES.md item 14: "how many people are playing Horizon right now", as Ludovic decided on 2026-10-22. Every player is counted, with or without data collection consent, and the launcher tells them. - **Game** (`crates/horizon-client/src/heartbeat.rs`): while the game runs, a thread of its own sends `POST /v1/live` once a minute: `{"session","version","platform","lan"}`. It sends at once when a world opens to or closes from LAN or friends (`is_published`, so server-thread single player counts too). The session ID is 128 random bits made at start and kept only in memory; it is not the install ID. There is no ping from a dedicated server, `--benchmark`, `--offscreen` or a `--frames`/`--world-frames` run, or with `HORIZON_NO_HEARTBEAT=1`. After a failure it waits twice as long, up to 10 minutes, and logs it once. - **Shared types** (`crates/horizon-telemetry/src/live.rs`): `Ping` (checked field by field, unknown fields refused), `Count`, `round` (exact under 10, then to 5 / 10 / 100), `send`/`fetch` behind a new `live` feature. The game takes only `live`, not `upload`. - **Server** (`crates/horizon-telemetry-server/src/live.rs`): an in-memory table (session → last seen, version, platform, LAN), never on disk, never with an address. A session counts while its last ping is under 2 minutes old. `GET /v1/live` returns `{"playing","lan","versions","platforms"}`, all rounded. It shows the 12 biggest versions and sums the rest under `other`. It is cached for 15 s and sends the website's CORS origin. Abuse limits: a separate token bucket per address for pings and reads (600/h, bursts of 60, so ten players can share one address), 512-byte bodies, and at most 200 000 sessions (503 past that). The upkeep tick forgets expired sessions. - **Launcher**: "N PLAYING NOW" in the Play page's status line when the server answers, read at start and every minute. Nothing shows when the server can't be reached. Players are told about the ping in three places: - an "Always on" row in the first-run question; - the same row in Settings → Data collection; - a one-time notice on the Play page ("Got it") for players who answered the question before the ping existed (`ping_notice_seen` in settings.json). `data status` / MCP also return the text. - **Docs**: docs/telemetry.md has a new section on the ping, and the server README covers its endpoints, settings and memory. The website gets a new section on privacy.html and new lines in the FAQ and troubleshooting pages. docs/play-with-friends.md now mentions the LAN flag. Like the rest of telemetry, `DEFAULT_ENDPOINT` stays `None`: until `HORIZON_TELEMETRY_URL` is set, or a server is put in `DEFAULT_ENDPOINT`, the game pings nothing and the launcher shows no count. No Railway service, domain or variable was created or changed. ## Screenshots (Mac mini, scratch launcher/game homes, local server) First-run question, with the ping row: ![consent](https://raw.githubusercontent.com/ludovic111/horizon/7f9cbd6bcf0fee883408ad91997f77c394aa945c/live-count/consent.png) Play page, a player who answered before: one-time notice, and "1 PLAYING NOW": ![play notice](https://raw.githubusercontent.com/ludovic111/horizon/7f9cbd6bcf0fee883408ad91997f77c394aa945c/live-count/play-notice.png) After "Got it": ![play count](https://raw.githubusercontent.com/ludovic111/horizon/7f9cbd6bcf0fee883408ad91997f77c394aa945c/live-count/play-count.png) Server unreachable: no count: ![unreachable](https://raw.githubusercontent.com/ludovic111/horizon/7f9cbd6bcf0fee883408ad91997f77c394aa945c/live-count/play-unreachable.png) Settings → Data collection: ![settings](https://raw.githubusercontent.com/ludovic111/horizon/7f9cbd6bcf0fee883408ad91997f77c394aa945c/live-count/settings.png) ## How tested End to end on the Mac mini: the release `horizon-telemetry-server` (default 120 s window) ran locally, and two real games (`fast` build, `horizon-ctl launch`) used `HORIZON_TELEMETRY_URL=http://127.0.0.1:18317`: ``` 10:27:05 before: {"playing":0,"lan":0,"versions":{},"platforms":{}} 10:27:15 two games: {"playing":2,"lan":0,"versions":{"dev 0.1.0":2},"platforms":{"macos":2}} 10:27:30 A /publish: {"playing":2,"lan":1,"versions":{"dev 0.1.0":2},"platforms":{"macos":2}} 10:27:37 B quit: {"playing":2,"lan":1,"versions":{"dev 0.1.0":2},"platforms":{"macos":2}} 10:29:24 after expiry: {"playing":1,"lan":1,"versions":{"dev 0.1.0":1},"platforms":{"macos":1}} ``` Self-check: ``` cargo fmt --check (workspace, launcher, server), clippy --all-targets -D warnings with pipefail: fmt workspace ok fmt launcher ok fmt server ok clippy workspace exit 0 errors 0 clippy launcher exit 0 errors 0 clippy server exit 0 errors 0 horizon-telemetry: 36 passed, 0 failed horizon-client --lib: test result: ok. 984 passed; 0 failed; 15 ignored; 0 measured; 0 filtered out; finished in 60.76s horizon-telemetry-server: 16 passed, 0 failed horizon-launcher: 109 passed, 0 failed Building probes... Probes built in 386s. Running 3 harnesses, 3 at a time here... PASS world_reopen 152s PASS world_options 301s PASS toggle_keys 307s 3 passed, 0 failed in 5.1 min. parity: PASS world_reopen 152s parity: PASS world_options 301s parity: PASS toggle_keys 307s parity: 3 passed, 0 failed in 5.1 min. ``` The game.rs change is two calls: `heartbeat::start()` in `run()`, which does nothing without a server URL, and one atomic store a frame. `tools/parity.py --changed origin/main` picks 102 harnesses because it matches on game.rs. I ran the three that cover startup and the run loop (above) rather than all 102. New tests: `horizon-telemetry` live (ping fields, checks, rounding), server `live` unit tests (expiry, cap, rare versions) and `tests/live.rs` (HTTP: count and expiry, bad pings, rate limit, full table, and the game's `send` + the launcher's `fetch` end to end), and the launcher's thousands separator. Not covered: the Linux launcher (Wayland/X11) needs vscreen on the desktop; the layout is the same GPUI code. ## Needs Ludovic (to switch it on) Nothing goes live with this PR. To switch it on, once Ludovic says go: 1. Host `horizon-telemetry-server` with its Dockerfile, as crates/horizon-telemetry-server/README.md says. That is the same service the opt-in collection needs (about $0.35 a month). The live count only adds RAM: about 100 bytes a player, 20 MB at the 200 000 cap. Set `HORIZON_TELEMETRY_TRUST_PROXY=1` behind Railway's proxy. The `HORIZON_TELEMETRY_LIVE_*` settings can stay at their defaults. 2. Point the clients at it: set `DEFAULT_ENDPOINT` in `crates/horizon-telemetry/src/lib.rs` to the server's HTTPS URL, in a small PR. That switches on both the opt-in uploads and the ping. A release then ships it. 3. Optional: the website could read `GET /v1/live` (CORS is set for playhorizon.dev). 4. Agents' automated game runs should export `HORIZON_NO_HEARTBEAT=1` (for example in horizon-parity/env.sh) so they stay out of the count. Legal wording: the privacy page now says the ping holds no personal data, and that the sending address is used only in memory for rate limiting. Ludovic may want to check that this matches what he wants to promise. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:09:15 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#3399
No description provided.