2020-08-22 22:43:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Servers;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
|
|
|
|
class StartupCommandService
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Generates a startup command for a given server instance.
|
|
|
|
*/
|
2020-08-23 02:01:42 +00:00
|
|
|
public function handle(Server $server, bool $hideAllValues = false): string
|
2020-08-22 22:43:28 +00:00
|
|
|
{
|
|
|
|
$find = ['{{SERVER_MEMORY}}', '{{SERVER_IP}}', '{{SERVER_PORT}}'];
|
|
|
|
$replace = [$server->memory, $server->allocation->ip, $server->allocation->port];
|
|
|
|
|
|
|
|
foreach ($server->variables as $variable) {
|
|
|
|
$find[] = '{{' . $variable->env_variable . '}}';
|
2021-10-30 20:41:38 +00:00
|
|
|
// @phpstan-ignore-next-line
|
2021-01-23 20:33:34 +00:00
|
|
|
$replace[] = ($variable->user_viewable && !$hideAllValues) ? ($variable->server_value ?? $variable->default_value) : '[hidden]';
|
2020-08-22 22:43:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return str_replace($find, $replace, $server->startup);
|
|
|
|
}
|
|
|
|
}
|