wasplib: latest
[waspsaliva.git] / waspsaliva
blobc8466ca342a6cd79de2b10ef544e73d783a152e3
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 rm -f /tmp/$(whoami)-wsxt
15 rm -f /tmp/$(whoami)-wsmen
16 if [ "$(echo $*|grep debug)" != "" ] || [ ! -z $4 ]; then dbg=0; fi
17 mkdir -p $chatlogdir
18 if [ -f $pwf ]; then pas=$(cat $pwf); fi
19 if [ "$(echo $srv|grep ':')" != "" ]; then
20 prt=$(echo $srv|cut -d ':' -f2)
21 srv=$(echo $srv|cut -d ':' -f1)
23 check_host() {
24 if [ -x $(which nc) ]; then return 0; fi
25 nc -zu $1 $2 && return 0;
26 return 1
29 mt=$mtpath/bin/minetest
31 startmt() {
32 if [ "$1" = "menu" ]; then mmt=$mt
33 else mmt="$mt --go --address $srv --port $prt --name $usr --password $passwd"; fi
34 $mmt 2>&1| while read k; do
35 l=$(echo $k|sed "s,\x1B\[[0-9;]*[a-zA-Z],_,g")
36 if [ "$(echo $l |grep '\[cchat\]\|\[hignore\]')" != "" ]; then
37 srvstr=$(echo $l|cut -d ' ' -f 5)
38 lgstr=$(echo $l|sed 's/ACTION\[Main\]://'|sed "s/ \[cchat\] //;s/$srvstr//")
39 if [ "$(echo $l |grep '\[sent\]')" != "" ]; then continue; fi
40 echo $lgstr >> $chatlogdir/$srvstr.txt
41 else
42 echo $l >> $logfile 2>&1;
43 if [ "$(echo $l|grep 'AUTOMT exit to menu')" != "" ]; then
44 # kill -9 $mtpid
45 touch /tmp/$(whoami)-wsxmen
46 break;
48 if [ "$(echo $l|grep 'AUTOMT Actually Quit')" != "" ]; then
49 # kill -9 $mtpid
50 touch /tmp/$(whoami)-wsxt
51 break;
53 fi
54 if [ $dbg -eq 0 ]; then echo $l; fi
55 done
57 if [ $tomenu -eq 0 ]; then
58 startmt menu
59 else
60 while true; do
61 if [ -f /tmp/$(whoami)-wsxt ]; then
62 rm -f /tmp/$(whoami)-wsxt
63 break
65 if [ -f /tmp/$(whoami)-wsxmen ]; then
66 rm -f /tmp/$(whoami)-wsxmen
67 startmt menu
68 break
70 sleep 1
71 if check_host $srv $prt; then
72 if ! ps $mtpid >/dev/null 2>&1 && [ ! -f /tmp/$(whoami)-wsxmen ] && [ ! -f /tmp/$(whoami)-wsxt ]; then startmt& fi
73 mtpid=$!
75 sleep 1
76 done
78 rm -f /tmp/$(whoami)-wsxt
79 rm -f /tmp/$(whoami)-wsmen