add current players script
This commit is contained in:
parent
7d98ee1080
commit
9402575a3a
1 changed files with 48 additions and 0 deletions
48
current_players.sh
Normal file
48
current_players.sh
Normal file
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
logfile=/opt/luanti/log/debug.log
|
||||
player_re="([a-zA-Z0-9\s]+ (digs|places|leaves)|[a-zA-Z0-9]+ \[[0-9\.]+\] joins) "
|
||||
left=""
|
||||
old_data="old"
|
||||
plays_re="(digs|places|joins)"
|
||||
leaves_re="leaves"
|
||||
|
||||
declare -A players
|
||||
|
||||
while true
|
||||
do
|
||||
data=$(tail -n500 "$logfile" | grep -o -E "$player_re")
|
||||
if [ "$data" != "$old_data" ]; then
|
||||
data=$(echo $data | sed -e 's/\[[0-9\.]*\]//g')
|
||||
flip=0
|
||||
for i in $data; do
|
||||
if [ $flip = 0 ]; then
|
||||
player="$i"
|
||||
flip=1
|
||||
else
|
||||
status="$i"
|
||||
play=$(echo "$status" | grep -o -E "$plays_re")
|
||||
left=$(echo "$status" | grep -o -E "$leaves_re")
|
||||
if [ ! "$play" = "" ]; then
|
||||
players[$player]=P
|
||||
elif [ ! "$left" = "" ]; then
|
||||
players[$player]=L
|
||||
fi
|
||||
flip=0
|
||||
fi
|
||||
|
||||
done
|
||||
#old_data=$data
|
||||
fi
|
||||
output="{\"players\":["
|
||||
c=""
|
||||
for key in "${!players[@]}"; do
|
||||
output="$output$c{\"player\":\"$key\",\"status\":\"${players[$key]}\"}"
|
||||
if [ "$c" = "" ]; then
|
||||
c=","
|
||||
fi
|
||||
done
|
||||
output="$output],\"updated\":\"$(date)\"}"
|
||||
echo $output | jq > players.json
|
||||
sleep 15
|
||||
done
|
Loading…
Reference in a new issue