Sfoglia il codice sorgente

palworld - allow additional config (#2100)

* palworld - allow additional config

* bump version

* test actual keys

* dont print passwords

* handle bools

* lint

* handle bools

* only create dirs if not exist

* bypass bools on sh

* handle weird cases with quoting
Stavros Kois 1 anno fa
parent
commit
c479033fc9

+ 1 - 1
library/ix-dev/community/palworld/Chart.yaml

@@ -3,7 +3,7 @@ description: Palworld is a multiplayer, open-world survival crafting game where
 annotations:
   title: Palworld
 type: application
-version: 1.0.2
+version: 1.0.3
 apiVersion: v2
 appVersion: palworld
 kubeVersion: '>=1.16.0-0'

+ 12 - 1
library/ix-dev/community/palworld/ci/basic-values.yaml

@@ -13,8 +13,19 @@ palworldStorage:
     type: pvc
 
 palworldConfig:
-  adminPassword: sec!@#%-_ret123@#%-_!@#%
+  adminPassword: asdfhjfgk7!@^&$1asdf
   backup:
     enabled: true
     interval: 60
     keep: 3
+  iniKeys:
+    - key: PlayerDamageRateAttack
+      value: 1.000000
+    - key: DropItemMaxNum
+      value: 4000
+    - key: Region
+      value: ""
+    - key: PalEggDefaultHatchingTime
+      value: 72.450000
+    - key: bEnablePlayerToPlayerDamage
+      value: true

+ 25 - 6
library/ix-dev/community/palworld/questions.yaml

@@ -25,9 +25,6 @@ questions:
             private: true
             required: true
             default: ""
-            valid_chars: "[a-zA-Z0-9!@#%-_]*"
-            valid_chars_error: |
-              Can contain at numbers, letters, and the following characters: !@#%-_
         - variable: server
           label: Server Configuration
           description: Configure the server for Palworld
@@ -56,9 +53,31 @@ questions:
                   type: string
                   private: true
                   default: ""
-                  valid_chars: "[a-zA-Z0-9!@#%-_]*"
-                  valid_chars_error: |
-                    Can contain at numbers, letters, and the following characters: !@#%-_
+        - variable: iniKeys
+          label: Configure INI Keys
+          description: |
+            Enter your INI keys </br>
+            Updates the keys in PalWorldSettings.ini
+          schema:
+            type: list
+            default: []
+            items:
+              - variable: iniKey
+                label: INI Key
+                schema:
+                  type: dict
+                  attrs:
+                    - variable: key
+                      label: Key
+                      schema:
+                        type: string
+                        default: ""
+                        required: true
+                    - variable: value
+                      label: Value
+                      schema:
+                        type: string
+                        default: ""
         - variable: backup
           label: Backup
           description: Configure the backup for Palworld

+ 45 - 23
library/ix-dev/community/palworld/templates/_palworld.tpl

@@ -88,32 +88,54 @@ workload:
             - |
               config={{ $srvDir }}/Pal/Saved/Config/LinuxServer
               cfgFile=${config}/PalWorldSettings.ini
-              mkdir -p ${config}
+              if [ ! -d ${config} ]; then
+                echo "Config directory not found, creating..."
+                mkdir -p ${config}
+              fi
               if [ ! -f ${cfgFile} ]; then
                 echo "Config file not found, fetching..."
-                # Fetch the config file if it doesn't exist, just like the container does
+                # -- Fetch the config file if it doesn't exist, just like the container does
                 wget -qO ${cfgFile} https://github.com/ich777/docker-steamcmd-server/raw/palworld/config/PalWorldSettings.ini
               fi
-              echo "Setting RCON status..."
-              sed -i 's/\(RCONEnabled=\)[^,]*/\1True/g' ${cfgFile}
-              echo "Set to [$(grep -Po 'RCONEnabled=[^,]*' ${cfgFile})]"
-              echo "Setting RCON Port..."
-              sed -i 's/\(RCONPort=\)[^,]*/\1{{ .Values.palworldNetwork.rconPort }}/g' ${cfgFile}
-              echo "Set to [$(grep -Po 'RCONPort=[^,]*' ${cfgFile})]"
-              echo "Setting Game Port..."
-              sed -i 's/\(PublicPort=\)[^,]*/\1{{ .Values.palworldNetwork.serverPort }}/g' ${cfgFile}
-              echo "Set to [$(grep -Po 'PublicPort=[^,]*' ${cfgFile})]"
-              echo "Setting Server Name..."
-              sed -i 's/\(ServerName=\)[^,]*/\1{{ .Values.palworldConfig.server.name | quote }}/g' ${cfgFile}
-              echo "Set to [$(grep -Po 'ServerName=[^,]*' ${cfgFile})]"
-              echo "Setting Server Description..."
-              sed -i 's/\(ServerDescription=\)[^,]*/\1{{ .Values.palworldConfig.server.description | quote }}/g' ${cfgFile}
-              echo "Set to [$(grep -Po 'ServerDescription=[^,]*' ${cfgFile})]"
-              echo "Setting Server Password..."
-              sed -i 's/\(ServerPassword=\)[^,]*/\1{{ .Values.palworldConfig.server.password | quote }}/g' ${cfgFile}
-              echo "Server Password set..."
-              echo "Setting Admin Password..."
-              sed -i 's/\(AdminPassword=\)[^,]*/\1{{ .Values.palworldConfig.adminPassword | quote }}/g' ${cfgFile}
-              echo "Admin Password set..."
+
+              set_ini_value() {
+                local key="${1}"
+                local value="${2}"
+                local quote="${3:-false}"
+                local print="${4:-true}"
+                # -- Escape special characters for sed
+                escaped_value=$(printf '%s\n' "$value" | sed 's/[&/\]/\\&/g')
+                if [ "$quote" = true ]; then
+                  escaped_value="\"${escaped_value}\""
+                fi
+
+                echo "Setting ${key}..."
+                sed -i "s|\(${key}=\)[^,]*|\1${escaped_value}|g" "${cfgFile}"
+                if [ "$print" = true ]; then
+                  echo "Set to $(grep -Po "(?<=${key}=)[^,]*" "${cfgFile}")"
+                fi
+              }
+
+              set_ini_value "RCONEnabled" True
+              set_ini_value "RCONPort" {{ .Values.palworldNetwork.rconPort }}
+              set_ini_value "PublicPort" {{ .Values.palworldNetwork.serverPort }}
+              set_ini_value "ServerName" {{ .Values.palworldConfig.server.name | quote }} true
+              set_ini_value "ServerDescription" {{ .Values.palworldConfig.server.description | quote }} true
+              set_ini_value "ServerPassword" {{ .Values.palworldConfig.server.password | squote }} true false
+              set_ini_value "AdminPassword" {{ .Values.palworldConfig.adminPassword | squote }} true false
+
+              {{- range $item := .Values.palworldConfig.iniKeys }}
+                {{- if mustHas (kindOf $item.value) (list "int" "int64" "float64") }}
+                  echo "Key {{ $item.key }} is a {{ kindOf $item.value }}, setting without quotes..."
+                  set_ini_value "{{ $item.key }}" {{ $item.value }}
+                {{- else if or (eq ((toString $item.value) | lower) "true") (eq ((toString $item.value) | lower) "false") }}
+                  echo "Key {{ $item.key }} is a boolean, setting without quotes..."
+                  set_ini_value "{{ $item.key }}" {{ (toString $item.value) | camelcase }}
+                {{- else }}
+                  echo "Key {{ $item.key }} is a {{ kindOf $item.value }}, setting with quotes..."
+                  set_ini_value "{{ $item.key }}" {{ $item.value | quote }} true
+                {{- end }}
+              {{- end }}
+
               echo "Done!"
 {{- end -}}

+ 11 - 0
library/ix-dev/community/palworld/templates/_params.tpl

@@ -15,4 +15,15 @@
   {{- if not .Values.palworldConfig.backup -}}
     {{- $_ := set .Values.palworldConfig "backup" dict -}}
   {{- end -}}
+
+  {{- $reservedKeys := list
+    "RCONEnabled" "RCONPort" "PublicPort" "ServerName"
+    "ServerDescription" "ServerPassword" "AdminPassword"
+  -}}
+
+  {{- range $item := .Values.palworldConfig.iniKeys }}
+    {{- if (mustHas $item.key $reservedKeys) -}}
+      {{- fail (printf "PalWorld - [%v] is a reserved key." $item.key) -}}
+    {{- end -}}
+  {{- end -}}
 {{- end -}}

+ 1 - 0
library/ix-dev/community/palworld/values.yaml

@@ -24,6 +24,7 @@ palworldConfig:
     - -useperfthreads
     - -NoAsyncLoadingThread
     - -UseMultithreadForDS
+  iniKeys: []
   updatePublicIP: false
   validate: false
   username: ''