fix(server): broadcast roster on plain connect and close (#88)
A reconnect with an existing name fires no intent, so the only roster the GM saw was the connecting connection's own resync; the row stayed offline while the player badge said Connected. Send the GM roster when a connection activates (skipping the connecting connection, which already got it in the 6.3 resync) and after a close, with the registry entry removed first so connected is recomputed. Also cover the server-initiated malformed-flood close. The setname ack-before-resync ordering is unchanged. Tests: WS connect/close/reconnect roster states; e2e GM row follows a player tab reload and close. protocol test updated for the extra roster on a second connection.
This commit is contained in:
@@ -612,6 +612,43 @@ test('restart: characters, reveals and encountered lists come back', async () =>
|
||||
}
|
||||
})
|
||||
|
||||
const rosterEntry = (frame, id) => frame.players.find(entry => entry.id === id)
|
||||
const waitRosterState = (ws, from, id, connected, timeoutMs = 5000) =>
|
||||
ws.waitFor((m, i) => i >= from && m.t === 'roster' &&
|
||||
rosterEntry(m, id)?.connected === connected, timeoutMs)
|
||||
|
||||
// A plain reconnect is not a `player.setname`: the GM's roster must still follow the connection
|
||||
// coming and going, or a player who reloads looks offline for ever (DESIGN 6.1 `roster`/6.3).
|
||||
test('roster: connected follows a plain connect and close, not only setname', async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const alice = await createPlayer(gm.ws)
|
||||
let mark = gm.ws.messages.length
|
||||
const first = await connectNamed(s.origin, alice.key, 'Alice')
|
||||
await waitRosterState(gm.ws, mark, alice.id, true)
|
||||
|
||||
// Close the player connection: no intent is sent, only the WS close.
|
||||
mark = gm.ws.messages.length
|
||||
first.ws.close()
|
||||
await waitRosterState(gm.ws, mark, alice.id, false)
|
||||
|
||||
// Reconnect with the same key and name: hello only, so no setname/roster from the player side.
|
||||
mark = gm.ws.messages.length
|
||||
const again = await openAs_(s.origin, alice.key)
|
||||
const hello = await again.ws.waitText('hello')
|
||||
assert.equal(hello.me.name, 'Alice', 'the reconnect is named from the stored player row')
|
||||
await waitRosterState(gm.ws, mark, alice.id, true)
|
||||
assert.equal(again.ws.messages.some(m => m.t === 'roster'), true,
|
||||
'the connecting connection still gets its own roster in the resync')
|
||||
|
||||
// And it goes offline again on close.
|
||||
mark = gm.ws.messages.length
|
||||
again.ws.close()
|
||||
await waitRosterState(gm.ws, mark, alice.id, false)
|
||||
gm.ws.close()
|
||||
})
|
||||
})
|
||||
|
||||
// Local alias so the imports stay at the top of the file.
|
||||
async function openAs_(origin, key) {
|
||||
const { cookie } = await signIn(origin, key)
|
||||
|
||||
@@ -43,8 +43,11 @@ test('hello is the first frame; n counts server frames per connection, never glo
|
||||
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, 6)
|
||||
// The second connection is a plain connect, so the first GM connection gets a roster with the
|
||||
// new `connected` state (6.1 roster) and its own counter advances by one.
|
||||
assert.equal((await gm.ws.waitFor(m => m.t === 'roster' && m.n === 6)).n, 6)
|
||||
// ... and the first connection's per-connection counter did not move with `other`'s.
|
||||
assert.equal((await gm.ws.request({ t: 'conn.ping', ts: 44 })).n, 7)
|
||||
for (const m of gm.ws.messages) assert.equal(typeof m.n, 'number', JSON.stringify(m))
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user