feat(rust): Teams from first-party clans (phase 9, protocol 6)
All checks were successful
PR Checks / server-tests (pull_request) Successful in 24s
PR Checks / frozen-manifest (pull_request) Successful in 46s
PR Checks / client-build (pull_request) Successful in 8m3s

A first-party Rust clan is a Team (R5). This module becomes the site's
Team provider and answers core from the plugin's `clans` board. Design
of record: docs/modules/rust/PLAN.md §24, D47-D58.

- The store: rust_clans, rust_clan_members and rust_clan_boards. A clan's
  identity is <serverId>:<clanId>:<createdMs> (D52), because the game
  restarts clan ids whenever its clan database version changes.
- The provider (D53): getTeams is complete only when every server's
  board is fresh, supported and untruncated. It is partial when some
  are, and refuses when none are. Freshness is judged by the website's
  clock, from when the board's `t` last advanced.
- Only a complete board may mark a clan gone. A board at the game's
  100-clan ceiling (D55), or one with an unreadable row, proves nothing
  about what it leaves out.
- Leadership is diffed board to board and published (D54). The five clan
  events are published as team.* kinds, and written to the Team feed as
  members-only lines (D49).
- Core only writes feed items for a Team it already holds. So the last 10
  minutes of clan events are re-offered on each board refresh, deduped by
  a sha1 key: core clamps a dedupeKey to 40 characters, and a readable key
  would be truncated into collisions.
- projectRoster and the clan page share one audience rule (D48): the
  clan's linked members and staff by default, re-read from the users row.
  The setting lives on Admin > Rust visibility, which also warns about
  uMod Clans (D47) and the ceiling.
- Public: GET servers/:id/clans (the list is public, D58) and
  GET clans/:externalId. The client adds a Clans tab and
  /rust/clans/:externalId, with three module slots for core's notify,
  activity and forum contributions (D56).
- Linking and unlinking an account ask core to reconcile Teams (D57).
- The clan kinds are staff-class in the public feed allowlist.
- PROTOCOL_VERSION is now 6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E14m6SuuY6i1vASFeGDBeY
This commit is contained in:
2026-09-23 05:14:18 -05:00
parent da1a393702
commit c94271104f
33 changed files with 3456 additions and 32 deletions

View File

@@ -701,3 +701,94 @@ CREATE TABLE IF NOT EXISTS rust_settings (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
ALTER TABLE rust_servers ADD COLUMN IF NOT EXISTS presence_audience VARCHAR(16) NULL;
-- ── Clans (phase 9, protocol 6) ───────────────────────────────────────────
--
-- Rust's FIRST-PARTY clans, which this module answers core's Team questions
-- from (R5, PLAN.md §24). Three tables, and the split is the same one the rest
-- of this file makes: what a board said (`rust_clans`, `rust_clan_members`),
-- and what this module knows about the board itself (`rust_clan_boards`).
--
-- **`external_id` is the Team's identity, and it is NOT the game's clan id.**
-- It is `<serverId>:<clanId>:<createdMs>` (D52). The game keeps clans in
-- `clans.<version>.db` with the version hard-coded, so a game update that bumps
-- it starts a fresh file whose ids restart at 1. Keyed on the id alone, the new
-- clan #1 would inherit the old clan #1's Team — its forum, its members-only
-- history — and core would read the swap as a rename.
--
-- **A clan that leaves the board is marked gone, not deleted.** `gone_at` is set
-- only when a board that is COMPLETE for its server no longer carries it: a
-- board truncated at the game's 100-clan ceiling (D55) proves nothing about a
-- clan it does not list. A gone clan is not offered to core, which is what lets
-- core archive its Team.
CREATE TABLE IF NOT EXISTS rust_clans (
external_id VARCHAR(160) NOT NULL PRIMARY KEY,
server_id VARCHAR(64) NOT NULL,
clan_id BIGINT NOT NULL,
created_ms BIGINT NOT NULL,
name VARCHAR(191) NOT NULL,
-- `#rrggbb`, as the plugin spells it. Stored as sent rather than parsed, and
-- re-checked on the way out (`model/clans`), because it ends up in a style.
color VARCHAR(16) NULL,
score BIGINT NOT NULL DEFAULT 0,
member_count INT UNSIGNED NOT NULL DEFAULT 0,
max_members INT UNSIGNED NULL,
first_seen DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
gone_at DATETIME NULL,
CONSTRAINT fk_rust_clans_server
FOREIGN KEY (server_id) REFERENCES rust_servers (id) ON DELETE CASCADE,
KEY idx_rust_clans_server (server_id, gone_at),
KEY idx_rust_clans_game_id (server_id, clan_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- One row per member per clan, replaced whole from each board.
--
-- `rank` is the role's rank, and **rank 1 is leader** — the game's own rule, and
-- several members may hold it. It is NULL when the member's role id matched no
-- role on the board: "not known" must never be read as "leads this clan".
--
-- There is deliberately no `last_seen`. The game has one; the plugin does not
-- send it, because when somebody was last on is presence (PLAN.md §23).
CREATE TABLE IF NOT EXISTS rust_clan_members (
external_id VARCHAR(160) NOT NULL,
steam_id VARCHAR(32) NOT NULL,
name VARCHAR(191) NULL,
role_rank INT NULL,
role_name VARCHAR(64) NULL,
joined_ms BIGINT NULL,
PRIMARY KEY (external_id, steam_id),
CONSTRAINT fk_rust_clan_members_clan
FOREIGN KEY (external_id) REFERENCES rust_clans (external_id) ON DELETE CASCADE,
KEY idx_rust_clan_members_steam (steam_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- What this module knows about each server's clan board, as opposed to what the
-- board said.
--
-- **Freshness is judged by THIS side's clock.** `board_t` is the plugin's own
-- timestamp on the board; `seen_at` is when this module first saw that value.
-- A board whose `t` stops advancing is a game that stopped talking, and the
-- age of `seen_at` is how long ago that was — comparing `board_t` to the
-- website's clock instead would let a game host whose clock runs ahead make a
-- stale board look current for as long as the skew lasts.
--
-- `umod_clans` is whether the optional uMod Clans plugin is loaded on that
-- server (D47): its clans are a separate system and never Teams, and the admin
-- page says so.
CREATE TABLE IF NOT EXISTS rust_clan_boards (
server_id VARCHAR(64) NOT NULL PRIMARY KEY,
board_t BIGINT NULL,
seen_at DATETIME NULL,
enabled TINYINT(1) NOT NULL DEFAULT 1,
supported TINYINT(1) NOT NULL DEFAULT 0,
truncated TINYINT(1) NOT NULL DEFAULT 0,
backend VARCHAR(64) NULL,
reason VARCHAR(255) NULL,
umod_clans TINYINT(1) NOT NULL DEFAULT 0,
clan_count INT UNSIGNED NOT NULL DEFAULT 0,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fk_rust_clan_boards_server
FOREIGN KEY (server_id) REFERENCES rust_servers (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;