diff --git a/app/Classes/Pterodactyl.php b/app/Classes/Pterodactyl.php index 620feea1..95893dca 100644 --- a/app/Classes/Pterodactyl.php +++ b/app/Classes/Pterodactyl.php @@ -287,7 +287,7 @@ class Pterodactyl * @param int $pterodactylId * @return mixed */ - public static function getServerAttributes(int $pterodactylId) + public static function getServerAttributes(int $pterodactylId, bool $deleteOn404 = false) { try { $response = self::client()->get("/application/servers/{$pterodactylId}?include=egg,node,nest,location"); @@ -299,7 +299,13 @@ class Pterodactyl - if ($response->failed()) throw self::getException("Failed to get server attributes from pterodactyl - ", $response->status()); + if ($response->failed()){ + if($deleteOn404){ //Delete the server if it does not exist (server deleted on pterodactyl) + Server::where('pterodactyl_id', $pterodactylId)->first()->delete(); + return; + } + else throw self::getException("Failed to get server attributes from pterodactyl - ", $response->status()); + } return $response->json()['attributes']; } diff --git a/app/Http/Controllers/ServerController.php b/app/Http/Controllers/ServerController.php index 20deffca..23aa53f8 100644 --- a/app/Http/Controllers/ServerController.php +++ b/app/Http/Controllers/ServerController.php @@ -30,8 +30,8 @@ class ServerController extends Controller foreach ($servers as $server) { //Get server infos from ptero - $serverAttributes = Pterodactyl::getServerAttributes($server->pterodactyl_id); - + $serverAttributes = Pterodactyl::getServerAttributes($server->pterodactyl_id, true); + if(!$serverAttributes) continue; $serverRelationships = $serverAttributes['relationships']; $serverLocationAttributes = $serverRelationships['location']['attributes'];