-
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.
- Loading branch information
1 parent
b8e9967
commit 8aefd08
Showing
22 changed files
with
245 additions
and
54 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20240326113958_played_add_kicked/migration.sql
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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE `Player` ADD COLUMN `kicked` BOOLEAN NOT NULL DEFAULT false; |
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,40 @@ | ||
<script lang="ts"> | ||
export let userId: number; | ||
async function kickPlayer(userId: number) { | ||
const res = await fetch("../kick/" + userId + "/", { method: "POST" }); | ||
if (!res.ok) alert((await res.json()).message); | ||
} | ||
</script> | ||
|
||
<button | ||
on:click={async () => await kickPlayer(userId)} | ||
tabindex="0" | ||
type="button" | ||
> | ||
<slot/> | ||
</button> | ||
|
||
<style> | ||
button { | ||
border: 0; | ||
padding: 0; | ||
background: none; | ||
position: relative; | ||
font: inherit; | ||
&:hover { | ||
cursor: pointer; | ||
/* Strikethrough, including icons */ | ||
&::after { | ||
content: ""; | ||
position: absolute; | ||
width: calc(100% + 10px); | ||
top: 50%; | ||
left: -5px; | ||
border-top: 2px solid black; | ||
} | ||
} | ||
} | ||
</style> |
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 |
---|---|---|
|
@@ -14,5 +14,4 @@ | |
flex-flow: wrap; | ||
justify-content: center; | ||
text-align: center; | ||
|
||
} |
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 |
---|---|---|
@@ -1 +1,7 @@ | ||
export type LocalDoor = { svgRef1: number; svgRef2: number }; | ||
export type LeaderboardPlayer = { | ||
id: number; | ||
name: string; | ||
points: number; | ||
kickable?: boolean; | ||
}; |
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,3 @@ | ||
export const load = async ({ locals }) => { | ||
return { userId: locals.user.id }; | ||
}; |
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
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,38 @@ | ||
import prisma from "$lib/server/prisma"; | ||
import { error } from "@sveltejs/kit"; | ||
import ablyServer from "$lib/server/ably-server"; | ||
|
||
export const POST = async ({ locals, params }) => { | ||
const requestedUserId = +params.userId; | ||
if (requestedUserId == locals.user.id) error(403, "You can't kick yourself!"); | ||
|
||
const gameId = +params.gameId; | ||
const requestingPlayer = await prisma.player.findUnique({ | ||
where: { | ||
userId_gameId: { userId: locals.user.id, gameId }, | ||
isHost: true, | ||
}, | ||
select: { game: { select: { state: true } } }, | ||
}); | ||
if (!requestingPlayer) error(403, "You are not a host of this game!"); | ||
if (requestingPlayer.game.state == "ENDED") | ||
error(403, "You can't kick a player after the game has ended!"); | ||
|
||
const requestedPlayer = await prisma.player.findUnique({ | ||
where: { userId_gameId: { userId: requestedUserId, gameId } }, | ||
select: { isHost: true, kicked: true }, | ||
}); | ||
if (!requestedPlayer) error(403, "This user isn't in your game!"); | ||
if (requestedPlayer.isHost) error(403, "You can't kick a host!"); | ||
if (requestedPlayer.kicked) error(403, "This player is already kicked"); | ||
|
||
await prisma.player.update({ | ||
where: { userId_gameId: { userId: requestedUserId, gameId } }, | ||
data: { kicked: true }, | ||
select: { id: true }, | ||
}); | ||
ablyServer.channels | ||
.get("game:" + gameId + ":announcements") | ||
.publish("kick", { userId: requestedUserId }); | ||
return new Response(); | ||
}; |
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
Oops, something went wrong.