3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

NICK: Fix small bug when casefolding

This commit is contained in:
Daniel Oaks 2016-10-16 20:35:50 +10:00
parent 83cb76331f
commit 1e956355bf
2 changed files with 16 additions and 5 deletions

View File

@ -9,6 +9,7 @@ import (
"fmt" "fmt"
"log" "log"
"net" "net"
"runtime/debug"
"strconv" "strconv"
"time" "time"
@ -211,6 +212,7 @@ func (client *Client) Idle() {
} }
} }
// Register sets the client details as appropriate when entering the network.
func (client *Client) Register() { func (client *Client) Register() {
if client.registered { if client.registered {
return return
@ -218,6 +220,7 @@ func (client *Client) Register() {
client.registered = true client.registered = true
client.Touch() client.Touch()
client.updateNickMask()
client.alertMonitors() client.alertMonitors()
} }
@ -278,18 +281,26 @@ func (client *Client) Friends(Capabilities ...Capability) ClientSet {
return friends return friends
} }
func (client *Client) updateNickMask() { // updateNick updates the casefolded nickname.
func (client *Client) updateNick() {
casefoldedName, err := CasefoldName(client.nick) casefoldedName, err := CasefoldName(client.nick)
if err != nil { 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 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) client.nickMaskString = fmt.Sprintf("%s!%s@%s", client.nick, client.username, client.hostname)
nickMaskCasefolded, err := Casefold(client.nickMaskString) nickMaskCasefolded, err := Casefold(client.nickMaskString)
if err != nil { 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 client.nickMaskCasefolded = nickMaskCasefolded
} }
@ -300,7 +311,7 @@ func (client *Client) SetNickname(nickname string) {
return return
} }
client.nick = nickname client.nick = nickname
client.updateNickMask() client.updateNick()
client.server.clients.Add(client) client.server.clients.Add(client)
} }

View File

@ -452,7 +452,7 @@ func userHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
if !client.HasUsername() { if !client.HasUsername() {
client.username = "~" + msg.Params[0] client.username = "~" + msg.Params[0]
client.updateNickMask() // don't bother updating nickmask here, it's not valid anyway
} }
if client.realname == "" { if client.realname == "" {
client.realname = msg.Params[3] client.realname = msg.Params[3]