2019-08-17 23:03:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Repositories\Wings;
|
|
|
|
|
2019-11-25 04:19:31 +00:00
|
|
|
use BadMethodCallException;
|
2019-09-06 03:33:27 +00:00
|
|
|
use Webmozart\Assert\Assert;
|
|
|
|
use Pterodactyl\Models\Server;
|
2019-08-17 23:03:10 +00:00
|
|
|
use GuzzleHttp\Exception\TransferException;
|
|
|
|
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
|
|
|
|
2019-09-06 03:33:27 +00:00
|
|
|
class DaemonServerRepository extends DaemonRepository
|
2019-08-17 23:03:10 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Returns details about a server from the Daemon instance.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
|
|
|
*/
|
|
|
|
public function getDetails(): array
|
|
|
|
{
|
2019-09-06 04:16:36 +00:00
|
|
|
Assert::isInstanceOf($this->server, Server::class);
|
2019-09-06 03:33:27 +00:00
|
|
|
|
2019-08-17 23:03:10 +00:00
|
|
|
try {
|
|
|
|
$response = $this->getHttpClient()->get(
|
2019-09-06 03:33:27 +00:00
|
|
|
sprintf('/api/servers/%s', $this->server->uuid)
|
2019-08-17 23:03:10 +00:00
|
|
|
);
|
|
|
|
} catch (TransferException $exception) {
|
|
|
|
throw new DaemonConnectionException($exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
return json_decode($response->getBody()->__toString(), true);
|
|
|
|
}
|
2019-11-16 21:33:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new server on the Wings daemon.
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
|
|
|
*/
|
|
|
|
public function create(array $data): void
|
|
|
|
{
|
|
|
|
Assert::isInstanceOf($this->server, Server::class);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$this->getHttpClient()->post(
|
|
|
|
'/api/servers', [
|
|
|
|
'json' => $data,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
} catch (TransferException $exception) {
|
|
|
|
throw new DaemonConnectionException($exception);
|
|
|
|
}
|
|
|
|
}
|
2019-11-24 23:08:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates details about a server on the Daemon.
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
|
|
|
*/
|
|
|
|
public function update(array $data): void
|
|
|
|
{
|
|
|
|
Assert::isInstanceOf($this->server, Server::class);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$this->getHttpClient()->patch('/api/servers/' . $this->server->uuid, ['json' => $data]);
|
|
|
|
} catch (TransferException $exception) {
|
|
|
|
throw new DaemonConnectionException($exception);
|
|
|
|
}
|
|
|
|
}
|
2019-11-25 04:19:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a server from the daemon.
|
|
|
|
*/
|
|
|
|
public function delete(): void
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('Method is not implemented.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reinstall a server on the daemon.
|
|
|
|
*/
|
|
|
|
public function reinstall(): void
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('Method is not implemented.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function suspend(): void
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('Method is not implemented.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function unsuspend(): void
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('Method is not implemented.');
|
|
|
|
}
|
2019-08-17 23:03:10 +00:00
|
|
|
}
|