2015-12-08 18:33:33 -05:00
|
|
|
<?php
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2015-12-08 18:33:33 -05:00
|
|
|
namespace Pterodactyl\Models;
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
use Database\Factories\EggFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
|
|
|
use Illuminate\Database\Eloquent\Concerns\HasVersion4Uuids;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
2022-10-14 10:59:20 -06:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2026-10-05 18:10:18 -04:00
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
|
|
|
|
use Pterodactyl\Contracts\Models\Identifiable;
|
2026-02-14 11:21:57 -08:00
|
|
|
use Pterodactyl\Models\Traits\HasRealtimeIdentifier;
|
2026-10-05 18:10:18 -04:00
|
|
|
use RuntimeException;
|
2022-10-14 10:59:20 -06:00
|
|
|
|
2019-09-22 15:30:53 -07:00
|
|
|
/**
|
2022-05-07 17:45:22 -04:00
|
|
|
* @property array<string, string> $docker_images
|
2019-09-22 15:30:53 -07:00
|
|
|
*/
|
2026-02-14 11:21:57 -08:00
|
|
|
#[Attributes\Identifiable('eegg')]
|
2026-10-05 18:10:18 -04:00
|
|
|
#[Fillable([
|
|
|
|
|
'name',
|
|
|
|
|
'description',
|
|
|
|
|
'features',
|
|
|
|
|
'docker_images',
|
|
|
|
|
'force_outgoing_ip',
|
|
|
|
|
'file_denylist',
|
|
|
|
|
'config_files',
|
|
|
|
|
'config_startup',
|
|
|
|
|
'config_logs',
|
|
|
|
|
'config_stop',
|
|
|
|
|
'config_from',
|
|
|
|
|
'startup',
|
|
|
|
|
'script_is_privileged',
|
|
|
|
|
'script_install',
|
|
|
|
|
'script_entry',
|
|
|
|
|
'script_container',
|
|
|
|
|
'copy_script_from',
|
|
|
|
|
])]
|
2026-02-14 11:21:57 -08:00
|
|
|
class Egg extends Model implements Identifiable
|
2015-12-08 18:33:33 -05:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
/** @use HasFactory<EggFactory> */
|
2024-10-21 19:18:20 -06:00
|
|
|
use HasFactory;
|
2026-10-05 18:10:18 -04:00
|
|
|
|
2026-02-14 11:21:57 -08:00
|
|
|
use HasRealtimeIdentifier;
|
2026-10-05 18:10:18 -04:00
|
|
|
use HasVersion4Uuids;
|
2024-10-21 19:18:20 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
public const string RESOURCE_NAME = 'egg';
|
2018-01-25 21:26:06 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
public const string EXPORT_VERSION = 'PTDL_v2';
|
2022-05-07 17:45:22 -04:00
|
|
|
|
2020-11-02 20:20:36 -08:00
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* Features that toggle frontend functionality for an egg, inherited from the parent
|
|
|
|
|
* egg it copies configuration from unless explicitly set to an empty array ("[]").
|
2015-12-08 18:33:33 -05:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
public const string FEATURE_EULA_POPUP = 'eula';
|
2015-12-08 18:33:33 -05:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
public const string FEATURE_FASTDL = 'fastdl';
|
2017-08-08 23:24:55 -05:00
|
|
|
|
|
|
|
|
protected $attributes = [
|
2020-11-02 20:20:36 -08:00
|
|
|
'features' => null,
|
2021-01-26 21:08:53 -08:00
|
|
|
'file_denylist' => null,
|
2017-08-08 23:24:55 -05:00
|
|
|
'config_stop' => null,
|
|
|
|
|
'config_startup' => null,
|
|
|
|
|
'config_logs' => null,
|
|
|
|
|
'config_files' => null,
|
2020-12-13 09:53:17 -08:00
|
|
|
'update_url' => null,
|
2017-08-08 23:24:55 -05:00
|
|
|
];
|
2016-12-12 20:30:57 +01:00
|
|
|
|
2017-04-27 16:16:57 -04:00
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* @return array<string, string>
|
2017-04-27 16:16:57 -04:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
protected function casts(): array
|
2017-04-27 16:16:57 -04:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
return [
|
|
|
|
|
'config_from' => 'integer',
|
2026-10-11 23:29:38 -04:00
|
|
|
'config_startup' => 'string',
|
|
|
|
|
'config_logs' => 'string',
|
|
|
|
|
'config_files' => 'string',
|
2026-10-05 18:10:18 -04:00
|
|
|
'script_is_privileged' => 'boolean',
|
|
|
|
|
'force_outgoing_ip' => 'boolean',
|
|
|
|
|
'copy_script_from' => 'integer',
|
|
|
|
|
'features' => 'array',
|
|
|
|
|
'docker_images' => 'array',
|
|
|
|
|
'file_denylist' => 'array',
|
|
|
|
|
];
|
|
|
|
|
}
|
2018-03-06 23:07:00 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
/**
|
|
|
|
|
* @return list<string>
|
|
|
|
|
*/
|
|
|
|
|
public function uniqueIds(): array
|
|
|
|
|
{
|
|
|
|
|
return ['uuid'];
|
2017-04-27 16:16:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* The tags applied to this egg. These replace the grouping the egg's nest used
|
|
|
|
|
* to provide, and are what the deployment gate matches a node's accepted games
|
|
|
|
|
* against.
|
|
|
|
|
*
|
|
|
|
|
* @return MorphToMany<Tag, $this>
|
2017-04-27 16:16:57 -04:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
public function tags(): MorphToMany
|
2017-04-27 16:16:57 -04:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
return $this->morphToMany(Tag::class, 'taggable', 'taggables', 'taggable_id', 'tag_id');
|
|
|
|
|
}
|
2018-03-06 23:07:00 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
/**
|
|
|
|
|
* The slugs of this egg's tags, used to gate node selection.
|
|
|
|
|
*
|
|
|
|
|
* @return string[]
|
|
|
|
|
*/
|
|
|
|
|
public function tagSlugs(): array
|
|
|
|
|
{
|
2026-10-11 16:47:03 -04:00
|
|
|
return $this->tags->map(fn (Tag $tag): string => $tag->slug)->all();
|
2017-04-27 16:16:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* @return HasMany<Server, $this>
|
2017-04-27 16:16:57 -04:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
public function servers(): HasMany
|
2017-04-27 16:16:57 -04:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
return $this->hasMany(Server::class, 'egg_id');
|
|
|
|
|
}
|
2018-03-06 23:07:00 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
/**
|
|
|
|
|
* @return HasMany<EggVariable, $this>
|
|
|
|
|
*/
|
|
|
|
|
public function variables(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(EggVariable::class, 'egg_id');
|
2017-10-03 20:18:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* Eggs that inherit their configuration from this egg.
|
|
|
|
|
*
|
|
|
|
|
* @return HasMany<self, $this>
|
|
|
|
|
*/
|
|
|
|
|
public function configuredChildren(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(self::class, 'config_from');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return BelongsTo<self, $this>
|
2017-10-03 20:18:27 -05:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
public function scriptFrom(): BelongsTo
|
2017-10-03 20:18:27 -05:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
return $this->belongsTo(self::class, 'copy_script_from');
|
|
|
|
|
}
|
2018-03-06 23:07:00 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
/**
|
|
|
|
|
* @return BelongsTo<self, $this>
|
|
|
|
|
*/
|
|
|
|
|
public function configFrom(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(self::class, 'config_from');
|
2017-10-03 20:18:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* Returns the install script for the egg; if egg is copying from another
|
|
|
|
|
* it will return the copied script.
|
|
|
|
|
*
|
|
|
|
|
* @return Attribute<string|null, never>
|
2017-10-03 20:18:27 -05:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
protected function copyScriptInstall(): Attribute
|
2017-10-03 20:18:27 -05:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
return Attribute::make(get: function (): ?string {
|
|
|
|
|
if (($this->script_install) !== null || ($this->copy_script_from) === null) {
|
|
|
|
|
return $this->script_install;
|
|
|
|
|
}
|
2018-03-06 23:07:00 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
return $this->copiedScriptEgg()->script_install;
|
|
|
|
|
});
|
2017-10-03 20:18:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* Returns the entry command for the egg; if egg is copying from another
|
|
|
|
|
* it will return the copied entry command.
|
|
|
|
|
*
|
|
|
|
|
* @return Attribute<string, never>
|
2017-10-03 20:18:27 -05:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
protected function copyScriptEntry(): Attribute
|
2017-10-03 20:18:27 -05:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
return Attribute::make(get: function (): string {
|
|
|
|
|
if (($this->copy_script_from) === null) {
|
|
|
|
|
return $this->script_entry;
|
|
|
|
|
}
|
2018-03-06 23:07:00 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
return $this->copiedScriptEgg()->script_entry;
|
|
|
|
|
});
|
2017-10-03 20:18:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* Returns the install container for the egg; if egg is copying from another
|
|
|
|
|
* it will return the copied install container.
|
|
|
|
|
*
|
|
|
|
|
* @return Attribute<string, never>
|
2017-10-03 20:18:27 -05:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
protected function copyScriptContainer(): Attribute
|
2017-10-03 20:18:27 -05:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
return Attribute::make(get: function (): string {
|
|
|
|
|
if (($this->copy_script_from) === null) {
|
|
|
|
|
return $this->script_container;
|
|
|
|
|
}
|
2018-03-06 23:07:00 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
return $this->copiedScriptEgg()->script_container;
|
|
|
|
|
});
|
2017-04-27 16:16:57 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-02 20:20:36 -08:00
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* @return Attribute<string|null, never>
|
2020-11-02 20:20:36 -08:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
protected function inheritConfigFiles(): Attribute
|
2020-11-02 20:20:36 -08:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
return Attribute::make(get: function (): ?string {
|
|
|
|
|
if (($this->config_files) !== null || ($this->config_from) === null) {
|
|
|
|
|
return $this->config_files;
|
|
|
|
|
}
|
2020-11-02 20:20:36 -08:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
return $this->inheritedConfigurationEgg()->config_files;
|
|
|
|
|
});
|
2020-11-02 20:20:36 -08:00
|
|
|
}
|
|
|
|
|
|
2021-01-10 17:02:14 -08:00
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* @return Attribute<string|null, never>
|
2021-01-10 17:02:14 -08:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
protected function inheritConfigStartup(): Attribute
|
2021-01-10 17:02:14 -08:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
return Attribute::make(get: function (): ?string {
|
|
|
|
|
if (($this->config_startup) !== null || ($this->config_from) === null) {
|
|
|
|
|
return $this->config_startup;
|
|
|
|
|
}
|
2021-01-10 17:02:14 -08:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
return $this->inheritedConfigurationEgg()->config_startup;
|
|
|
|
|
});
|
2021-01-10 17:02:14 -08:00
|
|
|
}
|
|
|
|
|
|
2017-03-19 19:36:50 -04:00
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* @return Attribute<string|null, never>
|
2017-03-19 19:36:50 -04:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
protected function inheritConfigLogs(): Attribute
|
2017-03-19 19:36:50 -04:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
return Attribute::make(get: function (): ?string {
|
|
|
|
|
if (($this->config_logs) !== null || ($this->config_from) === null) {
|
|
|
|
|
return $this->config_logs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->inheritedConfigurationEgg()->config_logs;
|
|
|
|
|
});
|
2017-03-19 19:36:50 -04:00
|
|
|
}
|
2017-02-05 17:58:17 -05:00
|
|
|
|
2017-03-19 19:36:50 -04:00
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* @return Attribute<string|null, never>
|
2017-03-19 19:36:50 -04:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
protected function inheritConfigStop(): Attribute
|
2017-03-19 19:36:50 -04:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
return Attribute::make(get: function (): ?string {
|
|
|
|
|
if (($this->config_stop) !== null || ($this->config_from) === null) {
|
|
|
|
|
return $this->config_stop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->inheritedConfigurationEgg()->config_stop;
|
|
|
|
|
});
|
2017-03-19 19:36:50 -04:00
|
|
|
}
|
2017-02-05 17:58:17 -05:00
|
|
|
|
2017-03-19 19:36:50 -04:00
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* Returns the features available to this egg from the parent configuration if there are
|
|
|
|
|
* no features defined for this egg specifically and there is a parent egg configured.
|
2025-12-20 15:55:13 -08:00
|
|
|
*
|
2026-10-05 18:10:18 -04:00
|
|
|
* @return Attribute<list<string>|null, never>
|
2017-03-19 19:36:50 -04:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
protected function inheritFeatures(): Attribute
|
2017-03-19 19:36:50 -04:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
return Attribute::make(get: function (): ?array {
|
|
|
|
|
if (($this->features) !== null || ($this->config_from) === null) {
|
|
|
|
|
return $this->features;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->inheritedConfigurationEgg()->features;
|
|
|
|
|
});
|
2017-03-19 19:36:50 -04:00
|
|
|
}
|
2017-02-02 16:01:18 -05:00
|
|
|
|
2017-08-08 23:24:55 -05:00
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* @return Attribute<list<string>|null, never>
|
2017-08-08 23:24:55 -05:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
protected function inheritFileDenylist(): Attribute
|
2017-04-27 16:16:57 -04:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
return Attribute::make(get: function (): ?array {
|
|
|
|
|
if (($this->config_from) === null) {
|
|
|
|
|
return $this->file_denylist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->inheritedConfigurationEgg()->file_denylist;
|
|
|
|
|
});
|
2017-04-27 16:16:57 -04:00
|
|
|
}
|
2017-10-03 20:18:27 -05:00
|
|
|
|
|
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* Eggs whose install script is their own.
|
2025-12-20 15:55:13 -08:00
|
|
|
*
|
2026-10-05 18:10:18 -04:00
|
|
|
* @param Builder<self> $query
|
2017-10-03 20:18:27 -05:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
#[Scope]
|
|
|
|
|
protected function scriptSources(Builder $query): void
|
2017-10-03 20:18:27 -05:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
$query->whereNull('copy_script_from');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function copiedScriptEgg(): self
|
|
|
|
|
{
|
|
|
|
|
return $this->scriptFrom ?? throw new RuntimeException('The configured script source egg does not exist.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function inheritedConfigurationEgg(): self
|
|
|
|
|
{
|
|
|
|
|
return $this->configFrom ?? throw new RuntimeException('The configured parent egg does not exist.');
|
2017-10-03 20:18:27 -05:00
|
|
|
}
|
2015-12-08 18:33:33 -05:00
|
|
|
}
|