You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.4 KiB

#!/bin/bash
#Configuration
conf_file="valheim-server.ini"
# No need to change anything under this line
# source config parser
. ./lib_ini.sh
server_path=$(ini_read "$conf_file" "server" "srvpath")
server_pass=$(ini_read "$conf_file" "server" "srvpass")
bot_nr=$(ini_read "$conf_file" "parser" "botnr")
targ_nr=$(ini_read "$conf_file" "parser" "targnr")
cd "$server_path"
mkdir -p .run
jcfile=".run/join-code.txt"
while true; do
check=$(grep "Session" logs/valheim.log | grep -i "registered" | grep -i "join code" | tail -1 | sed "s/.* join code \(.*\)/\1/")
if [[ ! -f "$jcfile" ]]; then
echo "$check" > "$jcfile"
elif [[ ! "$check" == $(cat $jcfile) ]]; then
echo "$check" > "$jcfile"
datum=$(date +"[%d.%m.%Y %H:%M] ")
message="$datum Valheim join code je: $check, s heslem $server_pass"
signal-cli -u "$bot_nr" send -m "$message" "$targ_nr" &> /dev/null
signal-cli -u "$bot_nr" receive &> /dev/null
fi
errcheck=$(grep -ic "code '4098': the operation was called with an invalid handle" logs/valheim.log)
if [[ $errcheck == 1 ]]; then
datum=$(date +"[%d.%m.%Y %H:%M] ")
message="$datum Valheim dedik chybuje - restart"
srvpid=$(LANG=C ps -ef | grep -v grep | grep -i [v]alheim_server.x86_64 | cut -d" " -f3)
kill $srvpid
signal-cli -u "$bot_nr" send -m "$message" "$targ_nr" &> /dev/null
signal-cli -u "$bot_nr" receive &> /dev/null
fi
sleep 30
done