From e6a381315f7ee06769e448fe4ab4a8b59be683c5 Mon Sep 17 00:00:00 2001 From: Daniel Ceregatti Date: Fri, 8 Sep 2023 12:13:29 -0700 Subject: [PATCH] Fix lack of root node in XML when normalizing. Refine output to only show relevant info when starting the server. Filter mod integration by current map, even if other mpmissions directories should exist. Remove previous cfgeconomy directories when starting, to prevent previous files from possibly existing. Orchestrate the retrieval and normalization of XML files as 'dz x ID' now does both. --- server/bin/dz | 67 +++++++++++++++++++++++++++++++++------------------ web/bin/dz | 25 ++++++++++--------- 2 files changed, 58 insertions(+), 34 deletions(-) diff --git a/server/bin/dz b/server/bin/dz index 093d775..990075b 100755 --- a/server/bin/dz +++ b/server/bin/dz @@ -128,10 +128,13 @@ 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(s)..." + echo "Copying pristine version of ${i} into local mpmission ${MAP}..." for dir in $(ls -d ${MPMISSIONS}/*) do - #echo "dir: ${dir}, basename: $(basename ${dir})" + if [[ ${dir} != ${MAP} ]] + then + continue + fi find /mpmissions/$(basename ${dir}) -name ${i} -exec cp -v {} ${SERVER_FILES}{} \; done done @@ -143,6 +146,7 @@ mergexml(){ 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) @@ -150,11 +154,22 @@ mergexml(){ CHILD=$(echo ${i} | cut -d: -f3) if [ -f "${WORKSHOP_DIR}/${ID}/${var,,}.xml" ] then - FOUND=1 - echo "Adding ${WORKSHOP_DIR}/${ID}/${var,,}.xml to cfgeconomycore..." + if [[ ${FOUND} = 0 ]] + then + MODNAME=$(get_mod_name ${ID}) + echo " Adding mod ${MODNAME}" + FOUND=1 + fi + echo -n " " for dir in $(ls ${MPMISSIONS}) do - mkdir -pv ${MPMISSIONS}/${dir}/${ID} + # 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 " @@ -170,17 +185,17 @@ mergexml(){ -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..." +# 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 +# fi +# done done } @@ -329,6 +344,16 @@ activelist(){ fi } +get_map_name(){ + MAP="none" + # Map name + if [[ -f ${SERVER_CFG_DST} ]] + then + MAP=$(grep -E "template=" ${SERVER_CFG_DST} | grep -vE "^//" | cut -d= -f2 | cut -d\; -f1 | tr -d '"') + fi + echo ${MAP} +} + # Display the status of everything status(){ loadconfig @@ -354,13 +379,7 @@ status(){ # Current parameters RUNNING="${RUNNING}\nRunning Parameters: $(cat /tmp/parameters)\nRunning mod parameter: $(cat /tmp/mod_command_line)" fi - - MAP="none" - # Map name - if [[ -f ${SERVER_CFG_DST} ]] - then - MAP=$(grep -E "template=" ${SERVER_CFG_DST} | grep -vE "^//") - fi + MAP=$(get_map_name) # Number of mods plus the list denoting on or off echo -ne " Server files installed: ${INSTALLED}" @@ -393,11 +412,13 @@ backup(){ do B="${BACKUP_DIR}/${DATE}/" echo "Backing up ${i} to ${B}..." - mkdir -p ${B} + mkdir -p ${B} 1> /dev/null cp -a "${i}" "${B}" done } +MAP=$(get_map_name) + # Capture the first argument and shift it off so we can pass $@ to every function C=${1} shift || { diff --git a/web/bin/dz b/web/bin/dz index 5c0ca74..2caac1f 100755 --- a/web/bin/dz +++ b/web/bin/dz @@ -63,22 +63,25 @@ installxml(){ cp ${WORKSHOP_DIR}/${ID}/${var,,}.xml /tmp/x if ! grep -q '<'${CHECK}'>' /tmp/x then - echo " - has no root node <${CHECK}>. fixing..." - xmlstarlet ed -s / -t elem -n "${CHECK}" -m /${CHILD} /${CHECK} /tmp/x > /tmp/y - mv /tmp/y /tmp/x + echo " - has no root node <${CHECK}>. fixing..." + echo '<'${CHECK}'>' > /tmp/y + cat /tmp/x >> /tmp/y + echo '' >> /tmp/y + xmlstarlet fo /tmp/y > /tmp/x fi if ! grep -q ' /tmp/y mv /tmp/y /tmp/x fi - xmllint --noout /tmp/x || { - echo "The final file failed lint tests, aborting..." - exit 1 - } - # Keep the normalized version in the /mods directory, where they should have been from the start - cp /tmp/x ${WORKSHOP_DIR}/${ID}/${var,,}.xml + xmllint --noout /tmp/x && ( + # Keep the normalized version in the /mods directory + cp /tmp/x ${WORKSHOP_DIR}/${ID}/${var,,}.xml + echo -e "${green}${WORKSHOP_DIR}/${ID}/${var,,}.xml passes XML lint test!${default}" + ) || ( + echo -e "${yellow}The final ${WORKSHOP_DIR}/${ID}/${var,,}.xml does not pass XML lint test! IT WAS NOT COPIED!${default}" + ) fi done exit 0 @@ -301,7 +304,7 @@ mod_install(){ # "Manage" XML files. xml(){ /files/bin/xml.sh ${1} - #installxml ${1} + installxml ${1} } # Capture the first argument and shift it off so we can pass $@ to every function