-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: kick banned player from the queue (#28)
- Loading branch information
1 parent
596259b
commit c4e7756
Showing
10 changed files
with
208 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { ObjectId } from 'mongodb' | ||
import { collections } from '../database/collections' | ||
import type { SteamId64 } from '../shared/types/steam-id-64' | ||
import { events } from '../events' | ||
|
||
export async function revokeBan(banId: ObjectId, adminId: SteamId64) { | ||
let ban = await collections.playerBans.findOne({ _id: banId }) | ||
if (!ban) { | ||
throw new Error(`ban not found: ${banId}`) | ||
} | ||
|
||
if (ban.end < new Date()) { | ||
throw new Error(`ban already expired: ${banId}`) | ||
} | ||
|
||
const after = (await collections.playerBans.findOneAndUpdate( | ||
{ _id: banId }, | ||
{ $set: { end: new Date() } }, | ||
{ | ||
returnDocument: 'after', | ||
}, | ||
))! | ||
events.emit('player/ban:revoked', { ban: after, admin: adminId }) | ||
return after | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import fp from 'fastify-plugin' | ||
import { events } from '../../events' | ||
import { safe } from '../../utils/safe' | ||
import { kick } from '../kick' | ||
import { collections } from '../../database/collections' | ||
|
||
export default fp( | ||
async () => { | ||
events.on('player/ban:added', async ({ ban }) => { | ||
await safe(async () => { | ||
const player = await collections.players.findOne({ _id: ban.player }) | ||
if (!player) { | ||
throw new Error(`player ${ban.player.toString()} not found`) | ||
} | ||
|
||
await kick(player.steamId) | ||
}) | ||
}) | ||
}, | ||
{ | ||
name: 'kick banned players', | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { users } from '../data' | ||
import { authUsers, expect } from '../fixtures/auth-users' | ||
import { QueuePage } from '../pages/queue.page' | ||
|
||
authUsers.use({ steamIds: [users[0].steamId, users[1].steamId] }) | ||
|
||
authUsers('banned player gets kicked', async ({ steamIds, pages }) => { | ||
const player = new QueuePage(pages.get(users[1].steamId)!) | ||
await player.joinQueue(0) | ||
|
||
const admin = users[0] | ||
const adminPage = pages.get(admin.steamId)! | ||
await adminPage.goto(`/players/${steamIds[1]}`) | ||
await adminPage.getByRole('link', { name: 'Edit player' }).click() | ||
await adminPage.getByRole('link', { name: 'Bans' }).click() | ||
await adminPage.getByRole('link', { name: 'Add ban' }).click() | ||
await adminPage.getByLabel('Reason').fill('Cheating') | ||
await adminPage.getByRole('button', { name: 'Save' }).click() | ||
|
||
await expect(player.slot(0).joinButton()).toBeDisabled() | ||
|
||
await adminPage.getByRole('button', { name: 'Revoke ban' }).click() | ||
}) |