diff --git a/README.md b/README.md index d9994ce..c1268f3 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,14 @@ SimpleAdmin groups have no display name or colour, so those come from a site con `"supporter": true` are listed apart from staff and can't sign in unless they hold `@css/generic`. +### Name history (optional) + +SimpleAdmin keeps one row per SteamID + IP in `sa_players_ips` and overwrites its name on each +connect, so a rename on the same IP loses the old name. `sql/players-ips-name-history.sql` adds +`name` to that table's primary key, so every name a SteamID has joined with is kept and shows up +on its player page and in name search. SimpleAdmin needs no changes. Run it once against the +SimpleAdmin database; the file has the revert. Names are still only recorded at connect. + ## Limitations and caveats - **Tested against a real MySQL 8.4** with SimpleAdmin 1.8.2b's migrations applied, and a fake game diff --git a/sql/players-ips-name-history.sql b/sql/players-ips-name-history.sql new file mode 100644 index 0000000..e71cc47 --- /dev/null +++ b/sql/players-ips-name-history.sql @@ -0,0 +1,30 @@ +-- Keep every name a SteamID has used, instead of overwriting it. +-- +-- CS2-SimpleAdmin records each connect with an upsert keyed on sa_players_ips' primary key, +-- (steamid, address), so a player who rejoins from the same IP under a new name overwrites the old +-- name. With name in the key, a new name on the same SteamID+IP is a new row; the same name again +-- still just bumps used_at. SimpleAdmin's own code is unchanged: its IP cache already keeps only +-- the newest row per IP, so multi-account and IP-ban checks behave as before. +-- +-- name becomes binary-collated so a case-only rename ("astra" -> "Astra") is also kept, and NOT +-- NULL because primary key columns can't be NULL (SimpleAdmin always writes a name). +-- +-- Only records names at connect, like before: a rename mid-session shows up on the next join. +-- Re-check after upgrading SimpleAdmin, in case a later migration rebuilds this table's key. + +UPDATE sa_players_ips SET name = '' WHERE name IS NULL; + +ALTER TABLE sa_players_ips + MODIFY name VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '', + DROP PRIMARY KEY, + ADD PRIMARY KEY (steamid, address, name); + +-- Revert (drops the older names, keeping the newest row per SteamID+IP): +-- +-- DELETE a FROM sa_players_ips a JOIN sa_players_ips b +-- ON a.steamid = b.steamid AND a.address = b.address +-- AND (a.used_at < b.used_at OR (a.used_at = b.used_at AND a.name < b.name)); +-- ALTER TABLE sa_players_ips +-- DROP PRIMARY KEY, +-- ADD PRIMARY KEY (steamid, address), +-- MODIFY name VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL;