From b1448d886043bc861de5eb5d0280241241f1bc5f Mon Sep 17 00:00:00 2001 From: Daniel Ceregatti Date: Sat, 9 Sep 2023 11:02:24 -0700 Subject: [PATCH] Add cfgeventspawns.xml integration! Add quirk to handle upstream XMLs not having the correct nodes. Add initial map install based on the map in the config. Add package to allow for XML merging in the server container. Add an environment variable that prevents the server from starting, to test mod XML integration at server start. Back up logs into dedicated directories based on the date when the server exits. Improve logic for copying XML files into mpmissions. Fix status output formatting. Get map name from the config at script start in the server script. Refactor XML env scripts so they don't have a hashbang. Refactor one mod's integration with the new file naming convention. --- files/mods/1710977250/xml.env | 2 - files/mods/2692979668/xml.env | 6 +- files/mods/2878980498/types.env | 1 - files/mods/2878980498/xml.env | 1 + files/mods/2906371600/xml.env | 2 - files/mods/2971190303/xml.env | 2 - server/Dockerfile | 1 + server/bin/dz | 191 +++++++++++++++++--------------- web/bin/dz | 10 ++ 9 files changed, 114 insertions(+), 102 deletions(-) delete mode 100644 files/mods/2878980498/types.env create mode 100644 files/mods/2878980498/xml.env diff --git a/files/mods/1710977250/xml.env b/files/mods/1710977250/xml.env index ad443d0..a91617d 100644 --- a/files/mods/1710977250/xml.env +++ b/files/mods/1710977250/xml.env @@ -1,3 +1 @@ -#!/usr/bin/env bash - TYPES=./info/bbp_types.xml diff --git a/files/mods/2692979668/xml.env b/files/mods/2692979668/xml.env index 3a45bbe..0722b75 100644 --- a/files/mods/2692979668/xml.env +++ b/files/mods/2692979668/xml.env @@ -1,9 +1,7 @@ -#!/usr/bin/env bash - CFGSPAWNABLETYPES=https://raw.githubusercontent.com/RedFalconKen/RedFalconFlightSystem-Heliz/main/Config%20Files/Event%20Spawn%20Config/RFFSHelis_cfgspawnabletypes.xml #CFGEVENTSPAWNS=https://raw.githubusercontent.com/RedFalconKen/RedFalconFlightSystem-Heliz/main/Config%20Files/Event%20Spawn%20Config/Banov/RFFSHelis_cfgeventspawns.xml -CFGEVENTSPAWNS=https://raw.githubusercontent.com/RedFalconKen/RedFalconFlightSystem-Heliz/main/Config%20Files/Event%20Spawn%20Config/Chernarus/RFFSHelis_cfgeventspawns.xml -#CFGEVENTSPAWNS=https://raw.githubusercontent.com/RedFalconKen/RedFalconFlightSystem-Heliz/main/Config%20Files/Event%20Spawn%20Config/DeerIsle/RFFSHelis_cfgeventspawns.xml +#CFGEVENTSPAWNS=https://raw.githubusercontent.com/RedFalconKen/RedFalconFlightSystem-Heliz/main/Config%20Files/Event%20Spawn%20Config/Chernarus/RFFSHelis_cfgeventspawns.xml +CFGEVENTSPAWNS=https://raw.githubusercontent.com/RedFalconKen/RedFalconFlightSystem-Heliz/main/Config%20Files/Event%20Spawn%20Config/DeerIsle/RFFSHelis_cfgeventspawns.xml #CFGEVENTSPAWNS=https://raw.githubusercontent.com/RedFalconKen/RedFalconFlightSystem-Heliz/main/Config%20Files/Event%20Spawn%20Config/Namalsk/RFFSHelis_cfgeventspawns.xml EVENTS=https://raw.githubusercontent.com/RedFalconKen/RedFalconFlightSystem-Heliz/main/Config%20Files/Event%20Spawn%20Config/RFFSHelis_events.xml TYPES=https://raw.githubusercontent.com/RedFalconKen/RedFalconFlightSystem-Heliz/main/Config%20Files/Types.XML/RFFSHelis_Types.xml diff --git a/files/mods/2878980498/types.env b/files/mods/2878980498/types.env deleted file mode 100644 index a36947d..0000000 --- a/files/mods/2878980498/types.env +++ /dev/null @@ -1 +0,0 @@ -TYPES=extras/types/rag_baseitems.xml diff --git a/files/mods/2878980498/xml.env b/files/mods/2878980498/xml.env new file mode 100644 index 0000000..fe9bac3 --- /dev/null +++ b/files/mods/2878980498/xml.env @@ -0,0 +1 @@ +TYPES=./extras/types/rag_baseitems.xml diff --git a/files/mods/2906371600/xml.env b/files/mods/2906371600/xml.env index 8e8155f..9cccf42 100644 --- a/files/mods/2906371600/xml.env +++ b/files/mods/2906371600/xml.env @@ -1,5 +1,3 @@ -#!/usr/bin/env bash - CFGSPAWNABLETYPES=https://raw.githubusercontent.com/RedFalconKen/RedFalconWatercraft/main/Config%20Files/Event%20Spawn%20Config/cfgspawnabletypes.xml CFGEVENTSPAWNS=https://github.com/RedFalconKen/RedFalconWatercraft/blob/main/Config%20Files/Event%20Spawn%20Config/DeerIsle/cfgeventspawns.xml EVENTS=https://raw.githubusercontent.com/RedFalconKen/RedFalconWatercraft/main/Config%20Files/Event%20Spawn%20Config/events.xml diff --git a/files/mods/2971190303/xml.env b/files/mods/2971190303/xml.env index 83ed28a..7b27f64 100644 --- a/files/mods/2971190303/xml.env +++ b/files/mods/2971190303/xml.env @@ -1,5 +1,3 @@ -#!/usr/bin/env bash - CFGSPAWNABLETYPES=./spawnabletypes.xml CFGEVENTSPAWNS=./cfgeventspawns_chernarus.xml #EVENTS=events.xml diff --git a/server/Dockerfile b/server/Dockerfile index 87f24e2..19a4ca1 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -13,6 +13,7 @@ RUN apt-get update && apt-get -y upgrade && apt-get -y install --no-install-reco curl \ ca-certificates \ git \ + gwenhywfar-tools \ jq \ libsdl2-2.0-0 \ libcap2 \ diff --git a/server/bin/dz b/server/bin/dz index 990075b..0c4e3b6 100755 --- a/server/bin/dz +++ b/server/bin/dz @@ -110,6 +110,10 @@ EOF # Make sure to clean up and report on exit, as these files remain in the container's volume report() { + if [[ ${DONT_START} != "" ]] + then + exit 0 + fi rm -f /tmp/mod_command_line /tmp/parameters echo echo -e "${yellow}========================================== error.log ==========================================" @@ -122,106 +126,112 @@ report() { find "${SERVER_PROFILE}" -name "*.RPT" -exec ls -la {} \; -exec tail -n 30 {} \; -exec rm -f {} \; echo echo -e "========================================== End log ======================================${default}" + # Back these files up into a new directory with the current time stamp in the name + DIR="${SERVER_PROFILE}/logs-$(date +%Y-%m-%d-%H-%M-%S)" + mkdir -p ${DIR} + cd ${SERVER_PROFILE} + mv -v *.log *.RPT *.mdmp ${DIR} 2> /dev/null } mergexml(){ - # First copy the pristine files from upstream - for i in cfgeconomycore.xml #cfgeventspawns.xml - do - echo "Copying pristine version of ${i} into local mpmission ${MAP}..." - for dir in $(ls -d ${MPMISSIONS}/*) - do - if [[ ${dir} != ${MAP} ]] - then - continue - fi - find /mpmissions/$(basename ${dir}) -name ${i} -exec cp -v {} ${SERVER_FILES}{} \; - done - done - - # Follow https://community.bistudio.com/wiki/DayZ:Central_Economy_mission_files_modding and make a single XML - # file for the ones that can go into it. - for link in $(ls -tdr ${SERVER_PROFILE}/@* 2> /dev/null) - do - ID=$(readlink ${link} | awk -F/ '{print $NF}') - # Going to have to maintain a matrix of file names -> root node -> child node permutations - C="" - FOUND=0 - for i in "CFGSPAWNABLETYPES:spawnabletypes:type" "EVENTS:events:event" "TYPES:types:type" - do - var=$(echo ${i} | cut -d: -f1) - CHECK=$(echo ${i} | cut -d: -f2) - CHILD=$(echo ${i} | cut -d: -f3) - if [ -f "${WORKSHOP_DIR}/${ID}/${var,,}.xml" ] - then - if [[ ${FOUND} = 0 ]] - then - MODNAME=$(get_mod_name ${ID}) - echo " Adding mod ${MODNAME}" - FOUND=1 - fi - echo -n " " - for dir in $(ls ${MPMISSIONS}) - do - # Only copy for the current map - if [[ ${dir} != ${MAP} ]] - then - continue - fi - rm -rf ${MPMISSIONS}/${dir}/${ID} - mkdir -p ${MPMISSIONS}/${dir}/${ID} - cp -v ${WORKSHOP_DIR}/${ID}/${var,,}.xml ${MPMISSIONS}/${dir}/${ID}/${var,,}.xml - done - C+="-s / -t elem -n file -a /file -t attr -n name -v ${var,,}.xml -a /file -t attr -n type -v ${CHECK} -m /file /ce " - fi - done - if [[ ${C} != "" ]] - then - # Merge into every mpmissions file - find ${MPMISSIONS} -name cfgeconomycore.xml -exec \ - xmlstarlet ed -L -s / -t elem -n ce \ - -a /ce -t attr -n folder -v "${ID}" \ - ${C} \ - -m /ce /economycore {} \; - fi - # These still have to be merged into the upstream file -# for i in "CFGEVENTSPAWNS:eventposdef:event" -# do -# var=$(echo ${i} | cut -d: -f1) -# CHECK=$(echo ${i} | cut -d: -f2) -# CHILD=$(echo ${i} | cut -d: -f3) -# if [ -f "${WORKSHOP_DIR}/${ID}/${var,,}.xml" ] -# then -# echo "Merging ${var,,}.xml (Not really...WIP)" -# xmlstarlet ed -L -s / -t name event -# fi -# done - done + echo + # First copy the pristine files from upstream + echo -e "${green}Copying upstream XML files into local mpmissions for map ${MAP}${default}": + find /mpmissions/${MAP} \( -name "cfgeconomycore.xml" -o -name "cfgeventspawns.xml" \) -exec cp -v {} ${SERVER_FILES}{} \; + # Follow https://community.bistudio.com/wiki/DayZ:Central_Economy_mission_files_modding + # First, remove any existing files, via the mod_ prefix + rm -rf ${MPMISSIONS}/${MAP}/mod_* + for link in $(ls -tdr ${SERVER_PROFILE}/@* 2> /dev/null) + do + ID=$(readlink ${link} | awk -F/ '{print $NF}') + # Going to have to maintain a matrix of file names -> root node -> child node permutations + C="" + FOUND=0 + for i in "CFGSPAWNABLETYPES:spawnabletypes:type" "EVENTS:events:event" "TYPES:types:type" + do + var=$(echo ${i} | cut -d: -f1) + CHECK=$(echo ${i} | cut -d: -f2) + CHILD=$(echo ${i} | cut -d: -f3) + if [ -f "${WORKSHOP_DIR}/${ID}/${var,,}.xml" ] + then + if [[ ${FOUND} = 0 ]] + then + MODNAME=$(get_mod_name ${ID}) + echo + echo -e "${green}Adding mod ${MODNAME}${default}" + FOUND=1 + fi + echo -n "Copy " + mkdir -p ${MPMISSIONS}/${MAP}/mod_${ID} + cp -v ${WORKSHOP_DIR}/${ID}/${var,,}.xml ${MPMISSIONS}/${MAP}/mod_${ID}/${var,,}.xml + C+="-s / -t elem -n file -a /file -t attr -n name -v ${var,,}.xml -a /file -t attr -n type -v ${CHECK} -m /file /ce " + fi + done + if [[ ${C} != "" ]] + then + # Merge into the current mpmissions file + echo "Create new XML node -> ${MPMISSIONS}/${MAP}/cfgeconomycore.xml" + find ${MPMISSIONS}/${MAP} -name cfgeconomycore.xml -exec \ + xmlstarlet ed -L -s / -t elem -n ce \ + -a /ce -t attr -n folder -v "mod_${ID}" ${C} \ + -m /ce /economycore {} \; + fi + # These are merged directly into the upstream file + for i in "CFGEVENTSPAWNS:eventposdef:event" + do + var=$(echo ${i} | cut -d: -f1) + CHECK=$(echo ${i} | cut -d: -f2) + CHILD=$(echo ${i} | cut -d: -f3) + if [ -f "${WORKSHOP_DIR}/${ID}/${var,,}.xml" ] + then + echo "Merge XML ${WORKSHOP_DIR}/${ID}/${var,,}.xml -> ${MPMISSIONS}/${MAP}/${var,,}.xml" + rm -f /tmp/x /tmp/y + xmlmerge -o /tmp/x ${WORKSHOP_DIR}/${ID}/${var,,}.xml ${MPMISSIONS}/${MAP}/${var,,}.xml + xmlstarlet fo /tmp/x > /tmp/y + # Ensure the XML is valid + xmllint --noout /tmp/y || ( + echo + echo "Merged XML file ${MPMISSIONS}/${MAP}/${var,,}.xml is not valid! Can't continue!" + echo + exit 1 + ) + mv /tmp/y ${MPMISSIONS}/${MAP}/${var,,}.xml + fi + done + done } # Start the server in the foreground start(){ - # Ensure mpmissions has at least one map. If not, copy it from the local read-only volume that stores pristine mpmissons directories - if [ ! -d "${MPMISSIONS}/dayzOffline.chernarusplus" ] - then - echo - echo "Performing one-time copy of Chernarus mpmissions..." - echo - cp -av /mpmissions/dayzOffline.chernarusplus ${MPMISSIONS} - fi - # If we're developing, just block the container - if [[ ${DEVELOPMENT} = "1" ]] - then - echo "DEVELOPMENT mode, blocking..." - tail -f /dev/null - exit 0 - fi + # Ensure mpmissions has at least one map. If not, copy it from the local read-only volume that stores pristine mpmissons directories + if [ ! -d "${MPMISSIONS}/${MAP}" ] + then + echo + echo "Performing one-time copy of ${MAP} mpmissions..." + echo + cp -av /mpmissions/${MAP} ${MPMISSIONS} + fi + # If we're developing, just block the container + if [[ ${DEVELOPMENT} = "1" ]] + then + echo "DEVELOPMENT mode, blocking. Unset DEVELOPMENT in the current environment to run the server." + tail -f /dev/null + exit 0 + fi # Do the report on exit. Set here so that it only happens once we're starting the server, and not for other actions. trap ' report ' EXIT get_mods mergexml + if [[ ${DONT_START} != "" ]] + then + echo + echo "Not starting server, as DONT_START is set" + echo + exit 0 + fi + echo cd ${SERVER_FILES} # Run the server. Allow docker to restart the container if the script exits with a code other than 0. This is so we can # safely shut the container down without killing the server within. @@ -322,7 +332,7 @@ rcon(){ activelist(){ X=1 C="${green}" - spaces=" " + spaces=" " have=no for link in $(ls -tdr ${SERVER_PROFILE}/@* 2> /dev/null) do @@ -335,7 +345,7 @@ activelist(){ ID=$(readlink ${link} | awk -F/ '{print $NF}') MODNAME=$(get_mod_name ${ID}) SIZE=$(du -sh "${WORKSHOP_DIR}/${ID}" | awk '{print $1}') - printf "${C}%.3d %s %.23s %s https://steamcommunity.com/sharedfiles/filedetails/?id=%s %s${default}\n" ${X} ${ID} "${MODNAME}" "${spaces:${#MODNAME}+1}" ${ID} ${SIZE} + printf "${C}%.3d %s %.30s %s https://steamcommunity.com/sharedfiles/filedetails/?id=%s %s${default}\n" ${X} ${ID} "${MODNAME}" "${spaces:${#MODNAME}+1}" ${ID} ${SIZE} X=$((X+1)) done if [[ ${have} = "no" ]] @@ -379,7 +389,7 @@ status(){ # Current parameters RUNNING="${RUNNING}\nRunning Parameters: $(cat /tmp/parameters)\nRunning mod parameter: $(cat /tmp/mod_command_line)" fi - MAP=$(get_map_name) + MAP=${MAP} # Number of mods plus the list denoting on or off echo -ne " Server files installed: ${INSTALLED}" @@ -399,7 +409,6 @@ Working parameters: ${parameters} Working mod parameter: ${mod_command_line}" if [[ "${INSTALLED}" = "${YES}" ]] then - MAP=$(grep template ${SERVER_CFG_DST} | grep -v "^//" | cut -d= -f2 | cut -d\; -f1) echo "Map: ${MAP}" fi echo diff --git a/web/bin/dz b/web/bin/dz index 2caac1f..d3fdfbf 100755 --- a/web/bin/dz +++ b/web/bin/dz @@ -61,6 +61,16 @@ installxml(){ then echo "Normalizing ${WORKSHOP_DIR}/${ID}/${var,,}.xml..." cp ${WORKSHOP_DIR}/${ID}/${var,,}.xml /tmp/x + # Quirks + # Some cfgeventspanws.xml files have instead of . Let's just try to fix that first. + if [[ ${var} = "CFGEVENTSPAWNS" ]] + then + if grep -q '' /tmp/x + then + echo " - (Quirk) has instead of . fixing..." + xmlstarlet ed -L -r "events" -v "eventposdef" /tmp/x + fi + fi if ! grep -q '<'${CHECK}'>' /tmp/x then echo " - has no root node <${CHECK}>. fixing..."