3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-26 13:59:44 +01:00

nickname: Preserve case when setting NICK

This commit is contained in:
Daniel Oaks 2016-10-14 00:31:13 +10:00
parent 9ccd6037a6
commit d226a0c6d3

View File

@ -17,15 +17,16 @@ func nickHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
return true return true
} }
nickname, err := CasefoldName(msg.Params[0]) nicknameRaw := strings.TrimSpace(msg.Params[0])
nickname, err := CasefoldName(nicknameRaw)
if len(strings.TrimSpace(msg.Params[0])) < 1 { if len(nicknameRaw) < 1 {
client.Send(nil, server.name, ERR_NONICKNAMEGIVEN, client.nick, "No nickname given") client.Send(nil, server.name, ERR_NONICKNAMEGIVEN, client.nick, "No nickname given")
return false return false
} }
if err != nil || len(strings.TrimSpace(msg.Params[0])) > server.limits.NickLen { if err != nil || len(nicknameRaw) > server.limits.NickLen {
client.Send(nil, server.name, ERR_ERRONEUSNICKNAME, client.nick, msg.Params[0], "Erroneous nickname") client.Send(nil, server.name, ERR_ERRONEUSNICKNAME, client.nick, nicknameRaw, "Erroneous nickname")
return false return false
} }
@ -36,14 +37,14 @@ func nickHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
//TODO(dan): There's probably some races here, we should be changing this in the primary server thread //TODO(dan): There's probably some races here, we should be changing this in the primary server thread
target := server.clients.Get(nickname) target := server.clients.Get(nickname)
if target != nil && target != client { if target != nil && target != client {
client.Send(nil, server.name, ERR_NICKNAMEINUSE, client.nick, msg.Params[0], "Nickname is already in use") client.Send(nil, server.name, ERR_NICKNAMEINUSE, client.nick, nicknameRaw, "Nickname is already in use")
return false return false
} }
if client.registered { if client.registered {
client.ChangeNickname(nickname) client.ChangeNickname(nicknameRaw)
} else { } else {
client.SetNickname(nickname) client.SetNickname(nicknameRaw)
} }
server.tryRegister(client) server.tryRegister(client)
return false return false