automt: some fixes

This commit is contained in:
cora 2020-11-26 13:43:55 +01:00 committed by Schmappie Eldress
parent b4da45df12
commit 75e85290cb

49
automt
View File

@ -1,5 +1,6 @@
#!/bin/sh #!/bin/sh
if [ $# -lt 1 ]; then echo "usage: automt [ menu ] || [server username password]"; exit 1; fi tomenu=1
if [ $# -lt 1 ]; then tomenu=0; fi
pwf=~/.mtpw pwf=~/.mtpw
srv=$1 srv=$1
prt=30000 prt=30000
@ -10,7 +11,7 @@ chatlogdir=~/.wschat
mtpid=0 mtpid=0
mtpath=$(dirname $0) mtpath=$(dirname $0)
dbg=1 dbg=1
if [ ! -z $4 ]; then dbg=0; fi if [ "$(echo $*|grep debug)" != "" ] || [ ! -z $4 ]; then dbg=0; fi
mkdir -p $chatlogdir mkdir -p $chatlogdir
if [ -f $pwf ]; then pas=$(cat $pwf); fi if [ -f $pwf ]; then pas=$(cat $pwf); fi
if [ "$(echo $srv|grep ':')" != "" ]; then if [ "$(echo $srv|grep ':')" != "" ]; then
@ -24,11 +25,12 @@ check_host() {
} }
mt=$mtpath/bin/minetest mt=$mtpath/bin/minetest
amt="$mt --go --address $srv --port $prt --name $usr --password $passwd"
if [ "$1" = "menu" ]; then mmt=$mt; else mmt=$amt; fi
startmt() { startmt() {
$mmt 2>&1|sed 's/[\x01-\x1F\x7F]//g' | while read l; do if [ "$1" = "menu" ]; then mmt=$mt
else mmt="$mt --go --address $srv --port $prt --name $usr --password $passwd"; fi
$mmt 2>&1| while read k; do
l=$(echo $k|sed "s,\x1B\[[0-9;]*[a-zA-Z],_,g")
if [ "$(echo $l |grep '\[cchat\]\|\[hignore\]')" != "" ]; then if [ "$(echo $l |grep '\[cchat\]\|\[hignore\]')" != "" ]; then
srvstr=$(echo $l|cut -d ' ' -f 5) srvstr=$(echo $l|cut -d ' ' -f 5)
lgstr=$(echo $l|sed 's/ACTION\[Main\]://'|sed "s/ \[cchat\] //;s/$srvstr//") lgstr=$(echo $l|sed 's/ACTION\[Main\]://'|sed "s/ \[cchat\] //;s/$srvstr//")
@ -50,21 +52,24 @@ startmt() {
if [ $dbg -eq 0 ]; then echo $l; fi if [ $dbg -eq 0 ]; then echo $l; fi
done done
} }
if [ $tomenu -eq 0 ]; then
startmt menu
else
while true; do while true; do
if [ -f /tmp/$(whoami)-wsxt ]; then if [ -f /tmp/$(whoami)-wsxt ]; then
rm /tmp/$(whoami)-wsxt rm -f /tmp/$(whoami)-wsxt
break break
fi fi
if [ -f /tmp/$(whoami)-wsxmen ]; then if [ -f /tmp/$(whoami)-wsxmen ]; then
rm /tmp/$(whoami)-wsxmen rm -f /tmp/$(whoami)-wsxmen
startmt menu startmt menu
break break
fi fi
sleep 1 sleep 1
if check_host $srv $prt; then if check_host $srv $prt; then
if ! ps $mtpid >/dev/null 2>&1 && [ ! -f /tmp/$(whoami)-wsxmen ] && [ ! -f /tmp/$(whoami)-wsxt ]; then startmt& fi if ! ps $mtpid >/dev/null 2>&1 && [ ! -f /tmp/$(whoami)-wsxmen ] && [ ! -f /tmp/$(whoami)-wsxt ]; then startmt& fi
mtpid=$! mtpid=$!
fi fi
sleep 1 sleep 1
done done
fi