repository = $repository; } /** * Send a command to a running server. * * @param \Pterodactyl\Http\Requests\Api\Client\Servers\SendCommandRequest $request * @param \Pterodactyl\Models\Server $server * @return \Illuminate\Http\Response * * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException */ public function index(SendCommandRequest $request, Server $server): Response { try { $this->repository->setServer($server)->send($request->input('command')); } catch (DaemonConnectionException $exception) { $previous = $exception->getPrevious(); if ($previous instanceof BadResponseException) { if ( $previous->getResponse() instanceof ResponseInterface && $previous->getResponse()->getStatusCode() === Response::HTTP_BAD_GATEWAY ) { throw new HttpException( Response::HTTP_BAD_GATEWAY, 'Server must be online in order to send commands.', $exception ); } } throw $exception; } return $this->returnNoContent(); } }