Created
February 25, 2018 14:10
-
-
Save packer-/077be0c50709b7395b4a622c45fd43d1 to your computer and use it in GitHub Desktop.
parse demos and xonotic logs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cutlog=./cutlog | |
demo_csv=./demolist.csv | |
# delete useless demo files | |
for demo in $(find sv_autodemos/ -type f -name '*.dem'); do | |
grep '\^1Server is restarting\.\.\.' "$demo" &>/dev/null || rm -vf "$demo" # does not contain a full game | |
grep ' \^7wins\.' "$demo" &>/dev/null || rm -vf "$demo" # does not contain a winner | |
done | |
# example demo name: | |
# 2018-02-10_19-55-42_hub3aeroq3a_nex_r4_3_77-251-214-158-50903.dem | |
# 2018-02-10_20-46-35_hub3aeroq3a_nex_r4_4_-2a04-4540-6b02-9001-96de-80ff-feb1-da5c--42772.dem | |
echo "% 1) demo, 2) pov, 3) winner, 4) loser" > "$demo_csv" | |
for demo in $(find sv_autodemos/ -type f -name '*.dem'); do | |
d_name="${demo##*/}" | |
d_name="${d_name%\.dem}" | |
d_date="${d_name%%_*}" | |
d_time="${d_name#${d_date}_}" | |
d_time="${d_time%%_*}" | |
d_ipport="${d_name##*_}" | |
d_status="${d_name%_${d_ipport}}" | |
d_status="${d_status##*_}" | |
d_mapname="${d_name#${d_date}_${d_time}_}" | |
d_mapname="${d_mapname%_${d_status}_${d_ipport}}" | |
d_ip="${d_ipport%-*}" | |
d_port="${d_ipport#${d_ip}-}" | |
d_ip="${d_ip%-}" | |
d_ip="${d_ip#-}" # ip4 or ipv6 seperated by dashes | |
# adjust time format | |
d_time="${d_time//-/:}" | |
# parse player nicks from demo data | |
winner="$(grep -ao '[[:print:]]* ^7wins\.' "$demo"| sed 's/ \^7wins\.//')" | |
loser="$(grep -ao '[[:print:]]* ^7is now with the gods in Valhalla.' "$demo" | sed 's/ \^7is now with the gods in Valhalla\.//')" | |
# cleanup colorcodes | |
winnerc="$(echo $winner | sed -r 's/\^[0-9]//g;s/\^x[a-fA-F0-9]{3}//g')" | |
loserc="$(echo $loser | sed -r 's/\^[0-9]//g;s/\^x[a-fA-F0-9]{3}//g')" | |
# remove all chars except | |
winnerc2="$(echo $winnerc | sed -r 's/[^A-Za-z0-9]//g')" | |
loserc2="$(echo $loserc | sed -r 's/[^A-Za-z0-9]//g')" | |
# from server log obtain the required lines to sort demos | |
for log in $(find logs/ -type f -name '*.log'); do | |
sed -n "/\[$d_date ${d_time}\]/,/ wins\./p" "$log" | tac | sed -n '1 ,/] host:/p' | tac > "$cutlog" | |
if [[ ! -s "$cutlog" ]]; then | |
continue | |
fi | |
player4=false | |
player6=false | |
# get rid of spectators | |
# get rid of fresh connecting clients | |
# try to find the player | |
grep -Ev "${d_ip//-/.}:${d_port}.*-666 #${d_status} " "$cutlog" | \ | |
grep -Ev "${d_ip//-/.}:${d_port}.*0 #${d_status}.*unconnected" | \ | |
grep -E "${d_ip//-/.}:${d_port}.*-?[0-9]{1,2} #${d_status} " &>/dev/null && player4=true | |
if [[ $player4 == false ]]; then # try ipv6 | |
grep -Ev "\[${d_ip//-/:}\]:${d_port}.*-666 #${d_status} " "$cutlog" | \ | |
grep -Ev "\[${d_ip//-/:}\]:${d_port}.*0 #${d_status}.*unconnected" | \ | |
grep -E "\[${d_ip//-/:}\]:${d_port}.*-?[0-9]{1,2} #$d_status " &>/dev/null && player6=true | |
fi | |
if [[ $player4 == false ]] && [[ $player6 == false ]]; then | |
continue | |
else | |
compnick="$(grep -E ":${d_port}.*-?[0-9]{1,2} #$d_status " "$cutlog" | sed 's/\s\+/ /g' | cut -d\ -f9- | sed -r 's/[^A-Za-z0-9]//g')" | |
if [[ "$compnick" == "$winnerc2" ]]; then | |
pov="$winnerc" | |
elif [[ "$compnick" == "$loserc2" ]]; then | |
pov="$loserc" | |
else | |
pov="unknown" | |
fi | |
echo "$demo, $pov, $winnerc, $loserc" >> "$demo_csv" | |
echo "$demo" | |
fi | |
done | |
done | |
sort -n "$demo_csv" -o "$demo_csv" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment