Files

30 lines
1.0 KiB
PHP
Raw Permalink Normal View History

2026-10-05 18:10:18 -04:00
<?php
declare(strict_types=1);
namespace Pterodactyl\Actions\Servers;
use Illuminate\Http\Response;
use Pterodactyl\Contracts\Servers\SendsServerCommands;
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
2026-10-11 14:01:27 -04:00
use Pterodactyl\Facades\Activity;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Facades\Daemon;
use Pterodactyl\Models\Server;
use Symfony\Component\HttpKernel\Exception\HttpException;
final readonly class SendServerCommand implements SendsServerCommands
{
public function send(Server $server, string $command): void
{
try {
Daemon::server($server)->commands($command);
} catch (DaemonConnectionException $daemonConnectionException) {
throw_if($daemonConnectionException->getStatusCode() === Response::HTTP_BAD_GATEWAY, HttpException::class, Response::HTTP_BAD_GATEWAY, 'Server must be online in order to send commands.', $daemonConnectionException);
throw $daemonConnectionException;
}
2026-10-11 14:01:27 -04:00
Activity::event('server:console.command')->subject($server)->property('command', $command)->log();
2026-10-05 18:10:18 -04:00
}
}