diff --git a/automt b/automt index 24597593a..fdc0acc96 100755 --- a/automt +++ b/automt @@ -1,5 +1,6 @@ #!/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 srv=$1 prt=30000 @@ -10,7 +11,7 @@ chatlogdir=~/.wschat mtpid=0 mtpath=$(dirname $0) dbg=1 -if [ ! -z $4 ]; then dbg=0; fi +if [ "$(echo $*|grep debug)" != "" ] || [ ! -z $4 ]; then dbg=0; fi mkdir -p $chatlogdir if [ -f $pwf ]; then pas=$(cat $pwf); fi if [ "$(echo $srv|grep ':')" != "" ]; then @@ -24,11 +25,12 @@ check_host() { } 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() { - $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 srvstr=$(echo $l|cut -d ' ' -f 5) 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 done } - +if [ $tomenu -eq 0 ]; then + startmt menu + else while true; do - if [ -f /tmp/$(whoami)-wsxt ]; then - rm /tmp/$(whoami)-wsxt - break - fi - if [ -f /tmp/$(whoami)-wsxmen ]; then - rm /tmp/$(whoami)-wsxmen - startmt menu - break - fi - sleep 1 - if check_host $srv $prt; then - if ! ps $mtpid >/dev/null 2>&1 && [ ! -f /tmp/$(whoami)-wsxmen ] && [ ! -f /tmp/$(whoami)-wsxt ]; then startmt& fi - mtpid=$! - fi - sleep 1 -done + if [ -f /tmp/$(whoami)-wsxt ]; then + rm -f /tmp/$(whoami)-wsxt + break + fi + if [ -f /tmp/$(whoami)-wsxmen ]; then + rm -f /tmp/$(whoami)-wsxmen + startmt menu + break + fi + sleep 1 + if check_host $srv $prt; then + if ! ps $mtpid >/dev/null 2>&1 && [ ! -f /tmp/$(whoami)-wsxmen ] && [ ! -f /tmp/$(whoami)-wsxt ]; then startmt& fi + mtpid=$! + fi + sleep 1 + done +fi