From 70f533ee07795311ab90437b77f3c3c5e7c003ac Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Mon, 29 Jun 2020 04:32:39 -0400 Subject: [PATCH] fix #1155 --- irc/client.go | 9 ++------- irc/commands.go | 39 +++++++++++++++++---------------------- irc/getters.go | 8 ++++++++ irc/handlers.go | 7 ++++++- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/irc/client.go b/irc/client.go index bc36a41c..8dc4e9dd 100644 --- a/irc/client.go +++ b/irc/client.go @@ -723,16 +723,11 @@ func (client *Client) playReattachMessages(session *Session) { // // Touch indicates that we received a line from the client (so the connection is healthy -// at this time, modulo network latency and fakelag). `active` means not a PING or suchlike -// (i.e. the user should be sitting in front of their client). -func (client *Client) Touch(active bool, session *Session) { +// at this time, modulo network latency and fakelag). +func (client *Client) Touch(session *Session) { var markDirty bool now := time.Now().UTC() client.stateMutex.Lock() - if active { - client.lastActive = now - session.lastActive = now - } if client.accountSettings.AutoreplayMissed || session.deviceID != "" { client.setLastSeen(now, session.deviceID) if now.Sub(client.lastSeenLastWrite) > lastSeenWriteInterval { diff --git a/irc/commands.go b/irc/commands.go index 0870c80b..bfe0a7dd 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 - leaveClientIdle bool // if true, leaves the client active time alone - allowedInBatch bool // allowed in client-to-server batches - minParams int - capabs []string + handler func(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool + oper bool + usablePreReg bool + allowedInBatch bool // allowed in client-to-server batches + minParams int + capabs []string } // Run runs this command with the given client/message. @@ -67,7 +66,7 @@ func (cmd *Command) Run(server *Server, client *Client, session *Session, msg ir // TODO: eliminate idletimer entirely in favor of this measurement if client.registered { - client.Touch(!cmd.leaveClientIdle, session) + client.Touch(session) } return exiting @@ -159,9 +158,8 @@ func init() { minParams: 2, }, "ISON": { - handler: isonHandler, - minParams: 1, - leaveClientIdle: true, + handler: isonHandler, + minParams: 1, }, "JOIN": { handler: joinHandler, @@ -243,16 +241,14 @@ func init() { minParams: 1, }, "PING": { - handler: pingHandler, - usablePreReg: true, - minParams: 1, - leaveClientIdle: true, + handler: pingHandler, + usablePreReg: true, + minParams: 1, }, "PONG": { - handler: pongHandler, - usablePreReg: true, - minParams: 1, - leaveClientIdle: true, + handler: pongHandler, + usablePreReg: true, + minParams: 1, }, "PRIVMSG": { handler: messageHandler, @@ -349,9 +345,8 @@ func init() { minParams: 4, }, "WHO": { - handler: whoHandler, - minParams: 1, - leaveClientIdle: true, + handler: whoHandler, + minParams: 1, }, "WHOIS": { handler: whoisHandler, diff --git a/irc/getters.go b/irc/getters.go index 1ba2c97c..c7f207f0 100644 --- a/irc/getters.go +++ b/irc/getters.go @@ -418,6 +418,14 @@ func (client *Client) detailsNoMutex() (result ClientDetails) { return } +func (client *Client) UpdateActive(session *Session) { + now := time.Now().UTC() + client.stateMutex.Lock() + defer client.stateMutex.Unlock() + client.lastActive = now + session.lastActive = now +} + func (channel *Channel) Name() string { channel.stateMutex.RLock() defer channel.stateMutex.RUnlock() diff --git a/irc/handlers.go b/irc/handlers.go index 64b271f6..a0477e6c 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -1955,7 +1955,12 @@ func messageHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R return false } - if rb.session.isTor && utils.IsRestrictedCTCPMessage(message) { + isCTCP := utils.IsRestrictedCTCPMessage(message) + if histType == history.Privmsg && !isCTCP { + client.UpdateActive(rb.session) + } + + if rb.session.isTor && isCTCP { // note that error replies are never sent for NOTICE if histType != history.Notice { rb.Notice(client.t("CTCP messages are disabled over Tor"))