diff --git a/irc/channel.go b/irc/channel.go index 6e5f94ff..e19d3980 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -113,13 +113,13 @@ func (channel *Channel) Join(client *Client, key string) { return } + client.channels.Add(channel) channel.members.Add(client) if len(channel.members) == 1 { channel.members[client][ChannelCreator] = true channel.members[client][ChannelOperator] = true } - client.channels.Add(channel) channel.Reply(RplJoin(client, channel)) channel.GetTopic(client) channel.Names(client) diff --git a/irc/reply.go b/irc/reply.go index 57a359a5..3b5456a0 100644 --- a/irc/reply.go +++ b/irc/reply.go @@ -40,8 +40,8 @@ func NewStringReply(source Identifier, code StringCode, } func (reply *StringReply) Format(client *Client) []string { - message := fmt.Sprintf(":%s %s %s", - reply.id, reply.code, reply.message) + message := fmt.Sprintf(":%s %s %s%s", + reply.id, reply.code, reply.message, CRLF) return []string{message} } @@ -64,8 +64,8 @@ func NewNumericReply(source Identifier, code NumericCode, format string, } func (reply *NumericReply) Format(client *Client) []string { - message := fmt.Sprintf(":%s %s %s %s", - reply.id, reply.code, client.Nick(), reply.message) + message := fmt.Sprintf(":%s %s %s %s%s", + reply.id, reply.code, client.Nick(), reply.message, CRLF) return []string{message} } diff --git a/irc/server.go b/irc/server.go index 07582578..c99f87cf 100644 --- a/irc/server.go +++ b/irc/server.go @@ -376,9 +376,9 @@ func (m *JoinCommand) HandleServer(s *Server) { return } - for name := range m.channels { + for name, key := range m.channels { channel := s.GetOrMakeChannel(name) - channel.Join(client, m.channels[name]) + channel.Join(client, key) } } diff --git a/irc/socket.go b/irc/socket.go index 9854102a..567c6be3 100644 --- a/irc/socket.go +++ b/irc/socket.go @@ -24,7 +24,7 @@ type Socket struct { func NewSocket(conn net.Conn) *Socket { socket := &Socket{ conn: conn, - done: make(chan bool), + done: make(chan bool, 1), reader: bufio.NewReader(conn), receive: make(chan string, 16), send: make(chan string, 16), @@ -86,9 +86,6 @@ func (socket *Socket) writeLines() { if _, err := socket.writer.WriteString(line); socket.isError(err, W) { break } - if _, err := socket.writer.WriteString(CRLF); socket.isError(err, W) { - break - } if err := socket.writer.Flush(); socket.isError(err, W) { break @@ -98,6 +95,9 @@ func (socket *Socket) writeLines() { } case done = <-socket.done: + if DEBUG_NET { + log.Printf("%s done", socket) + } continue } }