tools: name players through player.setname, and the character groups and four fault classes (#23)

This commit is contained in:
2026-11-15 12:01:30 +01:00
parent f134534c6c
commit c4b97ec16c
10 changed files with 405 additions and 132 deletions
+181 -6
View File
@@ -19,6 +19,10 @@
## OWNER_PROP the `owner` property bucket reached someone who does not control the token
## GM_PROP the `gm` property bucket reached a player at all
## STATUS_SOURCE a player frame carried the `source` of a status (5.5, 6.1 note 6)
## ACTUAL_NAME an actual name the subject was never told reached it (8)
## CHAR_LIST another player's character record or encountered entry reached the subject
## CONTROLLER_CHANGE a token changed controller in a group that asked for no such thing (8)
## CHAR_OWNER_PROP a character's owner bucket reached a player who does not own it (8)
## GEOMETRY the recomputed polygon disagrees with the clear-segment oracle (sanity)
## PROTOCOL a frame the catalogue does not allow, a bad `n` sequence, a missing hello block
##
@@ -27,10 +31,13 @@ import std/[algorithm, json, math, options, os, sets, strutils, tables]
import geometry
const
AllowedTypes = ["hello", "ack", "token", "token_gone", "vision", "explored"]
BannedKeys = ["walls", "wall", "wall_gone", "a", "b", "open", "kind", "controller", "gm_only",
"flags", "descriptive_name", "actual_name", "reveal_all", "revealed", "source",
"radius_own", "extra"]
AllowedTypes = ["hello", "ack", "roster", "token", "token_gone", "vision", "explored",
"character", "character_gone", "encountered"]
BannedAlways = ["walls", "wall", "wall_gone", "a", "b", "open", "kind", "controller", "gm_only",
"flags", "radius_own", "extra"]
BannedToken = ["descriptive_name", "actual_name", "reveal_all", "revealed"]
BannedCharacterTop = ["owner", "reveal_all", "revealed"] ## top-level only: `props.owner` is fine
BannedEncountered = ["player", "character_id", "pos"]
type
TruthToken = object
@@ -42,15 +49,28 @@ type
radius: float
props: JsonNode ## the GM's three buckets (the truth for every bucket question)
statuses: seq[string] ## the status names the GM sees, in order
characterId: string ## "" = a plain token (8)
descriptive, actual: string ## a plain token's own names ("" for a linked token)
revealAll: bool ## a plain token's reveal flag, "" names otherwise
revealed: seq[int] ## the players a plain token's actual name was revealed to
TruthCharacter = object
owner: int
descriptive, actual: string
revealAll: bool
revealed: seq[int]
props: JsonNode
Truth = object
walls: seq[Wall]
tokens: Table[string, TruthToken]
characters: Table[string, TruthCharacter]
Group = object
label: string
gmMsgs: seq[JsonNode]
subjMsgs: seq[JsonNode]
intents: seq[JsonNode] ## what the clients asked for in this group (see CONTROLLER_CHANGE)
var fails = 0
var classes: CountTable[string]
@@ -86,6 +106,8 @@ proc readGroups(path, subject: string): seq[Group] =
let who = j["who"].getStr
if who == "GM": groups[current].gmMsgs.add j["m"]
elif who == subject: groups[current].subjMsgs.add j["m"]
of "intent":
if current >= 0: groups[current].intents.add j
else: discard
groups
@@ -136,11 +158,33 @@ proc applyGmTokens(truth: var Truth, m: JsonNode) =
if m["vision_radius"].kind != JNull: t.visionRadius = some(m["vision_radius"].getFloat)
t.props = m["props"]
for st in m["statuses"]: t.statuses.add st["status"].getStr
# Slice 8 (#23): the GM frame always carries `character_id`, and a plain token carries its own
# names and reveal state (a linked token's live on the `character` record).
if m.hasKey("character_id") and m["character_id"].kind != JNull:
t.characterId = m["character_id"].getStr
if m.hasKey("descriptive_name"):
t.descriptive = m["descriptive_name"].getStr
t.actual = m["actual_name"].getStr
t.revealAll = m["reveal_all"].getBool
for p in m["revealed"]: t.revealed.add p.getInt
truth.tokens[m["id"].getStr] = t
of "token_gone":
truth.tokens.del m["id"].getStr
else: discard
proc applyGmCharacters(truth: var Truth, m: JsonNode) =
case m["t"].getStr
of "character":
var c = TruthCharacter(owner: m["owner"].getInt,
descriptive: m["descriptive_name"].getStr,
actual: m["actual_name"].getStr,
revealAll: m["reveal_all"].getBool, props: m["props"])
for p in m["revealed"]: c.revealed.add p.getInt
truth.characters[m["id"].getStr] = c
of "character_gone":
truth.characters.del m["id"].getStr
else: discard
# ---------------------------------------------------------------------------------------------------
# Independent oracles
@@ -191,6 +235,24 @@ proc keysDeep(node: JsonNode, into: var HashSet[string]) =
# ---------------------------------------------------------------------------------------------------
proc subjectKnewActual(truth: Truth, t: TruthToken, me: int): bool =
## DESIGN 8: a player is told a subject's actual name when they own the character it belongs to,
## when the GM revealed it to everyone, or when the GM revealed it to them.
if t.characterId.len > 0:
if not truth.characters.hasKey(t.characterId): return false
let c = truth.characters[t.characterId]
result = c.owner == me or c.revealAll or me in c.revealed
else:
result = t.revealAll or me in t.revealed
proc subjectNames(truth: Truth, t: TruthToken): (string, string) =
## The descriptive and actual name of what a token figures: the character's when linked (8).
if t.characterId.len > 0 and truth.characters.hasKey(t.characterId):
let c = truth.characters[t.characterId]
(c.descriptive, c.actual)
else:
(t.descriptive, t.actual)
proc checkArgs(): (string, string) =
if paramCount() < 2:
echo "usage: leakcheck <transcript.jsonl> <SUBJECT>"
@@ -223,12 +285,16 @@ proc main() =
var groupsSeen = 0
var recomputedSoFar: HashSet[int] # every cell the subject has ever seen, recomputed
var seenAny: HashSet[string] # token ids the subject was legitimately shown
var encounterable: HashSet[string] # token ids the subject may have met (independent oracle)
var viewCharacters: HashSet[string] # character ids the subject was sent
var prevController: Table[string, int] # controller of each token at the previous group
for g in groups:
inc groupsSeen
for m in g.gmMsgs:
applyGmWalls(truth, wallIds, m)
applyGmTokens(truth, m)
applyGmCharacters(truth, m)
# player ids: the subject from its hello, the other from any token it does not control
for m in g.subjMsgs:
@@ -253,6 +319,15 @@ proc main() =
let polys = polygonsOf(truth, me, sceneDefault)
let otherPolys = if other != 0: polygonsOf(truth, other, sceneDefault) else: @[]
# The encountered oracle, computed from the GM's truth and the subject's own polygons - never
# from what the subject was sent: every token the subject can see right now is one it may have
# met. It only grows, exactly like the server's list (8).
var visibleNow = initHashSet[string]()
for id, actual in truth.tokens:
if actual.controller == me or (not actual.gmOnly and insideAny(polys, actual.pos)):
visibleNow.incl id
encounterable.incl id
# the other player's explored cells, independently (attribute leaks, 3.1 OTHER_PLAYER)
for (_, pts) in otherPolys:
for (cx, cy) in cellsTouched(pts, float(cell)):
@@ -276,8 +351,19 @@ proc main() =
if k == "source":
# 5.5 / 6.1 note 6: a viewer sees the status, never what caused it.
fail "STATUS_SOURCE", "player frame carries a status source"
elif k in BannedKeys:
elif k in BannedAlways:
fail "WALLDATA", "player frame has wall-ish/GM-only key " & k
if t == "token":
for k in BannedToken:
if k in keys: fail "WALLDATA", "a `token` frame for a player carries " & k
elif t == "character":
# An owner reads both names and its own `props.owner`; it must never learn `owner` (theirs),
# `reveal_all` or the list of players a name was revealed to.
for k, _ in m:
if k in BannedCharacterTop: fail "CHAR_LIST", "a `character` frame carries " & k
elif t == "encountered":
for k in BannedEncountered:
if k in keys: fail "CHAR_LIST", "an `encountered` frame carries " & k
case t
of "ack":
# only a bad shape is interesting here; the driver already checked the outcomes it expected
@@ -321,6 +407,34 @@ proc main() =
let wantMine = actual.controller == me
if m["mine"].getBool != wantMine:
fail (if wantMine: "OWN_VIEW" else: "OTHER_PLAYER"), "mine flag on " & id
# names (8): the one name this recipient may see, from the character when the token is linked
let (dname, aname) = subjectNames(truth, actual)
let knows = subjectKnewActual(truth, actual, me)
let wantName = if knows: aname else: dname
if m["name"].getStr != wantName:
if aname != dname and m["name"].getStr == aname:
fail "ACTUAL_NAME", "token " & id & " carries an actual name the subject was not told"
else:
fail "OWN_VIEW", "token " & id & " name " & m["name"].getStr & " != " & wantName
# `character_id` goes only to the GM and the character's owner (6.1 leak note 2): showing it
# to anyone else would link two tokens of one character (10.3 CHAR_LIST).
if m.hasKey("character_id"):
let owned = actual.characterId.len > 0 and truth.characters.hasKey(actual.characterId) and
truth.characters[actual.characterId].owner == me
if not owned or m["character_id"].getStr != actual.characterId:
fail "CHAR_LIST", "token " & id & " carries character_id to a non-owner"
# cprops: the character's `public` bucket and nothing else, `{}` when there is nothing to say
if m.hasKey("cprops"):
for name, _ in m["cprops"]:
if name != "public":
fail "CHAR_OWNER_PROP", "token " & id & " cprops carries the " & name & " bucket"
var want = newJObject()
if actual.characterId.len > 0 and truth.characters.hasKey(actual.characterId) and
truth.characters[actual.characterId].owner != me:
want = truth.characters[actual.characterId].props["public"]
let got = if m["cprops"].hasKey("public"): m["cprops"]["public"] else: newJObject()
if got != want:
fail "CHAR_OWNER_PROP", "token " & id & " cprops public bucket is not the truth"
view[id] = m
let visible = wantMine or (not actual.gmOnly and insideAny(polys, actual.pos))
if not visible:
@@ -341,6 +455,52 @@ proc main() =
let actual = truth.tokens[id]
if actual.controller == me or (not actual.gmOnly and insideAny(polys, actual.pos)):
fail "WITHHELD", "token_gone for a token still visible: " & id
of "character":
# 6.1: a player gets only the characters it owns, with both names and the public/owner
# buckets. Anything else is CHAR_LIST (10.3).
let id = m["id"].getStr
if not truth.characters.hasKey(id):
fail "CHAR_LIST", "a character record the GM's truth does not have: " & id
elif truth.characters[id].owner != me:
fail "CHAR_LIST", "another player's character record: " & id
else:
let c = truth.characters[id]
if m["descriptive_name"].getStr != c.descriptive or
m["actual_name"].getStr != c.actual:
fail "PROTOCOL", "character " & id & " names differ from the truth"
for name, value in m["props"]:
if not c.props.hasKey(name) or c.props[name] != value:
fail (if name == "public": "OWN_VIEW" else: "CHAR_OWNER_PROP"),
"character " & id & " has a " & name & " bucket that is not the truth"
viewCharacters.incl id
of "character_gone":
let id = m["id"].getStr
if id notin viewCharacters:
fail "PROTOCOL", "character_gone for a character this player never had: " & id
viewCharacters.excl id
of "encountered":
# 6.1: the subject's own list only; an entry names a token the subject really did see, under
# the name it knows (8). No position, no character link.
for e in m["set"]:
let id = e["id"].getStr
if id notin encounterable:
fail "CHAR_LIST", "encountered entry the subject never saw: " & id
elif truth.tokens.hasKey(id):
let (dname, aname) = subjectNames(truth, truth.tokens[id])
# Only a *different* name leaks: a subject whose two names are the same string has no
# secret to keep.
if aname != dname and e["name"].getStr == aname and
not subjectKnewActual(truth, truth.tokens[id], me):
fail "ACTUAL_NAME", "encountered " & id & " carries an unrevealed actual name"
if m.hasKey("del"):
for d in m["del"]:
if d.getStr notin encounterable:
fail "CHAR_LIST", "del for an entry the subject never had: " & d.getStr
of "roster":
# 6.1 leak note 4: players see named players only.
for pl in m["players"]:
if pl["name"].kind == JNull or pl["name"].getStr.len == 0:
fail "PROTOCOL", "the roster handed a player an unnamed entry"
of "vision":
var got: seq[(string, seq[Vec])]
for p in m["polys"]:
@@ -396,9 +556,24 @@ proc main() =
exploredSent.incl k
else: discard
# --- CONTROLLER_CHANGE (10.3) ----------------------------------------------------------------
# A token's controller may move only when an intent asked for it (`token.create` names one,
# `token.update` patches `controller`, `player.remove` hands them to the GM). A character edit
# that changed a controller would show up here (DESIGN 8: the controller is set on the token).
var controllerIntent = false
for it in g.intents:
let t = it["t"].getStr
if t == "token.create" or t == "player.remove": controllerIntent = true
elif t == "token.update" and it["f"].hasKey("controller"): controllerIntent = true
for id, actual in truth.tokens:
if prevController.hasKey(id) and prevController[id] != actual.controller and
not controllerIntent:
fail "CONTROLLER_CHANGE", "token " & id & " changed controller in group " & g.label
prevController[id] = actual.controller
# --- the set of tokens the subject should hold at the end of this group ---------------------
for id, actual in truth.tokens:
let want = actual.controller == me or (not actual.gmOnly and insideAny(polys, actual.pos))
let want = id in visibleNow
let have = view.hasKey(id)
if want and not have:
fail "WITHHELD", "visible token never sent: " & id & " (group " & g.label & ")"