From a4b3fb0e8302e36fdf33df36e1765d846c93e09a Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Sun, 30 Dec 2018 18:05:27 -0500 Subject: [PATCH] changes to client idle time counting 1. Remove leaveClientIdle (unused) 2. s/leaveClientActive/leaveClientIdle/ 3. make ISON a leaveClientIdle command (some clients send it periodically if a /msg window is left open) --- irc/client.go | 6 ------ irc/commands.go | 41 ++++++++++++++++++++--------------------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/irc/client.go b/irc/client.go index 921056b9..ebcaa066 100644 --- a/irc/client.go +++ b/irc/client.go @@ -332,12 +332,6 @@ func (client *Client) Active() { client.atime = time.Now() } -// Touch marks the client as alive (as it it has a connection to us and we -// can receive messages from it). -func (client *Client) Touch() { - client.idletimer.Touch() -} - // Ping sends the client a PING message. func (client *Client) Ping() { client.Send(nil, "", "PING", client.nick) diff --git a/irc/commands.go b/irc/commands.go index 7fcf1463..af2ee92b 100644 --- a/irc/commands.go +++ b/irc/commands.go @@ -12,13 +12,12 @@ import ( // Command represents a command accepted from a client. type Command struct { - handler func(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool - oper bool - usablePreReg bool - leaveClientActive bool // if true, leaves the client active time alone. reversed because we can't default a struct element to True - leaveClientIdle bool - minParams int - capabs []string + handler func(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool + oper bool + usablePreReg bool + leaveClientIdle bool // if true, leaves the client active time alone + minParams int + capabs []string } // Run runs this command with the given client/message. @@ -54,11 +53,10 @@ func (cmd *Command) Run(server *Server, client *Client, msg ircmsg.IrcMessage) b server.tryRegister(client) } - if !cmd.leaveClientIdle { - client.Touch() - } + // most servers do this only for PING/PONG, but we'll do it for any command: + client.idletimer.Touch() - if !cmd.leaveClientActive { + if !cmd.leaveClientIdle { client.Active() } @@ -118,8 +116,9 @@ func init() { minParams: 2, }, "ISON": { - handler: isonHandler, - minParams: 1, + handler: isonHandler, + minParams: 1, + leaveClientIdle: true, }, "JOIN": { handler: joinHandler, @@ -200,16 +199,16 @@ func init() { minParams: 1, }, "PING": { - handler: pingHandler, - usablePreReg: true, - minParams: 1, - leaveClientActive: true, + handler: pingHandler, + usablePreReg: true, + minParams: 1, + leaveClientIdle: true, }, "PONG": { - handler: pongHandler, - usablePreReg: true, - minParams: 1, - leaveClientActive: true, + handler: pongHandler, + usablePreReg: true, + minParams: 1, + leaveClientIdle: true, }, "PRIVMSG": { handler: privmsgHandler,