Skip to content

Commit e96ead4

Browse files
committed
Update API calls to Wings to only pass the required details with the changes to the installer system
1 parent 869bc22 commit e96ead4

File tree

4 files changed

+23
-39
lines changed

4 files changed

+23
-39
lines changed

app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Pterodactyl\Http\Controllers\Api\Remote\Servers;
44

55
use Carbon\CarbonImmutable;
6-
use Illuminate\Support\Arr;
76
use Illuminate\Http\Request;
87
use Illuminate\Http\Response;
98
use Illuminate\Http\JsonResponse;
@@ -87,20 +86,7 @@ public function archive(Request $request, string $uuid)
8786
return $this->processFailedTransfer($server->transfer);
8887
}
8988

90-
// We want to generate a new configuration using the new node_id value from the
91-
// transfer, and not the old node value.
92-
$data = $this->configurationStructureService->handle($server, [
93-
'node_id' => $server->transfer->new_node,
94-
]);
95-
96-
$allocations = $server->getAllocationMappings();
97-
$primary = array_key_first($allocations);
98-
Arr::set($data, 'allocations.default.ip', $primary);
99-
Arr::set($data, 'allocations.default.port', $allocations[$primary][0]);
100-
Arr::set($data, 'service.skip_scripts', true);
101-
Arr::set($data, 'suspended', false);
102-
103-
$this->connection->transaction(function () use ($data, $server) {
89+
$this->connection->transaction(function () use ($server) {
10490
// This token is used by the new node the server is being transferred to. It allows
10591
// that node to communicate with the old node during the process to initiate the
10692
// actual file transfer.
@@ -119,7 +105,7 @@ public function archive(Request $request, string $uuid)
119105
$this->daemonTransferRepository
120106
->setServer($server)
121107
->setNode($server->transfer->newNode)
122-
->notify($server, $data, $server->node, $token->toString());
108+
->notify($server, $token);
123109
});
124110

125111
return new JsonResponse([], Response::HTTP_NO_CONTENT);

app/Repositories/Wings/DaemonServerRepository.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ public function getDetails(): array
3535
*
3636
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
3737
*/
38-
public function create(array $data): void
38+
public function create(bool $startOnCompletion = true): void
3939
{
4040
Assert::isInstanceOf($this->server, Server::class);
4141

4242
try {
43-
$this->getHttpClient()->post(
44-
'/api/servers',
45-
[
46-
'json' => $data,
47-
]
48-
);
49-
} catch (TransferException $exception) {
43+
$this->getHttpClient()->post('/api/servers', [
44+
'json' => [
45+
'uuid' => $this->server->uuid,
46+
'start_on_completion' => $startOnCompletion,
47+
],
48+
]);
49+
} catch (GuzzleException $exception) {
5050
throw new DaemonConnectionException($exception);
5151
}
5252
}

app/Repositories/Wings/DaemonTransferRepository.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,31 @@
22

33
namespace Pterodactyl\Repositories\Wings;
44

5-
use Pterodactyl\Models\Node;
5+
use Lcobucci\JWT\Token\Plain;
66
use Pterodactyl\Models\Server;
7-
use GuzzleHttp\Exception\TransferException;
7+
use GuzzleHttp\Exception\GuzzleException;
88
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
99

1010
class DaemonTransferRepository extends DaemonRepository
1111
{
1212
/**
13-
* @throws DaemonConnectionException
13+
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
1414
*/
15-
public function notify(Server $server, array $data, Node $node, string $token): void
15+
public function notify(Server $server, Plain $token): void
1616
{
1717
try {
1818
$this->getHttpClient()->post('/api/transfer', [
1919
'json' => [
2020
'server_id' => $server->uuid,
21-
'url' => $node->getConnectionAddress() . sprintf('/api/servers/%s/archive', $server->uuid),
22-
'token' => 'Bearer ' . $token,
23-
'server' => $data,
21+
'url' => $server->node->getConnectionAddress() . sprintf('/api/servers/%s/archive', $server->uuid),
22+
'token' => 'Bearer ' . $token->toString(),
23+
'server' => [
24+
'uuid' => $server->uuid,
25+
'start_on_completion' => false,
26+
],
2427
],
2528
]);
26-
} catch (TransferException $exception) {
29+
} catch (GuzzleException $exception) {
2730
throw new DaemonConnectionException($exception);
2831
}
2932
}

app/Services/Servers/ServerCreationService.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,10 @@ public function handle(array $data, DeploymentObject $deployment = null): Server
162162

163163
try {
164164
$this->daemonServerRepository->setServer($server)->create(
165-
array_merge(
166-
$this->configurationStructureService->handle($server),
167-
[
168-
'start_on_completion' => Arr::get($data, 'start_on_completion', false),
169-
],
170-
),
165+
Arr::get($data, 'start_on_completion', false) ?? false
171166
);
172167
} catch (DaemonConnectionException $exception) {
173-
$this->serverDeletionService->withForce(true)->handle($server);
168+
$this->serverDeletionService->withForce()->handle($server);
174169

175170
throw $exception;
176171
}

0 commit comments

Comments
 (0)