[www] token drop functionality

This commit is contained in:
Devin Zuczek
2026-09-22 21:41:48 -04:00
parent 8ef8f9af50
commit b81974476e
5 changed files with 246 additions and 2 deletions
+19
View File
@@ -238,6 +238,25 @@ export async function getPlayerIdsInRoom(
return results.map((r) => r.accountId)
}
/**
* Everyone online right now, anywhere — the same population {@link countOnlinePlayers}
* counts, as ids. Unexpired presence only, one row per account, lobby (null-instance)
* presence included: a player sat in a menu is as online as one in a room, and a gift to
* "everyone online" that skipped them would look to them like being skipped on purpose.
* Ordered so a pass over it is deterministic.
*/
export async function getOnlinePlayerIds(db: D1Database, now = nowSeconds()): Promise<number[]> {
const { results } = await db
.prepare(
`SELECT DISTINCT account_id AS accountId FROM presence
WHERE expires_at > ?1
ORDER BY account_id`
)
.bind(now)
.all<{ accountId: number }>()
return results.map((r) => r.accountId)
}
/**
* How many players are online right now, anywhere — one row per account, so this is
* the player count a status page means. Counts unexpired presence only: rows outlive