From a9a93d2657e998b0c955af9d61d6cce804600a24 Mon Sep 17 00:00:00 2001 From: CroneKorkN Date: Sun, 18 Jan 2026 18:32:07 +0100 Subject: [PATCH] config and params are text fields --- ARCHITECTURE.md | 54 +++++++--------- app/controllers/config_options_controller.rb | 36 ----------- .../server_templates_controller.rb | 2 +- app/controllers/startup_params_controller.rb | 36 ----------- app/models/config_option.rb | 6 -- app/models/server_template.rb | 2 - app/models/startup_param.rb | 6 -- app/views/server_templates/index.html.slim | 4 -- app/views/server_templates/show.html.slim | 62 +++---------------- app/views/servers/new.html.slim | 14 ++--- config/routes.rb | 2 - .../20260118162621_create_config_options.rb | 13 ---- .../20260118162623_create_startup_params.rb | 13 ---- ..._and_startup_params_to_server_templates.rb | 6 ++ ...onfig_options_and_startup_params_tables.rb | 6 ++ db/schema.rb | 26 +------- 16 files changed, 51 insertions(+), 237 deletions(-) delete mode 100644 app/controllers/config_options_controller.rb delete mode 100644 app/controllers/startup_params_controller.rb delete mode 100644 app/models/config_option.rb delete mode 100644 app/models/startup_param.rb delete mode 100644 db/migrate/20260118162621_create_config_options.rb delete mode 100644 db/migrate/20260118162623_create_startup_params.rb create mode 100644 db/migrate/20260118190000_add_config_and_startup_params_to_server_templates.rb create mode 100644 db/migrate/20260118200000_drop_config_options_and_startup_params_tables.rb diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 5e855f7..c15bf0d 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -18,11 +18,9 @@ L4D Tools is a Rails web application for managing Left4Dead 2 game servers. User ``` User (Steam ID + username) -├── ServerTemplate (name) +├── ServerTemplate (name, config, startup_params) │ ├── TemplateOverlay (overlay + position) -│ │ └── Overlay (name, type: system|custom, path) -│ ├── ConfigOption (config_key, config_value) -│ └── StartupParam (param_key, param_value) +│ │ └── Overlay (name, type: system|custom, slug) ├── Server (name, port, status, template_id) │ └── (references ServerTemplate) └── Activity (action, resource_type, resource_id, details) @@ -69,13 +67,15 @@ Add Overlays: → Position auto-assigned (0, 1, 2, ...) → First overlay = highest priority (mounted last, visible first) -Add Config Options: - → Enter key (e.g., "sv_pure") and value (e.g., "2") - → Renders as: sv_pure "2" in server.cfg +Edit Server Config: + → Multi-line text area for server.cfg contents + → Enter raw config format: sv_pure 2\nsv_maxplayers 4\n... + → Saved directly as template.config text field -Add Startup Parameters: - → Enter param key (e.g., "+map") and value (e.g., "c1m1_hotel") - → Renders as: +map c1m1_hotel in launch command +Edit Startup Parameters: + → Multi-line text area for command line parameters + → Enter raw format: +map c1m1_hotel\n+difficulty Hard\n... + → Saved directly as template.startup_params text field ``` ### 4. Spawn Server from Template @@ -152,11 +152,10 @@ DELETE /server_templates/:id → ServerTemplatesController#destroy POST /server_templates/:st_id/overlays/:id → OverlaysController#create DELETE /server_templates/:st_id/overlays/:id → OverlaysController#destroy -POST /server_templates/:st_id/config_options → ConfigOptionsController#create -DELETE /server_templates/:st_id/config_options/:id → ConfigOptionsController#destroy - -POST /server_templates/:st_id/startup_params → StartupParamsController#create -DELETE /server_templates/:st_id/startup_params/:id → StartupParamsController#destroy +GET /overlays → OverlaysController#index +GET /overlays/new → OverlaysController#new +POST /overlays → OverlaysController#create +DELETE /overlays/:id → OverlaysController#destroy GET /servers → ServersController#index GET /servers/:id → ServersController#show @@ -167,8 +166,6 @@ POST /servers/:id/stop → ServersController#stop POST /servers/:id/restart → ServersController#restart DELETE /servers/:id → ServersController#destroy -GET /overlays → OverlaysController#index - WS /cable → ActionCable (LogChannel) ``` @@ -183,16 +180,19 @@ WS /cable → ActionCable (LogChannel) - `user_id` (references, nullable—system overlays have NULL user_id) - `name` (string, NOT NULL) - `overlay_type` (string, NOT NULL, default: "system", enum: ["system", "custom"]) -- `path` (string, NOT NULL) +- `slug` (string, NOT NULL—POSIX-safe directory name, auto-derived from name) - `description` (text) -- Validates: name uniqueness per user, overlay_type inclusion +- Validates: name uniqueness per user, overlay_type inclusion, slug is single directory (no slashes) +- Before validation: normalizes slug to lowercase, replaces special chars with underscores - Scopes: system_overlays, custom_overlays, for_user **ServerTemplate** - `user_id` (references, NOT NULL) - `name` (string, NOT NULL) +- `config` (text, nullable—server.cfg contents) +- `startup_params` (text, nullable—command line parameters) - Validates: name uniqueness per user -- Has many: template_overlays → overlays, config_options, startup_params, servers +- Has many: template_overlays → overlays, servers **TemplateOverlay** (join table) - `server_template_id` (references, NOT NULL) @@ -201,18 +201,6 @@ WS /cable → ActionCable (LogChannel) - Validates: uniqueness of (server_template_id, overlay_id) and (server_template_id, position) - Ordered by position ascending -**ConfigOption** -- `server_template_id` (references, NOT NULL) -- `config_key` (string, NOT NULL) -- `config_value` (string, NOT NULL) -- Validates: key uniqueness per template - -**StartupParam** -- `server_template_id` (references, NOT NULL) -- `param_key` (string, NOT NULL) -- `param_value` (string, NOT NULL) -- Validates: key uniqueness per template - **Server** - `user_id` (references, NOT NULL) - `server_template_id` (references, NOT NULL) @@ -238,7 +226,7 @@ WS /cable → ActionCable (LogChannel) **ConfigGenerator** - `generate(server)` → Creates `/opt/l4d2/servers/{server_id}/server.cfg` -- Iterates template.config_options, renders as `key "value"` format +- Writes template.config text directly to server.cfg file **Launcher** - `spawn(server)` → Setup dirs, generate config, mount overlayfs, create systemd unit, start diff --git a/app/controllers/config_options_controller.rb b/app/controllers/config_options_controller.rb deleted file mode 100644 index d86de2f..0000000 --- a/app/controllers/config_options_controller.rb +++ /dev/null @@ -1,36 +0,0 @@ -class ConfigOptionsController < ApplicationController - before_action :set_server_template - - def create - @config_option = @server_template.config_options.build(config_option_params) - - if @config_option.save - Activity.log(current_user, "added_config", "ServerTemplate", @server_template.id, { key: @config_option.config_key }) - redirect_to @server_template, notice: "Config option added!" - else - redirect_to @server_template, alert: "Failed to add config option" - end - end - - def destroy - @config_option = ConfigOption.find(params[:id]) - authorize_user! - @config_option.destroy - Activity.log(current_user, "removed_config", "ServerTemplate", @server_template.id, { key: @config_option.config_key }) - redirect_to @server_template, notice: "Config option deleted!" - end - - private - - def set_server_template - @server_template = current_user.server_templates.find(params[:server_template_id]) - end - - def config_option_params - params.require(:config_option).permit(:config_key, :config_value) - end - - def authorize_user! - redirect_to dashboard_path, alert: "Not authorized" unless @server_template.user_id == current_user.id - end -end diff --git a/app/controllers/server_templates_controller.rb b/app/controllers/server_templates_controller.rb index 9df122b..c1ebd86 100644 --- a/app/controllers/server_templates_controller.rb +++ b/app/controllers/server_templates_controller.rb @@ -54,7 +54,7 @@ class ServerTemplatesController < ApplicationController end def server_template_params - params.require(:server_template).permit(:name) + params.require(:server_template).permit(:name, :config, :startup_params) end def authorize_user! diff --git a/app/controllers/startup_params_controller.rb b/app/controllers/startup_params_controller.rb deleted file mode 100644 index 27d29cf..0000000 --- a/app/controllers/startup_params_controller.rb +++ /dev/null @@ -1,36 +0,0 @@ -class StartupParamsController < ApplicationController - before_action :set_server_template - - def create - @startup_param = @server_template.startup_params.build(startup_param_params) - - if @startup_param.save - Activity.log(current_user, "added_param", "ServerTemplate", @server_template.id, { key: @startup_param.param_key }) - redirect_to @server_template, notice: "Startup parameter added!" - else - redirect_to @server_template, alert: "Failed to add parameter" - end - end - - def destroy - @startup_param = StartupParam.find(params[:id]) - authorize_user! - @startup_param.destroy - Activity.log(current_user, "removed_param", "ServerTemplate", @server_template.id, { key: @startup_param.param_key }) - redirect_to @server_template, notice: "Startup parameter deleted!" - end - - private - - def set_server_template - @server_template = current_user.server_templates.find(params[:server_template_id]) - end - - def startup_param_params - params.require(:startup_param).permit(:param_key, :param_value) - end - - def authorize_user! - redirect_to dashboard_path, alert: "Not authorized" unless @server_template.user_id == current_user.id - end -end diff --git a/app/models/config_option.rb b/app/models/config_option.rb deleted file mode 100644 index 16ccfbd..0000000 --- a/app/models/config_option.rb +++ /dev/null @@ -1,6 +0,0 @@ -class ConfigOption < ApplicationRecord - belongs_to :server_template - - validates :config_key, presence: true - validates :config_key, uniqueness: { scope: :server_template_id } -end diff --git a/app/models/server_template.rb b/app/models/server_template.rb index 6ab5ed1..c5a7e05 100644 --- a/app/models/server_template.rb +++ b/app/models/server_template.rb @@ -2,8 +2,6 @@ class ServerTemplate < ApplicationRecord belongs_to :user has_many :template_overlays, dependent: :destroy has_many :overlays, through: :template_overlays, source: :overlay - has_many :config_options, dependent: :destroy - has_many :startup_params, dependent: :destroy has_many :servers, dependent: :destroy validates :name, presence: true, uniqueness: { scope: :user_id } diff --git a/app/models/startup_param.rb b/app/models/startup_param.rb deleted file mode 100644 index bf223bd..0000000 --- a/app/models/startup_param.rb +++ /dev/null @@ -1,6 +0,0 @@ -class StartupParam < ApplicationRecord - belongs_to :server_template - - validates :param_key, presence: true - validates :param_key, uniqueness: { scope: :server_template_id } -end diff --git a/app/views/server_templates/index.html.slim b/app/views/server_templates/index.html.slim index cd3ee67..9c3a222 100644 --- a/app/views/server_templates/index.html.slim +++ b/app/views/server_templates/index.html.slim @@ -8,16 +8,12 @@ tr th Name th Overlays - th Config Options - th Startup Params th Actions tbody - @server_templates.each do |template| tr td = link_to template.name, template td = template.overlays.count - td = template.config_options.count - td = template.startup_params.count td = link_to "Edit", edit_server_template_path(template), class: "btn btn--small" = link_to "Spawn", new_server_path(server_template_id: template.id), class: "btn btn--small btn--success" diff --git a/app/views/server_templates/show.html.slim b/app/views/server_templates/show.html.slim index 83b3a44..6e917a1 100644 --- a/app/views/server_templates/show.html.slim +++ b/app/views/server_templates/show.html.slim @@ -24,64 +24,22 @@ - else p No overlays selected. - section.config-options - h3 Config Options - - config_option = @server_template.config_options.build - = form_with model: config_option, url: server_template_config_options_path(@server_template), method: :post, local: true do |f| + section.config + h3 Server Config + = form_with model: @server_template, url: server_template_path(@server_template), method: :patch, local: true do |f| .form-group - = f.label :config_key, "Key" - = f.text_field :config_key, placeholder: "e.g., sv_pure" + = f.label :config, "server.cfg contents" + = f.text_area :config, placeholder: "sv_pure 2\nsv_maxplayers 4\n...", rows: 10 - .form-group - = f.label :config_value, "Value" - = f.text_field :config_value, placeholder: "e.g., 2" - - = f.submit "Add Option", class: "btn btn--small" - - - if @server_template.config_options.any? - table - thead - tr - th Key - th Value - th Actions - tbody - - @server_template.config_options.select(&:persisted?).each do |opt| - tr - td = opt.config_key - td = opt.config_value - td = link_to "Delete", server_template_config_option_path(@server_template, opt), method: :delete, data: { confirm: "Sure?" }, class: "btn btn--small btn--danger" - - else - p No config options yet. + = f.submit "Save Config", class: "btn btn--small" section.startup-params h3 Startup Parameters - - startup_param = @server_template.startup_params.build - = form_with model: startup_param, url: server_template_startup_params_path(@server_template), method: :post, local: true do |f| + = form_with model: @server_template, url: server_template_path(@server_template), method: :patch, local: true do |f| .form-group - = f.label :param_key, "Key" - = f.text_field :param_key, placeholder: "e.g., +map" + = f.label :startup_params, "Command line parameters" + = f.text_area :startup_params, placeholder: "+map c1m1_hotel\n+difficulty Hard\n...", rows: 10 - .form-group - = f.label :param_value, "Value" - = f.text_field :param_value, placeholder: "e.g., c1m1_hotel" - - = f.submit "Add Parameter", class: "btn btn--small" - - - if @server_template.startup_params.any? - table - thead - tr - th Key - th Value - th Actions - tbody - - @server_template.startup_params.select(&:persisted?).each do |param| - tr - td = param.param_key - td = param.param_value - td = link_to "Delete", server_template_startup_param_path(@server_template, param), method: :delete, data: { confirm: "Sure?" }, class: "btn btn--small btn--danger" - - else - p No startup parameters yet. + = f.submit "Save Parameters", class: "btn btn--small" = link_to "Back", server_templates_path, class: "btn" diff --git a/app/views/servers/new.html.slim b/app/views/servers/new.html.slim index f7b220c..d47cc72 100644 --- a/app/views/servers/new.html.slim +++ b/app/views/servers/new.html.slim @@ -36,20 +36,14 @@ p None h4 Config Options - - if @server_template.config_options.any? - table - - @server_template.config_options.each do |opt| - tr - td = opt.config_key - td = opt.config_value + - if @server_template.config.present? + pre = @server_template.config - else p None h4 Startup Parameters - - if @server_template.startup_params.any? - ul - - @server_template.startup_params.each do |param| - li "#{param.param_key} #{param.param_value}" + - if @server_template.startup_params.present? + pre = @server_template.startup_params - else p None diff --git a/config/routes.rb b/config/routes.rb index e3d41ac..111a826 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,8 +13,6 @@ Rails.application.routes.draw do # Server resources resources :server_templates do resources :overlays, only: [ :create, :destroy ] - resources :config_options, only: [ :create, :destroy ] - resources :startup_params, only: [ :create, :destroy ] end resources :overlays, only: [ :index, :new, :create, :destroy ] diff --git a/db/migrate/20260118162621_create_config_options.rb b/db/migrate/20260118162621_create_config_options.rb deleted file mode 100644 index 96ada1a..0000000 --- a/db/migrate/20260118162621_create_config_options.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateConfigOptions < ActiveRecord::Migration[8.1] - def change - create_table :config_options do |t| - t.references :server_template, null: false, foreign_key: true - t.string :config_key, null: false - t.string :config_value, null: false - - t.timestamps - end - - add_index :config_options, [ :server_template_id, :config_key ], unique: true - end -end diff --git a/db/migrate/20260118162623_create_startup_params.rb b/db/migrate/20260118162623_create_startup_params.rb deleted file mode 100644 index 05550fc..0000000 --- a/db/migrate/20260118162623_create_startup_params.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateStartupParams < ActiveRecord::Migration[8.1] - def change - create_table :startup_params do |t| - t.references :server_template, null: false, foreign_key: true - t.string :param_key, null: false - t.string :param_value, null: false - - t.timestamps - end - - add_index :startup_params, [ :server_template_id, :param_key ], unique: true - end -end diff --git a/db/migrate/20260118190000_add_config_and_startup_params_to_server_templates.rb b/db/migrate/20260118190000_add_config_and_startup_params_to_server_templates.rb new file mode 100644 index 0000000..b111c6d --- /dev/null +++ b/db/migrate/20260118190000_add_config_and_startup_params_to_server_templates.rb @@ -0,0 +1,6 @@ +class AddConfigAndStartupParamsToServerTemplates < ActiveRecord::Migration[8.1] + def change + add_column :server_templates, :config, :text + add_column :server_templates, :startup_params, :text + end +end diff --git a/db/migrate/20260118200000_drop_config_options_and_startup_params_tables.rb b/db/migrate/20260118200000_drop_config_options_and_startup_params_tables.rb new file mode 100644 index 0000000..e3a323e --- /dev/null +++ b/db/migrate/20260118200000_drop_config_options_and_startup_params_tables.rb @@ -0,0 +1,6 @@ +class DropConfigOptionsAndStartupParamsTables < ActiveRecord::Migration[8.1] + def change + drop_table :config_options + drop_table :startup_params + end +end diff --git a/db/schema.rb b/db/schema.rb index de913cf..6528063 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.1].define(version: 2026_01_18_180000) do +ActiveRecord::Schema[8.1].define(version: 2026_01_18_200000) do create_table "activities", force: :cascade do |t| t.string "action", null: false t.datetime "created_at", null: false @@ -23,16 +23,6 @@ ActiveRecord::Schema[8.1].define(version: 2026_01_18_180000) do t.index ["user_id"], name: "index_activities_on_user_id" end - create_table "config_options", force: :cascade do |t| - t.string "config_key", null: false - t.string "config_value", null: false - t.datetime "created_at", null: false - t.integer "server_template_id", null: false - t.datetime "updated_at", null: false - t.index ["server_template_id", "config_key"], name: "index_config_options_on_server_template_id_and_config_key", unique: true - t.index ["server_template_id"], name: "index_config_options_on_server_template_id" - end - create_table "overlays", force: :cascade do |t| t.datetime "created_at", null: false t.text "description" @@ -46,8 +36,10 @@ ActiveRecord::Schema[8.1].define(version: 2026_01_18_180000) do end create_table "server_templates", force: :cascade do |t| + t.text "config" t.datetime "created_at", null: false t.string "name", null: false + t.text "startup_params" t.datetime "updated_at", null: false t.integer "user_id", null: false t.index ["user_id", "name"], name: "index_server_templates_on_user_id_and_name", unique: true @@ -71,16 +63,6 @@ ActiveRecord::Schema[8.1].define(version: 2026_01_18_180000) do t.index ["user_id"], name: "index_servers_on_user_id" end - create_table "startup_params", force: :cascade do |t| - t.datetime "created_at", null: false - t.string "param_key", null: false - t.string "param_value", null: false - t.integer "server_template_id", null: false - t.datetime "updated_at", null: false - t.index ["server_template_id", "param_key"], name: "index_startup_params_on_server_template_id_and_param_key", unique: true - t.index ["server_template_id"], name: "index_startup_params_on_server_template_id" - end - create_table "template_overlays", force: :cascade do |t| t.datetime "created_at", null: false t.integer "overlay_id", null: false @@ -102,12 +84,10 @@ ActiveRecord::Schema[8.1].define(version: 2026_01_18_180000) do end add_foreign_key "activities", "users" - add_foreign_key "config_options", "server_templates" add_foreign_key "overlays", "users" add_foreign_key "server_templates", "users" add_foreign_key "servers", "server_templates" add_foreign_key "servers", "users" - add_foreign_key "startup_params", "server_templates" add_foreign_key "template_overlays", "overlays" add_foreign_key "template_overlays", "server_templates" end