Simplify logic when a server is in an unsupported state

This commit is contained in:
Dane Everitt 2021-01-30 13:28:31 -08:00
parent be26921fcc
commit e30a765071
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
10 changed files with 76 additions and 294 deletions
app/Models

View file

@ -6,6 +6,7 @@ use Closure;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Query\JoinClause;
use Znck\Eloquent\Traits\BelongsToThrough;
use Pterodactyl\Exceptions\Http\Server\ServerStateConflictException;
/**
* @property int $id
@ -371,4 +372,23 @@ class Server extends Model
{
return $this->hasMany(AuditLog::class);
}
/**
* Checks if the server is currently in a user-accessible state. If not, an
* exception is raised. This should be called whenever something needs to make
* sure the server is not in a weird state that should block user access.
*
* @throws \Pterodactyl\Exceptions\Http\Server\ServerStateConflictException
*/
public function validateCurrentState()
{
if (
$this->isSuspended() ||
!$this->isInstalled() ||
$this->status === self::STATUS_RESTORING_BACKUP ||
!is_null($this->transfer)
) {
throw new ServerStateConflictException($this);
}
}
}