2017-07-08 13:14:59 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
createScoreboard() {
|
|
|
|
NAME="$1"
|
|
|
|
FILE="$2"
|
|
|
|
|
|
|
|
KILL=0
|
|
|
|
FF=0
|
|
|
|
DEATH=0
|
|
|
|
RESPAWN=0
|
|
|
|
|
|
|
|
#escape '[' -> somehow escapes all special chars, lol?
|
|
|
|
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++))
|
|
|
|
;;
|
|
|
|
*${ESC_NAME}[" "]*von:*)
|
|
|
|
((DEATH++))
|
|
|
|
;;
|
|
|
|
*Spieler:*${ESC_NAME}*)
|
|
|
|
((RESPAWN++))
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done < <(grep -- "${ESC_NAME}" ${FILE})
|
|
|
|
|
2017-07-08 15:34:36 +02:00
|
|
|
printf "\t{\"name\":\"$NAME\", \"kill\":${KILL}, \"ff\":${FF}, \"death\":${DEATH}, \"respawn\":${RESPAWN}}"
|
|
|
|
if [[ -z ${3} ]]; then
|
|
|
|
printf ",\n"
|
|
|
|
else
|
|
|
|
printf "\n"
|
2017-07-08 13:14:59 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-08 15:34:36 +02:00
|
|
|
FILE="$1/war.log"
|
2017-07-08 13:14:59 +02:00
|
|
|
PLAYERS=()
|
|
|
|
|
|
|
|
while IFS='' read -r line || [[ -n "$line" ]]; do
|
|
|
|
if [[ $line =~ [^[:space:]] ]]; then
|
|
|
|
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
|
|
|
|
|
|
|
|
if [[ $RES =~ [^[:space:]] && " ${PLAYERS[*]} " != *" $RES "* ]]; then
|
|
|
|
PLAYERS+=("$RES")
|
|
|
|
fi
|
|
|
|
if [[ $RES1 =~ [^[:space:]] && " ${PLAYERS[*]} " != *" $RES1 "* ]]; then
|
|
|
|
PLAYERS+=("$RES1")
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done < ${FILE}
|
|
|
|
|
2017-07-08 15:34:36 +02:00
|
|
|
echo "["
|
2017-07-08 13:14:59 +02:00
|
|
|
|
2017-07-08 15:34:36 +02:00
|
|
|
for ((i=0; i<${#PLAYERS[*]}; i++));
|
2017-07-08 13:14:59 +02:00
|
|
|
do
|
2017-07-08 15:34:36 +02:00
|
|
|
if [[ "$((i+1))" -eq "${#PLAYERS[*]}" ]]; then
|
|
|
|
last="true"
|
|
|
|
fi
|
|
|
|
createScoreboard "${PLAYERS[i]}" ${FILE} ${last}
|
2017-07-08 13:14:59 +02:00
|
|
|
done
|
2017-07-08 15:34:36 +02:00
|
|
|
echo "]"
|