2019-09-06 03:33:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Repositories\Wings;
|
|
|
|
|
2019-09-06 04:11:19 +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:11:19 +00:00
|
|
|
|
2019-09-06 03:33:27 +00:00
|
|
|
class DaemonCommandRepository extends DaemonRepository
|
|
|
|
{
|
2019-09-06 04:11:19 +00:00
|
|
|
/**
|
|
|
|
* Sends a command or multiple commands to a running server instance.
|
|
|
|
*
|
2020-07-15 04:16:38 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
2019-09-06 04:11:19 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function send(array|string $command): ResponseInterface
|
2019-09-06 04:11:19 +00:00
|
|
|
{
|
2019-09-06 04:16:36 +00:00
|
|
|
Assert::isInstanceOf($this->server, Server::class);
|
2019-09-06 04:11:19 +00:00
|
|
|
|
2020-07-15 04:16:38 +00:00
|
|
|
try {
|
|
|
|
return $this->getHttpClient()->post(
|
|
|
|
sprintf('/api/servers/%s/commands', $this->server->uuid),
|
|
|
|
[
|
|
|
|
'json' => ['commands' => is_array($command) ? $command : [$command]],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
} catch (TransferException $exception) {
|
|
|
|
throw new DaemonConnectionException($exception);
|
|
|
|
}
|
2019-09-06 04:11:19 +00:00
|
|
|
}
|
2019-09-06 03:33:27 +00:00
|
|
|
}
|