opt-cc/api/war-parser/run.sh

98 lines
2.8 KiB
Bash
Raw Permalink Normal View History

2017-07-08 13:14:59 +02:00
#!/usr/bin/env bash
createScoreboard() {
NAME="$1"
FILE="$2"
WAR_ID="$3"
2017-07-08 13:14:59 +02:00
KILL=0
FF=0
2017-08-05 23:19:23 +02:00
REVIVE=0
2017-07-08 13:14:59 +02:00
DEATH=0
RESPAWN=0
2017-07-08 16:14:29 +02:00
FLAG=0
FRACTION=
2017-07-08 13:14:59 +02:00
2017-07-08 16:14:29 +02:00
#escape '[' -> somehow escapes all special chars, hah?
2017-07-08 13:14:59 +02:00
ESC_NAME=$(echo "$NAME" | sed -r 's/[\[]+/\\[/g')
while IFS= read -r line; do
case "$line" in
*\(WEST\)[" "]von:[" "]${ESC_NAME}[" "]\(EAST\)* | *\(EAST\)[" "]von:[" "]${ESC_NAME}[" "]\(WEST\)*)
((KILL++))
;;
*\(EAST\)[" "]von:[" "]${ESC_NAME}[" "]\(EAST\)* | *\(WEST\)[" "]von:[" "]${ESC_NAME}[" "]\(WEST\)*)
((FF++))
;;
2017-08-05 23:19:23 +02:00
*\(EAST\)[" "]wurde[" "]von[" "]${ESC_NAME}[" "]\(EAST\)[" "]wiederbelebt* | *\(WEST\)[" "]wurde[" "]von[" "]${ESC_NAME}[" "]\(WEST\)[" "]wiederbelebt*)
((REVIVE++))
;;
2017-07-08 13:14:59 +02:00
*${ESC_NAME}[" "]*von:*)
((DEATH++))
;;
2017-08-10 19:55:19 +02:00
*Flagge[" "]erobert[" "]von[" "]${ESC_NAME}* | *Flagge[" "]gesichert[" "]von[" "]${ESC_NAME}*)
2017-07-12 11:06:43 +02:00
((FLAG++))
;;
2017-07-08 13:14:59 +02:00
*Spieler:*${ESC_NAME}*)
((RESPAWN++))
;;
esac
2017-07-08 16:14:29 +02:00
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
2017-07-08 13:14:59 +02:00
done < <(grep -- "${ESC_NAME}" ${FILE})
2017-08-05 23:19:23 +02:00
printf "\t{\"name\":\"$NAME\", \"fraction\":\"$FRACTION\", \"kill\":${KILL}, \"friendlyFire\":${FF}, \"revive\":${REVIVE}, \"death\":${DEATH}, \"respawn\":${RESPAWN}, \"flagTouch\":${FLAG}, \"warId\":\"${WAR_ID}\"} "
if [[ -z ${4} ]]; then
printf ",\n"
else
printf "\n"
2017-07-08 13:14:59 +02:00
fi
}
FILE="$1/war.log"
WAR_ID="$2"
2017-07-08 13:14:59 +02:00
PLAYERS=()
while IFS='' read -r line || [[ -n "$line" ]]; do
if [[ -n $line ]]; then
2017-07-08 13:14:59 +02:00
case "$line" in
*"TFAR_RadioRequestEvent"*)
RES=$(echo "$(grep -oP ':[0-9]+\s\(\K.*?(?=\)\sREMOTE)' <<< "$line")")
;;
*"Respawn"*)
RES=$(echo "$(grep -oP '\|\|\sSpieler:\s\K.*?(?=\s-\sKosten:)' <<< "$line")")
;;
*"Abschuss"*)
RES=$(echo "$(grep -oP '\|\|\s\K.*?(?=\s\((EAST|WEST|CIV))' <<< "$line")")
RES1=$(echo "$(grep -oP 'von:\s\K.*?(?=\s\((EAST|WEST|CIV))' <<< "$line")")
;;
esac
2017-07-08 16:14:29 +02:00
if [[ $RES != *"Error: No unit"* && $RES1 != *"Error: No unit"* ]]; then
if [[ -n $RES && " ${PLAYERS[*]} " != *" $RES "* ]]; then
2017-07-08 16:14:29 +02:00
PLAYERS+=("$RES")
fi
if [[ -n $RES1 && " ${PLAYERS[*]} " != *" $RES1 "* ]]; then
2017-07-08 16:14:29 +02:00
PLAYERS+=("$RES1")
fi
2017-07-08 13:14:59 +02:00
fi
fi
done < ${FILE}
echo "["
2017-07-08 13:14:59 +02:00
for ((i=0; i<${#PLAYERS[*]}; i++));
2017-07-08 13:14:59 +02:00
do
if [[ "$((i+1))" -eq "${#PLAYERS[*]}" ]]; then
last="true"
fi
createScoreboard "${PLAYERS[i]}" ${FILE} ${WAR_ID} ${last}
2017-07-08 13:14:59 +02:00
done
echo "]"