diff --git a/app/Filament/Resources/EggResource/Pages/CreateEgg.php b/app/Filament/Resources/EggResource/Pages/CreateEgg.php index c4c381f1a..ef42215d8 100644 --- a/app/Filament/Resources/EggResource/Pages/CreateEgg.php +++ b/app/Filament/Resources/EggResource/Pages/CreateEgg.php @@ -7,6 +7,8 @@ use Filament\Resources\Pages\CreateRecord; use AbdelhamidErrahmouni\FilamentMonacoEditor\MonacoEditor; use Filament\Forms; use Filament\Forms\Form; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Str; class CreateEgg extends CreateRecord { @@ -37,9 +39,14 @@ class CreateEgg extends CreateRecord ->columnSpanFull() ->helperText('A description of this Egg that will be displayed throughout the Panel as needed.'), Forms\Components\Textarea::make('startup') - ->rows(2) + ->rows(3) ->columnSpanFull() ->required() + ->placeholder(implode("\n", [ + 'java -Xms128M -XX:MaxRAMPercentage=95.0 -jar {{SERVER_JARFILE}}', + './srcds_run -game steamgamename -console -port {{SERVER_PORT}} +ip 0.0.0.0 -strictportbind -norestart +sv_setsteamaccount {{STEAM_ACC}}', + './Application -flag', + ])) ->helperText('The default startup command that should be used for new servers using this Egg.'), Forms\Components\KeyValue::make('docker_images') ->columnSpan(['default' => 1, 'sm' => 1, 'md' => 3, 'lg' => 3]) @@ -79,30 +86,46 @@ class CreateEgg extends CreateRecord Forms\Components\Tabs\Tab::make('Process Management') ->columns() ->schema([ - Forms\Components\Select::make('config_from') + Forms\Components\Hidden::make('config_from') + ->default(null) ->label('Copy Settings From') - ->placeholder('None') - ->relationship('configFrom', 'name', ignoreRecord: true) + // ->placeholder('None') + // ->relationship('configFrom', 'name', ignoreRecord: true) ->helperText('If you would like to default to settings from another Egg select it from the menu above.'), + Forms\Components\TextInput::make('config_stop') ->maxLength(191) + ->required() + ->datalist(['stop', 'quit', '^C', 'quit']) ->label('Stop Command') ->helperText('The command that should be sent to server processes to stop them gracefully. If you need to send a SIGINT you should enter ^C here.'), - Forms\Components\Textarea::make('config_startup')->rows(10)->json() - ->label('Start Configuration') - ->helperText('List of values the daemon should be looking for when booting a server to determine completion.'), - Forms\Components\Textarea::make('config_files')->rows(10)->json() + Forms\Components\Textarea::make('config_files') + ->rows(5) + ->json() + ->required() ->label('Configuration Files') + ->placeholder("{\n 'server.properties': {\n 'parser': 'properties',\n 'find': {\n 'server-ip': '0.0.0.0',\n 'server-port': '{{server.build.default.port}}',\n 'query.port': '{{server.build.default.port}}'\n }\n }\n}") ->helperText('This should be a JSON representation of configuration files to modify and what parts should be changed.'), - Forms\Components\Textarea::make('config_logs')->rows(10)->json() + + Forms\Components\KeyValue::make('config_startup') + ->required() + ->label('Start Configuration') + ->keyPlaceholder('done') + ->valuePlaceholder('listening on') + ->helperText('List of values the daemon should be looking for when booting a server to determine completion.'), + Forms\Components\KeyValue::make('config_logs') ->label('Log Configuration') - ->helperText('This should be a JSON representation of where log files are stored, and whether or not the daemon should be creating custom logs.'), + ->keyPlaceholder('location') + ->valuePlaceholder('logs/application.log') + ->helperText('This should be how the log files are stored, and whether or not the daemon should be creating custom logs.'), ]), Forms\Components\Tabs\Tab::make('Egg Variables') ->columnSpanFull() ->columns(2) ->schema([ Forms\Components\Repeater::make('variables') + ->label('') + ->addActionLabel('Add New Egg Variable') ->grid() ->relationship('variables') ->name('name') @@ -112,6 +135,7 @@ class CreateEgg extends CreateRecord ->collapsed() ->orderColumn() ->columnSpan(2) + ->defaultItems(0) ->itemLabel(fn (array $state) => $state['name']) ->mutateRelationshipDataBeforeCreateUsing(function (array $data): array { $data['default_value'] ??= ''; @@ -150,19 +174,20 @@ class CreateEgg extends CreateRecord ->columns(3) ->schema([ - Forms\Components\Select::make('copy_script_from') - ->placeholder('None') - ->relationship('scriptFrom', 'name', ignoreRecord: true), + Forms\Components\Hidden::make('copy_script_from'), + //->placeholder('None') + //->relationship('scriptFrom', 'name', ignoreRecord: true), Forms\Components\TextInput::make('script_container') ->required() ->maxLength(191) ->default('alpine:3.4'), - Forms\Components\TextInput::make('script_entry') - ->required() - ->maxLength(191) - ->default('ash'), + Forms\Components\Select::make('script_entry') + ->selectablePlaceholder(false) + ->default('bash') + ->options(['bash', 'ash', '/bin/bash']) + ->required(), MonacoEditor::make('script_install') ->columnSpanFull() @@ -174,4 +199,21 @@ class CreateEgg extends CreateRecord ])->columnSpanFull()->persistTabInQueryString(), ]); } + + protected function handleRecordCreation(array $data): Model + { + $data['uuid'] ??= Str::uuid()->toString(); + + if (is_array($data['config_startup'])) { + $data['config_startup'] = json_encode($data['config_startup']); + } + + if (is_array($data['config_logs'])) { + $data['config_logs'] = json_encode($data['config_logs']); + } + + logger()->info('new egg', $data); + + return parent::handleRecordCreation($data); + } } diff --git a/app/Models/Egg.php b/app/Models/Egg.php index 66f377fcb..7cc0888b8 100644 --- a/app/Models/Egg.php +++ b/app/Models/Egg.php @@ -6,6 +6,7 @@ use App\Exceptions\Service\Egg\HasChildrenException; use App\Exceptions\Service\HasActiveServersException; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Support\Str; /** * @property int $id @@ -80,7 +81,9 @@ class Egg extends Model * Fields that are not mass assignable. */ protected $fillable = [ + 'uuid', 'name', + 'author', 'description', 'features', 'docker_images', @@ -140,12 +143,20 @@ class Egg extends Model 'features' => 'array', 'docker_images' => 'array', 'file_denylist' => 'array', + 'config_startup' => 'array', + 'config_logs' => 'array', 'tags' => 'array', ]; } protected static function booted(): void { + static::creating(function (self $egg) { + $egg->uuid ??= Str::uuid()->toString(); + + return true; + }); + static::deleting(function (self $egg) { throw_if($egg->servers()->count(), new HasActiveServersException(trans('exceptions.egg.delete_has_servers')));