Merge pull request #1185 from ludovic111/feat/live-player-count

🤖 Agent: merged after integration wave 2 on the desktop (integ/w2 @ 38307d15 = main c16b41ab + this wave): fmt, clippy -D warnings, workspace + launcher + telemetry-server tests, release build and every affected parity harness pass; the 3 harness failures and the panel test passed on rerun (known flakes).
This commit is contained in:
Ludovic Marie
2026-10-22 15:12:17 +02:00
committed by GitHub
21 changed files with 1064 additions and 46 deletions
+3 -2
View File
@@ -42,8 +42,9 @@ log = "0.4"
chrono = { version = "0.4.42", default-features = false, features = ["clock", "std"] }
flate2 = { version = "1.1.10", default-features = false, features = ["zlib-rs", "runtime_detection"] }
horizon-theme = { path = "../horizon-theme" }
# Opt-in data collection: the game keeps, the launcher sends (docs/telemetry.md).
horizon-telemetry = { path = "../horizon-telemetry", default-features = false }
# Opt-in data collection: the game keeps, the launcher sends (docs/telemetry.md); `live` is
# the anonymous "I'm playing" ping the game sends itself (`heartbeat.rs`).
horizon-telemetry = { path = "../horizon-telemetry", default-features = false, features = ["live"] }
horizon-bench = { path = "../horizon-bench" }
arboard = { version = "3.6.1", default-features = false, features = ["wayland-data-control"] }
zip = { version = "2", default-features = false, features = ["deflate"] }
+12
View File
@@ -11008,6 +11008,8 @@ impl ApplicationHandler for Game<'_> {
}
let updated = Instant::now();
self.track_toggle_screens();
// For the "I'm playing" ping: an atomic, sent on when it changes.
horizon_client::heartbeat::set_lan(self.is_published());
let steps = self.clock.advance(elapsed);
for _ in 0..steps {
let started = Instant::now();
@@ -12815,6 +12817,16 @@ pub fn run() -> Result<()> {
// 10 to 200 ms to get one back.
horizon_threads::favour_current();
}
// Someone is playing: the anonymous ping behind the launcher's "N playing now". Not for a
// server, a benchmark or a run that quits by itself.
if options.dedicated.is_none()
&& options.benchmark.is_none()
&& !options.offscreen
&& options.frames.is_none()
&& options.world_frames.is_none()
{
horizon_client::heartbeat::start();
}
let started = Instant::now();
horizon_client::spans::enable(options.spikes.is_some());
let vanilla_root = options.resources.clone();
+74
View File
@@ -0,0 +1,74 @@
//! The anonymous "I'm playing" ping (`horizon_telemetry::live`, docs/telemetry.md) behind the
//! launcher's "N playing now". While the game runs, a thread of its own sends a random session
//! ID made here and kept only in memory, the version, the platform and whether a LAN or
//! play-with-friends world is open, every minute and at once when that last one changes.
//! It sends nothing when there is no server (`HORIZON_TELEMETRY_URL`, none by default) or
//! with `HORIZON_NO_HEARTBEAT=1` (automated runs).
use std::sync::OnceLock;
use std::sync::atomic::{AtomicBool, Ordering};
use std::thread::Thread;
use std::time::Duration;
use horizon_telemetry::live::{self, Ping};
/// A world is open to LAN or to friends.
static LAN: AtomicBool = AtomicBool::new(false);
static PINGER: OnceLock<Thread> = OnceLock::new();
/// After a failure the next ping waits longer, doubling up to this.
const MAX_WAIT: Duration = Duration::from_secs(600);
/// Starts the pings, once. Call when the game itself starts (not a dedicated server, not a
/// benchmark or an automated run).
pub fn start() {
if PINGER.get().is_some() || std::env::var_os("HORIZON_NO_HEARTBEAT").is_some() {
return;
}
let Some(endpoint) = horizon_telemetry::endpoint() else {
return;
};
let spawned = std::thread::Builder::new()
.name("Heartbeat".into())
.spawn(move || run(&endpoint));
match spawned {
Ok(handle) => {
let _ = PINGER.set(handle.thread().clone());
}
Err(e) => log::warn!("Horizon: no live count ping: {e}"),
}
}
/// Whether a world is open to LAN or friends; a change is sent at once.
pub fn set_lan(open: bool) {
if LAN.swap(open, Ordering::Relaxed) != open
&& let Some(pinger) = PINGER.get()
{
pinger.unpark();
}
}
fn run(endpoint: &str) {
let session = live::session_id();
let version = crate::telemetry::version();
let mut wait = live::INTERVAL;
let mut failed = false;
loop {
let ping = Ping::new(&session, &version, LAN.load(Ordering::Relaxed));
match live::send(endpoint, &ping) {
Ok(()) => {
wait = live::INTERVAL;
failed = false;
}
Err(e) => {
// Said once, not every minute the server is away.
if !failed {
log::info!("Horizon: the live count ping failed ({e}); trying again later");
}
failed = true;
wait = (wait * 2).min(MAX_WAIT);
}
}
// Woken early by `set_lan`; a spurious wake only sends one ping more.
std::thread::park_timeout(wait);
}
}
+1
View File
@@ -80,6 +80,7 @@ pub mod graphics;
pub mod graphics_style;
pub mod graphics_ui;
pub mod health;
pub mod heartbeat;
pub mod hotbar;
pub mod hud;
pub mod hud_layout;
+2 -1
View File
@@ -1,6 +1,7 @@
//! The game's part in opt-in data collection (`horizon_telemetry`, docs/telemetry.md). When the
//! player allows it, the game keeps a scrubbed crash report, or a play session's performance
//! summary, in the outbox. It never sends anything itself: the launcher does, at its next start.
//! summary, in the outbox. It never sends those itself: the launcher does, at its next start (the
//! game's only sending is the anonymous "I'm playing" ping, `heartbeat.rs`).
//! Without the player's yes for that kind nothing is kept, and crash-reports/ stays local.
use std::path::Path;
use std::sync::atomic::{AtomicU32, Ordering};
+8 -1
View File
@@ -1,6 +1,6 @@
# horizon-telemetry-server
This server receives what players choose to send (performance summaries, crash and bug reports, benchmark uploads: [docs/telemetry.md](../../docs/telemetry.md)) and stores it in one SQLite file. It serves anonymous totals to the website. It is one small Rust process, about 7 MB of memory when idle.
This server receives what players choose to send (performance summaries, crash and bug reports, benchmark uploads: [docs/telemetry.md](../../docs/telemetry.md)) and stores it in one SQLite file. It serves anonymous totals to the website. It also keeps the live player count from the games' anonymous "I'm playing" pings, in memory only. It is one small Rust process, about 7 MB of memory when idle.
cargo run --release # in this folder: its own workspace, like the launcher's
PORT=8080 HORIZON_TELEMETRY_DB=/data/telemetry.sqlite3 horizon-telemetry-server
@@ -14,6 +14,8 @@ The launcher sends to it when `HORIZON_TELEMETRY_URL` is set (and to `DEFAULT_EN
| `POST /v1/batch` | A zstd batch (`Content-Encoding: zstd`, at most 256 KiB, 1 MiB inflated, 64 items). Returns 204. Returns 400 for a bad batch, 413 for one too large, 415 if it is not zstd, 429 when over a limit. |
| `DELETE /v1/installs/<id>` | Deletes everything that install sent. Its share of the daily totals is rebuilt at once. |
| `GET /v1/aggregate?days=30` | The totals the website reads. Cached 10 minutes, with `Access-Control-Allow-Origin` set to the website. |
| `POST /v1/live` | A game's "I'm playing" ping (JSON, at most 512 bytes). Returns 204. Returns 400 for a bad ping, 413 for one too large, 429 over the address's limit, 503 when it holds `LIVE_MAX_SESSIONS` already. |
| `GET /v1/live` | How many play now, rounded: `playing`, `lan`, `versions`, `platforms`. Made again at most every 15 seconds, with the same `Access-Control-Allow-Origin`. |
| `GET /healthz` | `ok` |
The totals are grouped per version, OS, GPU vendor and render distance. Each group has its sessions, install-days, hours played, the 14 frame-time buckets summed, and the mean p50 and p99 frame times. Groups with fewer than 5 install-days are left out. The totals also list crash counts per version and the newest 50 benchmark uploads.
@@ -27,6 +29,8 @@ The totals are grouped per version, OS, GPU vendor and render distance. Each gro
Measured: **about 190 bytes per play session** on disk, indexes included (`tests/server.rs`, 10 000 sessions). 1 000 players playing twice a day for 180 days is about 70 MB.
The live count is a table in memory: a session ID, when it last pinged, its version, platform and LAN flag, about 100 bytes a session. A session counts while its last ping is under 2 minutes old and is forgotten after that. Nothing of it reaches the disk, so a restart empties it; it is whole again a minute later.
The day stored is the day the server received an item. The sender's IP address is never written down. The per-address rate limit keeps addresses in memory for an hour at most.
Raw rows are deleted after `HORIZON_TELEMETRY_RETENTION_DAYS` (180). The daily totals stay; they hold no install ID.
@@ -43,6 +47,9 @@ All are environment variables:
- `HORIZON_TELEMETRY_ITEMS_PER_DAY` per install (100)
- `HORIZON_TELEMETRY_TRUST_PROXY=1` behind a proxy (the client's address is then the first of `X-Forwarded-For`)
- `HORIZON_TELEMETRY_ALLOW_ORIGIN` (`https://playhorizon.dev`)
- `HORIZON_TELEMETRY_LIVE_PER_HOUR` per address, pings and reads (600, bursts of 60: ten players behind one address)
- `HORIZON_TELEMETRY_LIVE_WINDOW_SECONDS` (120)
- `HORIZON_TELEMETRY_LIVE_MAX_SESSIONS` (200 000)
## Hosting
+131 -26
View File
@@ -3,12 +3,15 @@
//! - `POST /v1/batch`: a zstd batch from the launcher, checked by `horizon_telemetry::batch`.
//! - `DELETE /v1/installs/<id>`: everything an install sent goes.
//! - `GET /v1/aggregate?days=30`: the anonymous totals the website reads, cached.
//! - `POST /v1/live`: a game's anonymous "I'm playing" ping (`live`, in memory only).
//! - `GET /v1/live`: how many play now, rounded, cached briefly.
//! - `GET /healthz`.
//!
//! Abuse limits: a token bucket per IP address (kept in memory for an hour, never stored), a
//! daily item cap per install, and the batch size limits. Raw rows expire after
//! `retention_days`; the daily totals stay. One small process and one SQLite file: see
//! `README.md` for running it.
//! daily item cap per install, and the batch size limits. The live count has its own, larger
//! bucket per address (several players can share one) and a cap on the sessions it holds. Raw
//! rows expire after `retention_days`; the daily totals stay. One small process and one SQLite
//! file: see `README.md` for running it.
use std::collections::HashMap;
use std::net::{IpAddr, SocketAddr};
use std::sync::{Arc, Mutex};
@@ -21,8 +24,11 @@ use axum::response::{IntoResponse, Response};
use axum::routing::{delete, get, post};
use horizon_telemetry::batch;
pub mod live;
pub mod store;
use horizon_telemetry::live::{MAX_PING_BYTES, Ping};
use live::Live;
use store::Store;
pub struct Config {
@@ -38,6 +44,13 @@ pub struct Config {
pub trust_proxy: bool,
/// The website allowed to read the totals from a browser.
pub allow_origin: String,
/// Live count requests (pings and reads) an IP address may make an hour, with a burst of a
/// tenth of it. A game pings once a minute, so the default lets ten play behind one address.
pub live_per_hour: f64,
/// How long a session counts after its last ping.
pub live_window: Duration,
/// Sessions the live count holds at most; a new one past that is refused.
pub live_max_sessions: usize,
}
impl Default for Config {
@@ -49,13 +62,17 @@ impl Default for Config {
items_per_day: 100,
trust_proxy: false,
allow_origin: "https://playhorizon.dev".into(),
live_per_hour: 600.0,
live_window: horizon_telemetry::live::WINDOW,
live_max_sessions: 200_000,
}
}
}
impl Config {
/// The defaults, with `HORIZON_TELEMETRY_RETENTION_DAYS`, `…_MIN_INSTALL_DAYS`,
/// `…_REQUESTS_PER_HOUR`, `…_ITEMS_PER_DAY`, `…_TRUST_PROXY` (1) and `…_ALLOW_ORIGIN`.
/// `…_REQUESTS_PER_HOUR`, `…_ITEMS_PER_DAY`, `…_TRUST_PROXY` (1), `…_ALLOW_ORIGIN`,
/// `…_LIVE_PER_HOUR`, `…_LIVE_WINDOW_SECONDS` and `…_LIVE_MAX_SESSIONS`.
pub fn from_env() -> Self {
let var = |k: &str| std::env::var(format!("HORIZON_TELEMETRY_{k}")).ok();
let d = Self::default();
@@ -74,6 +91,15 @@ impl Config {
.unwrap_or(d.items_per_day),
trust_proxy: var("TRUST_PROXY").is_some_and(|v| v == "1"),
allow_origin: var("ALLOW_ORIGIN").unwrap_or(d.allow_origin),
live_per_hour: var("LIVE_PER_HOUR")
.and_then(|v| v.parse().ok())
.unwrap_or(d.live_per_hour),
live_window: var("LIVE_WINDOW_SECONDS")
.and_then(|v| v.parse().ok())
.map_or(d.live_window, Duration::from_secs),
live_max_sessions: var("LIVE_MAX_SESSIONS")
.and_then(|v| v.parse().ok())
.unwrap_or(d.live_max_sessions),
}
}
}
@@ -82,13 +108,21 @@ pub struct App {
store: Mutex<Store>,
config: Config,
/// Tokens left and when they were counted, per client address.
buckets: Mutex<HashMap<IpAddr, (f64, Instant)>>,
buckets: Mutex<Buckets>,
/// The same for the live count's requests.
live_buckets: Mutex<Buckets>,
/// Who is playing now (`live`).
live: Mutex<Live>,
/// `GET /v1/live`'s answer and when it was made.
live_cache: Mutex<Option<(Instant, String)>>,
/// `/v1/aggregate` answers by `days`, with when they were made.
cache: Mutex<HashMap<u32, (Instant, String)>>,
/// Today, in days since 1970 (a test moves it).
today: Box<dyn Fn() -> u32 + Send + Sync>,
}
type Buckets = HashMap<IpAddr, (f64, Instant)>;
const CACHE_FOR: Duration = Duration::from_secs(600);
fn status(code: StatusCode, message: &str) -> Response {
@@ -105,10 +139,14 @@ impl App {
config: Config,
today: Box<dyn Fn() -> u32 + Send + Sync>,
) -> Arc<Self> {
let live = Live::new(config.live_window, config.live_max_sessions);
Arc::new(Self {
store: Mutex::new(store),
config,
buckets: Mutex::default(),
live_buckets: Mutex::default(),
live: Mutex::new(live),
live_cache: Mutex::default(),
cache: Mutex::default(),
today,
})
@@ -120,18 +158,16 @@ impl App {
/// Takes a token for `ip`; false when it has none left.
fn allow(&self, ip: IpAddr) -> bool {
let rate = self.config.requests_per_hour / 3600.0;
let burst = (self.config.requests_per_hour / 10.0).max(1.0);
let mut buckets = self.buckets.lock().unwrap_or_else(|e| e.into_inner());
let now = Instant::now();
let (tokens, at) = buckets.entry(ip).or_insert((burst, now));
*tokens = (*tokens + now.duration_since(*at).as_secs_f64() * rate).min(burst);
*at = now;
if *tokens < 1.0 {
return false;
}
*tokens -= 1.0;
true
take(&self.buckets, self.config.requests_per_hour, ip)
}
/// [`Self::allow`] for the live count's requests.
fn allow_live(&self, ip: IpAddr) -> bool {
take(&self.live_buckets, self.config.live_per_hour, ip)
}
fn live(&self) -> std::sync::MutexGuard<'_, Live> {
self.live.lock().unwrap_or_else(|e| e.into_inner())
}
fn client(&self, headers: &HeaderMap, peer: Option<SocketAddr>) -> IpAddr {
@@ -160,14 +196,18 @@ impl App {
self.store().newest_day(install).ok().flatten()
}
/// Daily upkeep: totals rebuilt, expired rows removed, idle rate-limit entries forgotten.
/// Daily upkeep: totals rebuilt, expired rows removed, idle rate-limit entries and live
/// sessions forgotten.
pub fn maintain(&self) -> rusqlite::Result<usize> {
let oldest = (self.today)().saturating_sub(self.config.retention_days);
let removed = self.store().expire(oldest)?;
self.buckets
.lock()
.unwrap_or_else(|e| e.into_inner())
.retain(|_, (_, at)| at.elapsed() < Duration::from_secs(3600));
for buckets in [&self.buckets, &self.live_buckets] {
buckets
.lock()
.unwrap_or_else(|e| e.into_inner())
.retain(|_, (_, at)| at.elapsed() < Duration::from_secs(3600));
}
self.live().forget_expired(Instant::now());
if removed > 0 {
self.cache.lock().unwrap_or_else(|e| e.into_inner()).clear();
}
@@ -175,6 +215,23 @@ impl App {
}
}
/// Takes a token for `ip` from its bucket in `buckets` (`per_hour`, bursts of a tenth of it);
/// false when it has none left.
fn take(buckets: &Mutex<Buckets>, per_hour: f64, ip: IpAddr) -> bool {
let rate = per_hour / 3600.0;
let burst = (per_hour / 10.0).max(1.0);
let mut buckets = buckets.lock().unwrap_or_else(|e| e.into_inner());
let now = Instant::now();
let (tokens, at) = buckets.entry(ip).or_insert((burst, now));
*tokens = (*tokens + now.duration_since(*at).as_secs_f64() * rate).min(burst);
*at = now;
if *tokens < 1.0 {
return false;
}
*tokens -= 1.0;
true
}
fn peer(req: &Request) -> Option<SocketAddr> {
req.extensions()
.get::<ConnectInfo<SocketAddr>>()
@@ -278,18 +335,65 @@ async fn aggregate(State(app): State<Arc<App>>, Query(window): Query<Window>) ->
}
}
};
json_response(&app, json, CACHE_FOR.as_secs())
}
/// `POST /v1/live`: one "I'm playing". 204, or 400 for a bad ping, 413 for one too large, 429
/// over the address's limit, 503 when the table is full.
async fn ping(State(app): State<Arc<App>>, req: Request) -> Response {
if !app.allow_live(app.client(req.headers(), peer(&req))) {
return status(StatusCode::TOO_MANY_REQUESTS, "too many requests");
}
let Ok(body) = axum::body::to_bytes(req.into_body(), MAX_PING_BYTES).await else {
return status(StatusCode::PAYLOAD_TOO_LARGE, "a ping is at most 512 bytes");
};
let ping: Ping = match serde_json::from_slice(&body) {
Ok(ping) => ping,
Err(e) => return status(StatusCode::BAD_REQUEST, &e.to_string()),
};
if let Err(e) = ping.check() {
return status(StatusCode::BAD_REQUEST, e);
}
match app.live().ping(&ping, Instant::now()) {
Ok(()) => StatusCode::NO_CONTENT.into_response(),
Err(live::Full) => status(StatusCode::SERVICE_UNAVAILABLE, "try again later"),
}
}
/// `GET /v1/live`: the rounded live count (`horizon_telemetry::live::Count`), made again at
/// most every eighth of the window.
async fn playing(State(app): State<Arc<App>>, req: Request) -> Response {
if !app.allow_live(app.client(req.headers(), peer(&req))) {
return status(StatusCode::TOO_MANY_REQUESTS, "too many requests");
}
let fresh_for = app.config.live_window / 8;
let json = {
let mut cache = app.live_cache.lock().unwrap_or_else(|e| e.into_inner());
match &*cache {
Some((at, json)) if at.elapsed() < fresh_for => json.clone(),
_ => {
let json =
serde_json::to_string(&app.live().count(Instant::now())).unwrap_or_default();
*cache = Some((Instant::now(), json.clone()));
json
}
}
};
json_response(&app, json, fresh_for.as_secs())
}
fn json_response(app: &App, json: String, max_age: u64) -> Response {
let origin =
HeaderValue::from_str(&app.config.allow_origin).unwrap_or(HeaderValue::from_static("*"));
let cache = HeaderValue::from_str(&format!("public, max-age={max_age}"))
.unwrap_or(HeaderValue::from_static("no-cache"));
(
[
(
header::CONTENT_TYPE,
HeaderValue::from_static("application/json"),
),
(
header::CACHE_CONTROL,
HeaderValue::from_static("public, max-age=600"),
),
(header::CACHE_CONTROL, cache),
(header::ACCESS_CONTROL_ALLOW_ORIGIN, origin),
],
json,
@@ -300,6 +404,7 @@ async fn aggregate(State(app): State<Arc<App>>, Query(window): Query<Window>) ->
pub fn router(app: Arc<App>) -> Router {
Router::new()
.route("/v1/batch", post(receive))
.route("/v1/live", post(ping).get(playing))
.route("/v1/installs/{id}", delete(forget))
.route("/v1/aggregate", get(aggregate))
.route("/healthz", get(|| async { "ok" }))
+201
View File
@@ -0,0 +1,201 @@
//! Who is playing now, from the games' "I'm playing" pings (`horizon_telemetry::live`). Kept in
//! memory only: a session ID, when it last pinged, its version, platform and LAN flag. A
//! session counts while its last ping is under the window old and is forgotten after it. No
//! address is kept, and nothing is written to disk, so a restart starts the count again (it
//! is whole again a minute later).
use std::collections::{BTreeMap, HashMap};
use std::time::{Duration, Instant};
use horizon_telemetry::live::{Count, PLATFORMS, Ping, round};
/// Versions listed by name in a count; the rest are summed under `other`.
const VERSIONS_SHOWN: usize = 12;
struct Seen {
at: Instant,
version: Box<str>,
platform: u8,
lan: bool,
}
pub struct Live {
sessions: HashMap<u128, Seen>,
window: Duration,
max_sessions: usize,
}
/// The table is full and this session is new.
#[derive(Debug, PartialEq, Eq)]
pub struct Full;
impl Live {
pub fn new(window: Duration, max_sessions: usize) -> Self {
Self {
sessions: HashMap::new(),
window,
max_sessions,
}
}
/// Records `ping` (already checked) as seen at `now`.
pub fn ping(&mut self, ping: &Ping, now: Instant) -> Result<(), Full> {
let Ok(id) = u128::from_str_radix(&ping.session, 16) else {
return Ok(());
};
if !self.sessions.contains_key(&id) && self.sessions.len() >= self.max_sessions {
self.forget_expired(now);
if self.sessions.len() >= self.max_sessions {
return Err(Full);
}
}
let platform = PLATFORMS
.iter()
.position(|p| *p == ping.platform)
.unwrap_or(PLATFORMS.len() - 1) as u8;
self.sessions.insert(
id,
Seen {
at: now,
version: ping.version.as_str().into(),
platform,
lan: ping.lan,
},
);
Ok(())
}
/// Drops the sessions whose last ping is older than the window.
pub fn forget_expired(&mut self, now: Instant) {
let window = self.window;
self.sessions
.retain(|_, s| now.saturating_duration_since(s.at) < window);
}
/// Who is playing at `now`, rounded.
pub fn count(&mut self, now: Instant) -> Count {
self.forget_expired(now);
let mut versions: HashMap<&str, u64> = HashMap::new();
let mut platforms = [0u64; PLATFORMS.len()];
let mut lan = 0;
for s in self.sessions.values() {
*versions.entry(&s.version).or_default() += 1;
platforms[usize::from(s.platform)] += 1;
lan += u64::from(s.lan);
}
let mut by_count: Vec<(&str, u64)> = versions.into_iter().collect();
by_count.sort_by(|a, b| b.1.cmp(&a.1).then(a.0.cmp(b.0)));
let mut shown = BTreeMap::new();
let mut other = 0;
for (i, (version, n)) in by_count.into_iter().enumerate() {
if i < VERSIONS_SHOWN {
shown.insert(version.to_owned(), round(n));
} else {
other += n;
}
}
if other > 0 {
*shown.entry("other".to_owned()).or_default() += round(other);
}
Count {
playing: round(self.sessions.len() as u64),
lan: round(lan),
versions: shown,
platforms: PLATFORMS
.iter()
.zip(platforms)
.filter(|(_, n)| *n > 0)
.map(|(p, n)| ((*p).to_owned(), round(n)))
.collect(),
}
}
/// Sessions held now, counted or not yet forgotten.
pub fn len(&self) -> usize {
self.sessions.len()
}
pub fn is_empty(&self) -> bool {
self.sessions.is_empty()
}
}
#[cfg(test)]
mod tests {
use super::*;
fn ping(n: u32, version: &str, platform: &str, lan: bool) -> Ping {
Ping {
session: format!("{n:032x}"),
version: version.into(),
platform: platform.into(),
lan,
}
}
#[test]
fn sessions_count_until_the_window_passes() {
let t = Instant::now();
let mut live = Live::new(Duration::from_secs(120), 100);
live.ping(&ping(1, "0.2.0", "linux", false), t).unwrap();
live.ping(&ping(2, "0.2.0", "macos", true), t).unwrap();
// The same session again is still one.
live.ping(
&ping(1, "0.2.0", "linux", false),
t + Duration::from_secs(60),
)
.unwrap();
let count = live.count(t + Duration::from_secs(61));
assert_eq!((count.playing, count.lan), (2, 1));
assert_eq!(count.versions, BTreeMap::from([("0.2.0".into(), 2)]));
assert_eq!(
count.platforms,
BTreeMap::from([("linux".into(), 1), ("macos".into(), 1)])
);
// Session 2 stopped pinging two minutes ago; session 1 pinged a minute later.
let count = live.count(t + Duration::from_secs(150));
assert_eq!((count.playing, count.lan), (1, 0));
assert_eq!(live.len(), 1);
assert_eq!(live.count(t + Duration::from_secs(181)), Count::default());
assert!(live.is_empty());
}
#[test]
fn a_full_table_takes_no_new_session_until_one_expires() {
let t = Instant::now();
let mut live = Live::new(Duration::from_secs(120), 2);
live.ping(&ping(1, "0.2.0", "linux", false), t).unwrap();
live.ping(&ping(2, "0.2.0", "linux", false), t).unwrap();
assert_eq!(live.ping(&ping(3, "0.2.0", "linux", false), t), Err(Full));
// A known session still refreshes.
live.ping(
&ping(1, "0.2.0", "linux", false),
t + Duration::from_secs(100),
)
.unwrap();
let later = t + Duration::from_secs(130);
live.ping(&ping(3, "0.2.0", "linux", false), later).unwrap();
assert_eq!(live.count(later).playing, 2);
}
#[test]
fn rare_versions_are_summed_and_counts_rounded() {
let t = Instant::now();
let mut live = Live::new(Duration::from_secs(120), 1000);
for n in 0..40 {
live.ping(&ping(n, "0.2.0", "windows", n % 4 == 0), t)
.unwrap();
}
for n in 0..(VERSIONS_SHOWN as u32 + 3) {
live.ping(&ping(100 + n, &format!("dev {n}"), "other", false), t)
.unwrap();
}
let count = live.count(t);
assert_eq!(count.playing, 55);
assert_eq!(count.lan, 10);
assert_eq!(count.versions["0.2.0"], 40);
assert_eq!(count.versions["other"], 4);
assert_eq!(count.versions.len(), VERSIONS_SHOWN + 1);
assert_eq!(count.platforms["windows"], 40);
assert_eq!(count.platforms["other"], 15);
}
}
@@ -0,0 +1,190 @@
//! The live count through its HTTP interface, and end to end with the game's ping and the
//! launcher's read (`horizon_telemetry::live`).
use std::sync::Arc;
use std::time::Duration;
use axum::body::Body;
use axum::http::{Request, StatusCode, header};
use horizon_telemetry::live::{self, Count, Ping};
use horizon_telemetry_server::store::Store;
use horizon_telemetry_server::{App, Config, router};
use http_body_util::BodyExt;
use tower::ServiceExt;
fn app(config: Config) -> Arc<App> {
App::new(Store::open(":memory:").unwrap(), config)
}
fn quick() -> Config {
Config {
live_per_hour: 100_000.0,
live_window: Duration::from_secs(1),
trust_proxy: true,
..Config::default()
}
}
fn ping(n: u32, version: &str, lan: bool) -> String {
serde_json::to_string(&Ping {
session: format!("{n:032x}"),
version: version.into(),
platform: "linux".into(),
lan,
})
.unwrap()
}
async fn send(app: &Arc<App>, req: Request<Body>) -> (StatusCode, axum::http::HeaderMap, String) {
let res = router(app.clone()).oneshot(req).await.unwrap();
let (code, headers) = (res.status(), res.headers().clone());
let body = res.into_body().collect().await.unwrap().to_bytes();
(code, headers, String::from_utf8_lossy(&body).into_owned())
}
async fn post(app: &Arc<App>, body: impl Into<Body>, from: &str) -> StatusCode {
let req = Request::post("/v1/live")
.header("x-forwarded-for", from)
.body(body.into())
.unwrap();
send(app, req).await.0
}
async fn count(app: &Arc<App>) -> Count {
let req = Request::get("/v1/live")
.header("x-forwarded-for", "198.51.100.1")
.body(Body::empty())
.unwrap();
let (code, headers, body) = send(app, req).await;
assert_eq!(code, StatusCode::OK, "{body}");
assert_eq!(headers[header::CONTENT_TYPE], "application/json");
assert_eq!(
headers[header::ACCESS_CONTROL_ALLOW_ORIGIN],
"https://playhorizon.dev"
);
serde_json::from_str(&body).unwrap()
}
#[tokio::test]
async fn sessions_count_while_they_ping_and_expire_after() {
let app = app(quick());
assert_eq!(
post(&app, ping(1, "0.2.0", false), "203.0.113.1").await,
StatusCode::NO_CONTENT
);
assert_eq!(
post(&app, ping(2, "0.2.0", true), "203.0.113.2").await,
StatusCode::NO_CONTENT
);
// A second ping from the same session is still one player.
assert_eq!(
post(&app, ping(1, "0.2.0", false), "203.0.113.1").await,
StatusCode::NO_CONTENT
);
let now = count(&app).await;
assert_eq!((now.playing, now.lan), (2, 1));
assert_eq!(now.versions["0.2.0"], 2);
assert_eq!(now.platforms["linux"], 2);
// Session 1 keeps pinging; session 2 stops.
for _ in 0..5 {
tokio::time::sleep(Duration::from_millis(250)).await;
post(&app, ping(1, "0.2.0", false), "203.0.113.1").await;
}
let later = count(&app).await;
assert_eq!((later.playing, later.lan), (1, 0));
tokio::time::sleep(Duration::from_millis(1200)).await;
assert_eq!(count(&app).await, Count::default());
}
#[tokio::test]
async fn bad_pings_are_refused() {
let app = app(quick());
let from = "203.0.113.3";
assert_eq!(post(&app, "not json", from).await, StatusCode::BAD_REQUEST);
assert_eq!(
post(&app, ping(1, "<b>0.2</b>", false), from).await,
StatusCode::BAD_REQUEST
);
let extra = r#"{"session":"00000000000000000000000000000001","version":"0.2.0","platform":"linux","lan":false,"name":"Steve"}"#;
assert_eq!(post(&app, extra, from).await, StatusCode::BAD_REQUEST);
assert_eq!(
post(&app, "x".repeat(4096), from).await,
StatusCode::PAYLOAD_TOO_LARGE
);
assert_eq!(count(&app).await.playing, 0);
}
#[tokio::test]
async fn an_address_is_rate_limited_on_its_own_bucket() {
let app = app(Config {
live_per_hour: 60.0,
trust_proxy: true,
..Config::default()
});
// A burst of a tenth of the hour's 60, then 429.
let mut codes = Vec::new();
for n in 0..8 {
codes.push(post(&app, ping(n, "0.2.0", false), "203.0.113.4").await);
}
assert_eq!(
codes
.iter()
.filter(|c| **c == StatusCode::NO_CONTENT)
.count(),
6
);
assert_eq!(codes[7], StatusCode::TOO_MANY_REQUESTS);
// Another address is not held back.
assert_eq!(
post(&app, ping(9, "0.2.0", false), "203.0.113.5").await,
StatusCode::NO_CONTENT
);
}
#[tokio::test]
async fn a_full_table_refuses_new_sessions() {
let app = app(Config {
live_max_sessions: 2,
..quick()
});
for n in 0..2 {
assert_eq!(
post(&app, ping(n, "0.2.0", false), "203.0.113.6").await,
StatusCode::NO_CONTENT
);
}
assert_eq!(
post(&app, ping(2, "0.2.0", false), "203.0.113.6").await,
StatusCode::SERVICE_UNAVAILABLE
);
assert_eq!(
post(&app, ping(1, "0.2.0", false), "203.0.113.6").await,
StatusCode::NO_CONTENT
);
}
#[tokio::test]
async fn the_games_ping_and_the_launchers_read_reach_it_end_to_end() {
let app = app(Config {
live_window: Duration::from_secs(120),
..quick()
});
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let url = format!("http://{}", listener.local_addr().unwrap());
let service = router(app.clone()).into_make_service_with_connect_info::<std::net::SocketAddr>();
tokio::spawn(async move { axum::serve(listener, service).await.unwrap() });
let count = tokio::task::spawn_blocking(move || {
let a = Ping::new(&live::session_id(), "0.2.0", false);
let b = Ping::new(&live::session_id(), "dev 0.1.0", true);
live::send(&url, &a)?;
live::send(&url, &b)?;
live::fetch(&url)
})
.await
.unwrap()
.unwrap();
assert_eq!((count.playing, count.lan), (2, 1));
assert_eq!(count.versions.len(), 2);
assert_eq!(count.platforms[live::platform()], 2);
}
+4 -2
View File
@@ -13,12 +13,14 @@ serde_json = "1"
ruzstd = "0.9"
# The random install ID and outbox file names.
getrandom = "0.3"
# Sending, for the launcher; the ingest server builds without it.
# Sending, for the launcher (and the game's "I'm playing" ping); the ingest server builds without it.
ureq = { version = "2", default-features = false, features = ["tls"], optional = true }
[features]
default = ["upload"]
default = ["upload", "live"]
upload = ["dep:ureq"]
# The "I'm playing" ping and reading the live count (`live`), for the game and the launcher.
live = ["dep:ureq"]
[[test]]
name = "consent_gating"
+7 -2
View File
@@ -6,11 +6,15 @@
//! connection. Items are small summaries (percentiles and histogram buckets, never raw streams),
//! dated to the day, with no account, world, server or address in them ([`scrub`]); they leave
//! in zstd batches ([`batch`]). `docs/telemetry.md` lists every field.
//!
//! The one exception is [`live`]: the anonymous "I'm playing" ping the game sends while it
//! runs, for the live player count. It holds no install ID and nothing about the player.
use std::path::{Path, PathBuf};
use std::time::{SystemTime, UNIX_EPOCH};
pub mod batch;
pub mod consent;
pub mod live;
pub mod outbox;
pub mod payload;
pub mod scrub;
@@ -29,8 +33,9 @@ pub const SCHEMA: u32 = 1;
/// and until the player answers nothing new is kept or sent.
pub const CONSENT_VERSION: u32 = 1;
/// The ingest server, or none while there isn't one: then nothing is ever sent and the outbox
/// stays within its caps. `HORIZON_TELEMETRY_URL` overrides it (tests, a local server).
/// The ingest server, or none while there isn't one: then nothing is ever sent (no ping either)
/// and the outbox stays within its caps. `HORIZON_TELEMETRY_URL` overrides it (tests, a local
/// server).
pub const DEFAULT_ENDPOINT: Option<&str> = None;
/// Where items are sent, if anywhere.
+215
View File
@@ -0,0 +1,215 @@
//! The anonymous "I'm playing" ping, and the live count it feeds ("N playing now" in the
//! launcher).
//!
//! Unlike everything else in this crate it does not wait for consent: Ludovic decided
//! (2026-10-22) to count every player and tell them, in the launcher's first-run question, its
//! Settings and the privacy page. So a ping holds only what the count needs: a random session ID
//! made when the game starts and kept only in its memory (not the install ID), the Horizon
//! version, the platform and whether a LAN or play-with-friends world is open. The game sends
//! one every [`INTERVAL`]; the server counts a session while its last ping is under
//! [`WINDOW`] old, keeps nothing on disk and serves the counts rounded ([`round`]).
use std::collections::BTreeMap;
use std::time::Duration;
use serde::{Deserialize, Serialize};
/// How often the game pings while it runs.
pub const INTERVAL: Duration = Duration::from_secs(60);
/// How long a session counts after its last ping: two pings, so one lost on the way doesn't
/// drop it.
pub const WINDOW: Duration = Duration::from_secs(120);
/// The platforms a ping may name; anything else is `other`.
pub const PLATFORMS: [&str; 4] = ["linux", "macos", "windows", "other"];
/// The largest ping body the server reads.
pub const MAX_PING_BYTES: usize = 512;
const MAX_VERSION: usize = 40;
/// One "I'm playing", as it is sent: `{"session":"…","version":"…","platform":"…","lan":false}`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Ping {
/// 128 random bits in hex, made when the game starts ([`session_id`]) and never written down.
pub session: String,
/// The release (`v2026.10.15`, `0.2.0`) or `dev 0.1.0` for a build from source.
pub version: String,
/// One of [`PLATFORMS`].
pub platform: String,
/// A world is open to LAN or to friends over the internet.
pub lan: bool,
}
impl Ping {
pub fn new(session: &str, version: &str, lan: bool) -> Self {
Self {
session: session.to_owned(),
version: version.to_owned(),
platform: platform().to_owned(),
lan,
}
}
/// Why the server refuses this ping, if it does.
pub fn check(&self) -> Result<(), &'static str> {
if !crate::consent::is_install_id(&self.session) {
return Err("session: 32 lowercase hex digits");
}
let version_ok = !self.version.is_empty()
&& self.version.len() <= MAX_VERSION
&& self
.version
.bytes()
.all(|b| b.is_ascii_alphanumeric() || b" .+-_".contains(&b));
if !version_ok {
return Err("version: at most 40 letters, digits, spaces and .+-_");
}
if !PLATFORMS.contains(&self.platform.as_str()) {
return Err("platform: linux, macos, windows or other");
}
Ok(())
}
}
/// A new session ID: 128 random bits in hex.
pub fn session_id() -> String {
crate::random_hex(16)
}
/// This machine's entry in [`PLATFORMS`].
pub fn platform() -> &'static str {
match std::env::consts::OS {
os @ ("linux" | "macos" | "windows") => os,
_ => "other",
}
}
/// The live count, as `GET /v1/live` serves it: every number already [`round`]ed.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct Count {
/// Sessions that pinged within the window.
pub playing: u64,
/// Of those, the ones with a LAN or play-with-friends world open.
pub lan: u64,
/// Per version: the most played ones, the rest summed under `other`.
pub versions: BTreeMap<String, u64>,
/// Per platform.
pub platforms: BTreeMap<String, u64>,
}
/// Rounds a count for showing: exact under 10, then to the nearest 5 under 100, the nearest 10
/// under 1000 and the nearest 100 above. Small numbers stay true; large ones don't pretend to
/// a precision a two-minute window doesn't have.
pub fn round(n: u64) -> u64 {
let step = match n {
0..10 => return n,
10..100 => 5,
100..1000 => 10,
_ => 100,
};
(n + step / 2) / step * step
}
/// Sends `ping` to `endpoint` (`https://host`, without a trailing slash).
#[cfg(feature = "live")]
pub fn send(endpoint: &str, ping: &Ping) -> Result<(), String> {
agent()
.post(&format!("{endpoint}/v1/live"))
.set("Content-Type", "application/json")
.send_string(&serde_json::to_string(ping).map_err(|e| e.to_string())?)
.map(drop)
.map_err(|e| e.to_string())
}
/// The live count at `endpoint`.
#[cfg(feature = "live")]
pub fn fetch(endpoint: &str) -> Result<Count, String> {
let body = agent()
.get(&format!("{endpoint}/v1/live"))
.call()
.map_err(|e| e.to_string())?
.into_string()
.map_err(|e| e.to_string())?;
serde_json::from_str(&body).map_err(|e| e.to_string())
}
#[cfg(feature = "live")]
fn agent() -> ureq::Agent {
ureq::AgentBuilder::new()
.timeout(Duration::from_secs(5))
.build()
}
#[cfg(test)]
mod tests {
use super::*;
fn ping() -> Ping {
Ping::new(&session_id(), "v2026.10.15", false)
}
#[test]
fn a_ping_holds_only_the_four_fields() {
let json = serde_json::to_value(Ping::new(&"a".repeat(32), "0.2.0", true)).unwrap();
let mut keys: Vec<&str> = json
.as_object()
.unwrap()
.keys()
.map(|k| k.as_str())
.collect();
keys.sort_unstable();
assert_eq!(keys, ["lan", "platform", "session", "version"]);
assert!(serde_json::to_string(&ping()).unwrap().len() < MAX_PING_BYTES);
}
#[test]
fn session_ids_are_fresh_each_time() {
let (a, b) = (session_id(), session_id());
assert_ne!(a, b);
assert!(ping().check().is_ok());
}
#[test]
fn bad_pings_are_refused() {
let bad = |f: fn(&mut Ping)| {
let mut p = ping();
f(&mut p);
p.check().is_err()
};
assert!(bad(|p| p.session = "ABC".into()));
assert!(bad(|p| p.session = "G".repeat(32)));
assert!(bad(|p| p.version = String::new()));
assert!(bad(|p| p.version = "1".repeat(41)));
assert!(bad(|p| p.version = "<script>".into()));
assert!(bad(|p| p.platform = "haiku".into()));
assert!(!bad(|p| p.version = "dev 0.1.0".into()));
let extra = r#"{"session":"00000000000000000000000000000000","version":"0.2.0","platform":"linux","lan":false,"name":"Steve"}"#;
assert!(serde_json::from_str::<Ping>(extra).is_err());
}
#[test]
fn counts_round_more_as_they_grow() {
let cases = [
(0, 0),
(1, 1),
(9, 9),
(10, 10),
(12, 10),
(13, 15),
(97, 95),
(98, 100),
(104, 100),
(105, 110),
(994, 990),
(995, 1000),
(1049, 1000),
(1050, 1100),
];
for (n, shown) in cases {
assert_eq!(round(n), shown, "{n}");
}
}
}
+2 -1
View File
@@ -94,7 +94,8 @@ run at once there, and each must finish within 10 seconds however slowly its byt
- **A relay** (only if one is configured) sees the IP addresses of the host and the guests, the short
code's first half, when sessions start and end and the size of encrypted frames. It can't see the
secret, the key or the game (names, chat, the world). It logs counts every five minutes, nothing else.
- **Horizon** sees nothing: there is no Horizon service.
- **Horizon** runs no service for it. The game's anonymous "I'm playing" ping says only whether a
LAN or friends world is open, never its address, code or name ([telemetry.md](telemetry.md)).
## Identity
+25
View File
@@ -2,6 +2,8 @@
Horizon collects nothing unless the player says yes. The launcher asks once, with four separate switches that are all off until the player turns one on, and the same switches stay in Settings. The game and the launcher obey the same answer. The code is in `crates/horizon-telemetry`.
The one exception is the anonymous ["I'm playing" ping](#the-im-playing-ping) behind the launcher's "N playing now": it holds nothing about the player, and the launcher says so next to the switches.
## Consent
`telemetry/consent.json` in the game folder (`HORIZON_HOME`, else `horizon` in the platform data folder):
@@ -46,10 +48,33 @@ Never sent: account names or UUIDs, world names, server or LAN addresses, chat,
- `HORIZON_TELEMETRY_URL` sets the server. There is none by default: until there is, nothing is sent and the outbox stays within its caps.
- `SCHEMA` versions the format. New optional fields keep it. A field that changes meaning or goes bumps it, and the server keeps reading the older ones.
## The "I'm playing" ping
Ludovic decided on 2026-10-22 to count every player, with or without consent, and to tell them. The launcher's first-run question and Settings → Data collection show it as an "Always on" row next to the switches. Players who answered the question before the ping existed see the same text once on the Play page. The privacy page on playhorizon.dev says the same.
While the game runs (not a dedicated server, a benchmark or a run that quits by itself), a thread of its own (`crates/horizon-client/src/heartbeat.rs`) sends `POST /v1/live` once a minute. It also sends one at once when a world is opened to or closed from LAN or friends:
```json
{ "session": "9b1c…", "version": "v2026.10.22", "platform": "macos", "lan": false }
```
- `session` is 128 random bits made when the game starts. It is kept only in the game's memory and is not the install ID, so two sessions of one player can't be linked.
- `version` is the release, `platform` is `linux`, `macos`, `windows` or `other`, and `lan` says whether a LAN or play-with-friends world is open.
- Nothing else: no account, install ID, world, server, settings or hardware. The server checks each field (`live::Ping::check`) and refuses anything more.
The server keeps sessions in memory only, never on disk, and never with the sender's address. A session counts while its last ping is under 2 minutes old. `GET /v1/live` gives the count, rounded (`live::round`: exact under 10, then to 5, 10 and 100):
```json
{ "playing": 1240, "lan": 85, "versions": { "v2026.10.22": 1100, "other": 140 }, "platforms": { "linux": 300, "macos": 240, "windows": 700 } }
```
The launcher reads it when it opens and every minute after, and shows "N playing now" on the Play page. It shows nothing when the server can't be reached. Like the rest, there is no server by default (`HORIZON_TELEMETRY_URL`): until there is one, the game sends no ping and the launcher shows no count. `HORIZON_NO_HEARTBEAT=1` keeps automated runs out of the count.
## Server
- `POST /v1/batch`
- `DELETE /v1/installs/<install_id>`: deletes everything sent under that ID.
- `GET /v1/aggregate`: the anonymous totals the website's results page reads.
- `POST /v1/live` and `GET /v1/live`: the "I'm playing" ping and the live count.
`crates/horizon-telemetry-server` is the server. Its [README](../crates/horizon-telemetry-server/README.md) covers storage (about 190 bytes per play session), retention (180 days of raw rows, anonymous daily totals kept), rate limits and hosting.
+6
View File
@@ -2066,6 +2066,8 @@ pub enum Msg {
PackLine(String),
/// A modpack step ended: the pack as it now is.
PackDone(Result<Box<crate::modpacks::Imported>, String>),
/// How many play Horizon now, or none when the server can't be reached (`telemetry`).
Playing(Option<u64>),
}
/// A running process; its output arrives as `Msg::Line`, its end as `Msg::Exit`.
@@ -2156,6 +2158,10 @@ pub struct Settings {
/// Whether new versions include betas (releases not promoted to stable yet). Off by default.
#[serde(default)]
pub beta_builds: bool,
/// The player has read what the "I'm playing" ping holds (`telemetry::PING`): on the
/// first-run question, or on the Play page once if they answered that before it existed.
#[serde(default)]
pub ping_notice_seen: bool,
}
impl Settings {
+59 -4
View File
@@ -45,6 +45,41 @@ fn kind_id(prefix: &str, kind: DataKind) -> &'static str {
}
}
/// Where a switch would be: the ping has none.
fn always_on(t: &Theme) -> Div {
caps("Always on").flex_none().text_color(t.muted)
}
/// The "I'm playing" ping on the first-run question, laid out as the switches' rows.
fn ping_row(t: &Theme) -> Div {
div()
.flex()
.items_start()
.gap(px(16.))
.py(px(10.))
.border_b_1()
.border_color(t.rule)
.child(
div()
.flex()
.flex_col()
.flex_1()
.min_w_0()
.gap(px(2.))
.child(
text(theme::UI)
.text_color(t.ink)
.child(telemetry::PING_NAME),
)
.child(
text(theme::CAPTION)
.text_color(t.muted)
.child(telemetry::PING),
),
)
.child(always_on(t))
}
/// The exact JSON, in mono, scrolling inside a plate.
fn json_view(view: &(String, String), t: &Theme, scroll: &Scrollbar) -> Div {
div()
@@ -87,6 +122,11 @@ impl Launcher {
Ok(consent) => self.collection.consent = consent,
Err(e) => self.collection.note = Some(format!("Could not save your choice: {e}")),
}
// The question and Settings say what the "I'm playing" ping holds, beside the switches.
if !self.settings.ping_notice_seen {
self.settings.ping_notice_seen = true;
self.settings.save();
}
self.collection.view = None;
}
@@ -148,9 +188,17 @@ impl Launcher {
.child("Help make Horizon faster and steadier?"),
)
.child(text(theme::UI).text_color(t.muted).child(
"Horizon can send a few things to its developers. Everything is off until you turn it on, and Settings can change it any time.",
"Horizon can send a few things to its developers. Each switch is off until you turn it on, and Settings can change it any time.",
))
.child(div().flex().flex_col().border_t_1().border_color(t.rule).children(rows))
.child(
div()
.flex()
.flex_col()
.border_t_1()
.border_color(t.rule)
.children(rows)
.child(ping_row(&t)),
)
.child(text(theme::CAPTION).text_color(t.muted).child(telemetry::NEVER))
.child(
div()
@@ -244,6 +292,13 @@ impl Launcher {
&t,
));
}
list = list.child(index_row(
telemetry::SWITCHES.len() + 1,
telemetry::PING_NAME,
Some(div().child(telemetry::PING).into_any_element()),
Some(always_on(&t).into_any_element()),
&t,
));
let waiting = horizon_telemetry::outbox::pending(&telemetry::home()).len();
let id = match consent.install_id.as_str() {
"" => "No install ID: nothing has been collected".to_string(),
@@ -299,7 +354,7 @@ impl Launcher {
})),
);
list = list.child(index_row(
telemetry::SWITCHES.len() + 1,
telemetry::SWITCHES.len() + 2,
"Your data",
Some(
div()
@@ -316,7 +371,7 @@ impl Launcher {
.gap(px(16.))
.child(text(theme::HEADING).text_color(t.ink).child("Data collection"))
.child(text(theme::UI).max_w(px(600.)).text_color(t.muted).child(
"Off unless you turn it on. What each switch sends is below it; the privacy page on playhorizon.dev says how long it is kept.",
"Each switch is off unless you turn it on. What it sends is below it; the privacy page on playhorizon.dev says how long it is kept.",
))
.child(list)
.child(text(theme::CAPTION).text_color(t.muted).child(telemetry::NEVER))
+83 -1
View File
@@ -163,6 +163,8 @@ struct Launcher {
args_focus: FocusHandle,
/// Opt-in data collection: the player's answer and Settings' section (`collection`).
collection: collection::Collection,
/// How many play Horizon now, while the server answers ("N playing now" on the Play page).
playing: Option<u64>,
tx: Sender<Msg>,
rx: Receiver<Msg>,
_appearance: Subscription,
@@ -280,6 +282,7 @@ impl Launcher {
friend_focus: cx.focus_handle(),
joining: None,
collection: collection::Collection::load(),
playing: None,
tx,
rx,
_appearance: appearance,
@@ -317,6 +320,7 @@ impl Launcher {
this.fetch_links();
// What the game and the launcher kept, if the player allows it and there is a server.
telemetry::send_in_background();
telemetry::watch_playing(this.tx.clone());
this
}
@@ -426,6 +430,7 @@ impl Launcher {
// The page reads is_prepared when drawn; `changed` redraws it.
Msg::Reused(_) => self.installed = backend::installed(),
Msg::Keychain(persistent) => self.keychain = persistent,
Msg::Playing(playing) => self.playing = playing,
Msg::Session(session) => {
if let Some(tag) = self.starting_client.take() {
let mut cmd = backend::client_command(&tag);
@@ -1146,6 +1151,19 @@ fn centered(text_: &str, t: &Theme) -> Div {
.child(text(theme::UI).text_color(t.muted).child(text_.to_string()))
}
/// `1234` as `1,234`.
fn thousands(n: u64) -> String {
let digits = n.to_string();
let mut out = String::new();
for (i, c) in digits.chars().enumerate() {
if i > 0 && (digits.len() - i).is_multiple_of(3) {
out.push(',');
}
out.push(c);
}
out
}
/// A mono line in upper case: the status above a title, the footer's links.
fn caps(s: impl AsRef<str>) -> Div {
text(theme::MICRO).child(s.as_ref().to_uppercase())
@@ -1688,9 +1706,11 @@ impl Launcher {
_ => None,
};
let title = "Horizon";
// Never squeezed by the rows below: the ping notice can make it tall.
let mut hero =
div()
.flex()
.flex_none()
.flex_col()
.gap(px(14.))
.pt(px(24.))
@@ -1704,7 +1724,18 @@ impl Launcher {
.child(
caps(if prepared { "Ready" } else { "Needs preparing" })
.text_color(if prepared { t.success } else { t.muted }),
),
)
.children(self.playing.map(|n| {
div()
.flex()
.items_center()
.gap(px(10.))
.child(div().size(px(4.)).rounded_full().bg(t.rule))
.child(
caps(format!("{} playing now", thousands(n)))
.text_color(t.muted),
)
})),
)
.child(text(theme::DISPLAY).text_color(t.ink).child(title))
.child(text(theme::BODY).max_w(px(560.)).text_color(t.muted).child(
@@ -1747,6 +1778,45 @@ impl Launcher {
),
});
}
// Players who answered the first-run question before the ping existed read about it
// once here.
if !self.settings.ping_notice_seen && !self.collection.consent.needs_asking() {
hero = hero.child(
plate(&t)
.flex()
.flex_none()
.flex_col()
.gap(px(8.))
.p(px(16.))
.w_full()
.max_w(px(640.))
.child(
text(theme::UI)
.text_color(t.ink)
.child(telemetry::PING_NAME),
)
.child(
text(theme::CAPTION)
.text_color(t.muted)
.child(telemetry::PING),
)
.child(
div()
.id("ping-notice-ok")
.text_size(px(theme::UI.px))
.text_color(t.accent)
.font_weight(FontWeight::MEDIUM)
.cursor_pointer()
.hover(|s| s.opacity(0.8))
.child("Got it")
.on_click(cx.listener(|this, _: &ClickEvent, _, cx| {
this.settings.ping_notice_seen = true;
this.settings.save();
cx.notify();
})),
),
);
}
hero
}
@@ -2918,3 +2988,15 @@ fn main() {
cx.activate(true);
});
}
#[cfg(test)]
mod tests {
#[test]
fn counts_get_thousands_separators() {
let shown: Vec<String> = [0, 7, 999, 1000, 12_300, 1_234_500]
.into_iter()
.map(super::thousands)
.collect();
assert_eq!(shown, ["0", "7", "999", "1,000", "12,300", "1,234,500"]);
}
}
+30
View File
@@ -1,6 +1,8 @@
//! Opt-in data collection from the launcher (`horizon_telemetry`): the player's answer, what
//! would be sent, deleting it, bug reports and benchmark uploads, and sending the outbox when
//! the launcher starts and closes. The window, the CLI and the MCP server all go through here.
//! Also the live count's side here: what the "I'm playing" ping holds, in words, and reading
//! how many play now (`horizon_telemetry::live`).
use std::path::{Path, PathBuf};
use horizon_telemetry::payload::{Bug, Crash, Perf, System, Timings};
@@ -37,6 +39,33 @@ pub const SWITCHES: [(Kind, &str, &str); 4] = [
/// Never sent, whatever the switches say.
pub const NEVER: &str = "Never sent: your account name or UUID, world names, server addresses, chat, or your IP address. Each report is dated to the day, under a random install ID you can delete.";
/// The anonymous "I'm playing" ping the game sends whatever the switches say (Ludovic's
/// decision, 2026-10-22: count everyone, and tell them). Shown on the first-run question, in
/// Settings, and once on the Play page to players who answered before it existed.
pub const PING_NAME: &str = "\"I'm playing\" ping";
pub const PING: &str = "While you play, the game sends an anonymous \"I'm playing\" ping once a minute, so the launcher can show how many people play Horizon right now. It holds: a random number made when the game starts and forgotten when it closes, the Horizon version, your OS (Linux, macOS or Windows), and whether you have a world open to LAN or friends. It doesn't hold: your account, your install ID, world or server names, or anything you do in the game, and the server doesn't keep your IP address. It is sent whatever the switches say.";
/// How many play Horizon now (rounded), if the server says.
pub fn playing_now() -> Option<u64> {
let endpoint = horizon_telemetry::endpoint()?;
horizon_telemetry::live::fetch(&endpoint)
.ok()
.map(|count| count.playing)
}
/// Sends [`playing_now`] to the window as `Msg::Playing` now and every minute, on its own
/// thread. Nothing at all when there is no server.
pub fn watch_playing(tx: std::sync::mpsc::Sender<backend::Msg>) {
if horizon_telemetry::endpoint().is_none() {
return;
}
std::thread::spawn(move || {
while tx.send(backend::Msg::Playing(playing_now())).is_ok() {
std::thread::sleep(horizon_telemetry::live::INTERVAL);
}
});
}
pub fn home() -> PathBuf {
backend::game_home()
}
@@ -249,6 +278,7 @@ pub fn status_json() -> serde_json::Value {
"install_id": consent.install_id,
"waiting": outbox::pending(&home()).len(),
"server": horizon_telemetry::endpoint(),
"ping": PING,
})
}
+1 -1
View File
@@ -56,7 +56,7 @@ In part. Horizon runs the full-screen effects of Java shader packs, not their ge
## Does Horizon collect data?
Only if you say yes, and each kind has its own switch. Everything is off by default. See [Privacy](/privacy).
Only if you say yes, and each kind has its own switch. Everything is off by default. The one thing sent without asking is an anonymous "I'm playing" ping, for the count of how many play right now: it holds a random number made each time the game starts, the version, your OS and whether a world is open to LAN, and nothing about you. See [Privacy](/privacy).
## How often does it update?
+1 -1
View File
@@ -52,4 +52,4 @@ A Horizon bug is any place where it differs from vanilla 26.3, so "vanilla does
## Data the launcher can send
The launcher can send performance statistics, crash reports, bug reports and benchmarks, but only the kinds you allow, and everything is off until you say yes. See [Privacy](/privacy) for what is sent, how long it is kept and how to delete it.
The launcher can send performance statistics, crash reports, bug reports and benchmarks, but only the kinds you allow, and everything is off until you say yes. The game also sends an anonymous "I'm playing" ping while it runs, for the live player count. See [Privacy](/privacy) for what is sent, how long it is kept and how to delete it.
+9 -4
View File
@@ -17,8 +17,8 @@
<main id="main" class="section">
<div class="container">
<p class="kicker"><span>Privacy</span>Data collection</p>
<h1 class="display">Nothing leaves without your yes.</h1>
<p class="lede">The Horizon launcher can send a few things that help make the game faster and steadier. It asks first, each kind has its own switch, and every switch is off until you turn it on.</p>
<h1 class="display">Nothing about you leaves without your yes.</h1>
<p class="lede">The Horizon launcher can send a few things that help make the game faster and steadier. It asks first, each kind has its own switch, and every switch is off until you turn it on. The only thing sent without asking is an anonymous "I'm playing" ping, which says nothing about you.</p>
<div class="prose">
<h2>What can be sent</h2>
<p>Only the kinds you allow, from the launcher's first-run question or Settings → Data collection:</p>
@@ -32,11 +32,16 @@
<p>Never sent: your Microsoft or Minecraft account name or UUID, world names, server or LAN addresses, chat, and your user name or home folder in file paths. Before anything is kept, those are replaced with placeholders, along with e-mail and IP addresses. The server does not store the IP address requests come from.</p>
<p>The launcher shows exactly what would be sent: Settings → Data collection → View what would be sent, or <code>horizon-launcher data show</code>. Every field is listed in <a href="https://github.com/ludovic111/horizon/blob/main/docs/telemetry.md">docs/telemetry.md</a>.</p>
<h2>The "I'm playing" ping</h2>
<p>While you play, the game sends an anonymous "I'm playing" ping once a minute, so the launcher can show how many people play Horizon right now. It is sent whatever the switches say, and the launcher says so next to them.</p>
<p>It holds: a random number made when the game starts and forgotten when it closes, the Horizon version, your operating system (Linux, macOS or Windows), and whether you have a world open to LAN or to friends. It doesn't hold: your account, your install ID, world or server names, your hardware or settings, or anything you do in the game. The random number changes every time you start the game, so two of your sessions can't be linked to each other or to you.</p>
<p>The server keeps the pings in memory only, never on disk, and not with the address they came from (that is used only to stop abuse, as below). A session counts while it pinged in the last two minutes and is then forgotten. What it shows is the number playing now, per version and with a world open, rounded.</p>
<h2>Why</h2>
<p>To find what is slow or crashes on which machines, and fix it. Benchmark uploads also show other players how Horizon runs on hardware like theirs. Nothing is sold, shared for advertising, or used to identify you.</p>
<p>To find what is slow or crashes on which machines, and fix it. The ping shows players, and Horizon, how many people play right now. Benchmark uploads also show other players how Horizon runs on hardware like theirs. Nothing is sold, shared for advertising, or used to identify you.</p>
<h2>On what basis</h2>
<p>Your consent (Article 6(1)(a) of the EU's General Data Protection Regulation). It is given kind by kind, recorded on your computer with the version of the question you answered and when, and withdrawn at any time with the same switches. Withdrawing deletes what was waiting to be sent. When what is collected changes, the launcher asks again, and nothing new is sent until you answer.</p>
<p>For the switches: your consent (Article 6(1)(a) of the EU's General Data Protection Regulation). It is given kind by kind, recorded on your computer with the version of the question you answered and when, and withdrawn at any time with the same switches. Withdrawing deletes what was waiting to be sent. When what is collected changes, the launcher asks again, and nothing new is sent until you answer. The ping holds nothing that identifies you; the address it comes from is used only to limit how often one address may send, kept in memory for an hour at most and never stored.</p>
<h2>Where and how long</h2>
<p>Items wait on your computer (<code>telemetry/</code> in the game folder) and are sent compressed when the launcher starts or closes, to Horizon's own server at <a href="https://railway.com">Railway</a>. The server keeps them for <strong>180 days</strong>, then deletes them. What stays after that are anonymous totals per day, Horizon version, operating system, GPU maker and render distance (for example "120 sessions on macOS with Apple GPUs at render distance 12"). They hold no install ID, and groups too small to be anonymous are never shown.</p>