Skip to content

Commit ee0da20

Browse files
committed
Update command sending from server API to use new daemon code
1 parent 161e0f6 commit ee0da20

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

app/Http/Controllers/Api/Client/Servers/CommandController.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@
77
use Psr\Http\Message\ResponseInterface;
88
use GuzzleHttp\Exception\ClientException;
99
use GuzzleHttp\Exception\RequestException;
10+
use Pterodactyl\Repositories\Wings\DaemonCommandRepository;
1011
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
1112
use Pterodactyl\Http\Requests\Api\Client\Servers\SendCommandRequest;
1213
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
13-
use Pterodactyl\Contracts\Repository\Daemon\CommandRepositoryInterface;
1414
use Symfony\Component\HttpKernel\Exception\PreconditionFailedHttpException;
1515

1616
class CommandController extends ClientApiController
1717
{
1818
/**
19-
* @var \Pterodactyl\Contracts\Repository\Daemon\CommandRepositoryInterface
19+
* @var \Pterodactyl\Repositories\Wings\DaemonCommandRepository
2020
*/
2121
private $repository;
2222

2323
/**
2424
* CommandController constructor.
2525
*
26-
* @param \Pterodactyl\Contracts\Repository\Daemon\CommandRepositoryInterface $repository
26+
* @param \Pterodactyl\Repositories\Wings\DaemonCommandRepository $repository
2727
*/
28-
public function __construct(CommandRepositoryInterface $repository)
28+
public function __construct(DaemonCommandRepository $repository)
2929
{
3030
parent::__construct();
3131

@@ -43,12 +43,9 @@ public function __construct(CommandRepositoryInterface $repository)
4343
public function index(SendCommandRequest $request): Response
4444
{
4545
$server = $request->getModel(Server::class);
46-
$token = $request->attributes->get('server_token');
4746

4847
try {
49-
$this->repository->setServer($server)
50-
->setToken($token)
51-
->send($request->input('command'));
48+
$this->repository->setServer($server)->send($request->input('command'));
5249
} catch (RequestException $exception) {
5350
if ($exception instanceof ClientException) {
5451
if ($exception->getResponse() instanceof ResponseInterface && $exception->getResponse()->getStatusCode() === 412) {

app/Repositories/Wings/DaemonCommandRepository.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22

33
namespace Pterodactyl\Repositories\Wings;
44

5+
use Webmozart\Assert\Assert;
6+
use Pterodactyl\Models\Server;
7+
use Psr\Http\Message\ResponseInterface;
8+
59
class DaemonCommandRepository extends DaemonRepository
610
{
11+
/**
12+
* Sends a command or multiple commands to a running server instance.
13+
*
14+
* @param string|string[] $command
15+
* @return \Psr\Http\Message\ResponseInterface
16+
*/
17+
public function send($command): ResponseInterface
18+
{
19+
Assert::isInstanceOf(Server::class, $this->server);
20+
21+
return $this->getHttpClient()->post(
22+
sprintf('/api/servers/%s/commands', $this->server->uuid),
23+
[
24+
'json' => ['commands' => is_array($command) ? $command : [$command]],
25+
]
26+
);
27+
}
728
}

0 commit comments

Comments
 (0)