diff --git a/ansible/roles/podman/tasks/containers/home/zomboid.yml b/ansible/roles/podman/tasks/containers/home/zomboid.yml index 7a9b10f..9d50a72 100644 --- a/ansible/roles/podman/tasks/containers/home/zomboid.yml +++ b/ansible/roles/podman/tasks/containers/home/zomboid.yml @@ -23,6 +23,15 @@ # than the container's subuid. Getting this wrong silently broke world resets: # the script's first log line failed with EACCES and set -e killed it before it # stopped the server, so `@bot` resets did nothing at all. +- name: create zomboid canonical config directory + become: true + ansible.builtin.file: + path: "{{ zomboid_path }}/config-template" + state: directory + owner: "{{ podman_user }}" + group: "{{ podman_user }}" + mode: 0755 + - name: create zomboid host-side log directory become: true ansible.builtin.file: @@ -219,6 +228,33 @@ state: started daemon_reload: true +# The intended world settings, kept somewhere the server cannot reach. +# +# PZ reads Server/_SandboxVars.lua only when it creates a world, and then +# writes the *running world's* settings back over that same file. So the file in +# Server/ is an output, not an input: once any world is created with defaults, +# the server stamps those defaults into it and every later wipe regenerates from +# them. That is how a Sophie world quietly became an Apocalypse one -- 139 values +# reverted, loot rates from 0.35 back to 0.9, CharacterFreePoints from 0 to 60. +# +# This copy is what a wipe restores from, so settings survive it. Seeded once and +# then left alone, so it is the file to hand-edit when changing the world: +# edit here, then wipe, and the new world comes up with the edits. +- name: seed canonical zomboid world settings + become: true + ansible.builtin.copy: + src: "zomboid/sophie/{{ item }}.lua" + dest: "{{ zomboid_path }}/config-template/{{ item }}.lua" + force: "{{ zomboid_config_force | bool }}" + owner: "{{ podman_user }}" + group: "{{ podman_user }}" + mode: 0644 + loop: + - SandboxVars + - spawnregions + - spawnpoints + tags: zomboid-conf + # The server's own logs, not the container's. PZ holds these fds open for the # life of the process, so copytruncate is mandatory -- a rename would leave it # writing into an unlinked inode and the file would appear to stop growing. diff --git a/ansible/roles/podman/templates/zomboid/world-reset.sh.j2 b/ansible/roles/podman/templates/zomboid/world-reset.sh.j2 index 12fc8d2..f0a6d1a 100644 --- a/ansible/roles/podman/templates/zomboid/world-reset.sh.j2 +++ b/ansible/roles/podman/templates/zomboid/world-reset.sh.j2 @@ -55,6 +55,24 @@ else log "No database found at $DB_PATH" fi +# Restore the intended world settings before the server regenerates. +# +# Without this the wipe silently changes the game. PZ writes the running world's +# settings back over Server/_SandboxVars.lua, so by the time we delete the +# save that file already describes the world we are throwing away -- and if that +# world had defaults, the replacement inherits them. Restoring from the canonical +# copy is what makes a wipe reset the world and keep the settings. +CONFIG_TEMPLATE="{{ podman_home }}/.local/share/volumes/zomboid/config-template" +SERVER_DIR="{{ podman_home }}/.local/share/volumes/zomboid/data/Server" +for f in SandboxVars spawnregions spawnpoints; do + if [[ -f "${CONFIG_TEMPLATE}/${f}.lua" ]]; then + podman unshare cp "${CONFIG_TEMPLATE}/${f}.lua" "${SERVER_DIR}/${SERVER_NAME}_${f}.lua" + log "Restored ${SERVER_NAME}_${f}.lua from canonical config" + else + log "WARNING: no canonical ${f}.lua; the new world will inherit whatever the server last wrote" + fi +done + # Start server log "Starting zomboid service..." systemctl --user start zomboid.service