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

strings: Fix nick bugs, use UsernameCaseMapped

This commit is contained in:
Daniel Oaks 2017-01-14 02:32:15 +10:00
parent c6e8e4bef3
commit 2b240faa90
4 changed files with 13 additions and 10 deletions

View File

@ -397,11 +397,11 @@ func (client *Client) SetNickname(nickname string) error {
// ChangeNickname changes the existing nickname of the client.
func (client *Client) ChangeNickname(nickname string) error {
origNickMask := client.nickMaskString
client.updateNickMask()
err := client.server.clients.Replace(client.nick, nickname, client)
if err == nil {
client.server.whoWas.Append(client)
client.nick = nickname
client.updateNickMask()
for friend := range client.Friends() {
friend.Send(nil, origNickMask, "NICK", nickname)
}

View File

@ -128,13 +128,12 @@ func (clients *ClientLookupSet) Replace(oldNick, newNick string, client *Client)
clients.ByNickMutex.Lock()
defer clients.ByNickMutex.Unlock()
oldClient := clients.getNoMutex(newNick)
if oldClient != nil {
oldClient := clients.ByNick[newNick]
if oldClient == nil || oldClient == client {
// whoo
} else {
return ErrNicknameInUse
}
if oldClient != client {
return ErrNicknameMismatch
}
if oldNick == newNick {
// if they're only changing case, don't need to remove+re-add them

View File

@ -305,7 +305,7 @@ func (server *Server) setISupport() {
// add RPL_ISUPPORT tokens
server.isupport = NewISupportList()
server.isupport.Add("AWAYLEN", strconv.Itoa(server.limits.AwayLen))
server.isupport.Add("CASEMAPPING", "rfc7700")
server.isupport.Add("CASEMAPPING", casemappingName)
server.isupport.Add("CHANMODES", strings.Join([]string{ChannelModes{BanMask, ExceptMask, InviteMask}.String(), "", ChannelModes{UserLimit, Key}.String(), ChannelModes{InviteOnly, Moderated, NoOutside, OpOnlyTopic, ChanRoleplaying, Secret}.String()}, ","))
server.isupport.Add("CHANNELLEN", strconv.Itoa(server.limits.ChannelLen))
server.isupport.Add("CHANTYPES", "#")

View File

@ -12,18 +12,22 @@ import (
"golang.org/x/text/secure/precis"
)
const (
casemappingName = "rfc7613"
)
var (
errInvalidCharacter = errors.New("Invalid character")
)
// Casefold returns a casefolded string, without doing any name or channel character checks.
func Casefold(str string) (string, error) {
return precis.Nickname.CompareKey(str)
return precis.UsernameCaseMapped.CompareKey(str)
}
// CasefoldChannel returns a casefolded version of a channel name.
func CasefoldChannel(name string) (string, error) {
lowered, err := precis.Nickname.CompareKey(name)
lowered, err := Casefold(name)
if err != nil {
return "", err
@ -47,7 +51,7 @@ func CasefoldChannel(name string) (string, error) {
// CasefoldName returns a casefolded version of a nick/user name.
func CasefoldName(name string) (string, error) {
lowered, err := precis.Nickname.CompareKey(name)
lowered, err := Casefold(name)
if err != nil {
return "", err