diff --git a/app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php b/app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php index 5962f307..6b1df3b9 100644 --- a/app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php +++ b/app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php @@ -3,7 +3,6 @@ namespace Pterodactyl\Http\Controllers\Api\Remote\Servers; use Carbon\CarbonImmutable; -use Illuminate\Support\Arr; use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Http\JsonResponse; @@ -87,20 +86,7 @@ class ServerTransferController extends Controller return $this->processFailedTransfer($server->transfer); } - // We want to generate a new configuration using the new node_id value from the - // transfer, and not the old node value. - $data = $this->configurationStructureService->handle($server, [ - 'node_id' => $server->transfer->new_node, - ]); - - $allocations = $server->getAllocationMappings(); - $primary = array_key_first($allocations); - Arr::set($data, 'allocations.default.ip', $primary); - Arr::set($data, 'allocations.default.port', $allocations[$primary][0]); - Arr::set($data, 'service.skip_scripts', true); - Arr::set($data, 'suspended', false); - - $this->connection->transaction(function () use ($data, $server) { + $this->connection->transaction(function () use ($server) { // This token is used by the new node the server is being transferred to. It allows // that node to communicate with the old node during the process to initiate the // actual file transfer. @@ -119,7 +105,7 @@ class ServerTransferController extends Controller $this->daemonTransferRepository ->setServer($server) ->setNode($server->transfer->newNode) - ->notify($server, $data, $server->node, $token->toString()); + ->notify($server, $token); }); return new JsonResponse([], Response::HTTP_NO_CONTENT); diff --git a/app/Repositories/Wings/DaemonServerRepository.php b/app/Repositories/Wings/DaemonServerRepository.php index f61ac29c..f013ac08 100644 --- a/app/Repositories/Wings/DaemonServerRepository.php +++ b/app/Repositories/Wings/DaemonServerRepository.php @@ -35,18 +35,18 @@ class DaemonServerRepository extends DaemonRepository * * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException */ - public function create(array $data): void + public function create(bool $startOnCompletion = true): void { Assert::isInstanceOf($this->server, Server::class); try { - $this->getHttpClient()->post( - '/api/servers', - [ - 'json' => $data, - ] - ); - } catch (TransferException $exception) { + $this->getHttpClient()->post('/api/servers', [ + 'json' => [ + 'uuid' => $this->server->uuid, + 'start_on_completion' => $startOnCompletion, + ], + ]); + } catch (GuzzleException $exception) { throw new DaemonConnectionException($exception); } } diff --git a/app/Repositories/Wings/DaemonTransferRepository.php b/app/Repositories/Wings/DaemonTransferRepository.php index 74a1e3dc..3939a47c 100644 --- a/app/Repositories/Wings/DaemonTransferRepository.php +++ b/app/Repositories/Wings/DaemonTransferRepository.php @@ -2,28 +2,31 @@ namespace Pterodactyl\Repositories\Wings; -use Pterodactyl\Models\Node; +use Lcobucci\JWT\Token\Plain; use Pterodactyl\Models\Server; -use GuzzleHttp\Exception\TransferException; +use GuzzleHttp\Exception\GuzzleException; use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException; class DaemonTransferRepository extends DaemonRepository { /** - * @throws DaemonConnectionException + * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException */ - public function notify(Server $server, array $data, Node $node, string $token): void + public function notify(Server $server, Plain $token): void { try { $this->getHttpClient()->post('/api/transfer', [ 'json' => [ 'server_id' => $server->uuid, - 'url' => $node->getConnectionAddress() . sprintf('/api/servers/%s/archive', $server->uuid), - 'token' => 'Bearer ' . $token, - 'server' => $data, + 'url' => $server->node->getConnectionAddress() . sprintf('/api/servers/%s/archive', $server->uuid), + 'token' => 'Bearer ' . $token->toString(), + 'server' => [ + 'uuid' => $server->uuid, + 'start_on_completion' => false, + ], ], ]); - } catch (TransferException $exception) { + } catch (GuzzleException $exception) { throw new DaemonConnectionException($exception); } } diff --git a/app/Services/Servers/ServerCreationService.php b/app/Services/Servers/ServerCreationService.php index e538e6dd..48fa8cc3 100644 --- a/app/Services/Servers/ServerCreationService.php +++ b/app/Services/Servers/ServerCreationService.php @@ -162,15 +162,10 @@ class ServerCreationService try { $this->daemonServerRepository->setServer($server)->create( - array_merge( - $this->configurationStructureService->handle($server), - [ - 'start_on_completion' => Arr::get($data, 'start_on_completion', false), - ], - ), + Arr::get($data, 'start_on_completion', false) ?? false ); } catch (DaemonConnectionException $exception) { - $this->serverDeletionService->withForce(true)->handle($server); + $this->serverDeletionService->withForce()->handle($server); throw $exception; }