commit 45e8974d485327efbfd74fe7d61459a55585c99c
parent 632a44da435c60018410cd955c034fe9d19fe62f
Author: sin <sin@2f30.org>
Date: Wed, 5 Jun 2013 15:58:50 +0100
add fifo support + netjoin cmd
Diffstat:
2 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/src/irc/irc.go b/src/irc/irc.go
@@ -145,6 +145,15 @@ func (i *Context) JoinChannel(c string, key string) {
return
}
+func (i *Context) JoinChannels() {
+ i.Lock()
+ defer i.Unlock()
+ for j, v := range i.network.channels {
+ i.Join(v.name, v.key)
+ i.network.channels[j].joined = true
+ }
+}
+
func (i *Context) PartChannel(s string, text string) error {
i.Lock()
defer i.Unlock()
diff --git a/src/kunt/kunt.go b/src/kunt/kunt.go
@@ -9,6 +9,7 @@ import (
"flag"
"fmt"
"games"
+ "io"
"io/ioutil"
"irc"
"log"
@@ -18,6 +19,7 @@ import (
"os"
"os/exec"
"strings"
+ "syscall"
"time"
)
@@ -315,6 +317,31 @@ func cmdCopyright(msg irc.Message) {
}
}
+func fifoCmdParse() {
+ fi, err := os.Open(".kfifo")
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer func() {
+ if err := fi.Close(); err != nil {
+ log.Fatal(err)
+ }
+ }()
+ for {
+ buf := make([]byte, 1024)
+ n, err := fi.Read(buf)
+ if err != nil && err != io.EOF {
+ log.Fatal(err)
+ }
+ if n > 0 {
+ buf = buf[0 : n-1]
+ if string(buf) == "netjoin" {
+ kunt.ircCtx.JoinChannels()
+ }
+ }
+ }
+}
+
var sslon = flag.Bool("s", false, "SSL support")
var quoteDb *mapfs.Mapfs
@@ -436,6 +463,9 @@ func main() {
kunt.ircCtx.Login()
kunt.ircCtx.JoinChannel("#2f30", "")
+ syscall.Mkfifo(".kfifo", 0600)
+ go fifoCmdParse()
+
donechan := make(chan bool)
select {
case stat := <-donechan: