keyProviderService = $keyProviderService; $this->repository = $repository; } /** * Send a command to a running server. * * @param \Pterodactyl\Http\Requests\Api\Client\Servers\SendCommandRequest $request * @return \Illuminate\Http\Response * * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException */ public function index(SendCommandRequest $request): Response { $server = $request->getModel(Server::class); $token = $this->keyProviderService->handle($server, $request->user()); try { $this->repository->setServer($server) ->setToken($token) ->send($request->input('command')); } catch (RequestException $exception) { if ($exception instanceof ClientException) { if ($exception->getResponse() instanceof ResponseInterface && $exception->getResponse()->getStatusCode() === 412) { throw new PreconditionFailedHttpException('Server is not online.'); } } throw new DaemonConnectionException($exception); } return $this->returnNoContent(); } }