Files
pterodactyl-panel/app/Services/Servers/StartupCommandService.php
T
6c0413e39b Start 2.0 development
Co-authored-by: Anthony <anthony@infraly.co>
Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
2026-10-05 18:10:18 -04:00

35 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Pterodactyl\Services\Servers;
use Pterodactyl\Models\Server;
use UnexpectedValueException;
class StartupCommandService
{
public function __construct(private readonly EnvironmentService $environmentService) {}
/**
* Generates a startup command for a given server instance.
*/
public function handle(Server $server, bool $hideAllValues = false): string
{
$server->loadMissing('allocation');
$allocation = $server->allocation ?? throw new UnexpectedValueException('The server does not have a primary allocation.');
$variables = $this->environmentService->variables($server);
$find = ['{{SERVER_MEMORY}}', '{{SERVER_IP}}', '{{SERVER_PORT}}'];
$replace = [(string) $server->memory, $allocation->ip, (string) $allocation->port];
foreach ($variables as $variable) {
$find[] = '{{'.$variable->env_variable.'}}';
$replace[] = (string) (($variable->user_viewable && ! $hideAllValues) ? ($variable->server_value ?? $variable->default_value) : '[hidden]');
}
return str_replace($find, $replace, $server->startup);
}
}