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:
@@ -341,3 +341,69 @@ test('GM roster, keys and token panel drive the real server', { timeout: 240000
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// #88: a plain reconnect is not a rename, so `roster` has to follow connections coming and going.
|
||||
async function waitRosterState(page, id, want, timeout = 30000) {
|
||||
try {
|
||||
await page.waitForFunction(
|
||||
([playerId, state]) => {
|
||||
const node = document.querySelector(
|
||||
`#gm-roster-list li[data-player="${playerId}"] .gm-roster-state, ` +
|
||||
`#gm-roster-list li[data-player="${playerId}"] #gm-roster-state`,
|
||||
)
|
||||
return node?.textContent === state
|
||||
},
|
||||
[id, want],
|
||||
{ timeout },
|
||||
)
|
||||
} catch (error) {
|
||||
const rows = await page.evaluate(() =>
|
||||
[...document.querySelectorAll('#gm-roster-list li')].map(li => li.textContent),
|
||||
)
|
||||
throw new Error(`${error.message}; roster was ${JSON.stringify(rows)}`)
|
||||
}
|
||||
}
|
||||
|
||||
test('GM roster connected follows a player tab reload and close', { timeout: 180000 }, async () => {
|
||||
await withStack(async ({ origin, gmKey }) => {
|
||||
const raw = await openAs(origin, gmKey)
|
||||
await raw.ws.waitText('hello')
|
||||
await raw.ws.waitText('walls')
|
||||
const bob = await createPlayer(raw.ws)
|
||||
await namePlayer(origin, bob.key, 'Bob')
|
||||
const browser = await launchBrowser()
|
||||
try {
|
||||
const gmView = await newPage(browser)
|
||||
const gm = gmView.page
|
||||
await gm.goto(`${origin}/`)
|
||||
await waitForVisible(gm, '#signin')
|
||||
await signIn(gm, gmKey)
|
||||
await waitForVisible(gm, '#gm-panels')
|
||||
await gm.locator(`#gm-roster-list li[data-player="${bob.id}"]`).waitFor({ state: 'visible' })
|
||||
await waitRosterState(gm, bob.id, 'offline')
|
||||
|
||||
const bobView = await newPage(browser)
|
||||
const bobPage = bobView.page
|
||||
await bobPage.goto(`${origin}/`)
|
||||
await waitForVisible(bobPage, '#signin')
|
||||
await signIn(bobPage, bob.key)
|
||||
await waitForVisible(bobPage, '#hud')
|
||||
await waitForText(bobPage, '#me', /^Bob$/)
|
||||
await waitRosterState(gm, bob.id, 'connected')
|
||||
|
||||
// A reload is a plain reconnect: no setname, but the GM row must end up online again.
|
||||
await bobPage.reload()
|
||||
await waitForVisible(bobPage, '#hud')
|
||||
await waitForText(bobPage, '#me', /^Bob$/)
|
||||
await waitRosterState(gm, bob.id, 'connected')
|
||||
|
||||
// Closing the tab must flip the row offline without any intent from the player.
|
||||
await bobView.context.close()
|
||||
await waitRosterState(gm, bob.id, 'offline')
|
||||
await gmView.context.close()
|
||||
} finally {
|
||||
raw.ws.close()
|
||||
await browser.close()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user