2017-10-06 04:09:43 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
|
|
*
|
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Servers;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
|
|
|
|
|
|
|
class ServerConfigurationStructureService
|
|
|
|
{
|
|
|
|
const REQUIRED_RELATIONS = ['allocation', 'allocations', 'pack', 'option'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Services\Servers\EnvironmentService
|
|
|
|
*/
|
2017-10-27 04:49:54 +00:00
|
|
|
private $environment;
|
2017-10-06 04:09:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
|
|
|
*/
|
2017-10-27 04:49:54 +00:00
|
|
|
private $repository;
|
2017-10-06 04:09:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ServerConfigurationStructureService constructor.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
|
|
|
* @param \Pterodactyl\Services\Servers\EnvironmentService $environment
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
ServerRepositoryInterface $repository,
|
|
|
|
EnvironmentService $environment
|
|
|
|
) {
|
|
|
|
$this->repository = $repository;
|
|
|
|
$this->environment = $environment;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-27 04:49:54 +00:00
|
|
|
* Return a configuration array for a specific server when passed a server model.
|
|
|
|
*
|
|
|
|
* @param \Pterodactyl\Models\Server $server
|
2017-10-06 04:09:43 +00:00
|
|
|
* @return array
|
2017-10-27 04:49:54 +00:00
|
|
|
*
|
2017-10-06 04:09:43 +00:00
|
|
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
|
|
*/
|
2017-10-27 04:49:54 +00:00
|
|
|
public function handle(Server $server): array
|
2017-10-06 04:09:43 +00:00
|
|
|
{
|
2017-10-27 04:49:54 +00:00
|
|
|
if (array_diff(self::REQUIRED_RELATIONS, $server->getRelations())) {
|
|
|
|
$server = $this->repository->getDataForCreation($server);
|
2017-10-06 04:09:43 +00:00
|
|
|
}
|
|
|
|
|
2017-11-04 17:49:05 +00:00
|
|
|
$pack = $server->getRelation('pack');
|
|
|
|
if (! is_null($pack)) {
|
|
|
|
$pack = $server->getRelation('pack')->uuid;
|
|
|
|
}
|
|
|
|
|
2017-10-06 04:09:43 +00:00
|
|
|
return [
|
|
|
|
'uuid' => $server->uuid,
|
|
|
|
'build' => [
|
|
|
|
'default' => [
|
|
|
|
'ip' => $server->allocation->ip,
|
|
|
|
'port' => $server->allocation->port,
|
|
|
|
],
|
|
|
|
'ports' => $server->allocations->groupBy('ip')->map(function ($item) {
|
|
|
|
return $item->pluck('port');
|
|
|
|
})->toArray(),
|
2017-10-27 04:49:54 +00:00
|
|
|
'env' => $this->environment->handle($server),
|
2019-08-03 20:41:24 +00:00
|
|
|
'oom_disabled' => $server->oom_disabled,
|
2017-10-06 04:09:43 +00:00
|
|
|
'memory' => (int) $server->memory,
|
|
|
|
'swap' => (int) $server->swap,
|
|
|
|
'io' => (int) $server->io,
|
|
|
|
'cpu' => (int) $server->cpu,
|
|
|
|
'disk' => (int) $server->disk,
|
|
|
|
'image' => $server->image,
|
|
|
|
],
|
|
|
|
'service' => [
|
2017-10-09 02:36:22 +00:00
|
|
|
'egg' => $server->egg->uuid,
|
2017-11-04 17:49:05 +00:00
|
|
|
'pack' => $pack,
|
2017-10-06 04:09:43 +00:00
|
|
|
'skip_scripts' => $server->skip_scripts,
|
|
|
|
],
|
|
|
|
'rebuild' => false,
|
|
|
|
'suspended' => (int) $server->suspended,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|