From 0d5327de8a764227e1e1a21b3fde75c6c6064c34 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sun, 21 Jan 2018 12:23:47 +1000 Subject: [PATCH] Fix some issues, add RPL_WHOISACCOUNT --- irc/client.go | 11 +++++++++-- irc/numerics.go | 1 + irc/server.go | 12 +++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/irc/client.go b/irc/client.go index cf6089e9..810ad562 100644 --- a/irc/client.go +++ b/irc/client.go @@ -322,10 +322,17 @@ func (client *Client) TryResume() { timestamp := client.resumeDetails.Timestamp var timestampString string if timestamp != nil { - timestampString := timestamp.UTC().Format("2006-01-02T15:04:05.999Z") + timestampString = timestamp.UTC().Format("2006-01-02T15:04:05.999Z") } - oldClient := server.clients.Get(oldnick) + // can't use server.clients.Get since we hold server.clients' tier 1 mutex + casefoldedName, err := CasefoldName(oldnick) + if err != nil { + client.Send(nil, server.name, ERR_CANNOT_RESUME, oldnick, "Cannot resume connection, old client not found") + return + } + + oldClient := server.clients.byNick[casefoldedName] if oldClient == nil { client.Send(nil, server.name, ERR_CANNOT_RESUME, oldnick, "Cannot resume connection, old client not found") return diff --git a/irc/numerics.go b/irc/numerics.go index 899781cd..182235ca 100644 --- a/irc/numerics.go +++ b/irc/numerics.go @@ -69,6 +69,7 @@ const ( RPL_CHANNELMODEIS = "324" RPL_UNIQOPIS = "325" RPL_CHANNELCREATED = "329" + RPL_WHOISACCOUNT = "330" RPL_NOTOPIC = "331" RPL_TOPIC = "332" RPL_TOPICTIME = "333" diff --git a/irc/server.go b/irc/server.go index 559cbee5..9ab0dc1f 100644 --- a/irc/server.go +++ b/irc/server.go @@ -1002,6 +1002,10 @@ func (client *Client) getWhoisOf(target *Client) { if target.flags[TLS] { client.Send(nil, client.server.name, RPL_WHOISSECURE, client.nick, target.nick, "is using a secure connection") } + accountName := target.AccountName() + if accountName != "" { + client.Send(nil, client.server.name, RPL_WHOISACCOUNT, client.nick, accountName, "is logged in as") + } if target.flags[Bot] { client.Send(nil, client.server.name, RPL_WHOISBOT, client.nick, target.nick, ircfmt.Unescape("is a $bBot$b on ")+client.server.networkName) } @@ -2093,8 +2097,10 @@ func resumeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { var timestamp *time.Time if 1 < len(msg.Params) { - timestamp, err = time.Parse("2006-01-02T15:04:05.999Z", msg.Params[1]) - if err != nil { + ts, err := time.Parse("2006-01-02T15:04:05.999Z", msg.Params[1]) + if err == nil { + timestamp = &ts + } else { client.Send(nil, server.name, ERR_CANNOT_RESUME, oldnick, "Timestamp is not in 2006-01-02T15:04:05.999Z format, ignoring it") } } @@ -2104,7 +2110,7 @@ func resumeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { Timestamp: timestamp, } - return true + return false } // USERHOST [ ...]