shithub: gridirc

Download patch

ref: 792407e805ebd3cbbe140886b5e72a9193a22e1f
author: sirjofri <sirjofri@sirjofri.de>
date: Sun Nov 21 15:07:50 EST 2021

adds files. absolute paths only currently

--- /dev/null
+++ b/gridirc.rc
@@ -1,0 +1,70 @@
+#!/bin/rc
+
+rfork en
+test -r /srv/gridircmq || {
+	/usr/sirjofri/src/gridirc/gridircprep
+}
+mount /srv/gridircmq /n/chat
+
+nick=user
+user=user
+prefix=9p.zone
+joined=false
+pids=()
+
+fn sigint{
+	for (i in $pids)
+		echo kill>/proc/$i/ctl
+	exit
+}
+
+fn sighup{
+	for (i in $pids)
+		echo kill>/proc/$i/ctl
+	exit
+}
+
+fn loopread{
+while(c=`{read})
+	echo :$1 PRIVMSG '#'$1 :$"c
+}
+
+fn startread{
+	{ cat /n/chat/$1 | loopread $1 } &
+	pids=($pids $apid)
+}
+
+fn loop{
+cmd=`{read}
+switch($cmd(1)){
+case NICK
+	nick=$cmd(2)
+	#echo nick $cmd(2)
+case USER
+	user=$cmd(2)
+	echo 001 $nick :Welcome $nick!$user@$prefix
+case JOIN
+	ch=`{echo $cmd(2) | sed 's/^:?#//g'}
+	echo :$nick JOIN '#'^$ch
+	echo 332 '#'^$ch :Channel $ch
+	echo 353 '#'^$ch :$ch $nick
+	echo 366 '#'^$ch :End of NAMES list
+	startread $ch
+case PRIVMSG
+	ch=`{echo $cmd(2) | sed 's/^#//g'}
+	msg=`{echo $cmd | sed 's/^[^:]*://'}
+	echo $nick → $msg >>/n/chat/$ch^WRITE
+	#echo msg: $msg
+case PING
+	echo $cmd | sed 's/PING/PONG/'
+case QUIT
+	for (i in $pids)
+		echo kill>/proc/$i/ctl
+	exit
+case *
+	#echo ignored
+}
+loop
+}
+
+loop
--- /dev/null
+++ b/gridircprep
@@ -1,0 +1,8 @@
+#!/bin/rc
+
+9fs net!chat.9p.zone!9990 /n/chat
+mq -s gridircmq -m /mnt/gridirc
+touch /mnt/gridirc/chat
+touch /mnt/gridirc/chatWRITE
+cat /n/chat/chat > /mnt/gridirc/chat &
+cat /mnt/gridirc/chatWRITE > /n/chat/chat &