_configuarion.tpl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. {{- define "terraria.configuration" -}}
  2. {{ include "terraria.validation" $ }}
  3. {{ $sizes := (dict "small" 1 "medium" 2 "large" 3) }}
  4. {{ $difficutlies := (dict "normal" 0 "expert" 1 "master" 2 "journey" 3) }}
  5. {{ $flags := (list "-port" "-world" "-maxplayers" "-password" "-secure" "-forceupdate" "-worldevil" "-difficulty" "-autocreate" "-seed") }}
  6. {{/* worldevil, dificulty and autocreate flags are only used
  7. when a world is generated. According to docs server will
  8. ingore them if a world exists, so we can safely pass
  9. them all the time and let server handle it.
  10. Also -autocreate must come before other flags.
  11. */}}
  12. - -autocreate
  13. - {{ get $sizes .Values.terrariaConfig.worldSize | quote }}
  14. - -worldevil
  15. - {{ .Values.terrariaConfig.worldEvil | quote }}
  16. - -difficulty
  17. - {{ get $difficutlies .Values.terrariaConfig.worldDifficulty | quote }}
  18. {{ with .Values.terrariaConfig.worldSeed }}
  19. - -seed
  20. - {{ . | quote }}
  21. {{ end }}
  22. - -port
  23. - {{ .Values.terrariaNetwork.serverPort | quote }}
  24. - -world
  25. - {{ printf "/root/.local/share/Terraria/Worlds/%s.wld" .Values.terrariaConfig.worldName | quote }}
  26. - -maxplayers
  27. - {{ .Values.terrariaConfig.maxPlayers | quote }}
  28. {{ with .Values.terrariaConfig.password }}
  29. - -password
  30. - {{ . | quote }}
  31. {{ end }}
  32. {{ if .Values.terrariaConfig.secure }}
  33. - -secure
  34. {{ end }}
  35. {{ if .Values.terrariaConfig.forceUpdate }}
  36. - -forceupdate
  37. {{ end }}
  38. {{ range $arg := .Values.terrariaConfig.additionalArgs }}
  39. {{ if (mustHas $arg.key $flags) }}
  40. {{ fail (printf "Terraria - Argument [%s] is already handled by the app, please use the corresponding field instead" $arg.key) }}
  41. {{ end }}
  42. - {{ $arg.key | quote }}
  43. {{ with $arg.value }}
  44. - {{ . | quote }}
  45. {{ end }}
  46. {{ end }}
  47. {{- end -}}
  48. {{- define "terraria.validation" -}}
  49. {{- if not (mustRegexMatch "^[a-zA-Z0-9-]+$" .Values.terrariaConfig.worldName) -}}
  50. {{- fail "Terraria - Expected World Name to only have [letters, numbers, dashes]" -}}
  51. {{- end -}}
  52. {{- if not .Values.terrariaConfig.maxPlayers -}}
  53. {{- fail "Terraria - Expected non-empty Max Players" -}}
  54. {{- end -}}
  55. {{- if gt (int .Values.terrariaConfig.maxPlayers) 255 -}}
  56. {{- fail "Terraria - Expected Max Players to be at most 255" -}}
  57. {{- end -}}
  58. {{- $evils := (list "crimson" "corrupt" "random") -}}
  59. {{- if not (mustHas .Values.terrariaConfig.worldEvil $evils) -}}
  60. {{- fail (printf "Terraria - Expected World Evil to be one of [%s], but got [%s]" (join ", " $evils) .Values.terrariaConfig.worldEvil) -}}
  61. {{- end -}}
  62. {{- $sizes := (list "small" "medium" "large") -}}
  63. {{- if not (mustHas .Values.terrariaConfig.worldSize $sizes) -}}
  64. {{- fail (printf "Terraria - Expected World Size to be one of [%s], but got [%s]" (join ", " $sizes) .Values.terrariaConfig.worldSize) -}}
  65. {{- end -}}
  66. {{- $difficutlies := (list "normal" "expert" "master" "journey") -}}
  67. {{- if not (mustHas .Values.terrariaConfig.worldDifficulty $difficutlies) -}}
  68. {{- fail (printf "Terraria - Expected World Difficulty to be one of [%s], but got [%s]" (join ", " $difficutlies) .Values.terrariaConfig.worldDifficulty) -}}
  69. {{- end -}}
  70. {{- end -}}