names: per-player reveal, one encountered write path, link by update (#27, #29, #30)

name.reveal wrote the subject's actual name into the encountered row of every
player who had met it: the SQL had no player predicate, so the leak was silent
live and visible only after a restart. rewriteEncountered is now the one path
that keeps a snapshot in step with its subject: it rewrites the SQLite row and
the live in-memory entry together from the name rule, takes onlyPlayer for
name.reveal (every player for reveal_all), and also runs on a rename, a link
change and an owner change, so the wire and a post-restart reload cannot
disagree (#30). The DB-only renameEncountered*/revealEncountered* helpers are
gone, which is what let the two stores drift.

token.update {character_id} now drops the token's own two names as part of the
link patch (#29): a plain token can be linked, names supplied with a link stay
invalid and unlinking still needs both names.

Tests: tcharacters covers the per-player row, the DB/memory equality, the link
handover; restart.test.mjs builds three named players, reveals to one of them
and asserts the rows directly and the whole resync over SIGTERM/SIGKILL, plus a
mid-session rename; leak.mjs/leakcheck.nim pit two players on the same subject
and pin each entry's expected name (STALE_NAME). Mutations e1-e3 and the
repointed b2 pin the three rules.
This commit is contained in:
2026-11-15 14:26:07 +01:00
parent e68c6eefbf
commit 8e045b0ac8
9 changed files with 528 additions and 93 deletions
+9 -1
View File
@@ -242,7 +242,15 @@ proc patched*(t: TokenRec, patch: TokenPatch): TokenRec =
if patch.kind.isSome: result.kind = patch.kind.get
if patch.descriptiveName.isSome: result.descriptiveName = patch.descriptiveName.get
if patch.actualName.isSome: result.actualName = patch.actualName.get
if patch.characterId.isSome: result.characterId = patch.characterId.get
if patch.characterId.isSome:
result.characterId = patch.characterId.get
# A link is a name handover (8): a linked token carries no names of its own, because the
# character's names are the ones a client sees. The handler refuses a patch that supplies names
# *with* a link, so dropping the stored pair here is what makes `token.update {character_id}`
# able to link a plain token at all (#29). An unlink must supply both names (6.1).
if result.characterId.isSome:
result.descriptiveName = ""
result.actualName = ""
if patch.controller.isSome: result.owner = patch.controller.get
if patch.gmOnly.isSome: result.gmOnly = patch.gmOnly.get
if patch.flags.isSome: result.flags = patch.flags.get