diff --git a/irc/client.go b/irc/client.go index 29addec0..6004490c 100644 --- a/irc/client.go +++ b/irc/client.go @@ -79,26 +79,24 @@ func (client *Client) Touch() { } if client.idleTimer == nil { - client.idleTimer = time.AfterFunc(IDLE_TIMEOUT, client.Idle) + client.idleTimer = time.AfterFunc(IDLE_TIMEOUT, client.connectionIdle) } else { client.idleTimer.Reset(IDLE_TIMEOUT) } } -type ClientIdle struct { - BaseCommand -} - func (client *Client) Idle() { + client.Reply(RplPing(client.server, client)) + if client.quitTimer == nil { client.quitTimer = time.AfterFunc(QUIT_TIMEOUT, client.connectionTimeout) } else { client.quitTimer.Reset(QUIT_TIMEOUT) } +} - cmd := &ClientIdle{} - cmd.SetClient(client) - client.server.commands <- cmd +func (client *Client) connectionIdle() { + client.server.idle <- client } func (client *Client) connectionTimeout() { diff --git a/irc/server.go b/irc/server.go index 0e6fd11b..5491f71d 100644 --- a/irc/server.go +++ b/irc/server.go @@ -19,6 +19,7 @@ type Server struct { commands chan Command conns chan net.Conn ctime time.Time + idle chan *Client motdFile string name string operators map[string]string @@ -33,6 +34,7 @@ func NewServer(config *Config) *Server { commands: make(chan Command), conns: make(chan net.Conn), ctime: time.Now(), + idle: make(chan *Client), motdFile: config.MOTD, name: config.Name, operators: make(map[string]string), @@ -60,6 +62,9 @@ func (server *Server) ReceiveCommands() { case client := <-server.toDestroy: client.Destroy() + case client := <-server.idle: + client.Idle() + case cmd := <-server.commands: client := cmd.Client() if DEBUG_SERVER { @@ -650,11 +655,6 @@ func (msg *ListCommand) HandleServer(server *Server) { client.Reply(RplListEnd(server)) } -func (msg *ClientIdle) HandleServer(server *Server) { - client := msg.Client() - client.Reply(RplPing(server, client)) -} - func (msg *NamesCommand) HandleServer(server *Server) { client := msg.Client() if len(server.channels) == 0 {