diff --git a/api/.sqlx/query-4d15f7b63cc1357d0f7bd08a497b0201d51891b09b5a2e8451c269958c283cb1.json b/api/.sqlx/query-4d15f7b63cc1357d0f7bd08a497b0201d51891b09b5a2e8451c269958c283cb1.json new file mode 100644 index 0000000..281c45c --- /dev/null +++ b/api/.sqlx/query-4d15f7b63cc1357d0f7bd08a497b0201d51891b09b5a2e8451c269958c283cb1.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "\n UPDATE players SET\n country_chosen = $2::text IS NOT NULL,\n country_from_server = country_from_server AND $2::text IS NULL,\n country_code = CASE WHEN $2::text IS NOT NULL THEN $2\n WHEN country_chosen THEN NULL ELSE country_code END,\n steam_profile_fetched_at = CASE WHEN $2::text IS NULL AND country_chosen THEN NULL\n ELSE steam_profile_fetched_at END\n WHERE steamid64 = $1\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int8", + "Text" + ] + }, + "nullable": [] + }, + "hash": "4d15f7b63cc1357d0f7bd08a497b0201d51891b09b5a2e8451c269958c283cb1" +} diff --git a/api/.sqlx/query-a9c1668c23595148dae099063553e60c7876573fdcdb78c49deb9fe758dcbba5.json b/api/.sqlx/query-a9c1668c23595148dae099063553e60c7876573fdcdb78c49deb9fe758dcbba5.json deleted file mode 100644 index 803009b..0000000 --- a/api/.sqlx/query-a9c1668c23595148dae099063553e60c7876573fdcdb78c49deb9fe758dcbba5.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n UPDATE players SET\n country_chosen = $2::text IS NOT NULL,\n country_code = CASE WHEN $2::text IS NOT NULL THEN $2\n WHEN country_chosen THEN NULL ELSE country_code END,\n steam_profile_fetched_at = CASE WHEN $2::text IS NULL AND country_chosen THEN NULL\n ELSE steam_profile_fetched_at END\n WHERE steamid64 = $1\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Int8", - "Text" - ] - }, - "nullable": [] - }, - "hash": "a9c1668c23595148dae099063553e60c7876573fdcdb78c49deb9fe758dcbba5" -} diff --git a/api/.sqlx/query-e8461c94cdc9a070ad92f8775d49ddddfd4e6a2d3d2e60667fc8bd7bf1720dc1.json b/api/.sqlx/query-e8461c94cdc9a070ad92f8775d49ddddfd4e6a2d3d2e60667fc8bd7bf1720dc1.json deleted file mode 100644 index 5f39239..0000000 --- a/api/.sqlx/query-e8461c94cdc9a070ad92f8775d49ddddfd4e6a2d3d2e60667fc8bd7bf1720dc1.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n UPDATE players SET\n avatar_url = $2,\n -- A country the player picked on their profile stays.\n country_code = CASE WHEN country_chosen THEN country_code ELSE $3 END,\n steam_profile_fetched_at = now(),\n name = CASE WHEN name_seen_at = '-infinity' AND $4::text IS NOT NULL THEN $4 ELSE name END\n WHERE steamid64 = $1\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Int8", - "Text", - "Text", - "Text" - ] - }, - "nullable": [] - }, - "hash": "e8461c94cdc9a070ad92f8775d49ddddfd4e6a2d3d2e60667fc8bd7bf1720dc1" -} diff --git a/api/.sqlx/query-edba6cf047a4c41a5fa80bf5e5c6de783bb61e2e78949dd939cb2c7979de7869.json b/api/.sqlx/query-edba6cf047a4c41a5fa80bf5e5c6de783bb61e2e78949dd939cb2c7979de7869.json new file mode 100644 index 0000000..00c8f4a --- /dev/null +++ b/api/.sqlx/query-edba6cf047a4c41a5fa80bf5e5c6de783bb61e2e78949dd939cb2c7979de7869.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "\n UPDATE players SET country_code = $2, country_from_server = true, country_chosen = false\n WHERE steamid64 = $1 AND name_seen_at <= $3\n AND (country_code IS DISTINCT FROM $2 OR NOT country_from_server)\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int8", + "Text", + "Timestamptz" + ] + }, + "nullable": [] + }, + "hash": "edba6cf047a4c41a5fa80bf5e5c6de783bb61e2e78949dd939cb2c7979de7869" +} diff --git a/api/.sqlx/query-fb61c057eeaad93846cb18dc80de808b8f42a0540f9eee7761f8845c487934f8.json b/api/.sqlx/query-fb61c057eeaad93846cb18dc80de808b8f42a0540f9eee7761f8845c487934f8.json new file mode 100644 index 0000000..88c2c6b --- /dev/null +++ b/api/.sqlx/query-fb61c057eeaad93846cb18dc80de808b8f42a0540f9eee7761f8845c487934f8.json @@ -0,0 +1,17 @@ +{ + "db_name": "PostgreSQL", + "query": "\n UPDATE players SET\n avatar_url = $2,\n -- Steam's country comes last: one a game server found or the player picked stays.\n country_code = CASE WHEN country_chosen OR country_from_server THEN country_code ELSE $3 END,\n steam_profile_fetched_at = now(),\n name = CASE WHEN name_seen_at = '-infinity' AND $4::text IS NOT NULL THEN $4 ELSE name END\n WHERE steamid64 = $1\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int8", + "Text", + "Text", + "Text" + ] + }, + "nullable": [] + }, + "hash": "fb61c057eeaad93846cb18dc80de808b8f42a0540f9eee7761f8845c487934f8" +} diff --git a/api/contract/runs.json b/api/contract/runs.json index 8e5b7e3..1253420 100644 --- a/api/contract/runs.json +++ b/api/contract/runs.json @@ -6,7 +6,8 @@ "server_run_id": "9b2f6a1e-4c1d-4e7a-9a51-3f0f6f1c2d10", "player": { "steamid64": "76561197960287930", - "name": "gabe" + "name": "gabe", + "country_code": "SE" }, "map": "bhop_badges", "style": "normal", diff --git a/api/crates/api/migrations/0052_players_country_from_server.sql b/api/crates/api/migrations/0052_players_country_from_server.sql new file mode 100644 index 0000000..9faf57b --- /dev/null +++ b/api/crates/api/migrations/0052_players_country_from_server.sql @@ -0,0 +1,6 @@ +-- Whether `players.country_code` came from a game server: its GeoIP lookup of the player's address, sent with a +-- run. A player's country has one source at a time, so this and `country_chosen` are never both true. Which +-- source wins is in `docs/site-api.md`. +ALTER TABLE players + ADD COLUMN country_from_server boolean NOT NULL DEFAULT false, + ADD CONSTRAINT players_one_country_source CHECK (NOT (country_chosen AND country_from_server)); diff --git a/api/crates/api/src/players.rs b/api/crates/api/src/players.rs index 90af67c..fc1f7be 100644 --- a/api/crates/api/src/players.rs +++ b/api/crates/api/src/players.rs @@ -162,6 +162,31 @@ pub async fn record_name( Ok(()) } +/// Makes `code`, found by a game server from the player's address, their country, replacing one they picked or +/// Steam's (the order is in `docs/site-api.md`). Only from their latest run, as for names: `record_name` has +/// already moved `name_seen_at` to the newest time a server saw them, so a run sent late from a queue can't roll +/// the country back. +pub async fn record_server_country( + conn: &mut PgConnection, + steamid64: SteamId64, + code: &str, + finished_at: DateTime, +) -> Result<(), sqlx::Error> { + sqlx::query!( + r#" + UPDATE players SET country_code = $2, country_from_server = true, country_chosen = false + WHERE steamid64 = $1 AND name_seen_at <= $3 + AND (country_code IS DISTINCT FROM $2 OR NOT country_from_server) + "#, + steamid64.get(), + code, + finished_at + ) + .execute(conn) + .await?; + Ok(()) +} + #[cfg(test)] mod tests { use super::SteamId64; diff --git a/api/crates/api/src/players/details.rs b/api/crates/api/src/players/details.rs index 56deff8..a793d37 100644 --- a/api/crates/api/src/players/details.rs +++ b/api/crates/api/src/players/details.rs @@ -1,5 +1,5 @@ //! What players say about themselves on their profile, `PUT /v1/players/{player}/details`: their setup (mouse, -//! DPI, sensitivity, mouse pad, keyboard, monitor, aspect ratio) and a country to show instead of Steam's. +//! DPI, sensitivity, mouse pad, keyboard, monitor, aspect ratio) and a country to show (order: `docs/site-api.md`). //! //! Anyone can type anything here, so every field is checked once, at this boundary: short single lines of //! text with no links or invisible characters, numbers in a sensible range, a ratio from a fixed list and a @@ -216,7 +216,8 @@ pub struct DetailsInput { pub monitor: Option, #[serde(default)] pub aspect: Option, - /// An ISO 3166-1 alpha-2 code to show instead of the Steam profile's country; null to show Steam's. + /// An ISO 3166-1 alpha-2 code to show instead of Steam's or a game server's, until a run's server finds one; + /// null to stop showing the player's pick. #[serde(default)] pub country_code: Option, /// Required when staff change someone else's details: why, for the staff log. @@ -346,12 +347,13 @@ async fn store( ) .execute(&mut *tx) .await?; - // Going back to Steam's country clears ours and marks the Steam profile stale, so the next view of the - // profile fetches it again. + // A pick replaces a game server's country. Dropping a pick clears it and marks the Steam profile stale, so + // the next view of the profile fetches Steam's again; dropping a pick the player doesn't have changes nothing. sqlx::query!( r#" UPDATE players SET country_chosen = $2::text IS NOT NULL, + country_from_server = country_from_server AND $2::text IS NULL, country_code = CASE WHEN $2::text IS NOT NULL THEN $2 WHEN country_chosen THEN NULL ELSE country_code END, steam_profile_fetched_at = CASE WHEN $2::text IS NULL AND country_chosen THEN NULL @@ -539,6 +541,37 @@ mod tests { ); } + #[sqlx::test] + async fn a_pick_replaces_a_servers_country_and_saving_without_one_keeps_it(db: PgPool) { + let token = player(&db, GABE, &[]).await; + sqlx::query("UPDATE players SET country_code = 'SE', country_from_server = true") + .execute(&db) + .await + .unwrap(); + let country = || async { + sqlx::query_as::<_, (Option, bool, bool)>( + "SELECT country_code, country_from_server, country_chosen FROM players", + ) + .fetch_one(&db) + .await + .unwrap() + }; + + assert_eq!( + save(&db, &token, GABE, json!({ "dpi": 800 })).await.status, + 204 + ); + assert_eq!(country().await, (Some("SE".into()), true, false)); + + sqlx::query("UPDATE player_details SET updated_at = now() - interval '1 minute'") + .execute(&db) + .await + .unwrap(); + let body = json!({ "country_code": "fi" }); + assert_eq!(save(&db, &token, GABE, body).await.status, 204); + assert_eq!(country().await, (Some("FI".into()), false, true)); + } + #[sqlx::test] async fn bad_values_are_refused(db: PgPool) { let token = player(&db, GABE, &[]).await; diff --git a/api/crates/api/src/players/profile.rs b/api/crates/api/src/players/profile.rs index 28d6dd9..ea97b13 100644 --- a/api/crates/api/src/players/profile.rs +++ b/api/crates/api/src/players/profile.rs @@ -30,9 +30,10 @@ pub struct PlayerProfile { /// The name from their latest run, or from Steam if they haven't played yet. pub name: String, pub avatar_url: Option, - /// ISO 3166-1 alpha-2: the one the player picked, or else their Steam profile's. None if neither has one. + /// ISO 3166-1 alpha-2: the latest one a game server found for them, the player's pick if they made it + /// since, or else their Steam profile's. None if none has one. pub country_code: Option, - /// Whether the player picked `country_code` themselves, rather than it coming from Steam. + /// Whether the player picked `country_code` themselves, rather than it coming from a game server or Steam. pub country_chosen: bool, /// Their setup, as they describe it. None when they've said nothing. pub details: Option, diff --git a/api/crates/api/src/players/steam_profile.rs b/api/crates/api/src/players/steam_profile.rs index e4a1b35..4079863 100644 --- a/api/crates/api/src/players/steam_profile.rs +++ b/api/crates/api/src/players/steam_profile.rs @@ -132,8 +132,8 @@ pub async fn refresh(db: &PgPool, steam: &Steam, steamid64: SteamId64) -> Result r#" UPDATE players SET avatar_url = $2, - -- A country the player picked on their profile stays. - country_code = CASE WHEN country_chosen THEN country_code ELSE $3 END, + -- Steam's country comes last: one a game server found or the player picked stays. + country_code = CASE WHEN country_chosen OR country_from_server THEN country_code ELSE $3 END, steam_profile_fetched_at = now(), name = CASE WHEN name_seen_at = '-infinity' AND $4::text IS NOT NULL THEN $4 ELSE name END WHERE steamid64 = $1 @@ -220,6 +220,51 @@ mod tests { assert!(queue(&steam, first), "a finished refresh frees its place"); } + /// A stand-in for Steam that answers every profile with `PUBLIC`. + async fn fake_steam() -> Steam { + let app = + axum::Router::new().route("/profiles/{id}/", axum::routing::get(|| async { PUBLIC })); + let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); + let address = listener.local_addr().unwrap(); + tokio::spawn(async move { axum::serve(listener, app).await.unwrap() }); + Steam::with_base(&url::Url::parse(&format!("http://{address}/")).unwrap()) + } + + #[sqlx::test] + async fn steams_country_comes_after_a_servers_and_the_players_own(db: PgPool) { + // Steam's own (none yet), a game server's, and the player's pick. + let players = [ + ("[U:1:1]", None, false, false, Some("NO")), + ("[U:1:2]", Some("SE"), true, false, Some("SE")), + ("[U:1:3]", Some("FI"), false, true, Some("FI")), + ]; + for (id, code, from_server, chosen, expected) in players { + let steamid64 = SteamId64::parse_any(id).unwrap(); + sqlx::query( + "INSERT INTO players (steamid64, name, name_seen_at, country_code, country_from_server, country_chosen) + VALUES ($1, 'nova', now(), $2, $3, $4)", + ) + .bind(steamid64.get()) + .bind(code) + .bind(from_server) + .bind(chosen) + .execute(&db) + .await + .unwrap(); + // A Steam each, so no refresh waits its turn behind another. + refresh(&db, &fake_steam().await, steamid64).await.unwrap(); + + let (country, avatar): (Option, Option) = + sqlx::query_as("SELECT country_code, avatar_url FROM players WHERE steamid64 = $1") + .bind(steamid64.get()) + .fetch_one(&db) + .await + .unwrap(); + assert!(avatar.is_some(), "{id}: the profile was stored"); + assert_eq!(country.as_deref(), expected, "{id}"); + } + } + #[sqlx::test] async fn a_failed_fetch_waits_before_trying_again(db: PgPool) { let steamid64 = SteamId64::parse_any("76561197960287930").unwrap(); diff --git a/api/crates/api/src/runs.rs b/api/crates/api/src/runs.rs index 5d1eb23..93103f3 100644 --- a/api/crates/api/src/runs.rs +++ b/api/crates/api/src/runs.rs @@ -78,6 +78,13 @@ pub struct RunPlayer { #[schema(value_type = String, example = "76561197960287930")] pub steamid64: SteamId64, pub name: String, + /// The player's country, as the game server found it from their address with SourceMod's `GeoipCode2`: an ISO + /// 3166-1 alpha-2 code. Leave it out when the lookup finds nothing; send only the code, never the address. It + /// becomes the player's flag. A code SourceJump doesn't know as a country is ignored and the run is stored + /// anyway. Runs only: detections ignore it. + #[serde(default, skip_serializing_if = "Option::is_none")] + #[schema(example = "SE")] + pub country_code: Option, } /// SourceJump's answer to a run. A resend gets the same answer, with a fresh upload link if one applies. @@ -224,6 +231,15 @@ async fn store( let finished_at = DateTime::from_timestamp(run.finished_at, 0).expect("checked before storing"); players::record_name(conn, run.player.steamid64, &run.player.name, finished_at).await?; + // An unknown code costs the player a flag, never their run. + if let Some(code) = run + .player + .country_code + .as_deref() + .and_then(players::countries::known_code) + { + players::record_server_country(conn, run.player.steamid64, code, finished_at).await?; + } let ban = restrictions::records_ban(conn, run.player.steamid64).await?; let map_id = maps::id_for(conn, &run.map).await?; @@ -610,6 +626,82 @@ pub(crate) mod tests { assert_eq!(submit(&db, &key, &any).await.status, 201); } + /// The run player's `country_code`, `country_from_server` and `country_chosen`. + async fn country(db: &PgPool) -> (Option, bool, bool) { + sqlx::query_as( + "SELECT country_code, country_from_server, country_chosen FROM players WHERE steamid64 = 76561197960287930", + ) + .fetch_one(db) + .await + .unwrap() + } + + fn with_country(server_run_id: &str, code: &str) -> Value { + let mut body = run(server_run_id, 30.0); + body["player"]["country_code"] = json!(code); + body + } + + #[sqlx::test] + async fn the_country_a_server_found_replaces_a_pick_and_steams(db: PgPool) { + let key = setup(&db).await; + + assert_eq!( + submit(&db, &key, &with_country("a", "se")).await.status, + 201 + ); + assert_eq!(country(&db).await, (Some("SE".into()), true, false)); + + // The player picks their own; a run without a country leaves it, the next one with a country replaces it. + sqlx::query("UPDATE players SET country_code = 'NO', country_chosen = true, country_from_server = false") + .execute(&db) + .await + .unwrap(); + assert_eq!(submit(&db, &key, &run("b", 31.0)).await.status, 201); + assert_eq!(country(&db).await, (Some("NO".into()), false, true)); + assert_eq!( + submit(&db, &key, &with_country("c", "SE")).await.status, + 201 + ); + assert_eq!(country(&db).await, (Some("SE".into()), true, false)); + + // A resend changes nothing, whatever country it carries. + assert_eq!( + submit(&db, &key, &with_country("a", "fi")).await.status, + 200 + ); + assert_eq!(country(&db).await, (Some("SE".into()), true, false)); + } + + #[sqlx::test] + async fn a_country_sourcejump_doesnt_know_is_ignored_and_the_run_stored(db: PgPool) { + let key = setup(&db).await; + + for (id, code) in [("a", "XX"), ("b", "A1"), ("c", "EU"), ("d", "Sweden")] { + assert_eq!( + submit(&db, &key, &with_country(id, code)).await.status, + 201, + "{code}" + ); + } + + assert_eq!(count(&db, "runs").await, 4); + assert_eq!(country(&db).await, (None, false, false)); + } + + #[sqlx::test] + async fn a_run_sent_late_cant_roll_the_country_back(db: PgPool) { + let key = setup(&db).await; + let mut newer = with_country("a", "SE"); + newer["finished_at"] = json!(1_792_400_100); + + submit(&db, &key, &newer).await; + submit(&db, &key, &with_country("b", "FI")).await; + + assert_eq!(count(&db, "runs").await, 2); + assert_eq!(country(&db).await, (Some("SE".into()), true, false)); + } + #[sqlx::test] async fn runs_need_a_valid_key(db: PgPool) { setup(&db).await; diff --git a/api/openapi.json b/api/openapi.json index 47b6a34..64eb706 100644 --- a/api/openapi.json +++ b/api/openapi.json @@ -6204,7 +6204,7 @@ "string", "null" ], - "description": "An ISO 3166-1 alpha-2 code to show instead of the Steam profile's country; null to show Steam's." + "description": "An ISO 3166-1 alpha-2 code to show instead of Steam's or a game server's, until a run's server finds one;\nnull to stop showing the player's pick." }, "dpi": { "type": [ @@ -8164,14 +8164,14 @@ }, "country_chosen": { "type": "boolean", - "description": "Whether the player picked `country_code` themselves, rather than it coming from Steam." + "description": "Whether the player picked `country_code` themselves, rather than it coming from a game server or Steam." }, "country_code": { "type": [ "string", "null" ], - "description": "ISO 3166-1 alpha-2: the one the player picked, or else their Steam profile's. None if neither has one." + "description": "ISO 3166-1 alpha-2: the latest one a game server found for them, the player's pick if they made it\nsince, or else their Steam profile's. None if none has one." }, "details": { "oneOf": [ @@ -9720,6 +9720,14 @@ "name" ], "properties": { + "country_code": { + "type": [ + "string", + "null" + ], + "description": "The player's country, as the game server found it from their address with SourceMod's `GeoipCode2`: an ISO\n3166-1 alpha-2 code. Leave it out when the lookup finds nothing; send only the code, never the address. It\nbecomes the player's flag. A code SourceJump doesn't know as a country is ignored and the run is stored\nanyway. Runs only: detections ignore it.", + "example": "SE" + }, "name": { "type": "string" }, diff --git a/docs/api.md b/docs/api.md index 4153656..092768b 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1,5 +1,5 @@ # API -How the `/v1/` API behaves for game servers, and rules every client can rely on. The website's own endpoints (sign-in, players, maps, servers, posts): `site-api.md`. The exact schema is `api/openapi.json`. Examples, checked by `cargo test`: `api/contract/`. +How the `/v1/` API behaves for game servers, and rules for every client. The website's own endpoints (sign-in, players, maps, servers, posts): `site-api.md`. The exact schema is `api/openapi.json`. Examples, checked by `cargo test`: `api/contract/`. ## Endpoints | Endpoint | Key | Code | @@ -24,54 +24,55 @@ How the `/v1/` API behaves for game servers, and rules every client can rely on. ## Rules every client can rely on - **Errors** always have the body `{"error": "..."}`. The message is for people; don't match on it. -- **Retrying:** `2xx` means stored. Network errors, `5xx` and `429` (too many) are temporary: keep the item queued and resend it later. Any other `4xx` is final: the request breaks a rule and resending never works, so the plugin drops it. +- **Retrying:** `2xx` means stored. Network errors, `5xx` and `429` (too many) are temporary: keep the item queued and resend it. Any other `4xx` is final: the request breaks a rule, so the plugin drops it. - **Idempotency:** runs and detections carry an ID from the game server (`server_run_id`, `server_detection_id`), unique per server. A resend gets `200` with the first answer and changes nothing; the first send gets `201`. - **SteamID64s** are JSON strings: too big for a JavaScript number, and SourcePawn has no 64-bit integers. - **Map names** are lowercased; other characters than `a-z 0-9 _ - .`, or only dots, are rejected. -- **Server times** (`finished_at`, `detected_at`) are Unix seconds by the game server's clock. The API also records when it received each item. Times over 5 minutes ahead of the API's clock get `422`. +- **Server times** (`finished_at`, `detected_at`) are Unix seconds by the game server's clock. The API also records when each item arrived. Times over 5 minutes ahead of the API's clock get `422`. ## Keys - One key per server, sent as `Authorization: Bearer sj_…`. Only its SHA-256 is stored, so a lost key is replaced, never recovered. - A missing, unknown or revoked key gets `401` on keyed endpoints (`ServerKey` in `servers/keys.rs`). The heartbeat never rejects for its key; it answers `valid`, `revoked`, `unknown` or `none`. - Every run and detection records the key it came with, so revoking a key can invalidate every run its server sent, with any key (staff choose, `site-api.md`). -- Staff issue, replace and revoke keys on `/staff/keys` (or `sourcejump-api keys issue ""`, `keys revoke `). A server holds one active key at a time (a unique index); a new key revokes its old one in the same step. How servers request keys is still open (`domain.md`). +- Staff issue, replace and revoke keys on `/staff/keys` (or `sourcejump-api keys issue ""`, `keys revoke `). A server holds one active key at a time (a unique index); a new key revokes the old in the same step. How servers request keys is still open (`domain.md`). ## Server heartbeats -- Every plugin server, keyed or not, sends one on map start and then every `next_heartbeat_seconds` (600 now): hostname, port, map, players and slots, versions (`shavit_version` null without shavit), plugins, compliance. +- Every plugin server, keyed or not, sends one on map start, then every `next_heartbeat_seconds` (600 now): hostname, port, map, players and slots, versions (`shavit_version` null without shavit), plugins, compliance. - A server is its address: the IP the heartbeat came from plus its reported port. Behind Caddy the IP is the last `X-Forwarded-For` entry, `country_code` Cloudflare's `CF-IPCountry` (`XX`, `T1`: none), trusted only from this machine (`client_address.rs`). The reported `ip` is for staff, never trusted. - Only the latest heartbeat per address is kept (`server_heartbeats`), at most 32 ports per IP; an hourly job drops unlisted ones silent 7 days. A valid key links the address to its `servers` row. - Over 64 KB gets `413`. Hostnames lose control characters, cut to 64. An IP (IPv6: /64) may send 120 at once, then 30 a minute; more get `429`, before any key check (`heartbeat_limit.rs`). ## Runs -- Accepted only if the run's ruleset version exists, its style is ranked in that version, its tickrate matches the ruleset's `tickrate` if set, and the plugin reports the server as compliant. Field ranges are checked once, at the boundary. +- Accepted only if the run's ruleset version exists, its style is ranked there, its tickrate matches the ruleset's `tickrate` if set, and the plugin reports the server as compliant. Field ranges are checked once, at the boundary. +- Optional `player.country_code`: the server's `GeoipCode2` for the player (never their IP) sets their flag; unknown codes are ignored. - `personal_bests` holds each player's fastest run per map, style and track, updated in the same transaction. A tie keeps the earlier run. -- Any keyed server can add a map by submitting a run on it. Which maps are ranked is a separate decision. +- Any keyed server adds a map by submitting a run on it; ranking it is a separate decision. ## Replays - The `replays` policy decides which replays are wanted (`request`: `new_personal_best`, the lead's call on 2026-10-19; `every_run` or `nothing`) and which styles' replays are public (`public_styles`: every ranked style, lead 2026-11-03). A missing policy asks for nothing and makes nothing public. -- A wanted replay gets a presigned `PUT` link, valid for an hour, to `uploads/replays/-.replay` in a private bucket. The server uploads there directly. A resend of the run returns a fresh link, with `last_refusal` (reason, time) if the last upload was refused, or no link once the replay is stored (delete the local copy). -- Every 30 s a job (`replays/processing.rs`) lists the uploads and checks each against its run: shavit format 12 only, frames fill the file exactly, same map (any case), track, player and tickrate, and the time within half a tick. Over 128 MB is refused. A good file is stored as SJR (`replays/sjr.rs`, a fifth the size) at `replays/-.sjr`; the upload is deleted. A bad one is deleted, its reason kept on the `replays` row, and the server may upload again. A stored replay never changes; a failing upload is retried. +- A wanted replay gets a presigned `PUT` link, valid for an hour, to `uploads/replays/-.replay` in a private bucket. The server uploads there directly. A resend returns a fresh link, with `last_refusal` (reason, time) if the last upload was refused, or no link once the replay is stored (delete the local copy). +- Every 30 s a job (`replays/processing.rs`) lists the uploads and checks each against its run: shavit format 12 only, frames fill the file exactly, same map (any case), track, player and tickrate, and the time within half a tick. Over 128 MB is refused. A good file is stored as SJR (`replays/sjr.rs`, a fifth the size) at `replays/-.sjr`; the upload is deleted. A bad one is deleted, its reason kept on the `replays` row; the server may upload again. A stored replay never changes; a failing upload is retried. - The bucket is public; random keys mean only the API reveals files. `GET /v1/runs/{id}` gives the SJR link (`replay.sjr_url`; invalidated runs too, lead 2026-11-03), its route from above (`replay.route`, `replay-viewer.md`), and `GET /v1/replays/{run_id}` the shavit file, rebuilt byte for byte at its first download and kept (own random key), only while the run is valid and its style is public. -- `GET /v1/maps/{map}/records` marks each record `has_replay` by the same rule, so a server only asks for files it will get. +- `GET /v1/maps/{map}/records` marks each record `has_replay` by the same rule, so servers ask only for files they'll get. ## Map records for `/wr` - `GET /v1/maps/{map}/leaderboard?style=&track=` pages one board (`total`, `next_cursor`); `player=` (any SteamID) adds their best and rank as `player_entry`. Opaque cursors name where a page ended, so paging survives that player improving; old run-ID ones work while the run is a PB. Its rows and `…/records`' carry `points` and `has_replay`. - Both send an `ETag` (`etag.rs`, a body hash); `If-None-Match` with it gets a bodiless `304` until the answer changes. So do `/v1/ruleset`, `…/zones` and `/v1/plugin/latest`. ## Record events -- `GET /v1/records/events` lists what happened to records, for servers announcing them or playing them on their bot: `run` (a new personal best, or a restored run that is one again), `replay` (its replay stored) and `invalidated` (staff took a run off a board; read the map's records again). Events are written with their change and kept a week. `previous_time` is the player's best on the board before that run, as it stood then (null: none; migration 0043). The same events feed the Discord posts of records and personal bests (`record_events/discord.rs`). -- Servers poll every 10 to 30 s with `after`, the `next` of their last answer; without it they get only a `next` from now. Cursors are opaque. `max_rank` (default 1) keeps runs at that rank or better now; `invalidated` events always come. +- `GET /v1/records/events` lists what happened to records, for servers announcing them or playing them on their bot: `run` (a new personal best, or a restored run that is one again), `replay` (its replay stored) and `invalidated` (staff took a run off a board; read the map's records again). Events are written with their change, kept a week. `previous_time` is the player's best on the board before that run, as it stood then (null: none; migration 0043). The same events feed the Discord posts of records and personal bests (`record_events/discord.rs`). +- Servers poll every 10 to 30 s with `after`, the `next` of their last answer; without it, only a `next` from now. Cursors are opaque. `max_rank` (default 1) keeps runs at that rank or better now; `invalidated` events always come. - Pages hold only events from transactions older than every running one, so a late commit is delayed, never skipped. - `GET /v1/records/stream` pushes the same events as server-sent events (`event:` kind, `id:` cursor, `data:` the event), starting from `Last-Event-ID`, `after` or now, with a comment every 15 s. One reader, woken by `NOTIFY`, reads each event once for every stream (`stream.rs`); an IP may hold 40 streams, `429` past that. Streams end at shutdown; clients reconnect with `Last-Event-ID`. - The ruleset's `features.record_events` and `features.record_stream` tell the plugin to follow them (migration 0035). ## Policies and versioned data -Rulesets, zone sets and `policies` (community policy the plugin doesn't need: `servers`, `replays`, `tiers`, typed in `policies.rs`) are append-only: database triggers refuse updates and deletes. A change is a new version, and the newest version is in force. Runs record the ruleset version they were played under. A new version ships as a migration (lead, 2026-10-21); a test checks every ruleset they publish (`RulesetDocument::check`). The CLI's `tiers count` publishes the tier count, logged. +Rulesets, zone sets and `policies` (community policy the plugin doesn't need: `servers`, `replays`, `tiers`, typed in `policies.rs`) are append-only: database triggers refuse updates and deletes. A change is a new version; the newest is in force. Runs record the ruleset version they were played under. A new version ships as a migration (lead, 2026-10-21); a test checks every ruleset they publish (`RulesetDocument::check`). The CLI's `tiers count` publishes the tier count, logged. - Ranked styles carry shavit `settings` and `flags`; `RankedStyle` (`ruleset.rs`) says how they match. Provisional values: migrations 0041–0042 (lead, 2026-11-04). ## Zones -Served in exactly the JSON array `shavit-zones-json` reads, so servers point `shavit_zones_json_url` at `/v1/maps/{map}/zones`. A `404` means SourceJump has no zones for the map, and servers don't submit there. The `SourceJump-Zone-Set-Version` header (on `304` too) names the set served. Staff publish zone sets (`staff-api.md`); everyone sees the set in force at `/maps/{map}/zones`. Runs carry a zone fingerprint, stored as sent; checking it comes with run verification. +Served in exactly the JSON array `shavit-zones-json` reads, so servers point `shavit_zones_json_url` at `/v1/maps/{map}/zones`. A `404`: SourceJump has no zones for the map; servers don't submit there. The `SourceJump-Zone-Set-Version` header (on `304` too) names the set served. Staff publish zone sets (`staff-api.md`); everyone sees the set in force at `/maps/{map}/zones`. Runs carry a zone fingerprint, stored as sent; checking it comes with run verification. ## Not yet decided or built -- Field names can still change: no client uses them yet. Once plugin work starts, the lead approves the contract and it's copied to the plugin repo. -- Whether old plugin endpoints keep working, how zones are submitted and reviewed, and whether keyless servers' queued runs can be imported later. +- Field names can still change: no client uses them yet. Once plugin work starts, the lead approves the contract and it goes to the plugin repo. +- Whether old plugin endpoints keep working, how zones are submitted and reviewed, and whether keyless servers' queued runs can be imported. diff --git a/docs/site-api.md b/docs/site-api.md index 3c832e4..29531dd 100644 --- a/docs/site-api.md +++ b/docs/site-api.md @@ -1,30 +1,31 @@ # Site API -What the endpoints behind the website do: sign-in, players, maps, the server list and community posts; the staff tools are in `staff-api.md`. Rules for every client (errors, retries, SteamIDs) and game servers' endpoints: `api.md`. +What the endpoints behind the website do: sign-in, players, maps, the server list and community posts; staff tools: `staff-api.md`. Rules for every client (errors, retries, SteamIDs) and game servers' endpoints: `api.md`. ## Sign-in and sessions Players sign in with Steam (OpenID 2.0); the endpoints answer browsers (redirects, cookies) via the site's origin (Caddy in production, Next.js locally). - Steam must confirm its answer (`check_authentication`). Only signed fields are read, the return URL must be our callback, a nonce works once, under 5 minutes old (`openid_nonces`). The callback URL must carry the value `/v1/auth/steam` put in the `sj_sign_in` cookie, tying sign-in to its browser. Refused: `/sign-in/failed`; cancelled: back where they were. - `return_to` must be a path on our site; anything else becomes `/`. - A session is 32 random bytes in the `sj_session` cookie (`HttpOnly; Secure; SameSite=Lax`). Only the SHA-256 is stored. It lasts 30 days from last use (expiry moves at most daily). -- Sign-out also requires our `Origin` header. A missing session answers `401` without `WWW-Authenticate`. +- Sign-out also needs our `Origin` header. A missing session answers `401` without `WWW-Authenticate`. - `SJ_PUBLIC_URL` is where players reach the site; redirects and the origin check use it. ## Players and privileges - Profiles take a SteamID64, SteamID2 or SteamID3 and answer with a SteamID64. - Per style, a profile counts completed maps (main tracks, out of the map list's count), completed bonuses and world records, and carries the first 50 main-track personal bests by map; `…/personal-bests?style=&tracks=main|bonuses&cursor=` pages on; `records=true` keeps only 2.0 world records. Without `style`, every style, newest first; `all_styles` counts across styles. Ranks: `main_standing`, `bonus_standing` (lead, 2026-11-04). Personal bests have a placement (ties share one), `tier` and `world_record_time`; profiles `tier_count`. -- `PUT /v1/players/{player}/details` (rules in `players/details.rs`): setup and a country (`GET /v1/countries`), a save per 5 s; others' need `manage_bans` and a logged reason. Old-site setup shows first. -- Avatar, country (unless the player picked one) and (until a run gives one) name come from their public Steam profile XML, fetched at sign-in, and when a day old after a run or a view (an hour after a failed one): one request per 2 s, 50 queued, one per player. Country names map to ISO codes in `players/countries.rs`. -- Staff privileges are a bitmap in `players.privileges` (`players/privileges.rs`). Bit positions never change; the API names privileges and never sends numbers. `players.restrictions` is unused (bans hold restrictions). The CLI's `privileges grant …`, `revoke`, `list` and the staff tools share `staff/privileges.rs`. +- `PUT /v1/players/{player}/details` (`players/details.rs`): setup and a country (`GET /v1/countries`), a save per 5 s; others' need `manage_bans` and a logged reason. Old-site setup shows first. +- Country: a run's server GeoIP code, else the player's pick (shown until the next such run), else Steam's. +- Avatar, country and (until a run gives one) name come from their public Steam profile XML, fetched at sign-in, and when a day old after a run or a view (an hour after a failed one): one request per 2 s, 50 queued, one per player. Country names map to ISO codes in `players/countries.rs`. +- Staff privileges are a bitmap in `players.privileges` (`players/privileges.rs`). Bit positions never change; the API names privileges, never numbers. `players.restrictions` is unused (bans hold restrictions). The CLI's `privileges grant …`, `revoke`, `list` and the staff tools share `staff/privileges.rs`. ## Maps and leaderboards - The map list holds every map with a run (`maps.last_run_at`, set by the ingest); whether one is ranked is open. Sorts: name, players, last/first run (`listed_at`), tier, main-track record; `tier` keeps one tier. `player` (any SteamID form) with `completed=true|false` keeps maps whose main track they have or haven't finished in the list's style; `completed` counts them. `stats`: tiers, 5 newest, 5 most players this week. -- Leaderboards rank personal bests per map, style and track; equal times share a place, and the earlier run is listed first. The world record of a tie belongs to whoever set it first. -- `GET /v1/maps/{map}` carries every style and track's top 25, `next_cursor` and WR history, so a map page switches between them without another request. `…/leaderboard?cursor=` pages on from there; cursors are opaque. -- WR history is every run faster than all runs that finished before it on that leaderboard, by `finished_at`. Ties don't count. +- Leaderboards rank personal bests per map, style and track; equal times share a place, the earlier run listed first. A tie's world record belongs to whoever set it first. +- `GET /v1/maps/{map}` carries every style and track's top 25, `next_cursor` and WR history, so a map page switches between them without a request. `…/leaderboard?cursor=` pages on from there; cursors are opaque. +- WR history is every run faster than all runs that finished before it on that board, by `finished_at`. Ties don't count. - Tiers: the `tiers` policy holds the tier count, `map_tiers` the tier per map and track (append-only, newest in force). The API serves no tier until a count is published. -- Any run opens by ID with stats, server and place (while it's a personal best); compliance and keys stay private. +- Any run opens by ID with stats, server and place (while a personal best); compliance and keys stay private. - Pre-2.0 runs (`legacy_*` tables, `legacy.rs`) count toward no 2.0 standing: not WRs, WR histories, placements or `…/records`. The normal style's main track has two more views, `view=all` (each player's faster of 2.0 and legacy) and `view=legacy`, on `…/leaderboard` and `…/personal-bests`; entries carry `legacy`; a legacy `run_id` is the old site's, at `GET /v1/legacy-runs/{id}` (no run page). A map's `legacy_record_history` charts the Pre-2.0 view. Banned players' legacy runs are left out. Legacy-only maps and players get pages and show in search. -- The tier count is published with the CLI's `tiers count` (it can't drop below a tier a map holds). Staff rate tracks and set images and descriptions on the map's Manage view (`/maps/{map}/manage`), or with the CLI's `maps tier` and `maps image`, logged. +- The CLI's `tiers count` publishes the tier count (never below a tier a map holds). Staff rate tracks and set images and descriptions on the map's Manage view (`/maps/{map}/manage`), or with the CLI's `maps tier` and `maps image`, logged. - A map holds up to 10 pictures (`map_images`, in order; the first is the cover). The API reads PNG, JPEG or WebP up to 15 MB, crops to 16:9, centred (at least 1920×1080), and stores 1920×1080 and 480×270 WebP at quality 80 (`maps/image.rs`), named by content hash, cached for good, deleted with the picture. `GET /v1/maps/{map}` carries `images`, each with both URLs and `focus` (0–100, the strip a banner shows); lists carry the cover as `image`. Browsers read the files from `SJ_S3_PUBLIC_URL`; the API only writes them (ADR 0006). - Staff set `description` (≤1000 chars), `released` (year, month or day) and `mapper` (made if new) diff --git a/web/src/api/schema.ts b/web/src/api/schema.ts index 26fd2fe..7a50b51 100644 --- a/web/src/api/schema.ts +++ b/web/src/api/schema.ts @@ -1537,7 +1537,10 @@ export interface components { /** @description New details for a profile. Every field is replaced: leave one out or null to clear it. */ DetailsInput: { aspect?: components["schemas"]["Aspect"] | null; - /** @description An ISO 3166-1 alpha-2 code to show instead of the Steam profile's country; null to show Steam's. */ + /** + * @description An ISO 3166-1 alpha-2 code to show instead of Steam's or a game server's, until a run's server finds one; + * null to stop showing the player's pick. + */ country_code?: string | null; /** * Format: int32 @@ -2347,9 +2350,12 @@ export interface components { */ all_styles: components["schemas"]["StyleTotals"]; avatar_url?: string | null; - /** @description Whether the player picked `country_code` themselves, rather than it coming from Steam. */ + /** @description Whether the player picked `country_code` themselves, rather than it coming from a game server or Steam. */ country_chosen: boolean; - /** @description ISO 3166-1 alpha-2: the one the player picked, or else their Steam profile's. None if neither has one. */ + /** + * @description ISO 3166-1 alpha-2: the latest one a game server found for them, the player's pick if they made it + * since, or else their Steam profile's. None if none has one. + */ country_code?: string | null; details?: components["schemas"]["PlayerDetails"] | null; /** @description Whether `details` are what they had on the old site, shown until they save their own. */ @@ -3015,6 +3021,14 @@ export interface components { world_record_time?: number | null; }; RunPlayer: { + /** + * @description The player's country, as the game server found it from their address with SourceMod's `GeoipCode2`: an ISO + * 3166-1 alpha-2 code. Leave it out when the lookup finds nothing; send only the code, never the address. It + * becomes the player's flag. A code SourceJump doesn't know as a country is ignored and the run is stored + * anyway. Runs only: detections ignore it. + * @example SE + */ + country_code?: string | null; name: string; /** @example 76561197960287930 */ steamid64: string; diff --git a/web/src/features/site/navigation.ts b/web/src/features/site/navigation.ts index 289106c..bc7fcae 100644 --- a/web/src/features/site/navigation.ts +++ b/web/src/features/site/navigation.ts @@ -54,4 +54,9 @@ export const communityLinks = [ brand: "tiktok", href: "https://www.tiktok.com/@sourcejump.net", }, + { + label: "Instagram", + brand: "instagram", + href: "https://www.instagram.com/sourcejump_official", + }, ] as const; diff --git a/web/src/ui/BrandIcon.tsx b/web/src/ui/BrandIcon.tsx index 813f996..a44aca9 100644 --- a/web/src/ui/BrandIcon.tsx +++ b/web/src/ui/BrandIcon.tsx @@ -1,8 +1,9 @@ // The logos of the services SourceJump's community uses, for links to them and Steam sign-in: each brand's current // mark, paths from Simple Icons (simpleicons.org, CC0), on a 24 × 24 grid. Plain, a logo takes the text color; // `colored`, it's drawn as the brand draws it: Discord's blurple, YouTube's red with a white play button, Steam's -// mark in its light client blue, TikTok's white note over its cyan and pink copies; `round`, as a round badge, -// the mark in white on a circle of the brand's color (YouTube's, its own round badge). +// mark in its light client blue, TikTok's white note over its cyan and pink copies, Instagram's pink; `round`, as a +// round badge, the mark in white on a circle of the brand's color (YouTube's, its own round badge; Instagram's, on its +// yellow-to-purple gradient). import { type SVGProps, useId } from "react"; import { classNames } from "./classNames"; @@ -16,10 +17,11 @@ const paths = { "M11.979 0C5.678 0 .511 4.86.022 11.037l6.432 2.658c.545-.371 1.203-.59 1.912-.59.063 0 .125.004.188.006l2.861-4.142V8.91c0-2.495 2.028-4.524 4.524-4.524 2.494 0 4.524 2.031 4.524 4.527s-2.03 4.525-4.524 4.525h-.105l-4.076 2.911c0 .052.004.105.004.159 0 1.875-1.515 3.396-3.39 3.396-1.635 0-3.016-1.173-3.331-2.727L.436 15.27C1.862 20.307 6.486 24 11.979 24c6.627 0 11.999-5.373 11.999-12S18.605 0 11.979 0zM7.54 18.21l-1.473-.61c.262.543.714.999 1.314 1.25 1.297.539 2.793-.076 3.332-1.375.263-.63.264-1.319.005-1.949s-.75-1.121-1.377-1.383c-.624-.26-1.29-.249-1.878-.03l1.523.63c.956.4 1.409 1.5 1.009 2.455-.397.957-1.497 1.41-2.454 1.012H7.54zm11.415-9.303c0-1.662-1.353-3.015-3.015-3.015-1.665 0-3.015 1.353-3.015 3.015 0 1.665 1.35 3.015 3.015 3.015 1.663 0 3.015-1.35 3.015-3.015zm-5.273-.005c0-1.252 1.013-2.266 2.265-2.266 1.249 0 2.266 1.014 2.266 2.266 0 1.251-1.017 2.265-2.266 2.265-1.253 0-2.265-1.014-2.265-2.265z", tiktok: "M12.525.02c1.31-.02 2.61-.01 3.91-.02.08 1.53.63 3.09 1.75 4.17 1.12 1.11 2.7 1.62 4.24 1.79v4.03c-1.44-.05-2.89-.35-4.2-.97-.57-.26-1.1-.59-1.62-.93-.01 2.92.01 5.84-.02 8.75-.08 1.4-.54 2.79-1.35 3.94-1.31 1.92-3.58 3.17-5.91 3.21-1.43.08-2.86-.31-4.08-1.03-2.02-1.19-3.44-3.37-3.65-5.71-.02-.5-.03-1-.01-1.49.18-1.9 1.12-3.72 2.58-4.96 1.66-1.44 3.98-2.13 6.15-1.72.02 1.48-.04 2.96-.04 4.44-.99-.32-2.15-.23-3.02.37-.63.41-1.11 1.04-1.36 1.75-.21.51-.15 1.07-.14 1.61.24 1.64 1.82 3.02 3.5 2.87 1.12-.01 2.19-.66 2.77-1.61.19-.33.4-.67.41-1.06.1-1.79.06-3.57.07-5.36.01-4.03-.01-8.05.02-12.07z", + instagram: + "M7.0301.084c-1.2768.0602-2.1487.264-2.911.5634-.7888.3075-1.4575.72-2.1228 1.3877-.6652.6677-1.075 1.3368-1.3802 2.127-.2954.7638-.4956 1.6365-.552 2.914-.0564 1.2775-.0689 1.6882-.0626 4.947.0062 3.2586.0206 3.6671.0825 4.9473.061 1.2765.264 2.1482.5635 2.9107.308.7889.72 1.4573 1.388 2.1228.6679.6655 1.3365 1.0743 2.1285 1.38.7632.295 1.6361.4961 2.9134.552 1.2773.056 1.6884.069 4.9462.0627 3.2578-.0062 3.668-.0207 4.9478-.0814 1.28-.0607 2.147-.2652 2.9098-.5633.7889-.3086 1.4578-.72 2.1228-1.3881.665-.6682 1.0745-1.3378 1.3795-2.1284.2957-.7632.4966-1.636.552-2.9124.056-1.2809.0692-1.6898.063-4.948-.0063-3.2583-.021-3.6668-.0817-4.9465-.0607-1.2797-.264-2.1487-.5633-2.9117-.3084-.7889-.72-1.4568-1.3876-2.1228C21.2982 1.33 20.628.9208 19.8378.6165 19.074.321 18.2017.1197 16.9244.0645 15.6471.0093 15.236-.005 11.977.0014 8.718.0076 8.31.0215 7.0301.0839m.1402 21.6932c-1.17-.0509-1.8053-.2453-2.2287-.408-.5606-.216-.96-.4771-1.3819-.895-.422-.4178-.6811-.8186-.9-1.378-.1644-.4234-.3624-1.058-.4171-2.228-.0595-1.2645-.072-1.6442-.079-4.848-.007-3.2037.0053-3.583.0607-4.848.05-1.169.2456-1.805.408-2.2282.216-.5613.4762-.96.895-1.3816.4188-.4217.8184-.6814 1.3783-.9003.423-.1651 1.0575-.3614 2.227-.4171 1.2655-.06 1.6447-.072 4.848-.079 3.2033-.007 3.5835.005 4.8495.0608 1.169.0508 1.8053.2445 2.228.408.5608.216.96.4754 1.3816.895.4217.4194.6816.8176.9005 1.3787.1653.4217.3617 1.056.4169 2.2263.0602 1.2655.0739 1.645.0796 4.848.0058 3.203-.0055 3.5834-.061 4.848-.051 1.17-.245 1.8055-.408 2.2294-.216.5604-.4763.96-.8954 1.3814-.419.4215-.8181.6811-1.3783.9-.4224.1649-1.0577.3617-2.2262.4174-1.2656.0595-1.6448.072-4.8493.079-3.2045.007-3.5825-.006-4.848-.0608M16.953 5.5864A1.44 1.44 0 1 0 18.39 4.144a1.44 1.44 0 0 0-1.437 1.4424M5.8385 12.012c.0067 3.4032 2.7706 6.1557 6.173 6.1493 3.4026-.0065 6.157-2.7701 6.1506-6.1733-.0065-3.4032-2.771-6.1565-6.174-6.1498-3.403.0067-6.156 2.771-6.1496 6.1738M8 12.0077a4 4 0 1 1 4.008 3.9921A3.9996 3.9996 0 0 1 8 12.0077", } as const; const YOUTUBE_PLAY = "M9.545 15.568V8.432L15.818 12z"; -/** YouTube's play button alone, centred on the circle and a little larger: the red frame around it is the badge. */ /** * YouTube's round badge as YouTube draws it: the white play block on a red circle, the play triangle cut out of it. * On a 1000-unit grid, scaled to the icon's 24. @@ -31,19 +33,23 @@ const YOUTUBE_ROUND = { }; /** Each badge's circle, in the brand's own color. */ -const roundFills: Record<"discord" | "steam" | "tiktok", string> = { - discord: "#5865f2", - // Steam's lighter blue: its darkest, #1b2838, all but vanishes on the footer. - steam: "#2a475e", - tiktok: "#000", -}; +const roundFills: Record<"discord" | "steam" | "tiktok" | "instagram", string> = + { + discord: "#5865f2", + // Its gradient's middle, under the gradient itself (drawn where the badge has one). + instagram: "#e1306c", + // Steam's lighter blue: its darkest, #1b2838, all but vanishes on the footer. + steam: "#2a475e", + tiktok: "#000", + }; /** * How large each mark sits in its circle, scaled about the centre. By eye rather than by box: TikTok's narrow note * at Discord's scale looked smaller than the rest. */ -const insets: Record<"discord" | "tiktok", string> = { +const insets: Record<"discord" | "tiktok" | "instagram", string> = { discord: "translate(12 12) scale(0.58) translate(-12 -12)", + instagram: "translate(12 12) scale(0.56) translate(-12 -12)", tiktok: "translate(12 12) scale(0.68) translate(-12 -12)", }; @@ -54,6 +60,7 @@ const colors: Record = { youtube: "text-[#ff0000]", steam: "text-[#c7d5e0]", tiktok: "text-[#fff]", + instagram: "text-[#e4405f]", }; /** @@ -72,7 +79,7 @@ export function BrandIcon({ round?: boolean; } & SVGProps) { const d = paths[brand]; - // Each Steam badge masks with its own id, so several on one page don't share one. + // Each Steam badge's mask and Instagram badge's gradient has its own id, so several on one page don't share one. const clip = useId(); if (round) { return ( @@ -96,7 +103,22 @@ export function BrandIcon({ ) : ( <> - + {brand === "instagram" && ( + // Instagram's glow: yellow from the bottom left, through orange and pink, to purple. + + + + + + + + )} + {brand === "tiktok" && ( <>