ref: f3afdf563f784c0a5703496f48c1a72dff4617f4
dir: /grid/chat/
#!/bin/rc
# grid/chat - minimal chat client for hubfs
# usage: grid/chat [-j CHANNEL] [-n NICK] [chatsrv]
rfork efn
fn helpmessage{
echo ' /c to list channels'
echo ' /h for this message'
echo ' /j CHANNEL to change channel'
echo ' /m MSG to emote'
echo ' /n NICK to change nick'
echo ' /q to quit'
}
fn close{
#echo $nick vanishes from $channel into the void. >>/n/$chatsrv/$channel
@{echo kill>/proc/$catkill/ctl}
}
fn shutdown{
close
exit
}
fn sighup{
shutdown
}
fn sigint{
shutdown
}
channel=chat
chatsrv=149.28.123.225
while (~ $1 -*){
switch($1){
case -j
channel = $2
shift 2
case -n
nick = $2
shift 2
case *
echo bad flag $1 -j CHANNEL -n NICK
shift
}
}
if(! ~ $1 '')
chatsrv=$1
if(! test -e /n/$chatsrv/chat)
mount /srv/$chatsrv /n/$chatsrv
if(! test -e /n/$chatsrv/chat){
echo no chat service named $chatsrv found >[1=2]
exit no.chatsrv
if(! test -e /n/$chatsrv/$channel)
echo no channel named $channel found >[1=2]
exit no.channel
}
label $channel
if(~ $#nick 0)
nick=thedæmon
#echo JOIN $nick to chat >>/n/$chatsrv/$channel
cat /n/$chatsrv/$channel &
catkill=$apid
while(talk=`{read}){
if(~ $talk /*){
switch($talk){
case /c
echo available channels:
lc /n/$chatsrv
echo -------------------
echo currently in $channel
echo
command=yes
case /h*
helpmessage
echo currently in $channel
echo
command=yes
case /j*
if (~ $talk(2) '')
echo must specify a channel
if not if(test -e /n/$chatsrv/$talk(2)){
close
channel=$talk(2)
cat /n/$chatsrv/$channel &
catkill=$apid
#echo JOIN $nick to $channel >>/n/$chatsrv/$channel
}
if not
echo channel does not exist
command=yes
case /m*
if(! ~ $talk(2) ''){
echo ' *' $nick $talk(2-) >>/n/$chatsrv/$channel
}
if not
echo must provide a message
command=yes
case /n*
if(! ~ $talk(2) ''){
echo ' *' $nick is now $talk(2) >>/n/$chatsrv/$channel
nick=$talk(2)
}
if not
echo must supply a nick
command=yes
case /q*
shutdown
case *
echo unknown command
command=yes
}
}
if(~ $talk '')
command=yes
if(! ~ $command yes){
line=`{echo $nick ' → ' $talk}
echo $line >>/n/$chatsrv/$channel
}
command=no
}