From 998e1c3050bda0125044d0a3e251c153fd47517b Mon Sep 17 00:00:00 2001 From: tj Date: Wed, 29 Sep 2010 08:58:32 +0200 Subject: [PATCH] Add support for server PASSWORD --- irc.go | 8 ++++++-- irc_struct.go | 9 +++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/irc.go b/irc.go index 1fb44da..562d905 100644 --- a/irc.go +++ b/irc.go @@ -58,7 +58,7 @@ func reader(irc *IRCConnection) { func writer(irc *IRCConnection) { for { b := []byte(<-irc.pwrite) - if b == nil { + if b == nil || irc.socket == nil { return } _, err := irc.socket.Write(b) @@ -145,10 +145,13 @@ func (i *IRCConnection) Connect(server string) os.Error { go pinger(i) i.pwrite <- fmt.Sprintf("NICK %s\r\n", i.nick) i.pwrite <- fmt.Sprintf("USER %s 0.0.0.0 0.0.0.0 :%s\r\n", i.user, i.user) + if len(i.password) > 0 { + i.pwrite <- fmt.Sprintf("PASS %s\r\n", i.password) + } return nil } -func IRC(nick string, user string) *IRCConnection { +func IRC(nick, user, password string) *IRCConnection { irc := new(IRCConnection) irc.registered = false irc.pread = make(chan string, 100) @@ -156,6 +159,7 @@ func IRC(nick string, user string) *IRCConnection { irc.Error = make(chan os.Error) irc.nick = nick irc.user = user + irc.password = password irc.setupCallbacks() return irc } diff --git a/irc_struct.go b/irc_struct.go index bd99452..79d35d9 100644 --- a/irc_struct.go +++ b/irc_struct.go @@ -17,12 +17,13 @@ type IRCConnection struct { user string registered bool server string + password string events map[string][]func(*IRCEvent) - - lastMessage int64; - ticker <-chan int64; - ticker2 <-chan int64; + + lastMessage int64 + ticker <-chan int64 + ticker2 <-chan int64 } type IRCEvent struct {