From 2d47f986ee3c94a4489cbeddd7bb1078464b116f Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 29 Aug 2021 13:32:55 -0700 Subject: [PATCH] Replace calls to server patch with a manual sync method --- .../Wings/DaemonServerRepository.php | 29 ++++--------------- .../Servers/BuildModificationService.php | 4 +-- app/Services/Servers/SuspensionService.php | 4 +-- 3 files changed, 8 insertions(+), 29 deletions(-) diff --git a/app/Repositories/Wings/DaemonServerRepository.php b/app/Repositories/Wings/DaemonServerRepository.php index 35df86d84..f61ac29c9 100644 --- a/app/Repositories/Wings/DaemonServerRepository.php +++ b/app/Repositories/Wings/DaemonServerRepository.php @@ -4,6 +4,7 @@ namespace Pterodactyl\Repositories\Wings; use Webmozart\Assert\Assert; use Pterodactyl\Models\Server; +use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\TransferException; use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException; @@ -51,17 +52,17 @@ class DaemonServerRepository extends DaemonRepository } /** - * Updates details about a server on the Daemon. + * Triggers a server sync on Wings. * * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException */ - public function update(array $data): void + public function sync(): void { Assert::isInstanceOf($this->server, Server::class); try { - $this->getHttpClient()->patch('/api/servers/' . $this->server->uuid, ['json' => $data]); - } catch (TransferException $exception) { + $this->getHttpClient()->post("/api/servers/{$this->server->uuid}/sync"); + } catch (GuzzleException $exception) { throw new DaemonConnectionException($exception); } } @@ -101,26 +102,6 @@ class DaemonServerRepository extends DaemonRepository } } - /** - * By default this function will suspend a server instance on the daemon. However, passing - * "true" as the first argument will unsuspend the server. - * - * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException - */ - public function suspend(bool $unsuspend = false): void - { - Assert::isInstanceOf($this->server, Server::class); - - try { - $this->getHttpClient()->patch( - '/api/servers/' . $this->server->uuid, - ['json' => ['suspended' => !$unsuspend]] - ); - } catch (TransferException $exception) { - throw new DaemonConnectionException($exception); - } - } - /** * Requests the daemon to create a full archive of the server. Once the daemon is finished * they will send a POST request to "/api/remote/servers/{uuid}/archive" with a boolean. diff --git a/app/Services/Servers/BuildModificationService.php b/app/Services/Servers/BuildModificationService.php index f93ad21e5..86658c6e8 100644 --- a/app/Services/Servers/BuildModificationService.php +++ b/app/Services/Servers/BuildModificationService.php @@ -91,9 +91,7 @@ class BuildModificationService // if it fails we can just continue on as normal. if (!empty($updateData['build'])) { try { - $this->daemonServerRepository->setServer($server)->update([ - 'build' => $updateData['build'], - ]); + $this->daemonServerRepository->setServer($server)->sync(); } catch (DaemonConnectionException $exception) { Log::warning($exception, ['server_id' => $server->id]); } diff --git a/app/Services/Servers/SuspensionService.php b/app/Services/Servers/SuspensionService.php index 3c61b1935..f7d0f77b1 100644 --- a/app/Services/Servers/SuspensionService.php +++ b/app/Services/Servers/SuspensionService.php @@ -63,9 +63,9 @@ class SuspensionService 'status' => $isSuspending ? Server::STATUS_SUSPENDED : null, ]); - // Only send the suspension request to wings if the server is not currently being transferred. + // Only trigger a Wings server sync if it is not currently being transferred. if (is_null($server->transfer)) { - $this->daemonServerRepository->setServer($server)->suspend($action === self::ACTION_UNSUSPEND); + $this->daemonServerRepository->setServer($server)->sync(); } }); }