2019-09-06 03:33:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Repositories\Wings;
|
|
|
|
|
2019-09-06 04:41:20 +00:00
|
|
|
use Webmozart\Assert\Assert;
|
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
2020-07-15 04:16:38 +00:00
|
|
|
use GuzzleHttp\Exception\TransferException;
|
|
|
|
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
2019-09-06 04:41:20 +00:00
|
|
|
|
2019-09-06 03:33:27 +00:00
|
|
|
class DaemonPowerRepository extends DaemonRepository
|
|
|
|
{
|
2019-09-06 04:41:20 +00:00
|
|
|
/**
|
|
|
|
* Sends a power action to the server instance.
|
|
|
|
*
|
2020-07-15 04:16:38 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
2019-09-06 04:41:20 +00:00
|
|
|
*/
|
|
|
|
public function send(string $action): ResponseInterface
|
|
|
|
{
|
|
|
|
Assert::isInstanceOf($this->server, Server::class);
|
|
|
|
|
2020-07-15 04:16:38 +00:00
|
|
|
try {
|
|
|
|
return $this->getHttpClient()->post(
|
|
|
|
sprintf('/api/servers/%s/power', $this->server->uuid),
|
|
|
|
['json' => ['action' => $action]]
|
|
|
|
);
|
|
|
|
} catch (TransferException $exception) {
|
|
|
|
throw new DaemonConnectionException($exception);
|
|
|
|
}
|
2019-09-06 04:41:20 +00:00
|
|
|
}
|
2019-09-06 03:33:27 +00:00
|
|
|
}
|