[match] dont allow invites into unpublished rooms

This commit is contained in:
Devin Zuczek
2026-09-30 17:17:11 -04:00
parent 7e10143454
commit 90c808c4a3
3 changed files with 187 additions and 8 deletions
+22
View File
@@ -127,6 +127,28 @@ export async function getLatestRoomInviteBetween(
}
}
/**
* Whether ANY live invite stands to `toPlayerId` for the room with this id, from anyone.
*
* This is the key that opens an unpublished room to a room MATCHMAKE
* (`POST /matchmake[/v2]/room/:roomId` on `match`): a room that isn't public admits its
* creator, its role holders, and whoever has been invited into it — and "invited" is a row
* here whose `room_id` is that room. Any row is enough and none is consumed: the caller may
* be retrying a join that failed downstream, and the row expires with the sweep anyway.
* A miss is, as everywhere in this module, "never invited" and "already swept" alike.
*/
export async function hasRoomInviteTo(
db: D1Database,
toPlayerId: number,
roomId: number
): Promise<boolean> {
const row = await db
.prepare(`SELECT 1 AS hit FROM room_invite WHERE to_player_id = ?1 AND room_id = ?2 LIMIT 1`)
.bind(toPlayerId, roomId)
.first<{ hit: number }>()
return row !== null
}
/**
* Record an invite from `fromPlayerId` to `toPlayerId` for a room, returning it as the
* client reads it back. `roomId` is null when the caller's room instance didn't resolve.