| @@ 70-90 (lines=21) @@ | ||
| 67 | * @throws \Pterodactyl\Exceptions\DisplayException |
|
| 68 | * @throws \GuzzleHttp\Exception\RequestException |
|
| 69 | */ |
|
| 70 | public function send($command) |
|
| 71 | { |
|
| 72 | // We don't use the user's specific daemon secret here since we |
|
| 73 | // are assuming that a call to this function has been validated. |
|
| 74 | try { |
|
| 75 | $response = $this->server->guzzleClient($this->user)->request('POST', '/server/command', [ |
|
| 76 | 'http_errors' => false, |
|
| 77 | 'json' => [ |
|
| 78 | 'command' => $command, |
|
| 79 | ], |
|
| 80 | ]); |
|
| 81 | ||
| 82 | if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) { |
|
| 83 | throw new DisplayException('Command sending responded with a non-200 error code (HTTP/' . $response->getStatusCode() . ').'); |
|
| 84 | } |
|
| 85 | ||
| 86 | return $response->getBody(); |
|
| 87 | } catch (ConnectException $ex) { |
|
| 88 | throw $ex; |
|
| 89 | } |
|
| 90 | } |
|
| 91 | } |
|
| 92 | ||
| @@ 70-88 (lines=19) @@ | ||
| 67 | * @throws \GuzzleHttp\Exception\RequestException |
|
| 68 | * @throws \Pterodactyl\Exceptions\DisplayException |
|
| 69 | */ |
|
| 70 | public function do($action) |
|
| 71 | { |
|
| 72 | try { |
|
| 73 | $response = $this->server->guzzleClient($this->user)->request('PUT', '/server/power', [ |
|
| 74 | 'http_errors' => false, |
|
| 75 | 'json' => [ |
|
| 76 | 'action' => $action, |
|
| 77 | ], |
|
| 78 | ]); |
|
| 79 | ||
| 80 | if ($response->getStatusCode() < 200 || $response->getStatusCode() >= 300) { |
|
| 81 | throw new DisplayException('Power toggle endpoint responded with a non-200 error code (HTTP/' . $response->getStatusCode() . ').'); |
|
| 82 | } |
|
| 83 | ||
| 84 | return $response->getBody(); |
|
| 85 | } catch (ConnectException $ex) { |
|
| 86 | throw $ex; |
|
| 87 | } |
|
| 88 | } |
|
| 89 | ||
| 90 | /** |
|
| 91 | * Starts a server. |
|