[api] wip reputation

This commit is contained in:
Devin Zuczek
2026-08-25 21:37:07 -04:00
parent 4bacdb0312
commit 4ff9609a8f
8 changed files with 1041 additions and 35 deletions
+25
View File
@@ -175,6 +175,31 @@ export async function countPlayersInInstance(
return row?.n ?? 0
}
/**
* WHO is standing in a room instance right now — the sibling of
* {@link countPlayersInInstance}, for when the answer has to be addressed rather than
* counted. The fan-out set for anything that happens in front of a room: a cheer plays its
* effect on every client in the instance, not just the two players involved.
*
* Reads only unexpired presence, so it is the LIVE occupancy — a player who crashed out
* drops off it when their row lapses. Ordered by account id for a stable result.
*/
export async function getPlayerIdsInInstance(
db: D1Database,
roomInstanceId: number,
now = nowSeconds()
): Promise<number[]> {
const { results } = await db
.prepare(
`SELECT account_id AS accountId FROM presence
WHERE room_instance_id = ?1 AND expires_at > ?2
ORDER BY account_id`
)
.bind(roomInstanceId, 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