chat update

This commit is contained in:
Fulton Browne 2021-05-27 16:52:32 +00:00
parent fdc243a657
commit 4bb0f1767b
1 changed files with 58 additions and 55 deletions

113
grid/chat
View File

@ -1,5 +1,7 @@
#!/bin/rc #!/bin/rc
# minimal chat client for hubfs: chat [-n NICK] [-j CHANNEL] [chatsrv] # minimal chat client for hubfs: chat [-n NICK] [-j CHANNEL] [chatsrv]
# dd -bs `{du -n /n/chat/chat | sed 's/ .*//'} -skip 1 -if /n/chat/chat
rfork enf
fn helpmessage{ fn helpmessage{
echo ------------------------- echo -------------------------
@ -8,19 +10,34 @@ fn helpmessage{
echo ------------------------- echo -------------------------
} }
rfork enf fn close{
echo PART $name from $channel >>/n/$chatsrv/$channel
@{echo kill>/proc/$catkill/ctl}
}
fn shutdown{
close
exit
}
fn sighup{
shutdown
}
fn sigint{
shutdown
}
channel=chat channel=chat
chatsrv=chat chatsrv=chat
while (~ $1 -*){ while (~ $1 -*){
switch($1){ switch($1){
case -n case -n
name = $2 name = $2
shift shift 2
shift
case -j case -j
channel = $2 channel = $2
shift shift 2
shift
case * case *
echo bad flag $1 '-n NICK -j CHANNEL' echo bad flag $1 '-n NICK -j CHANNEL'
shift shift
@ -47,58 +64,44 @@ cat /n/$chatsrv/$channel &
catkill=$apid catkill=$apid
while(talk=`{read}){ while(talk=`{read}){
if(~ $talk /*){ switch($talk(1)){
switch($talk){ case /q
case /q* shutdown
echo PART $name from $channel >>/n/$chatsrv/$channel case /n
@{echo kill>/proc/$catkill/ctl} if(! ~ $talk(2) ''){
exit echo nick $name ' -> ' $talk(2) >>/n/$chatsrv/$channel
case /n* name=$talk(2)
if(! ~ $talk(2) ''){
echo nick $name ' -> ' $talk(2) >>/n/$chatsrv/$channel
name=$talk(2)
}
if not
echo 'you need to provide a nick for /n NICK'
command=yes
case /j*
if (~ $talk(2) '')
echo must specify a channel to join
if not if(test -e /n/chat/$talk(2)){
echo PART $name from $channel >>/n/$chatsrv/$channel
@{echo kill>/proc/$catkill/ctl}
channel=$talk(2)
cat /n/chat/$channel &
catkill=$apid
echo JOIN $name to $channel >>/n/$chatsrv/$channel
}
if not
echo channel does not exist
command=yes
case /h*
helpmessage
echo currently in $channel
echo
command=yes
case /c
echo Available channels:
lc /n/$chatsrv
echo -------------------
echo currently in $channel
echo
command=yes
case *
echo unknown command
command=yes
} }
} if not
if(~ $talk '') echo 'you need to provide a nick for /n NICK'
command=yes case /j
if(! ~ $command yes){ if (~ $talk(2) '')
echo must specify a channel to join
if not if(test -e /n/chat/$talk(2)){
close
channel=$talk(2)
cat /n/chat/$channel &
catkill=$apid
echo JOIN $name to $channel >>/n/$chatsrv/$channel
}
if not
echo channel does not exist
case /h
helpmessage
echo currently in $channel
echo
case /c
echo Available channels:
lc /n/$chatsrv
echo -------------------
echo currently in $channel
echo
case *
# ts=`{date -u} # ts=`{date -u}
# ts=`{echo '('^$ts(4)^')'} # ts=`{echo '('^$ts(4)^')'}
line=`{echo $name ': ' $talk} if(! ~ $talk ''){
echo $line >>/n/chat/$channel line=`{echo $name '⇒ ' $talk}
echo $line >>/n/chat/$channel
}
} }
command=no
} }