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
+20 -17
View File
@@ -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.role, '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`)
assert.equal((await gm.ws.waitText('walls')).n, 2)
// 6.3: the roster, then the GM wall snapshot (slice 4, DESIGN 6.1 `walls`)
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 })
assert.equal(first.ok, true)
assert.equal(first.ts, 42) // the ack echoes ts
assert.equal(first.n, 3)
assert.equal((await gm.ws.request({ t: 'conn.ping', ts: 43 })).n, 4)
assert.equal(first.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)
const other = await openWs(s.origin, gm.cookie)
assert.equal((await other.waitText('hello')).n, 1)
assert.equal((await other.waitText('walls')).n, 2)
assert.equal((await other.request({ t: 'conn.ping', ts: 7 })).n, 3)
assert.equal((await other.waitText('roster')).n, 2)
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
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))
})
})
@@ -62,7 +64,7 @@ test('every server frame carries a catalogue type (nothing outside the wire cata
await gm.ws.sendText('{')
await sleep(100)
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}`)
assert.ok(!seen.has('event'), '`event` is reserved and not built (DESIGN 9)')
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: '' })).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)
assert.equal((await gm.ws.request({ t: 'name.reveal', subject: 'token', id: 'x',
player: 2 })).code, 'unknown-type')
// the only catalogue intent whose slice has not landed still answers exactly once
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',
actual_name: 'X' })).code, 'unknown-type')
// a built intent answers on its own fields instead
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)
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
@@ -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
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')
// a GM-only intent is refused to a named player too (step 6)
assert.equal((await gm.ws.request({ t: 'key.show', id: 2 })).code, 'unknown-type')
// a GM-only intent sent by a player is refused (step 6), named or not
assert.equal((await p.ws.request({ t: 'key.show', id: player.id })).code, 'not-allowed')
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')
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 })
const ack = await raw.waitText('ack')
assert.equal(ack.reqId, 900)
assert.equal(ack.ok, true)
assert.equal(ack.n, 3)
assert.equal(ack.n, 4)
raw.close()
})
})