]> git.lizzy.rs Git - plan9front.git/blobdiff - rc/bin/ircrc
games/doom: fix unterminated comment causing sound bugs (from qu7uux)
[plan9front.git] / rc / bin / ircrc
index 4e18a37c3f1648ca7b4087d54c4f20673f7ffb16..0a23ca02dfbd4efceda764b1d3d14e7a3c54deb8 100755 (executable)
@@ -6,10 +6,10 @@ server=irc.freenode.net
 port=6667
 realname='<nil>'
 target=''
-clonefile=/net/tcp/clone
 netdir=()
 nick=$user
 pass=()
+tls=0
 
 fn sighup {
        exit 'hang up'
@@ -34,9 +34,20 @@ fn work {
        echo NICK $nick > $netdir/data
        if (~ $#pass 1)
                echo PRIVMSG 'nickserv :'identify $"pass > $netdir/data
+       if(! ~ $target ''){
+               title
+               echo JOIN $target > $netdir/data
+       }
+       if(~ $target *,*)
+               target = `{echo $target | awk -F',' '{print $NF}'}
        while (cmd=`{read}) {
-       msg=()
-       out=()
+               s=$status
+               if(~ $s *eof) {
+                       echo  QUIT : Leaving... > $netdir/data
+                       exit
+               }
+               msg=()
+               out=()
                switch ($cmd(1)) {
                case /!
                        eval `{mshift $cmd} | while(rc=`{read})echo 'PRIVMSG '^$target^' :' $rc | tee $netdir/data
@@ -57,6 +68,8 @@ fn work {
                                target=$cmd(2)
                                title
                                msg = (JOIN `{mshift $cmd})
+                               if(~ $target *,*)
+                                       target = `{echo $target | awk -F',' '{print $NF}'}
                        }
                case /l
                        msg = (LIST `{mshift $cmd})
@@ -87,6 +100,8 @@ fn work {
                case /x
                        echo  QUIT : Leaving... > $netdir/data
                        exit
+               case /*
+                       echo unknown command
                case *
                        msg = 'PRIVMSG '^$target^' :'^$"cmd
                        out = '('^$target^')    ⇐     '^$"cmd
@@ -144,19 +159,17 @@ fn privmsg {
                        s = s ":" $i;
                printf("%s\n", s);
        }'
-
 }
 
 fn pretty {
-       while (~ `{cat $netdir/status} Established*) {
-               line=`{read}
+       while (line=`{read}) {
                switch ($line) {
+               case *PRIVMSG*
+                       line = `{echo -n $line | privmsg}
                case *JOIN* *QUIT* *PART* *NICK*
                        line = `{echo -n $line | misc}
                case *NOTICE*
                        line = `{echo -n $line | notice}
-               case *PRIVMSG*
-                       line = `{echo -n $line | privmsg}
                case *PING*
                        echo -n $line | sed 's/PING/PONG/' > $netdir/data
                        line = ()
@@ -169,17 +182,13 @@ fn pretty {
        exit
 }
 
-fn getip {
-       echo $1 ip | ndb/dnsquery | sed 1q | awk '{print $NF}'
-}
-
 fn title {
        if (! ~ $#winid 0) {
                if (test -f /mnt/acme/$winid/ctl)
                        echo name /$server/$target/-ircrc > /mnt/acme/$winid/ctl
        }
        if not
-               label ircrc $server - $target
+               label $target@$server
 }
 
 while (~ $1 -*) {
@@ -196,8 +205,10 @@ while (~ $1 -*) {
        case -t
                target=$2
                shift
+       case -T
+               tls=1
        case -*
-               echo 'usage: ircrc  [-p port] [-r realname] [-t target] [-n nick]  [server]' >[1=2]
+               echo 'usage: ircrc  [-p port] [-r realname] [-t target] [-n nick] [-T] [server]' >[1=2]
                exit 'usage'    
        }
        shift
@@ -214,23 +225,23 @@ if (~ $#* 1) {
        }
 }
 
-ip=`{getip $server}
-if (~ $#ip 0) {
-       echo cant translate $server
-       exit 'unknown host'
-}
-
 title
 userpass=`{auth/userpasswd 'server='^$server^' service=irc user='^$nick >[2]/dev/null}
-if(~ $#userpass 2 && ~ $nick $user) {
+if(~ $#userpass 2) {
        nick=$userpass(1)
        pass=$userpass(2)
 }
 
-<[4] $clonefile {
-       netdir=`{basename -d $clonefile} ^ / ^  `{cat /fd/4}
-       echo connect $ip!$port >$netdir/ctl || exit 'cannot connect'
-       echo connected to tcp!$ip!$port on $netdir
-       cat $netdir/data | tr -d '\r' | pretty & 
-       work
+p='/n/ircrc'
+bind '#|' $p
+echo connecting to tcp!$server!$port...
+if(~ $tls 0){
+       aux/trampoline tcp!$server!$port <>$p/data1 >[1=0] &
+}
+if not {
+       tlsclient tcp!$server!$port <>$p/data1 >[1=0] &
 }
+netdir=$p
+cat $netdir/data | tr -d '\x2\xd\x1f' | pretty &
+work
+