From 5788f65ce5691d7b48ddec87238210afdae24772 Mon Sep 17 00:00:00 2001 From: Florian Hartwich Date: Sat, 8 Jul 2017 16:14:29 +0200 Subject: [PATCH] Add fraction parsing --- api/war-parser/run.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/api/war-parser/run.sh b/api/war-parser/run.sh index 22bab0d..efa488e 100755 --- a/api/war-parser/run.sh +++ b/api/war-parser/run.sh @@ -8,8 +8,10 @@ createScoreboard() { FF=0 DEATH=0 RESPAWN=0 + FLAG=0 + FRACTION= - #escape '[' -> somehow escapes all special chars, lol? + #escape '[' -> somehow escapes all special chars, hah? ESC_NAME=$(echo "$NAME" | sed -r 's/[\[]+/\\[/g') while IFS= read -r line; do @@ -27,9 +29,16 @@ createScoreboard() { ((RESPAWN++)) ;; esac + + if [[ -z ${FRACTION} && ( "$line" == *${ESC_NAME}[" "]\(WEST\)* || "$line" == *${ESC_NAME}[" "]\(NATO\)* ) ]]; then + FRACTION="BLUFOR" + fi + if [[ -z ${FRACTION} && ( "$line" == *${ESC_NAME}[" "]\(EAST\)* || "$line" == *${ESC_NAME}[" "]\(CSAT\)* ) ]]; then + FRACTION="OPFOR" + fi done < <(grep -- "${ESC_NAME}" ${FILE}) - printf "\t{\"name\":\"$NAME\", \"kill\":${KILL}, \"ff\":${FF}, \"death\":${DEATH}, \"respawn\":${RESPAWN}}" + printf "\t{\"name\":\"$NAME\", \"fraction\":\"$FRACTION\", \"kill\":${KILL}, \"friendlyFire\":${FF}, \"death\":${DEATH}, \"respawn\":${RESPAWN}}, \"flagTouch\":${FLAG}} " if [[ -z ${3} ]]; then printf ",\n" else @@ -56,11 +65,13 @@ while IFS='' read -r line || [[ -n "$line" ]]; do ;; esac - if [[ $RES =~ [^[:space:]] && " ${PLAYERS[*]} " != *" $RES "* ]]; then - PLAYERS+=("$RES") - fi - if [[ $RES1 =~ [^[:space:]] && " ${PLAYERS[*]} " != *" $RES1 "* ]]; then - PLAYERS+=("$RES1") + if [[ $RES != *"Error: No unit"* && $RES1 != *"Error: No unit"* ]]; then + if [[ $RES =~ [^[:space:]] && " ${PLAYERS[*]} " != *" $RES "* ]]; then + PLAYERS+=("$RES") + fi + if [[ $RES1 =~ [^[:space:]] && " ${PLAYERS[*]} " != *" $RES1 "* ]]; then + PLAYERS+=("$RES1") + fi fi fi done < ${FILE}