Path: blob/1.0-develop/app/Services/Servers/DetailsModificationService.php
10276 views
<?php12namespace Pterodactyl\Services\Servers;34use Illuminate\Support\Arr;5use Pterodactyl\Models\Server;6use Illuminate\Database\ConnectionInterface;7use Pterodactyl\Traits\Services\ReturnsUpdatedModels;8use Pterodactyl\Repositories\Wings\DaemonServerRepository;9use Pterodactyl\Repositories\Wings\DaemonRevocationRepository;10use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;1112class DetailsModificationService13{14use ReturnsUpdatedModels;1516/**17* DetailsModificationService constructor.18*/19public function __construct(20private ConnectionInterface $connection,21private DaemonServerRepository $serverRepository,22private DaemonRevocationRepository $revocationRepository,23) {24}2526/**27* Update the details for a single server instance.28*29* @throws \Throwable30*/31public function handle(Server $server, array $data): Server32{33return $this->connection->transaction(function () use ($data, $server) {34$original = $server->user;3536$server->forceFill([37'external_id' => Arr::get($data, 'external_id'),38'owner_id' => Arr::get($data, 'owner_id'),39'name' => Arr::get($data, 'name'),40'description' => Arr::get($data, 'description') ?? '',41])->saveOrFail();4243// If the owner_id value is changed we need to revoke any tokens that exist for the server44// on the Wings instance so that the old owner no longer has any permission to access the45// websockets.46if (! $server->refresh()->user->is($original)) {47try {48$this->revocationRepository->setNode($server->node)->deauthorize(49$original->uuid,50[$server->uuid],51);52} catch (DaemonConnectionException $exception) {53// Do nothing. A failure here is not ideal, but it is likely to be caused by Wings54// being offline, or in an entirely broken state. Remember, these tokens reset every55// few minutes by default, we're just trying to help it along a little quicker.56}57}5859return $server;60});61}62}636465