diff --git a/irc/channel.go b/irc/channel.go index e19d3980..eceb926c 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -38,7 +38,7 @@ func (channel *Channel) Reply(reply Reply) { for client := range channel.members { if (reply.Code() == ReplyCode(PRIVMSG)) && - (reply.Source() == Identifier(client)) { + (reply.Source() == client.Id()) { continue } client.Reply(reply) diff --git a/irc/client.go b/irc/client.go index 5914e61e..88ac9a6b 100644 --- a/irc/client.go +++ b/irc/client.go @@ -28,7 +28,7 @@ type Client struct { phase Phase quitTimer *time.Timer realname string - replies chan string + replies chan Reply server *Server socket *Socket username string @@ -46,7 +46,7 @@ func NewClient(server *Server, conn net.Conn) *Client { phase: server.InitPhase(), server: server, socket: NewSocket(conn), - replies: make(chan string), + replies: make(chan Reply), } client.loginTimer = time.AfterFunc(LOGIN_TIMEOUT, client.connectionTimeout) @@ -96,8 +96,8 @@ func (client *Client) connectionClosed() { // func (client *Client) writeReplies() { - for line := range client.replies { - client.socket.Write(line) + for reply := range client.replies { + client.socket.Write(reply.Format(client)...) } client.socket.Close() client.doneWriting <- true @@ -195,9 +195,7 @@ func (client *Client) Reply(reply Reply) { } return } - for _, line := range reply.Format(client) { - client.replies <- line - } + client.replies <- reply } func (client *Client) IdleTime() time.Duration { diff --git a/irc/reply.go b/irc/reply.go index c52cb5d6..6157d766 100644 --- a/irc/reply.go +++ b/irc/reply.go @@ -10,7 +10,6 @@ type BaseReply struct { code ReplyCode id string message string - source Identifier } func (reply *BaseReply) Code() ReplyCode { @@ -19,11 +18,10 @@ func (reply *BaseReply) Code() ReplyCode { func (reply *BaseReply) SetSource(source Identifier) { reply.id = source.Id() - reply.source = source } -func (reply *BaseReply) Source() Identifier { - return reply.source +func (reply *BaseReply) Source() string { + return reply.id } type StringReply struct { diff --git a/irc/server.go b/irc/server.go index c99f87cf..fbf997bf 100644 --- a/irc/server.go +++ b/irc/server.go @@ -17,7 +17,7 @@ type Server struct { channels ChannelNameMap clients ClientNameMap commands chan Command - conns chan net.Conn + newConns chan net.Conn ctime time.Time idle chan *Client motdFile string @@ -31,7 +31,7 @@ func NewServer(config *Config) *Server { channels: make(ChannelNameMap), clients: make(ClientNameMap), commands: make(chan Command), - conns: make(chan net.Conn), + newConns: make(chan net.Conn), ctime: time.Now(), idle: make(chan *Client), motdFile: config.MOTD, @@ -54,7 +54,7 @@ func NewServer(config *Config) *Server { func (server *Server) ReceiveCommands() { for { select { - case conn := <-server.conns: + case conn := <-server.newConns: NewClient(server, conn) case client := <-server.idle: @@ -126,6 +126,10 @@ func newListener(config ListenerConfig) (net.Listener, error) { return net.Listen("tcp", config.Address) } +// +// listen goroutine +// + func (s *Server) listen(config ListenerConfig) { listener, err := newListener(config) if err != nil { @@ -148,7 +152,7 @@ func (s *Server) listen(config ListenerConfig) { log.Printf("%s accept: %s", s, conn.RemoteAddr()) } - s.conns <- conn + s.newConns <- conn } } diff --git a/irc/types.go b/irc/types.go index 1a5460ce..8e756fd9 100644 --- a/irc/types.go +++ b/irc/types.go @@ -176,7 +176,7 @@ type Replier interface { type Reply interface { Code() ReplyCode Format(*Client) []string - Source() Identifier + Source() string } type Command interface {