From 1e956355bfefdfe7f0d4bee7b7a545da90751ee5 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sun, 16 Oct 2016 20:35:50 +1000 Subject: [PATCH] NICK: Fix small bug when casefolding --- irc/client.go | 19 +++++++++++++++---- irc/server.go | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/irc/client.go b/irc/client.go index c9addf4e..6e4469ae 100644 --- a/irc/client.go +++ b/irc/client.go @@ -9,6 +9,7 @@ import ( "fmt" "log" "net" + "runtime/debug" "strconv" "time" @@ -211,6 +212,7 @@ func (client *Client) Idle() { } } +// Register sets the client details as appropriate when entering the network. func (client *Client) Register() { if client.registered { return @@ -218,6 +220,7 @@ func (client *Client) Register() { client.registered = true client.Touch() + client.updateNickMask() client.alertMonitors() } @@ -278,18 +281,26 @@ func (client *Client) Friends(Capabilities ...Capability) ClientSet { return friends } -func (client *Client) updateNickMask() { +// updateNick updates the casefolded nickname. +func (client *Client) updateNick() { casefoldedName, err := CasefoldName(client.nick) if err != nil { - log.Println(fmt.Sprintf("ERROR: Nick [%s] couldn't be casefolded... this should never happen.", client.nick)) + log.Println(fmt.Sprintf("ERROR: Nick [%s] couldn't be casefolded... this should never happen. Printing stacktrace.", client.nick)) + debug.PrintStack() } client.nickCasefolded = casefoldedName +} + +// updateNickMask updates the casefolded nickname and nickmask. +func (client *Client) updateNickMask() { + client.updateNick() client.nickMaskString = fmt.Sprintf("%s!%s@%s", client.nick, client.username, client.hostname) nickMaskCasefolded, err := Casefold(client.nickMaskString) if err != nil { - log.Println(fmt.Sprintf("ERROR: Nickmask [%s] couldn't be casefolded... this should never happen.", client.nickMaskString)) + log.Println(fmt.Sprintf("ERROR: Nickmask [%s] couldn't be casefolded... this should never happen. Printing stacktrace.", client.nickMaskString)) + debug.PrintStack() } client.nickMaskCasefolded = nickMaskCasefolded } @@ -300,7 +311,7 @@ func (client *Client) SetNickname(nickname string) { return } client.nick = nickname - client.updateNickMask() + client.updateNick() client.server.clients.Add(client) } diff --git a/irc/server.go b/irc/server.go index 47a0ec83..e046600b 100644 --- a/irc/server.go +++ b/irc/server.go @@ -452,7 +452,7 @@ func userHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { if !client.HasUsername() { client.username = "~" + msg.Params[0] - client.updateNickMask() + // don't bother updating nickmask here, it's not valid anyway } if client.realname == "" { client.realname = msg.Params[3]