be16401f90
- DEFAULT_ENDPOINT is https://telemetry.playhorizon.dev. The heartbeat, the launcher's live count and the outbox upload all go there; HORIZON_TELEMETRY_URL still names another server, and HORIZON_TELEMETRY_URL=off sends nothing at all. CI workflows and the harnesses that start the game or the launcher set off. Consent is unchanged: the four switches stay opt-in, only the anonymous ping is always on. - GET /v1/benchmarks/summary: players' benchmark uploads grouped by GPU, CPU, render distance and game, groups of 3+ installs only, medians per install then across installs, no install ID, day, OS version, driver, memory or screen. Cached 10 minutes, CORS for the website. Same rules as website/scripts/benchmarks.mjs, tested on the same fixtures; a deleted install leaves its groups at once. - /v1/aggregate no longer lists the newest 50 raw benchmark reports (hardware, driver, day, one install each): uploads are published only through the summary. - Behind Railway's proxy the rate limit counts X-Real-IP, else the last X-Forwarded-For entry (the one the proxy adds; a client could choose the first). Still in memory only, never stored or logged. - crates/horizon-telemetry-server/railway.json: Dockerfile build from the repository root, health check /healthz, one replica in europe-west4 (one SQLite file on the /data volume). - Docs: docs/telemetry.md, the server README (the summary's shape, Railway setup), the privacy page (the ping is on, where the data lives, how benchmark uploads are shown). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
75 lines
2.6 KiB
Rust
75 lines
2.6 KiB
Rust
//! 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 sending is turned off (`HORIZON_TELEMETRY_URL=off`) 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);
|
|
}
|
|
}
|