Skip to content

Commit

Permalink
fix: don't let players with active game join the queue
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc committed Aug 12, 2024
1 parent 04f9393 commit a42065a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/queue/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { mutex } from './mutex'

export async function join(slotId: number, steamId: SteamId64): Promise<QueueSlotModel[]> {
return await mutex.runExclusive(async () => {
logger.info({ steamId, slotId }, `join queue`)
logger.trace({ steamId, slotId }, `join queue`)
const player = await collections.players.findOne({ steamId })
if (!player) {
throw new Error(`player does not exist: ${steamId}`)
Expand All @@ -19,6 +19,10 @@ export async function join(slotId: number, steamId: SteamId64): Promise<QueueSlo
// throw new Error(`player has not accepted rules`)
// }

if (player.activeGame) {
throw new Error(`player has active game`)
}

const state = await getState()
if (![QueueState.waiting, QueueState.ready].includes(state)) {
throw new Error('invalid queue state')
Expand Down
10 changes: 8 additions & 2 deletions src/queue/views/html/queue-slot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ export async function QueueSlot(props: { slot: QueueSlotModel; actor?: SteamId64
/>
)
} else if (props.actor) {
slotContent = <JoinButton slotId={props.slot.id} />
const actor = await collections.players.findOne({ steamId: props.actor })
if (!props.actor) {
throw new Error(`actor invalid: ${props.actor}`)
}

slotContent = <JoinButton slotId={props.slot.id} disabled={Boolean(actor?.activeGame)} />
}

return (
Expand All @@ -59,13 +64,14 @@ export async function QueueSlot(props: { slot: QueueSlotModel; actor?: SteamId64
)
}

function JoinButton(props: { slotId: number }) {
function JoinButton(props: { slotId: number; disabled: boolean }) {
return (
<button
class="join-queue-button"
name="join"
value={`${props.slotId}`}
aria-label={`Join queue on slot ${props.slotId}`}
disabled={props.disabled}
>
<IconPlus />
</button>
Expand Down

0 comments on commit a42065a

Please sign in to comment.