54 lines
1.4 KiB
Bash
Executable File
54 lines
1.4 KiB
Bash
Executable File
#!/bin/sh
|
|
if [ -z $1 ] || [ -z $2 ] || [ -z $3 ]; then echo "usage: automat server username password"; exit 1; fi
|
|
pwf=~/.mtpw
|
|
srv=$1
|
|
prt=30000
|
|
usr=$2
|
|
passwd=$3
|
|
logfile=$HOME/.wslog
|
|
chatlogdir=~/.wschat
|
|
mtpid=0
|
|
mtpath=$(dirname $0)
|
|
dbg=1
|
|
quit=1
|
|
if [ ! -z $4 ]; then dbg=0; fi
|
|
mkdir -p $chatlogdir
|
|
if [ -f $pwf ]; then pas=$(cat $pwf); fi
|
|
check_host() {
|
|
if [ -x $(which nc) ]; then return 0; fi
|
|
nc -zu $1 $2 && return 0;
|
|
return 1
|
|
}
|
|
|
|
|
|
startmt() {
|
|
$mtpath/bin/minetest --go --address $srv --port $prt --name $usr --password $passwd 2>&1 | while read l; do
|
|
if [ "$(echo $l |grep '\[cchat\]')" != "" ]; then
|
|
srvstr=$(echo $l|cut -d ' ' -f 5)
|
|
lgstr=$(echo $l|sed 's/ACTION\[Main\]: \[cchat\] //'|sed "s/$srvstr//")
|
|
if [ "$(echo $l |grep '\[sent\]')" != "" ]; then continue; fi
|
|
echo $lgstr >> $chatlogdir/$srvstr.txt
|
|
else
|
|
echo $l >> $logfile;
|
|
if [ "$(echo $l|grep 'AUTOMT Actually Quit')" != "" ]; then
|
|
quit=0;
|
|
kill $mtpid
|
|
fi
|
|
fi
|
|
if [ $dbg -eq 0 ]; then echo $l; fi
|
|
done &
|
|
mtpid=$!
|
|
}
|
|
|
|
while true; do
|
|
if [ $quit -eq 0 ]; then
|
|
kill -9 $mtpid
|
|
exit
|
|
fi
|
|
sleep 1
|
|
if check_host $srv $prt; then
|
|
if ! ps $mtpid >/dev/null 2>&1 && [ $quit -eq 1 ]; then startmt; fi
|
|
fi
|
|
sleep 1
|
|
done
|