kamikaze: widen search area, add sponges as badnode
[waspsaliva.git] / waspsaliva
blob32d029f3c2fd7521feb4efa65e3075e57a49889d
1 #!/bin/sh
2 tomenu=1
3 if [ $# -lt 1 ]; then tomenu=0; fi
4 pwf=~/.mtpw
5 srv=$1
6 prt=30000
7 usr=$2
8 passwd=$3
9 logfile=$HOME/.wslog
10 chatlogdir=~/.wschat
11 mtpid=0
12 mtpath=$(dirname $0)
13 dbg=1
14 if [ "$(echo $*|grep debug)" != "" ] || [ ! -z $4 ]; then dbg=0; fi
15 mkdir -p $chatlogdir
16 if [ -f $pwf ]; then pas=$(cat $pwf); fi
17 if [ "$(echo $srv|grep ':')" != "" ]; then
18 prt=$(echo $srv|cut -d ':' -f2)
19 srv=$(echo $srv|cut -d ':' -f1)
21 check_host() {
22 if [ -x $(which nc) ]; then return 0; fi
23 nc -zu $1 $2 && return 0;
24 return 1
27 mt=$mtpath/bin/minetest
29 startmt() {
30 if [ "$1" = "menu" ]; then mmt=$mt
31 else mmt="$mt --go --address $srv --port $prt --name $usr --password $passwd"; fi
32 $mmt 2>&1| while read k; do
33 l=$(echo $k|sed "s,\x1B\[[0-9;]*[a-zA-Z],_,g")
34 if [ "$(echo $l |grep '\[cchat\]\|\[hignore\]')" != "" ]; then
35 srvstr=$(echo $l|cut -d ' ' -f 5)
36 lgstr=$(echo $l|sed 's/ACTION\[Main\]://'|sed "s/ \[cchat\] //;s/$srvstr//")
37 if [ "$(echo $l |grep '\[sent\]')" != "" ]; then continue; fi
38 echo $lgstr >> $chatlogdir/$srvstr.txt
39 else
40 echo $l >> $logfile 2>&1;
41 if [ "$(echo $l|grep 'AUTOMT exit to menu')" != "" ]; then
42 # kill -9 $mtpid
43 touch /tmp/$(whoami)-wsxmen
44 break;
46 if [ "$(echo $l|grep 'AUTOMT Actually Quit')" != "" ]; then
47 # kill -9 $mtpid
48 touch /tmp/$(whoami)-wsxt
49 break;
51 fi
52 if [ $dbg -eq 0 ]; then echo $l; fi
53 done
55 if [ $tomenu -eq 0 ]; then
56 startmt menu
57 else
58 while true; do
59 if [ -f /tmp/$(whoami)-wsxt ]; then
60 rm -f /tmp/$(whoami)-wsxt
61 break
63 if [ -f /tmp/$(whoami)-wsxmen ]; then
64 rm -f /tmp/$(whoami)-wsxmen
65 startmt menu
66 break
68 sleep 1
69 if check_host $srv $prt; then
70 if ! ps $mtpid >/dev/null 2>&1 && [ ! -f /tmp/$(whoami)-wsxmen ] && [ ! -f /tmp/$(whoami)-wsxt ]; then startmt& fi
71 mtpid=$!
73 sleep 1
74 done
76 rm -f /tmp/$(whoami)-wsxt
77 rm -f /tmp/$(whoami)-wsmen