Files
moonwell-web/app/Http/Controllers/Api/LauncherGameTicketController.php
T
2026-10-03 14:33:08 +04:00

57 lines
2.4 KiB
PHP

<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\GameAccount;
use App\Services\LauncherGameTicketService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use OpenApi\Attributes as OA;
class LauncherGameTicketController extends Controller
{
public function __construct(private readonly LauncherGameTicketService $tickets) {}
#[OA\Post(
path: '/api/launcher/game-ticket',
summary: 'Выдать одноразовый билет для входа в vMaNGOS',
description: 'Создаёт короткоживущий SRP-билет. Новый билет отзывает предыдущий.',
security: [['bearerAuth' => []]],
tags: ['Launcher Auth'],
requestBody: new OA\RequestBody(required: true, content: new OA\JsonContent(
required: ['client_build'],
properties: [new OA\Property(property: 'client_build', type: 'integer', example: 5875)],
)),
responses: [
new OA\Response(response: 200, description: 'Билет выдан', content: new OA\JsonContent(
required: ['account', 'ticket', 'expires_at'],
properties: [
new OA\Property(property: 'account', type: 'string', example: 'PLAYERONE'),
new OA\Property(property: 'ticket', type: 'string', pattern: '^[A-Z0-9]{16}$'),
new OA\Property(property: 'expires_at', type: 'string', format: 'date-time'),
],
)),
new OA\Response(response: 401, description: 'Launcher authentication required'),
new OA\Response(response: 422, description: 'Unsupported client build'),
new OA\Response(response: 429, description: 'Too many requests'),
],
)]
public function store(Request $request): JsonResponse
{
$build = (int) $request->validate([
'client_build' => ['required', 'integer', Rule::in([(int) config('moonwell.launcher.client_build')])],
])['client_build'];
/** @var GameAccount $account */
$account = $request->user();
$bearer = $request->bearerToken();
abort_if($bearer === null, 401);
return response()
->json($this->tickets->issue($account, $bearer, $build))
->header('Cache-Control', 'no-store');
}
}