ref: 7a65588484b6e122431b8c894def0abcf2b979f3
parent: 5d361d64d599b0d4d87f990e3e2a1b806d1bbb37
author: sirjofri <[email protected]>
date: Sat Dec 4 09:24:12 EST 2021
new version, thanks grobe0ba!
--- a/gridirc.rc
+++ b/gridirc.rc
@@ -1,19 +1,25 @@
#!/bin/rc
rfork en
+
+echo Beginning gridirc session $pid >[1=2]
+
srv net!chat.9p.zone!9990 gridirc.$pid /n/chat || {
- echo Fail!
+ echo Unable to srv chat >[1=2]
exit
}
echo -n >/env/gridircpids
fn managedexit{ # exit routine
+ unmount /n/chat
+ rm /srv/gridirc.$pid
+ echo Attempting to exit >[1=2]
pids=`{cat /env/gridircpids}
- for (i in $pids){
- echo killing reader $i
- echo kill >/proc/$i/ctl
+ for (i in $pids) {
+ echo Killing process $i >[1=2]
+ chmod 777 /proc/$i/ctl
+ echo kill >>/proc/$i/ctl
}
- rm /srv/gridirc.$pid
exit
}
@@ -27,10 +33,22 @@
fn startread{
currentdate=`{date -u}
-echo JOIN $2 $currentdate >>/n/chat/$1
-awk -v 'chan='^$1 -v 'nick='^$2 '
-BEGIN { doprint=0 }
-$0 ~ ENVIRON["currentdate"] { doprint=1 }
+host=$1
+chan=$2
+nick=$3
+
+echo JOIN $nick $currentdate >>/n/chat/$chan
+awk '
+BEGIN {
+ host=ENVIRON["host"]
+ chan=ENVIRON["chan"]
+ nick=ENVIRON["nick"]
+ doprint=0
+}
+$0 ~ ENVIRON["currentdate"] {
+ doprint=1
+ next
+}
!doprint { next }
doprint && NF >= 2 && $1 ~ nick && $2 ~ /^→$/ {
@@ -37,10 +55,9 @@
next
}
-doprint && NF > 1 && $1 ~ /^JOIN$/ {
- printf ":%s JOIN #%s\r\n", $2, chan
+function sendMsg(origin, recip, msg) {
+ printf ":%s PRIVMSG %s :%s\r\n", origin, recip, msg
fflush
- next
}
doprint && NF >= 2 {
@@ -49,63 +66,78 @@
$1=""
$2=""
sub(/^ +/, "")
- printf ":%s PRIVMSG #%s :%s\r\n", sender, chan, $0
- } else {
- printf ":%s PRIVMSG #%s :%s\r\n", chan, chan, $0
+ sendMsg(sender, sprintf("#%s", chan), $0)
}
- fflush
next
+
+# msg=""
+# split($0, msg_a)
+# for(i = 3; i <= length(msg_a); i++) {
+# msg = sprintf("%s %s", msg, msg_a[i])
+# }
+# sendMsg($1, sprintf("#%s", chan), msg)
+# next
}
doprint {
- printf ":%s PRIVMSG #%s :%s\r\n", chan, chan, $0
- fflush
+ sendMsg(host, chan, $0)
+ next
}
-' /n/chat/$1 &
+' /n/chat/$chan &
echo $apid >>/env/gridircpids
}
# mainloop
-awk '
+tr -d | awk -mr 512 '
BEGIN {
- nick="user"
- user="user"
+ RS="\n"
+ ORS="\r\n"
+ nick="nonick"
+ user="nouser"
host="9p.zone"
}
+function handleJoin(chan) {
+ printf ":%s JOIN #%s\r\n", nick, chan
+ printf ":%s 332 #%s :Channel %s\r\n", host, chan, chan
+ printf ":%s 353 = #%s :%s\r\n", host, chan, nick
+ printf ":%s 366 #%s :End of NAMES list\r\n", host, chan
+ joined[chan]=1
+ cmd=sprintf("startread %s %s %s &", host, chan, nick)
+ system(cmd)
+ fflush
+}
+
$1 ~ /^:/ {
$1=""
sub(/^ */, "")
+ fflush
}
-NF >= 2 && $1 ~ /^NICK$/ {
+$1 ~ /^NICK$/ {
nick=$2
}
-NF >= 2 && $1 ~ /^USER$/ {
+$1 ~ /^USER$/ {
user=$2
printf ":%s 001 %s :Welcome %s!%s@%s\r\n", host, nick, nick, user, host
printf ":%s 002 %s :Your host is %s\r\n", host, nick, host
printf ":%s 003 %s :This server was created some time ago\r\n", host, nick
- printf ":%s 004 %s :gridirc\r\n", host, nick
+ printf ":%s 004 %s gridirc 0.1-alpha i ov\r\n", host, nick
+ printf ":%s 375 %s :- %s Message of the day -\r\n", host, nick, host
+ printf ":%s 372 %s :- Welcome to the grid! -\r\n", host, nick
+ printf ":%s 372 %s :- Thanks to all contributors to 9p.zone! -\r\n", host, nick
+ printf ":%s 376 %s :End of /MOTD command\r\n", host, nick
+ handleJoin("chat")
fflush
}
-NF >= 2 && $1 ~ /^JOIN$/ {
+$1 ~ /^JOIN$/ {
sub(/^:?#/, "", $2)
- printf ":%s JOIN #%s\r\n", nick, $2
- printf ":%s 332 #%s :Channel %s\r\n", host, $2, $2
- if (joined[$2] == 1)
- next
- printf ":%s 353 #%s :%s %s\r\n", host, $2, $2, nick
- printf ":%s 366 #%s :End of NAMES list\r\n", host, $2
- joined[$2]=1
- cmd=sprintf("startread %s %s &", $2, nick)
- system(cmd)
- fflush
+ handleJoin($2)
}
-NF >= 2 && $1 ~ /^PRIVMSG$/ {
+$1 ~ /^PRIVMSG$/ {
sub(/^#/, "", $2)
chan=$2
sub(/^[^:]*:/, "")
@@ -114,7 +146,7 @@
fflush
}
-NF >= 2 && $1 ~ /^PART$/ {
+$1 ~ /^PART$/ {
sub(/^#/, "", $2)
chan=$2
$1=""
@@ -127,7 +159,7 @@
$1 ~ /^PING$/ {
sub(/^PING/, "PONG")
- printf "%s\r\n", $0
+ printf ":%s PONG %s :%s\r\n", host, host, host
fflush
}
@@ -135,10 +167,10 @@
exit
}
-$1 ~ /^VERSION/ || $1 ~ /^INFO/ {
- printf ":%s 351 %s :gridirc - bridge to IRC\r\n", host, nick
- fflush
-}
+#$1 ~ /^VERSION/ || $1 ~ /^INFO/ {
+# printf ":%s 351 %s :gridirc - bridge to IRC\r\n", host, nick
+# fflush
+#}
'
managedexit