osu match playing

This commit is contained in:
2026-02-28 04:35:21 +01:00
parent 133b9e552b
commit e147ba4432
24 changed files with 2433 additions and 45 deletions

View File

@@ -0,0 +1,41 @@
import { json, error } from '@sveltejs/kit';
import { db } from '$lib/server/db';
import { createMatch } from '$lib/server/match/engine';
import type { RequestHandler } from './$types';
export const GET: RequestHandler = async ({ locals }) => {
if (!locals.user) error(401, 'Not logged in');
const matches = await db.query.match.findMany({
with: {
participants: { with: { team: true } }
},
orderBy: (m, { desc }) => [desc(m.createdAt)]
});
return json(matches);
};
export const POST: RequestHandler = async ({ request, locals }) => {
if (!locals.user) error(401, 'Not logged in');
const body = await request.json();
const { name, config, mappoolId, teams } = body;
if (!name || !config || !mappoolId || !teams?.length) {
error(400, 'Missing required fields');
}
try {
const result = await createMatch({
name,
config,
mappoolId,
teams,
createdBy: locals.user.id
});
return json(result, { status: 201 });
} catch (e) {
error(400, e.message);
}
};

View File

@@ -0,0 +1,25 @@
import { json, error } from '@sveltejs/kit';
import { getMatchFull, cancelMatch } from '$lib/server/match/engine';
import type { RequestHandler } from './$types';
export const GET: RequestHandler = async ({ params, locals }) => {
if (!locals.user) error(401, 'Not logged in');
try {
const m = await getMatchFull(params.id);
return json(m);
} catch (e) {
error(404, e.message);
}
};
export const DELETE: RequestHandler = async ({ params, locals }) => {
if (!locals.user) error(401, 'Not logged in');
try {
const m = await cancelMatch(params.id);
return json(m);
} catch (e) {
error(400, e.message);
}
};

View File

@@ -0,0 +1,16 @@
import { json, error } from '@sveltejs/kit';
import { moveToLobby } from '$lib/server/match/engine';
import type { RequestHandler } from './$types';
export const POST: RequestHandler = async ({ params, request, locals }) => {
if (!locals.user) error(401, 'Not logged in');
const body = await request.json().catch(() => ({}));
try {
const m = await moveToLobby(params.id, body.osuLobbyId);
return json(m);
} catch (e) {
error(400, e.message);
}
};

View File

@@ -0,0 +1,19 @@
import { json, error } from '@sveltejs/kit';
import { pickMap } from '$lib/server/match/engine';
import type { RequestHandler } from './$types';
export const POST: RequestHandler = async ({ params, request, locals }) => {
if (!locals.user) error(401, 'Not logged in');
const { participantId, mappoolSlotId } = await request.json();
if (!participantId || !mappoolSlotId) {
error(400, 'participantId and mappoolSlotId required');
}
try {
const game = await pickMap(params.id, participantId, mappoolSlotId);
return json(game);
} catch (e) {
error(400, e.message);
}
};

View File

@@ -0,0 +1,19 @@
import { json, error } from '@sveltejs/kit';
import { submitRoll } from '$lib/server/match/engine';
import type { RequestHandler } from './$types';
export const POST: RequestHandler = async ({ params, request, locals }) => {
if (!locals.user) error(401, 'Not logged in');
const { participantId, value } = await request.json();
if (!participantId || value == null) {
error(400, 'participantId and value required');
}
try {
const m = await submitRoll(params.id, participantId, value);
return json(m);
} catch (e) {
error(400, e.message);
}
};

View File

@@ -0,0 +1,14 @@
import { json, error } from '@sveltejs/kit';
import { moveToRolling } from '$lib/server/match/engine';
import type { RequestHandler } from './$types';
export const POST: RequestHandler = async ({ params, locals }) => {
if (!locals.user) error(401, 'Not logged in');
try {
const m = await moveToRolling(params.id);
return json(m);
} catch (e) {
error(400, e.message);
}
};

View File

@@ -0,0 +1,19 @@
import { json, error } from '@sveltejs/kit';
import { submitGameScores } from '$lib/server/match/engine';
import type { RequestHandler } from './$types';
export const POST: RequestHandler = async ({ request, locals }) => {
if (!locals.user) error(401, 'Not logged in');
const { matchGameId, scores } = await request.json();
if (!matchGameId || !scores?.length) {
error(400, 'matchGameId and scores required');
}
try {
const m = await submitGameScores(matchGameId, scores);
return json(m);
} catch (e) {
error(400, e.message);
}
};

View File

@@ -0,0 +1,42 @@
import { json, error } from '@sveltejs/kit';
import { joinQueue, leaveQueue, getQueueStatus } from '$lib/server/match/engine';
import { db } from '$lib/server/db';
import { team, teamMember } from '$lib/server/db/schema';
import { eq, and } from 'drizzle-orm';
import type { RequestHandler } from './$types';
export const GET: RequestHandler = async ({ locals }) => {
if (!locals.user) error(401, 'Not logged in');
const status = await getQueueStatus(locals.user.id);
return json(status);
};
export const POST: RequestHandler = async ({ locals }) => {
if (!locals.user) error(401, 'Not logged in');
// Find user's personal team
const membership = await db.query.teamMember.findFirst({
where: eq(teamMember.userId, locals.user.id),
with: { team: true }
});
const personalTeam = membership?.team;
if (!personalTeam?.isPersonal) {
error(400, 'No personal team found');
}
try {
const result = await joinQueue(locals.user.id, personalTeam.id);
return json({ matched: !!result, match: result });
} catch (e) {
error(400, e.message);
}
};
export const DELETE: RequestHandler = async ({ locals }) => {
if (!locals.user) error(401, 'Not logged in');
await leaveQueue(locals.user.id);
return json({ ok: true });
};