tools: name players through player.setname, and the character groups and four fault classes (#23)
This commit is contained in:
@@ -26,9 +26,9 @@ async function mutate(client, payload) {
|
|||||||
client.waitFor((m, i) => i >= from && pred(m), ms) }
|
client.waitFor((m, i) => i >= from && pred(m), ms) }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function namedPlayer(stateDir, gm, name) {
|
async function namedPlayer(origin, gm, name) {
|
||||||
const player = await createPlayer(gm.ws)
|
const player = await createPlayer(gm.ws)
|
||||||
await namePlayer(stateDir, player.id, name)
|
await namePlayer(origin, player.key, name)
|
||||||
return player
|
return player
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ const frameOf = (ws, id) => [...ws.messages].reverse().find(m => m.t === 'token'
|
|||||||
test('token.resize: a per-token size, null back to the scene default, and the codes of 6.1', async () => {
|
test('token.resize: a per-token size, null back to the scene default, and the codes of 6.1', async () => {
|
||||||
await withGmServer(async (s, gmKey) => {
|
await withGmServer(async (s, gmKey) => {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const alice = await namedPlayer(s.stateDir, gm, 'Alice')
|
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
const tok = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc',
|
const tok = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc',
|
||||||
pos: [400, 400], descriptive_name: 'Alice',
|
pos: [400, 400], descriptive_name: 'Alice',
|
||||||
actual_name: 'Alice', controller: alice.id,
|
actual_name: 'Alice', controller: alice.id,
|
||||||
@@ -82,7 +82,7 @@ test('grow push and squeeze (5.6): pushed clear of a wall, or flagged squeezed w
|
|||||||
async () => {
|
async () => {
|
||||||
await withGmServer(async (s, gmKey) => {
|
await withGmServer(async (s, gmKey) => {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const alice = await namedPlayer(s.stateDir, gm, 'Alice')
|
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
// a 40 px corridor at x in [500, 540]: a token of r=15 fits, r=25 does not
|
// a 40 px corridor at x in [500, 540]: a token of r=15 fits, r=25 does not
|
||||||
const left = await gm.ws.request({ t: 'wall.add', scene: gm.sceneId, a: [500, 0], b: [500, 900],
|
const left = await gm.ws.request({ t: 'wall.add', scene: gm.sceneId, a: [500, 0], b: [500, 900],
|
||||||
kind: 'wall' })
|
kind: 'wall' })
|
||||||
@@ -140,7 +140,7 @@ test('stuck from a wall and from a GM placement, cleared by the removal and by a
|
|||||||
async () => {
|
async () => {
|
||||||
await withGmServer(async (s, gmKey) => {
|
await withGmServer(async (s, gmKey) => {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const alice = await namedPlayer(s.stateDir, gm, 'Alice')
|
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
const tok = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc',
|
const tok = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc',
|
||||||
pos: [1000, 1000], descriptive_name: 'Alice',
|
pos: [1000, 1000], descriptive_name: 'Alice',
|
||||||
actual_name: 'Alice', controller: alice.id,
|
actual_name: 'Alice', controller: alice.id,
|
||||||
@@ -190,7 +190,7 @@ test('stuck from a wall and from a GM placement, cleared by the removal and by a
|
|||||||
test('status.set and status.clear: the GM source, single entries, and the codes of 6.1', async () => {
|
test('status.set and status.clear: the GM source, single entries, and the codes of 6.1', async () => {
|
||||||
await withGmServer(async (s, gmKey) => {
|
await withGmServer(async (s, gmKey) => {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const alice = await namedPlayer(s.stateDir, gm, 'Alice')
|
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
const tok = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc', pos: [400, 400],
|
const tok = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc', pos: [400, 400],
|
||||||
descriptive_name: 'Alice', actual_name: 'Alice',
|
descriptive_name: 'Alice', actual_name: 'Alice',
|
||||||
controller: alice.id, flags: { vision: true } })
|
controller: alice.id, flags: { vision: true } })
|
||||||
@@ -252,7 +252,7 @@ test('status.set and status.clear: the GM source, single entries, and the codes
|
|||||||
test('prop.set / prop.unset: three buckets, the caps, and who may read which bucket', async () => {
|
test('prop.set / prop.unset: three buckets, the caps, and who may read which bucket', async () => {
|
||||||
await withGmServer(async (s, gmKey) => {
|
await withGmServer(async (s, gmKey) => {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const alice = await namedPlayer(s.stateDir, gm, 'Alice')
|
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
const tok = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc', pos: [400, 400],
|
const tok = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc', pos: [400, 400],
|
||||||
descriptive_name: 'Alice', actual_name: 'Alice',
|
descriptive_name: 'Alice', actual_name: 'Alice',
|
||||||
controller: alice.id, flags: { vision: true } })
|
controller: alice.id, flags: { vision: true } })
|
||||||
@@ -278,7 +278,7 @@ test('prop.set / prop.unset: three buckets, the caps, and who may read which buc
|
|||||||
assert.equal(playerFrame.props.gm, undefined)
|
assert.equal(playerFrame.props.gm, undefined)
|
||||||
|
|
||||||
// a bystander sees the public bucket only
|
// a bystander sees the public bucket only
|
||||||
const bob = await namedPlayer(s.stateDir, gm, 'Bob')
|
const bob = await namedPlayer(s.origin, gm, 'Bob')
|
||||||
await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc', pos: [420, 400],
|
await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc', pos: [420, 400],
|
||||||
descriptive_name: 'Bob', actual_name: 'Bob', controller: bob.id,
|
descriptive_name: 'Bob', actual_name: 'Bob', controller: bob.id,
|
||||||
flags: { vision: true } })
|
flags: { vision: true } })
|
||||||
@@ -363,7 +363,7 @@ test('restart: sizes, props and statuses come back with the same view', async ()
|
|||||||
let saved
|
let saved
|
||||||
try {
|
try {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const alice = await namedPlayer(stateDir, gm, 'Alice')
|
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
const tok = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc',
|
const tok = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc',
|
||||||
pos: [400, 400], descriptive_name: 'Alice',
|
pos: [400, 400], descriptive_name: 'Alice',
|
||||||
actual_name: 'Alice', controller: alice.id,
|
actual_name: 'Alice', controller: alice.id,
|
||||||
|
|||||||
+15
-5
@@ -4,8 +4,8 @@
|
|||||||
// prove nothing. The shipped build must contain no fault hook at all, and it must still pass.
|
// prove nothing. The shipped build must contain no fault hook at all, and it must still pass.
|
||||||
//
|
//
|
||||||
// Classes: HIDDEN_TOKEN, GMONLY_TOKEN, WALLDATA, WITHHELD, NO_REMOVE, OWN_VIEW, OTHER_PLAYER,
|
// Classes: HIDDEN_TOKEN, GMONLY_TOKEN, WALLDATA, WITHHELD, NO_REMOVE, OWN_VIEW, OTHER_PLAYER,
|
||||||
// EXPLORED, and from slice 7 (#22) OWNER_PROP, GM_PROP and STATUS_SOURCE. (The character and name
|
// EXPLORED, from slice 7 (#22) OWNER_PROP, GM_PROP, STATUS_SOURCE, and from slice 8 (#23)
|
||||||
// classes of 10.3 land with slice 8, the tile class with slice 9.)
|
// ACTUAL_NAME, CHAR_LIST, CONTROLLER_CHANGE, CHAR_OWNER_PROP. (The tile class lands with slice 9.)
|
||||||
import test from 'node:test'
|
import test from 'node:test'
|
||||||
import assert from 'node:assert/strict'
|
import assert from 'node:assert/strict'
|
||||||
import fs from 'node:fs'
|
import fs from 'node:fs'
|
||||||
@@ -16,10 +16,16 @@ import { projectRoot } from './lib.mjs'
|
|||||||
|
|
||||||
const results = path.join(projectRoot, 'results')
|
const results = path.join(projectRoot, 'results')
|
||||||
|
|
||||||
// fault -> the exact set of classes the checker must report (nothing more, nothing less)
|
// fault -> the exact set of classes the checker must report (nothing more, nothing less).
|
||||||
|
//
|
||||||
|
// `hidden` and `gmOnly` carry NO_REMOVE as well, and that is not a slack assertion: a state frame is
|
||||||
|
// sent only when its content changes (T11, 6.4), so a token leaked by one of these faults that stops
|
||||||
|
// changing leaves the client holding it with no message to correct it. From the client's side that
|
||||||
|
// is indistinguishable from a withheld `token_gone`, which is what NO_REMOVE reports. Both
|
||||||
|
// invariants really are broken by the fault.
|
||||||
const FAULTS = {
|
const FAULTS = {
|
||||||
hidden: ['HIDDEN_TOKEN'],
|
hidden: ['HIDDEN_TOKEN', 'NO_REMOVE'],
|
||||||
gmOnly: ['GMONLY_TOKEN'],
|
gmOnly: ['GMONLY_TOKEN', 'NO_REMOVE'],
|
||||||
walls: ['WALLDATA'],
|
walls: ['WALLDATA'],
|
||||||
withhold: ['WITHHELD'],
|
withhold: ['WITHHELD'],
|
||||||
otherOwner: ['OTHER_PLAYER'],
|
otherOwner: ['OTHER_PLAYER'],
|
||||||
@@ -30,6 +36,10 @@ const FAULTS = {
|
|||||||
ownerProp: ['OWNER_PROP'],
|
ownerProp: ['OWNER_PROP'],
|
||||||
gmProp: ['GM_PROP'],
|
gmProp: ['GM_PROP'],
|
||||||
statusSource: ['STATUS_SOURCE'],
|
statusSource: ['STATUS_SOURCE'],
|
||||||
|
actualName: ['ACTUAL_NAME'],
|
||||||
|
charList: ['CHAR_LIST'],
|
||||||
|
controllerChange: ['CONTROLLER_CHANGE'],
|
||||||
|
charOwnerProp: ['CHAR_OWNER_PROP'],
|
||||||
}
|
}
|
||||||
|
|
||||||
function classesOf(output) {
|
function classesOf(output) {
|
||||||
|
|||||||
+108
-28
@@ -50,11 +50,19 @@ export function runChecker(transcript, subject) {
|
|||||||
return { status: r.status, output: `${r.stdout ?? ''}${r.stderr ?? ''}` }
|
return { status: r.status, output: `${r.stdout ?? ''}${r.stderr ?? ''}` }
|
||||||
}
|
}
|
||||||
|
|
||||||
// One socket, its received frames, and where the transcript cursor is.
|
// One socket, its received frames, and where the transcript cursor is. Every intent a client sends
|
||||||
async function connect(origin, key, who, log) {
|
// is logged too (`k:'intent'`): the checker needs it to tell an intended controller change from one
|
||||||
|
// a character edit caused (the CONTROLLER_CHANGE class, DESIGN 10.3).
|
||||||
|
async function connect(origin, key, who, log, group) {
|
||||||
const { cookie } = await signIn(origin, key)
|
const { cookie } = await signIn(origin, key)
|
||||||
const ws = await openWs(origin, cookie)
|
const ws = await openWs(origin, cookie)
|
||||||
return { who, ws, logged: 0, log }
|
return {
|
||||||
|
who, ws, logged: 0, log,
|
||||||
|
request(fields) {
|
||||||
|
log({ k: 'intent', g: group(), who, t: fields.t, f: fields })
|
||||||
|
return ws.request(fields)
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen = false }) {
|
export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen = false }) {
|
||||||
@@ -63,7 +71,7 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
|
|||||||
const log = obj => lines.push(JSON.stringify(obj))
|
const log = obj => lines.push(JSON.stringify(obj))
|
||||||
const clients = []
|
const clients = []
|
||||||
|
|
||||||
const gm = await connect(origin, gmKey, 'GM', log)
|
const gm = await connect(origin, gmKey, 'GM', log, () => g)
|
||||||
clients.push(gm)
|
clients.push(gm)
|
||||||
await gm.ws.waitText('hello')
|
await gm.ws.waitText('hello')
|
||||||
const walls = await gm.ws.waitText('walls')
|
const walls = await gm.ws.waitText('walls')
|
||||||
@@ -113,30 +121,31 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
|
|||||||
const wallIds = []
|
const wallIds = []
|
||||||
|
|
||||||
const addWall = async fields => {
|
const addWall = async fields => {
|
||||||
const ack = await gm.ws.request({ t: 'wall.add', scene, ...fields })
|
const ack = await gm.request({ t: 'wall.add', scene, ...fields })
|
||||||
if (ack.ok !== true) throw new Error(`wall.add refused: ${JSON.stringify(ack)}`)
|
if (ack.ok !== true) throw new Error(`wall.add refused: ${JSON.stringify(ack)}`)
|
||||||
wallIds.push(ack.id)
|
wallIds.push(ack.id)
|
||||||
return ack.id
|
return ack.id
|
||||||
}
|
}
|
||||||
|
|
||||||
const createToken = async (id, fields) => {
|
const createToken = async (id, fields) => {
|
||||||
const ack = await gm.ws.request({ t: 'token.create', scene, ...fields })
|
const ack = await gm.request({ t: 'token.create', scene, ...fields })
|
||||||
if (ack.ok !== true) throw new Error(`token.create refused: ${JSON.stringify(ack)}`)
|
if (ack.ok !== true) throw new Error(`token.create refused: ${JSON.stringify(ack)}`)
|
||||||
ids[id] = ack.id
|
ids[id] = ack.id
|
||||||
return ack.id
|
return ack.id
|
||||||
}
|
}
|
||||||
const ids = {}
|
const ids = {}
|
||||||
|
const characters = {}
|
||||||
|
|
||||||
const move = async (client, id, pos) => {
|
const move = async (client, id, pos) => {
|
||||||
const ack = await client.ws.request({ t: 'token.move', id, pos })
|
const ack = await client.request({ t: 'token.move', id, pos })
|
||||||
return ack
|
return ack
|
||||||
}
|
}
|
||||||
|
|
||||||
// Two named players: the naming is the fixture of lib.mjs (player.setname is slice 8).
|
// Two named players: the naming is the fixture of lib.mjs (player.setname is slice 8).
|
||||||
const playerA = await createPlayer(gm.ws)
|
const playerA = await createPlayer(gm.ws)
|
||||||
const playerB = await createPlayer(gm.ws)
|
const playerB = await createPlayer(gm.ws)
|
||||||
await namePlayer(stateDir, playerA.id, 'Subject A')
|
await namePlayer(origin, playerA.key, 'Subject A')
|
||||||
await namePlayer(stateDir, playerB.id, 'Player B')
|
await namePlayer(origin, playerB.key, 'Player B')
|
||||||
|
|
||||||
await group('walls', async () => {
|
await group('walls', async () => {
|
||||||
for (const w of wallsToAdd) await addWall(w)
|
for (const w of wallsToAdd) await addWall(w)
|
||||||
@@ -157,12 +166,12 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
|
|||||||
actual_name: 'The Vault' })
|
actual_name: 'The Vault' })
|
||||||
})
|
})
|
||||||
|
|
||||||
const A = await connect(origin, playerA.key, 'A', log)
|
const A = await connect(origin, playerA.key, 'A', log, () => g)
|
||||||
clients.push(A)
|
clients.push(A)
|
||||||
await A.ws.waitText('hello')
|
await A.ws.waitText('hello')
|
||||||
await group('connect subject', async () => { await sleep(0) })
|
await group('connect subject', async () => { await sleep(0) })
|
||||||
|
|
||||||
const B = await connect(origin, playerB.key, 'B', log)
|
const B = await connect(origin, playerB.key, 'B', log, () => g)
|
||||||
clients.push(B)
|
clients.push(B)
|
||||||
await B.ws.waitText('hello')
|
await B.ws.waitText('hello')
|
||||||
await group('connect other', async () => { await sleep(0) })
|
await group('connect other', async () => { await sleep(0) })
|
||||||
@@ -177,7 +186,7 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
|
|||||||
await group('M2 is hidden behind the closed door', async () => { await sleep(0) })
|
await group('M2 is hidden behind the closed door', async () => { await sleep(0) })
|
||||||
|
|
||||||
await group('GM opens the door', async () => {
|
await group('GM opens the door', async () => {
|
||||||
const ack = await gm.ws.request({ t: 'door.set', scene, id: wallIds[1], open: true })
|
const ack = await gm.request({ t: 'door.set', scene, id: wallIds[1], open: true })
|
||||||
if (ack.ok !== true) throw new Error(`door.set refused: ${JSON.stringify(ack)}`)
|
if (ack.ok !== true) throw new Error(`door.set refused: ${JSON.stringify(ack)}`)
|
||||||
})
|
})
|
||||||
await group('A steps through the door', async () => {
|
await group('A steps through the door', async () => {
|
||||||
@@ -194,26 +203,26 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
|
|||||||
actual_name: 'Lantern' })
|
actual_name: 'Lantern' })
|
||||||
})
|
})
|
||||||
await group('GM removes it', async () => {
|
await group('GM removes it', async () => {
|
||||||
const ack = await gm.ws.request({ t: 'token.remove', id: ids.N1 })
|
const ack = await gm.request({ t: 'token.remove', id: ids.N1 })
|
||||||
if (ack.ok !== true) throw new Error(`token.remove refused: ${JSON.stringify(ack)}`)
|
if (ack.ok !== true) throw new Error(`token.remove refused: ${JSON.stringify(ack)}`)
|
||||||
})
|
})
|
||||||
await group('GM hides M1', async () => {
|
await group('GM hides M1', async () => {
|
||||||
const ack = await gm.ws.request({ t: 'token.update', id: ids.M1, gm_only: true })
|
const ack = await gm.request({ t: 'token.update', id: ids.M1, gm_only: true })
|
||||||
if (ack.ok !== true) throw new Error(`token.update refused: ${JSON.stringify(ack)}`)
|
if (ack.ok !== true) throw new Error(`token.update refused: ${JSON.stringify(ack)}`)
|
||||||
})
|
})
|
||||||
await group('GM unhides M1', async () => {
|
await group('GM unhides M1', async () => {
|
||||||
const ack = await gm.ws.request({ t: 'token.update', id: ids.M1, gm_only: false })
|
const ack = await gm.request({ t: 'token.update', id: ids.M1, gm_only: false })
|
||||||
if (ack.ok !== true) throw new Error(`token.update refused: ${JSON.stringify(ack)}`)
|
if (ack.ok !== true) throw new Error(`token.update refused: ${JSON.stringify(ack)}`)
|
||||||
})
|
})
|
||||||
await group('GM hands M1 to the subject', async () => {
|
await group('GM hands M1 to the subject', async () => {
|
||||||
const ack = await gm.ws.request({ t: 'token.update', id: ids.M1, controller: playerA.id })
|
const ack = await gm.request({ t: 'token.update', id: ids.M1, controller: playerA.id })
|
||||||
if (ack.ok !== true) throw new Error(`token.update refused: ${JSON.stringify(ack)}`)
|
if (ack.ok !== true) throw new Error(`token.update refused: ${JSON.stringify(ack)}`)
|
||||||
})
|
})
|
||||||
await group('GM moves the subject-owned token far away', async () => {
|
await group('GM moves the subject-owned token far away', async () => {
|
||||||
expectAck(await move(gm, ids.M1, [3000, 3000]), true)
|
expectAck(await move(gm, ids.M1, [3000, 3000]), true)
|
||||||
})
|
})
|
||||||
await group('GM hands M1 back to the GM', async () => {
|
await group('GM hands M1 back to the GM', async () => {
|
||||||
const ack = await gm.ws.request({ t: 'token.update', id: ids.M1, controller: null })
|
const ack = await gm.request({ t: 'token.update', id: ids.M1, controller: null })
|
||||||
if (ack.ok !== true) throw new Error(`token.update refused: ${JSON.stringify(ack)}`)
|
if (ack.ok !== true) throw new Error(`token.update refused: ${JSON.stringify(ack)}`)
|
||||||
})
|
})
|
||||||
await group('GM walks the other player in', async () => {
|
await group('GM walks the other player in', async () => {
|
||||||
@@ -226,14 +235,14 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
|
|||||||
await addWall({ a: [400, 900], b: [900, 900], kind: 'wall' })
|
await addWall({ a: [400, 900], b: [900, 900], kind: 'wall' })
|
||||||
})
|
})
|
||||||
await group('GM removes it again', async () => {
|
await group('GM removes it again', async () => {
|
||||||
const ack = await gm.ws.request({ t: 'wall.remove', scene, id: wallIds[wallIds.length - 1] })
|
const ack = await gm.request({ t: 'wall.remove', scene, id: wallIds[wallIds.length - 1] })
|
||||||
if (ack.ok !== true) throw new Error(`wall.remove refused: ${JSON.stringify(ack)}`)
|
if (ack.ok !== true) throw new Error(`wall.remove refused: ${JSON.stringify(ack)}`)
|
||||||
})
|
})
|
||||||
await group('GM puts M2 on the door line', async () => {
|
await group('GM puts M2 on the door line', async () => {
|
||||||
expectAck(await move(gm, ids.M2, [500, 600]), true)
|
expectAck(await move(gm, ids.M2, [500, 600]), true)
|
||||||
})
|
})
|
||||||
await group('GM closes the door: the server pushes M2 aside', async () => {
|
await group('GM closes the door: the server pushes M2 aside', async () => {
|
||||||
const ack = await gm.ws.request({ t: 'door.set', scene, id: wallIds[1], open: false })
|
const ack = await gm.request({ t: 'door.set', scene, id: wallIds[1], open: false })
|
||||||
if (ack.ok !== true) throw new Error(`door.set refused: ${JSON.stringify(ack)}`)
|
if (ack.ok !== true) throw new Error(`door.set refused: ${JSON.stringify(ack)}`)
|
||||||
})
|
})
|
||||||
// Slice 7 (#22): a token the subject can see, in every bucket and with a status. N2 sits 60 px
|
// Slice 7 (#22): a token the subject can see, in every bucket and with a status. N2 sits 60 px
|
||||||
@@ -242,39 +251,110 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
|
|||||||
await createToken('N2', { kind: 'item', pos: [660, 600], descriptive_name: 'a rune',
|
await createToken('N2', { kind: 'item', pos: [660, 600], descriptive_name: 'a rune',
|
||||||
actual_name: 'The Rune' })
|
actual_name: 'The Rune' })
|
||||||
})
|
})
|
||||||
await group('GM writes props into all three buckets on N2', async () => {
|
|
||||||
for (const [bucket, value] of [['public', 'cold'], ['owner', 3], ['gm', 'the duke']]) {
|
for (const [bucket, value] of [['public', 'cold'], ['owner', 3], ['gm', 'the duke']]) {
|
||||||
const ack = await gm.ws.request({ t: 'prop.set', target: 'token', id: ids.N2, bucket,
|
await group(`GM writes the ${bucket} prop of N2`, async () => {
|
||||||
|
const ack = await gm.request({ t: 'prop.set', target: 'token', id: ids.N2, bucket,
|
||||||
key: 'aura', value })
|
key: 'aura', value })
|
||||||
if (ack.ok !== true) throw new Error(`prop.set refused: ${JSON.stringify(ack)}`)
|
if (ack.ok !== true) throw new Error(`prop.set refused: ${JSON.stringify(ack)}`)
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
await group('GM sets a GM-sourced status on N2', async () => {
|
await group('GM sets a GM-sourced status on N2', async () => {
|
||||||
const ack = await gm.ws.request({ t: 'status.set', id: ids.N2, status: 'squeezed' })
|
const ack = await gm.request({ t: 'status.set', id: ids.N2, status: 'squeezed' })
|
||||||
if (ack.ok !== true) throw new Error(`status.set refused: ${JSON.stringify(ack)}`)
|
if (ack.ok !== true) throw new Error(`status.set refused: ${JSON.stringify(ack)}`)
|
||||||
})
|
})
|
||||||
await group('GM resizes N2', async () => {
|
await group('GM resizes N2', async () => {
|
||||||
const resized = await gm.ws.request({ t: 'token.resize', id: ids.N2, radius: 45 })
|
const resized = await gm.request({ t: 'token.resize', id: ids.N2, radius: 45 })
|
||||||
if (resized.ok !== true) throw new Error(`token.resize refused: ${JSON.stringify(resized)}`)
|
if (resized.ok !== true) throw new Error(`token.resize refused: ${JSON.stringify(resized)}`)
|
||||||
})
|
})
|
||||||
await group('GM adds a wall over N2 (stuck, source walls)', async () => {
|
await group('GM adds a wall over N2 (stuck, source walls)', async () => {
|
||||||
await addWall({ a: [700, 560], b: [700, 660], kind: 'wall' })
|
await addWall({ a: [700, 560], b: [700, 660], kind: 'wall' })
|
||||||
})
|
})
|
||||||
await group('GM unsets the public prop of N2', async () => {
|
await group('GM unsets the public prop of N2', async () => {
|
||||||
const unset = await gm.ws.request({ t: 'prop.unset', target: 'token', id: ids.N2,
|
const unset = await gm.request({ t: 'prop.unset', target: 'token', id: ids.N2,
|
||||||
bucket: 'public', key: 'aura' })
|
bucket: 'public', key: 'aura' })
|
||||||
if (unset.ok !== true) throw new Error(`prop.unset refused: ${JSON.stringify(unset)}`)
|
if (unset.ok !== true) throw new Error(`prop.unset refused: ${JSON.stringify(unset)}`)
|
||||||
})
|
})
|
||||||
await group('GM clears the GM-sourced status of N2', async () => {
|
await group('GM clears the GM-sourced status of N2', async () => {
|
||||||
const cleared = await gm.ws.request({ t: 'status.clear', id: ids.N2, status: 'squeezed',
|
const cleared = await gm.request({ t: 'status.clear', id: ids.N2, status: 'squeezed',
|
||||||
source: 'GM' })
|
source: 'GM' })
|
||||||
if (cleared.ok !== true) throw new Error(`status.clear refused: ${JSON.stringify(cleared)}`)
|
if (cleared.ok !== true) throw new Error(`status.clear refused: ${JSON.stringify(cleared)}`)
|
||||||
})
|
})
|
||||||
await group('GM removes the wall over N2', async () => {
|
await group('GM removes the wall over N2', async () => {
|
||||||
const ack = await gm.ws.request({ t: 'wall.remove', scene,
|
const ack = await gm.request({ t: 'wall.remove', scene,
|
||||||
id: wallIds[wallIds.length - 1] })
|
id: wallIds[wallIds.length - 1] })
|
||||||
if (ack.ok !== true) throw new Error(`wall.remove refused: ${JSON.stringify(ack)}`)
|
if (ack.ok !== true) throw new Error(`wall.remove refused: ${JSON.stringify(ack)}`)
|
||||||
})
|
})
|
||||||
|
// Slice 8 (#23): characters, names and the encountered list. Every group here is one the subject
|
||||||
|
// receives: A is in the room, and C1's token is placed next to A's own.
|
||||||
|
await group('GM creates a character owned by the other player', async () => {
|
||||||
|
const ack = await gm.request({ t: 'character.create', descriptive_name: 'a cloaked figure',
|
||||||
|
actual_name: 'Lady Vex', owner: playerB.id })
|
||||||
|
if (ack.ok !== true) throw new Error(`character.create refused: ${JSON.stringify(ack)}`)
|
||||||
|
characters.C1 = ack.id
|
||||||
|
})
|
||||||
|
await group('GM puts a token of the character in the subject sight', async () => {
|
||||||
|
const ack = await gm.request({ t: 'token.create', scene, kind: 'pc', pos: [600, 560],
|
||||||
|
character_id: characters.C1 })
|
||||||
|
if (ack.ok !== true) throw new Error(`token.create refused: ${JSON.stringify(ack)}`)
|
||||||
|
ids.C1 = ack.id
|
||||||
|
})
|
||||||
|
// One mutation per group (the driver's contract): the checker evaluates a group as one state, so
|
||||||
|
// two prop writes in one group would compare an intermediate frame against the final truth.
|
||||||
|
for (const [bucket, value] of [['public', 'noble'], ['owner', 4], ['gm', 'the duke']]) {
|
||||||
|
await group(`GM writes the ${bucket} prop of the character`, async () => {
|
||||||
|
const ack = await gm.request({ t: 'prop.set', target: 'character', id: characters.C1, bucket,
|
||||||
|
key: 'rank', value })
|
||||||
|
if (ack.ok !== true) throw new Error(`prop.set refused: ${JSON.stringify(ack)}`)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
await group('GM renames the character', async () => {
|
||||||
|
const ack = await gm.request({ t: 'character.update', id: characters.C1,
|
||||||
|
descriptive_name: 'a tall stranger' })
|
||||||
|
if (ack.ok !== true) throw new Error(`character.update refused: ${JSON.stringify(ack)}`)
|
||||||
|
})
|
||||||
|
await group('GM reveals the actual name to the subject only', async () => {
|
||||||
|
const ack = await gm.request({ t: 'name.reveal', subject: 'character', id: characters.C1,
|
||||||
|
player: playerA.id })
|
||||||
|
if (ack.ok !== true) throw new Error(`name.reveal refused: ${JSON.stringify(ack)}`)
|
||||||
|
})
|
||||||
|
await group('GM reveals the actual name to everyone', async () => {
|
||||||
|
const ack = await gm.request({ t: 'name.reveal_all', subject: 'character', id: characters.C1 })
|
||||||
|
if (ack.ok !== true) throw new Error(`name.reveal_all refused: ${JSON.stringify(ack)}`)
|
||||||
|
})
|
||||||
|
await group('GM hands the character to the subject (controllers must not move)', async () => {
|
||||||
|
const ack = await gm.request({ t: 'character.reassign', id: characters.C1, owner: playerA.id })
|
||||||
|
if (ack.ok !== true) throw new Error(`character.reassign refused: ${JSON.stringify(ack)}`)
|
||||||
|
})
|
||||||
|
await group('GM gives the character back to the other player', async () => {
|
||||||
|
const ack = await gm.request({ t: 'character.reassign', id: characters.C1, owner: playerB.id })
|
||||||
|
if (ack.ok !== true) throw new Error(`character.reassign refused: ${JSON.stringify(ack)}`)
|
||||||
|
})
|
||||||
|
await group('GM reveals a plain token actual name to the subject', async () => {
|
||||||
|
const ack = await gm.request({ t: 'name.reveal', subject: 'token', id: ids.N2,
|
||||||
|
player: playerA.id })
|
||||||
|
if (ack.ok !== true) throw new Error(`name.reveal refused: ${JSON.stringify(ack)}`)
|
||||||
|
})
|
||||||
|
await group('GM reveals that plain token to everyone', async () => {
|
||||||
|
const ack = await gm.request({ t: 'name.reveal_all', subject: 'token', id: ids.N2 })
|
||||||
|
if (ack.ok !== true) throw new Error(`name.reveal_all refused: ${JSON.stringify(ack)}`)
|
||||||
|
})
|
||||||
|
await group('GM hides the character token (the encountered entry stays, greyed)', async () => {
|
||||||
|
const ack = await gm.request({ t: 'token.update', id: ids.C1, gm_only: true })
|
||||||
|
if (ack.ok !== true) throw new Error(`token.update refused: ${JSON.stringify(ack)}`)
|
||||||
|
})
|
||||||
|
await group('GM shows it again', async () => {
|
||||||
|
const ack = await gm.request({ t: 'token.update', id: ids.C1, gm_only: false })
|
||||||
|
if (ack.ok !== true) throw new Error(`token.update refused: ${JSON.stringify(ack)}`)
|
||||||
|
})
|
||||||
|
await group('GM removes the character token (the entry stays, greyed)', async () => {
|
||||||
|
const ack = await gm.request({ t: 'token.remove', id: ids.C1 })
|
||||||
|
if (ack.ok !== true) throw new Error(`token.remove refused: ${JSON.stringify(ack)}`)
|
||||||
|
})
|
||||||
|
await group('GM removes one encountered entry of the subject', async () => {
|
||||||
|
const ack = await gm.request({ t: 'encountered.remove', player: playerA.id, id: ids.N2 })
|
||||||
|
if (ack.ok !== true) throw new Error(`encountered.remove refused: ${JSON.stringify(ack)}`)
|
||||||
|
})
|
||||||
|
|
||||||
await group('A walks away from the door', async () => {
|
await group('A walks away from the door', async () => {
|
||||||
expectAck(await move(A, ids.A, [560, 950]), true)
|
expectAck(await move(A, ids.A, [560, 950]), true)
|
||||||
})
|
})
|
||||||
@@ -290,7 +370,7 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
|
|||||||
|
|
||||||
fs.mkdirSync(path.dirname(transcript), { recursive: true })
|
fs.mkdirSync(path.dirname(transcript), { recursive: true })
|
||||||
fs.writeFileSync(transcript, lines.join('\n') + '\n')
|
fs.writeFileSync(transcript, lines.join('\n') + '\n')
|
||||||
return { transcript, groups: g, walls: wallIds, tokens: ids }
|
return { transcript, groups: g, walls: wallIds, tokens: ids, characters }
|
||||||
}
|
}
|
||||||
|
|
||||||
function expectAck(ack, ok) {
|
function expectAck(ack, ok) {
|
||||||
|
|||||||
+181
-6
@@ -19,6 +19,10 @@
|
|||||||
## OWNER_PROP the `owner` property bucket reached someone who does not control the token
|
## 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
|
## 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)
|
## 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)
|
## 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
|
## 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
|
import geometry
|
||||||
|
|
||||||
const
|
const
|
||||||
AllowedTypes = ["hello", "ack", "token", "token_gone", "vision", "explored"]
|
AllowedTypes = ["hello", "ack", "roster", "token", "token_gone", "vision", "explored",
|
||||||
BannedKeys = ["walls", "wall", "wall_gone", "a", "b", "open", "kind", "controller", "gm_only",
|
"character", "character_gone", "encountered"]
|
||||||
"flags", "descriptive_name", "actual_name", "reveal_all", "revealed", "source",
|
BannedAlways = ["walls", "wall", "wall_gone", "a", "b", "open", "kind", "controller", "gm_only",
|
||||||
"radius_own", "extra"]
|
"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
|
type
|
||||||
TruthToken = object
|
TruthToken = object
|
||||||
@@ -42,15 +49,28 @@ type
|
|||||||
radius: float
|
radius: float
|
||||||
props: JsonNode ## the GM's three buckets (the truth for every bucket question)
|
props: JsonNode ## the GM's three buckets (the truth for every bucket question)
|
||||||
statuses: seq[string] ## the status names the GM sees, in order
|
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
|
Truth = object
|
||||||
walls: seq[Wall]
|
walls: seq[Wall]
|
||||||
tokens: Table[string, TruthToken]
|
tokens: Table[string, TruthToken]
|
||||||
|
characters: Table[string, TruthCharacter]
|
||||||
|
|
||||||
Group = object
|
Group = object
|
||||||
label: string
|
label: string
|
||||||
gmMsgs: seq[JsonNode]
|
gmMsgs: seq[JsonNode]
|
||||||
subjMsgs: seq[JsonNode]
|
subjMsgs: seq[JsonNode]
|
||||||
|
intents: seq[JsonNode] ## what the clients asked for in this group (see CONTROLLER_CHANGE)
|
||||||
|
|
||||||
var fails = 0
|
var fails = 0
|
||||||
var classes: CountTable[string]
|
var classes: CountTable[string]
|
||||||
@@ -86,6 +106,8 @@ proc readGroups(path, subject: string): seq[Group] =
|
|||||||
let who = j["who"].getStr
|
let who = j["who"].getStr
|
||||||
if who == "GM": groups[current].gmMsgs.add j["m"]
|
if who == "GM": groups[current].gmMsgs.add j["m"]
|
||||||
elif who == subject: groups[current].subjMsgs.add j["m"]
|
elif who == subject: groups[current].subjMsgs.add j["m"]
|
||||||
|
of "intent":
|
||||||
|
if current >= 0: groups[current].intents.add j
|
||||||
else: discard
|
else: discard
|
||||||
groups
|
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)
|
if m["vision_radius"].kind != JNull: t.visionRadius = some(m["vision_radius"].getFloat)
|
||||||
t.props = m["props"]
|
t.props = m["props"]
|
||||||
for st in m["statuses"]: t.statuses.add st["status"].getStr
|
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
|
truth.tokens[m["id"].getStr] = t
|
||||||
of "token_gone":
|
of "token_gone":
|
||||||
truth.tokens.del m["id"].getStr
|
truth.tokens.del m["id"].getStr
|
||||||
else: discard
|
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
|
# 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) =
|
proc checkArgs(): (string, string) =
|
||||||
if paramCount() < 2:
|
if paramCount() < 2:
|
||||||
echo "usage: leakcheck <transcript.jsonl> <SUBJECT>"
|
echo "usage: leakcheck <transcript.jsonl> <SUBJECT>"
|
||||||
@@ -223,12 +285,16 @@ proc main() =
|
|||||||
var groupsSeen = 0
|
var groupsSeen = 0
|
||||||
var recomputedSoFar: HashSet[int] # every cell the subject has ever seen, recomputed
|
var recomputedSoFar: HashSet[int] # every cell the subject has ever seen, recomputed
|
||||||
var seenAny: HashSet[string] # token ids the subject was legitimately shown
|
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:
|
for g in groups:
|
||||||
inc groupsSeen
|
inc groupsSeen
|
||||||
for m in g.gmMsgs:
|
for m in g.gmMsgs:
|
||||||
applyGmWalls(truth, wallIds, m)
|
applyGmWalls(truth, wallIds, m)
|
||||||
applyGmTokens(truth, m)
|
applyGmTokens(truth, m)
|
||||||
|
applyGmCharacters(truth, m)
|
||||||
|
|
||||||
# player ids: the subject from its hello, the other from any token it does not control
|
# player ids: the subject from its hello, the other from any token it does not control
|
||||||
for m in g.subjMsgs:
|
for m in g.subjMsgs:
|
||||||
@@ -253,6 +319,15 @@ proc main() =
|
|||||||
let polys = polygonsOf(truth, me, sceneDefault)
|
let polys = polygonsOf(truth, me, sceneDefault)
|
||||||
let otherPolys = if other != 0: polygonsOf(truth, other, sceneDefault) else: @[]
|
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)
|
# the other player's explored cells, independently (attribute leaks, 3.1 OTHER_PLAYER)
|
||||||
for (_, pts) in otherPolys:
|
for (_, pts) in otherPolys:
|
||||||
for (cx, cy) in cellsTouched(pts, float(cell)):
|
for (cx, cy) in cellsTouched(pts, float(cell)):
|
||||||
@@ -276,8 +351,19 @@ proc main() =
|
|||||||
if k == "source":
|
if k == "source":
|
||||||
# 5.5 / 6.1 note 6: a viewer sees the status, never what caused it.
|
# 5.5 / 6.1 note 6: a viewer sees the status, never what caused it.
|
||||||
fail "STATUS_SOURCE", "player frame carries a status source"
|
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
|
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
|
case t
|
||||||
of "ack":
|
of "ack":
|
||||||
# only a bad shape is interesting here; the driver already checked the outcomes it expected
|
# 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
|
let wantMine = actual.controller == me
|
||||||
if m["mine"].getBool != wantMine:
|
if m["mine"].getBool != wantMine:
|
||||||
fail (if wantMine: "OWN_VIEW" else: "OTHER_PLAYER"), "mine flag on " & id
|
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
|
view[id] = m
|
||||||
let visible = wantMine or (not actual.gmOnly and insideAny(polys, actual.pos))
|
let visible = wantMine or (not actual.gmOnly and insideAny(polys, actual.pos))
|
||||||
if not visible:
|
if not visible:
|
||||||
@@ -341,6 +455,52 @@ proc main() =
|
|||||||
let actual = truth.tokens[id]
|
let actual = truth.tokens[id]
|
||||||
if actual.controller == me or (not actual.gmOnly and insideAny(polys, actual.pos)):
|
if actual.controller == me or (not actual.gmOnly and insideAny(polys, actual.pos)):
|
||||||
fail "WITHHELD", "token_gone for a token still visible: " & id
|
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":
|
of "vision":
|
||||||
var got: seq[(string, seq[Vec])]
|
var got: seq[(string, seq[Vec])]
|
||||||
for p in m["polys"]:
|
for p in m["polys"]:
|
||||||
@@ -396,9 +556,24 @@ proc main() =
|
|||||||
exploredSent.incl k
|
exploredSent.incl k
|
||||||
else: discard
|
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 ---------------------
|
# --- the set of tokens the subject should hold at the end of this group ---------------------
|
||||||
for id, actual in truth.tokens:
|
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)
|
let have = view.hasKey(id)
|
||||||
if want and not have:
|
if want and not have:
|
||||||
fail "WITHHELD", "visible token never sent: " & id & " (group " & g.label & ")"
|
fail "WITHHELD", "visible token never sent: " & id & " (group " & g.label & ")"
|
||||||
|
|||||||
+25
-26
@@ -6,7 +6,6 @@ import crypto from 'node:crypto'
|
|||||||
import fs from 'node:fs'
|
import fs from 'node:fs'
|
||||||
import net from 'node:net'
|
import net from 'node:net'
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import { DatabaseSync } from 'node:sqlite'
|
|
||||||
import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from 'node:url'
|
||||||
|
|
||||||
export const sleep = ms => new Promise(r => setTimeout(r, ms))
|
export const sleep = ms => new Promise(r => setTimeout(r, ms))
|
||||||
@@ -411,32 +410,32 @@ export async function collectAcks(client, ids, timeoutMs = 5000) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------
|
||||||
// Slice 5 (#20) fixtures: naming a player out of band.
|
// Slice 8 (#23): naming a player through the product's own intent.
|
||||||
//
|
//
|
||||||
// DESIGN 3.2 gives a player their display name at first sign-in, through `player.setname` - and
|
// DESIGN 3.2 gives a player their display name at first sign-in through `player.setname`, which
|
||||||
// `player.setname` is slice 8 (#23). Until then every non-GM connection is *unnamed*, and 6.1/6.5
|
// slice 8 builds. The harness therefore names a player the way a browser does: sign in with the
|
||||||
// refuse an unnamed player everything but `conn.ping`: no scene block, no resync, no intents. The
|
// player key, open a connection, send `player.setname`, wait for the ack and for the second `hello`
|
||||||
// player-side acceptance of this slice (leak test A and B, WS probing) therefore cannot be reached
|
// (6.1: the player's connections get `hello` + a full resync), then close the naming connection.
|
||||||
// through the product's own surface yet, so the harness writes the name into the DB before the
|
// Nothing here writes to the DB out of band: the old `node:sqlite` fixture is gone, so a harness can
|
||||||
// connection is opened. That is a fixture, not a product path: the unnamed-player gate itself is
|
// only reach a named player through the wire.
|
||||||
// pinned by tools/tokens.test.mjs (hello without a scene block, `not-allowed` for every intent).
|
export async function namePlayer(origin, key, name) {
|
||||||
export async function namePlayer(stateDir, playerId, name) {
|
const signed = await join(origin, key)
|
||||||
const dbPath = path.join(stateDir, 'state.db')
|
if (signed.status !== 303 || !signed.cookie) {
|
||||||
let lastError
|
throw new Error(`sign-in for namePlayer failed: ${signed.status}`)
|
||||||
for (let attempt = 0; attempt < 40; attempt++) {
|
|
||||||
const db = new DatabaseSync(dbPath)
|
|
||||||
try {
|
|
||||||
db.exec('PRAGMA busy_timeout=5000')
|
|
||||||
db.prepare('UPDATE player SET name = ? WHERE id = ?').run(name, playerId)
|
|
||||||
const row = db.prepare('SELECT name FROM player WHERE id = ?').get(playerId)
|
|
||||||
if (!row || row.name !== name) throw new Error(`naming player ${playerId} failed`)
|
|
||||||
return
|
|
||||||
} catch (e) {
|
|
||||||
lastError = e
|
|
||||||
} finally {
|
|
||||||
try { db.close() } catch {}
|
|
||||||
}
|
}
|
||||||
await sleep(25) // SQLITE_BUSY while the server holds the write lock: back off and retry
|
const ws = await openWs(origin, signed.cookie)
|
||||||
|
await ws.waitText('hello')
|
||||||
|
const from = ws.messages.length
|
||||||
|
const ack = await ws.request({ t: 'player.setname', name })
|
||||||
|
if (ack.ok !== true) {
|
||||||
|
ws.close()
|
||||||
|
throw new Error(`player.setname refused for "${name}": ${JSON.stringify(ack)}`)
|
||||||
}
|
}
|
||||||
throw lastError
|
// 6.1/6.3: `hello` again with `me.name`, then `roster` and the resync. Waiting for the second
|
||||||
|
// hello pins the effect, not just the ack.
|
||||||
|
const hello = await ws.waitFor((m, i) => i >= from && m.t === 'hello')
|
||||||
|
await ws.waitFor((m, i) => i >= from && m.t === 'roster')
|
||||||
|
ws.close()
|
||||||
|
await ws.closed
|
||||||
|
return { hello, ack, cookie: signed.cookie }
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-13
@@ -54,9 +54,9 @@ async function gmConnect(origin, gmKey) {
|
|||||||
return { ...conn, scene: walls.scene }
|
return { ...conn, scene: walls.scene }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function namedPlayer(stateDir, gm, name) {
|
async function namedPlayer(origin, gm, name) {
|
||||||
const player = await createPlayer(gm.ws)
|
const player = await createPlayer(gm.ws)
|
||||||
await namePlayer(stateDir, player.id, name)
|
await namePlayer(origin, player.key, name)
|
||||||
return player
|
return player
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ test('explored round trip: a fresh connection gets the whole grid the server acc
|
|||||||
const s = await startServer({ stateDir })
|
const s = await startServer({ stateDir })
|
||||||
try {
|
try {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const alice = await namedPlayer(stateDir, gm, 'Alice')
|
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
const tok = await visionToken(gm, alice, [200, 200])
|
const tok = await visionToken(gm, alice, [200, 200])
|
||||||
|
|
||||||
const p = await openAs(s.origin, alice.key)
|
const p = await openAs(s.origin, alice.key)
|
||||||
@@ -145,8 +145,8 @@ test('explored is strictly per player, before and after a restart', async () =>
|
|||||||
let alice, bob, before
|
let alice, bob, before
|
||||||
try {
|
try {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
alice = await namedPlayer(stateDir, gm, 'Alice')
|
alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
bob = await namedPlayer(stateDir, gm, 'Bob')
|
bob = await namedPlayer(s.origin, gm, 'Bob')
|
||||||
const aliceTok = await visionToken(gm, alice, [200, 200])
|
const aliceTok = await visionToken(gm, alice, [200, 200])
|
||||||
const bobTok = await visionToken(gm, bob, [3800, 3800])
|
const bobTok = await visionToken(gm, bob, [3800, 3800])
|
||||||
const a = await openAs(s.origin, alice.key)
|
const a = await openAs(s.origin, alice.key)
|
||||||
@@ -188,7 +188,7 @@ test('restart: every player\'s explored area is identical before and after (SIGT
|
|||||||
let alice, before
|
let alice, before
|
||||||
try {
|
try {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
alice = await namedPlayer(stateDir, gm, 'Alice')
|
alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
const tok = await visionToken(gm, alice, [200, 200])
|
const tok = await visionToken(gm, alice, [200, 200])
|
||||||
const p = await openAs(s.origin, alice.key)
|
const p = await openAs(s.origin, alice.key)
|
||||||
await p.ws.waitText('hello')
|
await p.ws.waitText('hello')
|
||||||
@@ -222,7 +222,7 @@ test('restart: the explored grid survives a SIGKILL', async () => {
|
|||||||
let alice, before
|
let alice, before
|
||||||
try {
|
try {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
alice = await namedPlayer(stateDir, gm, 'Alice')
|
alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
const tok = await visionToken(gm, alice, [400, 400])
|
const tok = await visionToken(gm, alice, [400, 400])
|
||||||
const p = await openAs(s.origin, alice.key)
|
const p = await openAs(s.origin, alice.key)
|
||||||
await p.ws.waitText('hello')
|
await p.ws.waitText('hello')
|
||||||
@@ -255,7 +255,7 @@ test('a wall removal\'s newly explored cells are persisted, even after the wall
|
|||||||
const s = await startServer({ stateDir })
|
const s = await startServer({ stateDir })
|
||||||
try {
|
try {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const alice = await namedPlayer(stateDir, gm, 'Alice')
|
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
// The wall goes in before Alice's token exists: explored only grows (5.1), so a token created
|
// The wall goes in before Alice's token exists: explored only grows (5.1), so a token created
|
||||||
// on the far side first would legitimately have explored it already.
|
// on the far side first would legitimately have explored it already.
|
||||||
// A wall at x = 500 hides everything to the right of Alice (her circle reaches x = 600).
|
// A wall at x = 500 hides everything to the right of Alice (her circle reaches x = 600).
|
||||||
@@ -310,7 +310,7 @@ test('the store holds 512-byte chunks, and they decode to exactly the explored g
|
|||||||
const s = await startServer({ stateDir })
|
const s = await startServer({ stateDir })
|
||||||
try {
|
try {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const alice = await namedPlayer(stateDir, gm, 'Alice')
|
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
const tok = await visionToken(gm, alice, [400, 400])
|
const tok = await visionToken(gm, alice, [400, 400])
|
||||||
const p = await openAs(s.origin, alice.key)
|
const p = await openAs(s.origin, alice.key)
|
||||||
await p.ws.waitText('hello')
|
await p.ws.waitText('hello')
|
||||||
@@ -342,7 +342,7 @@ test('write timing: a move\'s ack stays inside the 4.3 lock budget with explored
|
|||||||
const s = await startServer({ stateDir })
|
const s = await startServer({ stateDir })
|
||||||
try {
|
try {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const alice = await namedPlayer(stateDir, gm, 'Alice')
|
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
// On the ring, so the first move is not a teleport across the map (5.5's step cap).
|
// On the ring, so the first move is not a teleport across the map (5.5's step cap).
|
||||||
const tok = await visionToken(gm, alice, [2900, 2000])
|
const tok = await visionToken(gm, alice, [2900, 2000])
|
||||||
const p = await openAs(s.origin, alice.key)
|
const p = await openAs(s.origin, alice.key)
|
||||||
@@ -413,7 +413,7 @@ test('migration: a schema-4 DB (fixture) migrates under the real binary to the l
|
|||||||
}
|
}
|
||||||
const s = await startServer({ stateDir })
|
const s = await startServer({ stateDir })
|
||||||
try {
|
try {
|
||||||
assert.match(s.log(), /db_ready .*schema_version=6 applied=2/, s.log())
|
assert.match(s.log(), /db_ready .*schema_version=7 applied=3/, s.log())
|
||||||
// The old data is served unchanged through the product surface.
|
// The old data is served unchanged through the product surface.
|
||||||
const alice = { id: 2, key: 'ALIC-ALIC-ALIC-ALIC-ALIC' }
|
const alice = { id: 2, key: 'ALIC-ALIC-ALIC-ALIC-ALIC' }
|
||||||
const conn = await openAs(s.origin, alice.key)
|
const conn = await openAs(s.origin, alice.key)
|
||||||
@@ -434,11 +434,11 @@ test('migration: a schema-4 DB (fixture) migrates under the real binary to the l
|
|||||||
}
|
}
|
||||||
const db = new DatabaseSync(dbPath)
|
const db = new DatabaseSync(dbPath)
|
||||||
try {
|
try {
|
||||||
assert.equal(Number(db.prepare('PRAGMA user_version').get().user_version), 6)
|
assert.equal(Number(db.prepare('PRAGMA user_version').get().user_version), 7)
|
||||||
assert.deepEqual(db.prepare('SELECT version, name FROM schema_migration ORDER BY version').all()
|
assert.deepEqual(db.prepare('SELECT version, name FROM schema_migration ORDER BY version').all()
|
||||||
.map(r => [Number(r.version), r.name]),
|
.map(r => [Number(r.version), r.name]),
|
||||||
[[1, 'meta'], [2, 'auth'], [3, 'world'], [4, 'tokens'], [5, 'explored'],
|
[[1, 'meta'], [2, 'auth'], [3, 'world'], [4, 'tokens'], [5, 'explored'],
|
||||||
[6, 'token details']])
|
[6, 'token details'], [7, 'characters']])
|
||||||
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM explored_chunk').get().n), 0)
|
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM explored_chunk').get().n), 0)
|
||||||
assert.equal(db.prepare('SELECT name FROM player WHERE id = 2').get().name, 'Alice')
|
assert.equal(db.prepare('SELECT name FROM player WHERE id = 2').get().name, 'Alice')
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ async function setup(farWalls, nearWalls = []) {
|
|||||||
for (const w of nearWalls) await addWall(w)
|
for (const w of nearWalls) await addWall(w)
|
||||||
for (const w of farWalls) await addWall(w)
|
for (const w of farWalls) await addWall(w)
|
||||||
const player = await createPlayer(gm)
|
const player = await createPlayer(gm)
|
||||||
await namePlayer(stateDir, player.id, 'Prober')
|
await namePlayer(s.origin, player.key, 'Prober')
|
||||||
const tok = await gm.request({ t: 'token.create', scene, kind: 'pc', pos: START,
|
const tok = await gm.request({ t: 'token.create', scene, kind: 'pc', pos: START,
|
||||||
descriptive_name: 'prober', actual_name: 'Prober',
|
descriptive_name: 'prober', actual_name: 'Prober',
|
||||||
controller: player.id, flags: { vision: true } })
|
controller: player.id, flags: { vision: true } })
|
||||||
|
|||||||
+20
-17
@@ -27,22 +27,24 @@ test('hello is the first frame; n counts server frames per connection, never glo
|
|||||||
assert.equal(hello.proto, 1) // M3 ships proto 1 (DESIGN 6.2)
|
assert.equal(hello.proto, 1) // M3 ships proto 1 (DESIGN 6.2)
|
||||||
assert.equal(hello.role, 'gm')
|
assert.equal(hello.role, 'gm')
|
||||||
assert.deepEqual(hello.me, { id: 1, name: 'GM' })
|
assert.deepEqual(hello.me, { id: 1, name: 'GM' })
|
||||||
// the GM wall snapshot follows hello on the same connection (slice 4, DESIGN 6.1 `walls`)
|
// 6.3: the roster, then the GM wall snapshot (slice 4, DESIGN 6.1 `walls`)
|
||||||
assert.equal((await gm.ws.waitText('walls')).n, 2)
|
assert.equal((await gm.ws.waitText('roster')).n, 2)
|
||||||
|
assert.equal((await gm.ws.waitText('walls')).n, 3)
|
||||||
|
|
||||||
const first = await gm.ws.request({ t: 'conn.ping', ts: 42 })
|
const first = await gm.ws.request({ t: 'conn.ping', ts: 42 })
|
||||||
assert.equal(first.ok, true)
|
assert.equal(first.ok, true)
|
||||||
assert.equal(first.ts, 42) // the ack echoes ts
|
assert.equal(first.ts, 42) // the ack echoes ts
|
||||||
assert.equal(first.n, 3)
|
assert.equal(first.n, 4)
|
||||||
assert.equal((await gm.ws.request({ t: 'conn.ping', ts: 43 })).n, 4)
|
assert.equal((await gm.ws.request({ t: 'conn.ping', ts: 43 })).n, 5)
|
||||||
|
|
||||||
// a second connection of the same player counts on its own (H25: no global counter)
|
// a second connection of the same player counts on its own (H25: no global counter)
|
||||||
const other = await openWs(s.origin, gm.cookie)
|
const other = await openWs(s.origin, gm.cookie)
|
||||||
assert.equal((await other.waitText('hello')).n, 1)
|
assert.equal((await other.waitText('hello')).n, 1)
|
||||||
assert.equal((await other.waitText('walls')).n, 2)
|
assert.equal((await other.waitText('roster')).n, 2)
|
||||||
assert.equal((await other.request({ t: 'conn.ping', ts: 7 })).n, 3)
|
assert.equal((await other.waitText('walls')).n, 3)
|
||||||
|
assert.equal((await other.request({ t: 'conn.ping', ts: 7 })).n, 4)
|
||||||
// ... and the first connection's sequence did not move
|
// ... and the first connection's sequence did not move
|
||||||
assert.equal((await gm.ws.request({ t: 'conn.ping', ts: 44 })).n, 5)
|
assert.equal((await gm.ws.request({ t: 'conn.ping', ts: 44 })).n, 6)
|
||||||
for (const m of gm.ws.messages) assert.equal(typeof m.n, 'number', JSON.stringify(m))
|
for (const m of gm.ws.messages) assert.equal(typeof m.n, 'number', JSON.stringify(m))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -62,7 +64,7 @@ test('every server frame carries a catalogue type (nothing outside the wire cata
|
|||||||
await gm.ws.sendText('{')
|
await gm.ws.sendText('{')
|
||||||
await sleep(100)
|
await sleep(100)
|
||||||
const seen = new Set(gm.ws.messages.map(m => m.t))
|
const seen = new Set(gm.ws.messages.map(m => m.t))
|
||||||
assert.deepEqual([...seen].sort(), ['ack', 'error', 'hello', 'walls'])
|
assert.deepEqual([...seen].sort(), ['ack', 'error', 'hello', 'roster', 'walls'])
|
||||||
for (const m of gm.ws.messages) assert.ok(SERVER_TYPES.has(m.t), `off-catalogue type ${m.t}`)
|
for (const m of gm.ws.messages) assert.ok(SERVER_TYPES.has(m.t), `off-catalogue type ${m.t}`)
|
||||||
assert.ok(!seen.has('event'), '`event` is reserved and not built (DESIGN 9)')
|
assert.ok(!seen.has('event'), '`event` is reserved and not built (DESIGN 9)')
|
||||||
gm.ws.close()
|
gm.ws.close()
|
||||||
@@ -97,12 +99,13 @@ test('an unknown type is refused, unknown fields are ignored, and every intent g
|
|||||||
assert.equal((await gm.ws.request({ t: 'token.teleport', id: 'x' })).code, 'unknown-type')
|
assert.equal((await gm.ws.request({ t: 'token.teleport', id: 'x' })).code, 'unknown-type')
|
||||||
assert.equal((await gm.ws.request({ t: '' })).code, 'unknown-type')
|
assert.equal((await gm.ws.request({ t: '' })).code, 'unknown-type')
|
||||||
assert.equal((await gm.ws.request({ t: 'TOKEN.MOVE', id: 'x' })).code, 'unknown-type')
|
assert.equal((await gm.ws.request({ t: 'TOKEN.MOVE', id: 'x' })).code, 'unknown-type')
|
||||||
// a catalogue intent whose slice has not landed still answers exactly once (slice 8)
|
// the only catalogue intent whose slice has not landed still answers exactly once
|
||||||
assert.equal((await gm.ws.request({ t: 'name.reveal', subject: 'token', id: 'x',
|
|
||||||
player: 2 })).code, 'unknown-type')
|
|
||||||
assert.equal((await gm.ws.request({ t: 'scene.set', scene: 1 })).code, 'unknown-type')
|
assert.equal((await gm.ws.request({ t: 'scene.set', scene: 1 })).code, 'unknown-type')
|
||||||
assert.equal((await gm.ws.request({ t: 'character.create', descriptive_name: 'x',
|
// a built intent answers on its own fields instead
|
||||||
actual_name: 'X' })).code, 'unknown-type')
|
assert.equal((await gm.ws.request({ t: 'name.reveal', subject: 'token', id: 'x',
|
||||||
|
player: 2 })).code, 'not-found')
|
||||||
|
assert.equal((await gm.ws.request({ t: 'character.create' })).code, 'invalid')
|
||||||
|
assert.equal((await gm.ws.request({ t: 'scene.set' })).code, 'unknown-type')
|
||||||
// an intent whose slice HAS landed answers on its fields (empty token.create = invalid)
|
// an intent whose slice HAS landed answers on its fields (empty token.create = invalid)
|
||||||
assert.equal((await gm.ws.request({ t: 'token.create', scene: 1 })).code, 'invalid')
|
assert.equal((await gm.ws.request({ t: 'token.create', scene: 1 })).code, 'invalid')
|
||||||
// the reserved FFF hook is refused for everyone and is never ok
|
// the reserved FFF hook is refused for everyone and is never ok
|
||||||
@@ -147,8 +150,8 @@ test('an unnamed player: hello with a null name, ping works, everything else is
|
|||||||
// step 5 of 6.5, before the role and unknown-type checks
|
// step 5 of 6.5, before the role and unknown-type checks
|
||||||
assert.equal((await p.ws.request({ t: 'player.rename', id: player.id })).code, 'not-allowed')
|
assert.equal((await p.ws.request({ t: 'player.rename', id: player.id })).code, 'not-allowed')
|
||||||
assert.equal((await p.ws.request({ t: 'token.move', id: 'abcdefghijkl' })).code, 'not-allowed')
|
assert.equal((await p.ws.request({ t: 'token.move', id: 'abcdefghijkl' })).code, 'not-allowed')
|
||||||
// a GM-only intent is refused to a named player too (step 6)
|
// a GM-only intent sent by a player is refused (step 6), named or not
|
||||||
assert.equal((await gm.ws.request({ t: 'key.show', id: 2 })).code, 'unknown-type')
|
assert.equal((await p.ws.request({ t: 'key.show', id: player.id })).code, 'not-allowed')
|
||||||
p.ws.close(); gm.ws.close()
|
p.ws.close(); gm.ws.close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -286,12 +289,12 @@ test('the server pings the connection and answers a client Ping with a Pong', as
|
|||||||
const pong = await raw.waitFor(f => f.opcode === opcodes.pong && f.payload.toString() === 'hello')
|
const pong = await raw.waitFor(f => f.opcode === opcodes.pong && f.payload.toString() === 'hello')
|
||||||
assert.ok(pong)
|
assert.ok(pong)
|
||||||
|
|
||||||
// control frames are not counted by `n`: hello = 1, walls = 2, this ack = 3
|
// control frames are not counted by `n`: hello = 1, roster = 2, walls = 3, this ack = 4
|
||||||
raw.sendText({ t: 'conn.ping', reqId: 900, ts: 5 })
|
raw.sendText({ t: 'conn.ping', reqId: 900, ts: 5 })
|
||||||
const ack = await raw.waitText('ack')
|
const ack = await raw.waitText('ack')
|
||||||
assert.equal(ack.reqId, 900)
|
assert.equal(ack.reqId, 900)
|
||||||
assert.equal(ack.ok, true)
|
assert.equal(ack.ok, true)
|
||||||
assert.equal(ack.n, 3)
|
assert.equal(ack.n, 4)
|
||||||
raw.close()
|
raw.close()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -49,16 +49,16 @@ test('a fresh DB is created and migrated; re-opening applies nothing', async ()
|
|||||||
const first = await startServer({ stateDir })
|
const first = await startServer({ stateDir })
|
||||||
const firstLog = first.log()
|
const firstLog = first.log()
|
||||||
await stopServer(first)
|
await stopServer(first)
|
||||||
assert.match(firstLog, /db_ready .*schema_version=6 applied=6/, firstLog)
|
assert.match(firstLog, /db_ready .*schema_version=7 applied=7/, firstLog)
|
||||||
assert.ok(fs.existsSync(first.dbPath), 'state.db was not created')
|
assert.ok(fs.existsSync(first.dbPath), 'state.db was not created')
|
||||||
|
|
||||||
const db = new DatabaseSync(first.dbPath)
|
const db = new DatabaseSync(first.dbPath)
|
||||||
try {
|
try {
|
||||||
assert.equal(Number(db.prepare('PRAGMA user_version').get().user_version), 6)
|
assert.equal(Number(db.prepare('PRAGMA user_version').get().user_version), 7)
|
||||||
const rows = db.prepare('SELECT version, name FROM schema_migration ORDER BY version').all()
|
const rows = db.prepare('SELECT version, name FROM schema_migration ORDER BY version').all()
|
||||||
assert.deepEqual(rows.map(r => [Number(r.version), r.name]),
|
assert.deepEqual(rows.map(r => [Number(r.version), r.name]),
|
||||||
[[1, 'meta'], [2, 'auth'], [3, 'world'], [4, 'tokens'], [5, 'explored'],
|
[[1, 'meta'], [2, 'auth'], [3, 'world'], [4, 'tokens'], [5, 'explored'],
|
||||||
[6, 'token details']])
|
[6, 'token details'], [7, 'characters']])
|
||||||
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM meta').get().n), 0)
|
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM meta').get().n), 0)
|
||||||
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM player').get().n), 0)
|
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM player').get().n), 0)
|
||||||
// step 3 seeds the single v1 scene (Q3) with no walls and a counter at 1
|
// step 3 seeds the single v1 scene (Q3) with no walls and a counter at 1
|
||||||
@@ -71,10 +71,14 @@ test('a fresh DB is created and migrated; re-opening applies nothing', async ()
|
|||||||
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM explored_chunk').get().n), 0)
|
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM explored_chunk').get().n), 0)
|
||||||
// step 6 adds the three prop buckets and the status set (DESIGN 5.5, 8; #22), empty
|
// step 6 adds the three prop buckets and the status set (DESIGN 5.5, 8; #22), empty
|
||||||
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM entity_status').get().n), 0)
|
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM entity_status').get().n), 0)
|
||||||
for (const col of ['props_public', 'props_owner', 'props_gm']) {
|
for (const col of ['props_public', 'props_owner', 'props_gm', 'character_id', 'reveal_all']) {
|
||||||
assert.equal(Number(db.prepare(`SELECT count(*) AS n FROM pragma_table_info('entity')
|
assert.equal(Number(db.prepare(`SELECT count(*) AS n FROM pragma_table_info('entity')
|
||||||
WHERE name = '${col}'`).get().n), 1, col)
|
WHERE name = '${col}'`).get().n), 1, col)
|
||||||
}
|
}
|
||||||
|
// step 7 creates the character world (DESIGN 8, #23), empty
|
||||||
|
for (const table of ['character', 'name_reveal', 'encountered']) {
|
||||||
|
assert.equal(Number(db.prepare(`SELECT count(*) AS n FROM ${table}`).get().n), 0, table)
|
||||||
|
}
|
||||||
assert.equal(db.prepare('PRAGMA journal_mode').get().journal_mode, 'wal')
|
assert.equal(db.prepare('PRAGMA journal_mode').get().journal_mode, 'wal')
|
||||||
} finally {
|
} finally {
|
||||||
db.close()
|
db.close()
|
||||||
@@ -83,7 +87,7 @@ test('a fresh DB is created and migrated; re-opening applies nothing', async ()
|
|||||||
const second = await startServer({ stateDir })
|
const second = await startServer({ stateDir })
|
||||||
const secondLog = second.log().slice(firstLog.length)
|
const secondLog = second.log().slice(firstLog.length)
|
||||||
await stopServer(second)
|
await stopServer(second)
|
||||||
assert.match(secondLog, /db_ready .*schema_version=6 applied=0/, secondLog)
|
assert.match(secondLog, /db_ready .*schema_version=7 applied=0/, secondLog)
|
||||||
assert.doesNotMatch(secondLog, /applied=[1-9]/)
|
assert.doesNotMatch(secondLog, /applied=[1-9]/)
|
||||||
} finally {
|
} finally {
|
||||||
fs.rmSync(stateDir, { recursive: true, force: true })
|
fs.rmSync(stateDir, { recursive: true, force: true })
|
||||||
|
|||||||
+20
-18
@@ -17,10 +17,10 @@ async function gmConnect(origin, gmKey) {
|
|||||||
return { ...conn, scene: walls.scene, walls }
|
return { ...conn, scene: walls.scene, walls }
|
||||||
}
|
}
|
||||||
|
|
||||||
// A named player: naming is the harness fixture of lib.mjs until slice 8 brings player.setname.
|
// A named player: the harness names it through `player.setname` (lib.mjs, slice 8 / #23).
|
||||||
async function namedPlayer(stateDir, gm, name) {
|
async function namedPlayer(origin, gm, name) {
|
||||||
const player = await createPlayer(gm.ws)
|
const player = await createPlayer(gm.ws)
|
||||||
await namePlayer(stateDir, player.id, name)
|
await namePlayer(origin, player.key, name)
|
||||||
return player
|
return player
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ const tokenFrames = ws => ws.messages.filter(m => m.t === 'token')
|
|||||||
test('token.create: ack with the id, the token to the GM, invisible to a player out of range', async () => {
|
test('token.create: ack with the id, the token to the GM, invisible to a player out of range', async () => {
|
||||||
await withGmServer(async (s, gmKey) => {
|
await withGmServer(async (s, gmKey) => {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const player = await namedPlayer(s.stateDir, gm, 'Alice')
|
const player = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
const p = await playerConnect(s.origin, player)
|
const p = await playerConnect(s.origin, player)
|
||||||
|
|
||||||
const ack = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [400, 400],
|
const ack = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [400, 400],
|
||||||
@@ -73,7 +73,7 @@ test('token.create validation: the 6.1 table and the fields this slice cannot ho
|
|||||||
await withGmServer(async (s, gmKey) => {
|
await withGmServer(async (s, gmKey) => {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const scene = gm.scene
|
const scene = gm.scene
|
||||||
const player = await namedPlayer(s.stateDir, gm, 'Alice')
|
const player = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
const base = { kind: 'npc', pos: [100, 100], descriptive_name: 'a thing', actual_name: 'Thing' }
|
const base = { kind: 'npc', pos: [100, 100], descriptive_name: 'a thing', actual_name: 'Thing' }
|
||||||
const invalid = [
|
const invalid = [
|
||||||
{ ...base, descriptive_name: '' },
|
{ ...base, descriptive_name: '' },
|
||||||
@@ -118,8 +118,8 @@ test('token.create validation: the 6.1 table and the fields this slice cannot ho
|
|||||||
test('token.move: controller only, uniform nack, and one code for unknown and not-yours', async () => {
|
test('token.move: controller only, uniform nack, and one code for unknown and not-yours', async () => {
|
||||||
await withGmServer(async (s, gmKey) => {
|
await withGmServer(async (s, gmKey) => {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const alice = await namedPlayer(s.stateDir, gm, 'Alice')
|
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
const bob = await namedPlayer(s.stateDir, gm, 'Bob')
|
const bob = await namedPlayer(s.origin, gm, 'Bob')
|
||||||
const mine = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [400, 400],
|
const mine = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [400, 400],
|
||||||
descriptive_name: 'Alice', actual_name: 'Alice',
|
descriptive_name: 'Alice', actual_name: 'Alice',
|
||||||
controller: alice.id, flags: { vision: true } })
|
controller: alice.id, flags: { vision: true } })
|
||||||
@@ -166,7 +166,7 @@ test('token.move: controller only, uniform nack, and one code for unknown and no
|
|||||||
test('token.update: controller, gm_only, names, flags and the codes of 6.5', async () => {
|
test('token.update: controller, gm_only, names, flags and the codes of 6.5', async () => {
|
||||||
await withGmServer(async (s, gmKey) => {
|
await withGmServer(async (s, gmKey) => {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const alice = await namedPlayer(s.stateDir, gm, 'Alice')
|
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
const own = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [300, 400],
|
const own = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [300, 400],
|
||||||
descriptive_name: 'Alice', actual_name: 'Alice',
|
descriptive_name: 'Alice', actual_name: 'Alice',
|
||||||
controller: alice.id, flags: { vision: true } })
|
controller: alice.id, flags: { vision: true } })
|
||||||
@@ -219,7 +219,7 @@ test('token.update: controller, gm_only, names, flags and the codes of 6.5', asy
|
|||||||
test('token.remove: token_gone to whoever knew it, not-found after', async () => {
|
test('token.remove: token_gone to whoever knew it, not-found after', async () => {
|
||||||
await withGmServer(async (s, gmKey) => {
|
await withGmServer(async (s, gmKey) => {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const alice = await namedPlayer(s.stateDir, gm, 'Alice')
|
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [300, 400],
|
await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [300, 400],
|
||||||
descriptive_name: 'Alice', actual_name: 'Alice',
|
descriptive_name: 'Alice', actual_name: 'Alice',
|
||||||
controller: alice.id, flags: { vision: true } })
|
controller: alice.id, flags: { vision: true } })
|
||||||
@@ -239,7 +239,7 @@ test('token.remove: token_gone to whoever knew it, not-found after', async () =>
|
|||||||
test('connect resync: GM gets walls then every token; a player vision, explored, then its tokens', async () => {
|
test('connect resync: GM gets walls then every token; a player vision, explored, then its tokens', async () => {
|
||||||
await withGmServer(async (s, gmKey) => {
|
await withGmServer(async (s, gmKey) => {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const alice = await namedPlayer(s.stateDir, gm, 'Alice')
|
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
const visible = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'npc',
|
const visible = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'npc',
|
||||||
pos: [450, 400], descriptive_name: 'a wolf',
|
pos: [450, 400], descriptive_name: 'a wolf',
|
||||||
actual_name: 'Fang' })
|
actual_name: 'Fang' })
|
||||||
@@ -262,7 +262,8 @@ test('connect resync: GM gets walls then every token; a player vision, explored,
|
|||||||
assert.deepEqual(hello.extra, {})
|
assert.deepEqual(hello.extra, {})
|
||||||
assert.equal(hello.n, 1)
|
assert.equal(hello.n, 1)
|
||||||
const order = gm2.ws.messages.map(m => m.t)
|
const order = gm2.ws.messages.map(m => m.t)
|
||||||
assert.deepEqual(order.slice(0, 2), ['hello', 'walls'])
|
// 6.3 resync order: roster, walls, then every token (characters/encountered are slice 8).
|
||||||
|
assert.deepEqual(order.slice(0, 3), ['hello', 'roster', 'walls'])
|
||||||
assert.equal(order.filter(t => t === 'token').length, 3)
|
assert.equal(order.filter(t => t === 'token').length, 3)
|
||||||
assert.equal(order.includes('vision'), false, 'the GM never gets vision polygons')
|
assert.equal(order.includes('vision'), false, 'the GM never gets vision polygons')
|
||||||
assert.equal(order.includes('explored'), false, 'the GM never gets explored cells')
|
assert.equal(order.includes('explored'), false, 'the GM never gets explored cells')
|
||||||
@@ -273,15 +274,16 @@ test('connect resync: GM gets walls then every token; a player vision, explored,
|
|||||||
const a = await playerConnect(s.origin, alice, 1)
|
const a = await playerConnect(s.origin, alice, 1)
|
||||||
await sleep(150)
|
await sleep(150)
|
||||||
const aOrder = a.ws.messages.map(m => m.t)
|
const aOrder = a.ws.messages.map(m => m.t)
|
||||||
assert.deepEqual(aOrder.slice(0, 3), ['hello', 'vision', 'explored'])
|
// 6.3: hello, roster, the encountered list, then vision/explored and the tokens.
|
||||||
const explored = a.ws.messages[2]
|
assert.deepEqual(aOrder.slice(0, 5), ['hello', 'roster', 'encountered', 'vision', 'explored'])
|
||||||
|
const explored = a.ws.messages[4]
|
||||||
assert.equal(explored.full, true)
|
assert.equal(explored.full, true)
|
||||||
assert.ok(Array.isArray(explored.rle))
|
assert.ok(Array.isArray(explored.rle))
|
||||||
const ids = tokenFrames(a.ws).map(m => m.id).sort()
|
const ids = tokenFrames(a.ws).map(m => m.id).sort()
|
||||||
assert.deepEqual(ids, [mine.id].sort(),
|
assert.deepEqual(ids, [mine.id].sort(),
|
||||||
'a player gets only what it controls or sees (its own token is far away: controlled)')
|
'a player gets only what it controls or sees (its own token is far away: controlled)')
|
||||||
assert.equal(ids.includes(far.id), false)
|
assert.equal(ids.includes(far.id), false)
|
||||||
const vision = a.ws.messages[1]
|
const vision = a.ws.messages[3]
|
||||||
assert.equal(vision.polys.length, 1)
|
assert.equal(vision.polys.length, 1)
|
||||||
assert.equal(vision.polys[0].id, mine.id)
|
assert.equal(vision.polys[0].id, mine.id)
|
||||||
for (const pt of vision.polys[0].pts) {
|
for (const pt of vision.polys[0].pts) {
|
||||||
@@ -294,7 +296,7 @@ test('connect resync: GM gets walls then every token; a player vision, explored,
|
|||||||
test('an unnamed player gets nothing but hello, and every intent is refused (6.1, 6.5 step 5)', async () => {
|
test('an unnamed player gets nothing but hello, and every intent is refused (6.1, 6.5 step 5)', async () => {
|
||||||
await withGmServer(async (s, gmKey) => {
|
await withGmServer(async (s, gmKey) => {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const player = await createPlayer(gm.ws) // no name: slice 8 brings player.setname
|
const player = await createPlayer(gm.ws) // a fresh key: unnamed until player.setname
|
||||||
const p = await playerConnect(s.origin, player)
|
const p = await playerConnect(s.origin, player)
|
||||||
const hello = await p.ws.waitText('hello')
|
const hello = await p.ws.waitText('hello')
|
||||||
assert.deepEqual(Object.keys(hello).sort(), ['me', 'n', 'proto', 'role', 't'])
|
assert.deepEqual(Object.keys(hello).sort(), ['me', 'n', 'proto', 'role', 't'])
|
||||||
@@ -315,7 +317,7 @@ test('door closing pushes an overlapped token aside (5.5), and the push is a nor
|
|||||||
async () => {
|
async () => {
|
||||||
await withGmServer(async (s, gmKey) => {
|
await withGmServer(async (s, gmKey) => {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const alice = await namedPlayer(s.stateDir, gm, 'Alice')
|
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
const door = await gm.ws.request({ t: 'wall.add', scene: gm.scene, a: [500, 400], b: [500, 700],
|
const door = await gm.ws.request({ t: 'wall.add', scene: gm.scene, a: [500, 400], b: [500, 700],
|
||||||
kind: 'door' })
|
kind: 'door' })
|
||||||
const tok = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc',
|
const tok = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc',
|
||||||
@@ -350,7 +352,7 @@ test('restart: tokens, positions and controllers come back with the same view',
|
|||||||
let ids
|
let ids
|
||||||
try {
|
try {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const alice = await namedPlayer(stateDir, gm, 'Alice')
|
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
const t1 = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [400, 400],
|
const t1 = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [400, 400],
|
||||||
descriptive_name: 'Alice', actual_name: 'Alice',
|
descriptive_name: 'Alice', actual_name: 'Alice',
|
||||||
controller: alice.id, flags: { vision: true } })
|
controller: alice.id, flags: { vision: true } })
|
||||||
@@ -384,7 +386,7 @@ test('restart: tokens, positions and controllers come back with the same view',
|
|||||||
test('player.remove hands the player\'s tokens to the GM (3.2)', async () => {
|
test('player.remove hands the player\'s tokens to the GM (3.2)', async () => {
|
||||||
await withGmServer(async (s, gmKey) => {
|
await withGmServer(async (s, gmKey) => {
|
||||||
const gm = await gmConnect(s.origin, gmKey)
|
const gm = await gmConnect(s.origin, gmKey)
|
||||||
const alice = await namedPlayer(s.stateDir, gm, 'Alice')
|
const alice = await namedPlayer(s.origin, gm, 'Alice')
|
||||||
const tok = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [400, 400],
|
const tok = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [400, 400],
|
||||||
descriptive_name: 'Alice', actual_name: 'Alice',
|
descriptive_name: 'Alice', actual_name: 'Alice',
|
||||||
controller: alice.id, flags: { vision: true } })
|
controller: alice.id, flags: { vision: true } })
|
||||||
|
|||||||
Reference in New Issue
Block a user