Skip to content

Commit e87db88

Browse files
committed
Fix server data not updating correctly on daemon
1 parent 3e915e5 commit e87db88

File tree

3 files changed

+33
-42
lines changed

3 files changed

+33
-42
lines changed

app/Services/Servers/BuildModificationService.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Pterodactyl\Services\Servers;
44

5+
use Illuminate\Support\Arr;
56
use Pterodactyl\Models\Server;
67
use GuzzleHttp\Exception\RequestException;
78
use Illuminate\Database\ConnectionInterface;
@@ -34,16 +35,23 @@ class BuildModificationService
3435
*/
3536
private $repository;
3637

38+
/**
39+
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
40+
*/
41+
private $structureService;
42+
3743
/**
3844
* BuildModificationService constructor.
3945
*
4046
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $allocationRepository
47+
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $structureService
4148
* @param \Illuminate\Database\ConnectionInterface $connection
4249
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
4350
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
4451
*/
4552
public function __construct(
4653
AllocationRepositoryInterface $allocationRepository,
54+
ServerConfigurationStructureService $structureService,
4755
ConnectionInterface $connection,
4856
DaemonServerRepository $daemonServerRepository,
4957
ServerRepositoryInterface $repository
@@ -52,6 +60,7 @@ public function __construct(
5260
$this->daemonServerRepository = $daemonServerRepository;
5361
$this->connection = $connection;
5462
$this->repository = $repository;
63+
$this->structureService = $structureService;
5564
}
5665

5766
/**
@@ -95,28 +104,12 @@ public function handle(Server $server, array $data)
95104
'allocation_limit' => array_get($data, 'allocation_limit'),
96105
]);
97106

98-
$updateData = [
99-
'allocations' => [
100-
'default' => [
101-
'ip' => $server->allocation->ip,
102-
'port' => $server->allocation->port,
103-
],
104-
'mappings' => $server->getAllocationMappings(),
105-
],
106-
'build' => [
107-
'memory' => $server->memory,
108-
'swap' => $server->swap,
109-
'io' => $server->io,
110-
'cpu' => $server->cpu,
111-
'disk' => $server->disk,
112-
],
113-
'container' => [
114-
'oom_disabled' => $server->oom_disabled,
115-
],
116-
];
107+
$updateData = $this->structureService->handle($server);
117108

118109
try {
119-
$this->daemonServerRepository->setServer($server)->update($updateData);
110+
$this->daemonServerRepository->setServer($server)->update(
111+
Arr::only($updateData, ['allocations', 'build', 'container'])
112+
);
120113
$this->connection->commit();
121114
} catch (RequestException $exception) {
122115
throw new DaemonConnectionException($exception);

app/Services/Servers/ServerConfigurationStructureService.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ protected function returnCurrentFormat(Server $server)
7575
'uuid' => $server->uuid,
7676
'suspended' => (bool) $server->suspended,
7777
'environment' => $this->environment->handle($server),
78+
'invocation' => $server->startup,
7879
'build' => [
79-
'memory' => $server->memory,
80+
'memory_limit' => $server->memory,
8081
'swap' => $server->swap,
81-
'io' => $server->io,
82-
'cpu' => $server->cpu,
83-
'disk' => $server->disk,
82+
'io_weight' => $server->io,
83+
'cpu_limit' => $server->cpu,
84+
'disk_space' => $server->disk,
8485
],
8586
'service' => [
8687
'egg' => $server->egg->uuid,

app/Services/Servers/StartupModificationService.php

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Pterodactyl\Services\Servers;
44

5+
use Illuminate\Support\Arr;
56
use Pterodactyl\Models\User;
67
use Pterodactyl\Models\Server;
78
use GuzzleHttp\Exception\RequestException;
@@ -52,6 +53,11 @@ class StartupModificationService
5253
*/
5354
private $daemonServerRepository;
5455

56+
/**
57+
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
58+
*/
59+
private $structureService;
60+
5561
/**
5662
* StartupModificationService constructor.
5763
*
@@ -60,6 +66,7 @@ class StartupModificationService
6066
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $eggRepository
6167
* @param \Pterodactyl\Services\Servers\EnvironmentService $environmentService
6268
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
69+
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $structureService
6370
* @param \Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface $serverVariableRepository
6471
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
6572
*/
@@ -69,6 +76,7 @@ public function __construct(
6976
EggRepositoryInterface $eggRepository,
7077
EnvironmentService $environmentService,
7178
ServerRepositoryInterface $repository,
79+
ServerConfigurationStructureService $structureService,
7280
ServerVariableRepositoryInterface $serverVariableRepository,
7381
VariableValidatorService $validatorService
7482
) {
@@ -79,6 +87,7 @@ public function __construct(
7987
$this->serverVariableRepository = $serverVariableRepository;
8088
$this->validatorService = $validatorService;
8189
$this->daemonServerRepository = $daemonServerRepository;
90+
$this->structureService = $structureService;
8291
}
8392

8493
/**
@@ -110,19 +119,16 @@ public function handle(Server $server, array $data): Server
110119
});
111120
}
112121

113-
$daemonData = [];
114122
if ($this->isUserLevel(User::USER_LEVEL_ADMIN)) {
115-
$this->updateAdministrativeSettings($data, $server, $daemonData);
123+
$this->updateAdministrativeSettings($data, $server);
116124
}
117125

118-
$daemonData = array_merge_recursive($daemonData, [
119-
'build' => [
120-
'env|overwrite' => $this->environmentService->handle($server),
121-
],
122-
]);
126+
$updateData = $this->structureService->handle($server);
123127

124128
try {
125-
$this->daemonServerRepository->setServer($server)->update($daemonData);
129+
$this->daemonServerRepository->setServer($server)->update(
130+
Arr::only($updateData, ['environment', 'invocation', 'service'])
131+
);
126132
} catch (RequestException $exception) {
127133
$this->connection->rollBack();
128134
throw new DaemonConnectionException($exception);
@@ -138,12 +144,11 @@ public function handle(Server $server, array $data): Server
138144
*
139145
* @param array $data
140146
* @param \Pterodactyl\Models\Server $server
141-
* @param array $daemonData
142147
*
143148
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
144149
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
145150
*/
146-
private function updateAdministrativeSettings(array $data, Server &$server, array &$daemonData)
151+
private function updateAdministrativeSettings(array $data, Server &$server)
147152
{
148153
if (
149154
is_digit(array_get($data, 'egg_id'))
@@ -163,13 +168,5 @@ private function updateAdministrativeSettings(array $data, Server &$server, arra
163168
'skip_scripts' => array_get($data, 'skip_scripts') ?? isset($data['skip_scripts']),
164169
'image' => array_get($data, 'docker_image', $server->image),
165170
]);
166-
167-
$daemonData = array_merge($daemonData, [
168-
'build' => ['image' => $server->image],
169-
'service' => array_merge(
170-
$this->repository->getDaemonServiceData($server, true),
171-
['skip_scripts' => $server->skip_scripts]
172-
),
173-
]);
174171
}
175172
}

0 commit comments

Comments
 (0)