diff --git a/channel.go b/channel.go index 12feb94..b4ca49f 100644 --- a/channel.go +++ b/channel.go @@ -254,6 +254,7 @@ func (c *Channel) RemoveMember(client *Client) { } } +// UpdateMemberNick updates the listing of the client from the old nickname to what the client actually has func (c *Channel) UpdateMemberNick(client *Client, oldNick string) { c.membersMutex.Lock() defer c.membersMutex.Unlock() diff --git a/client.go b/client.go index 3060d5f..a7a021c 100644 --- a/client.go +++ b/client.go @@ -222,11 +222,26 @@ func (c *Client) UpdateNick(newNick string) { c.Server.UpdateClientNick(c, oldNick) c.channelMutex.RLock() defer c.channelMutex.RUnlock() - for _, channel := range c.channels { - channel.UpdateMemberNick(c, oldNick) - } - m := irc.Message{Prefix: c.Prefix, Command: irc.NICK, Trailing: newNick} + // Notify all people that should know (people on channels with this client) + m := irc.Message{Prefix: c.Prefix, Command: irc.NICK, Trailing: c.Nickname} + notified := map[string]interface{}{} // Just notify people once c.Encode(&m) + notified[c.Nickname] = nil + + for _, channel := range c.channels { + + channel.UpdateMemberNick(c, oldNick) + + for client := range channel.members { + cl, ok := c.Server.GetClientByNick(client) + _, alreadyNotified := notified[client] + if ok && !alreadyNotified { + cl.Encode(&m) + notified[client] = nil + } + } + } + c.Prefix.Name = newNick } diff --git a/commands.go b/commands.go index 1eb115f..df5e056 100644 --- a/commands.go +++ b/commands.go @@ -107,7 +107,6 @@ func NickHandler(message *irc.Message, client *Client) { client.Server.AddClientNick(client) client.Welcome() } else if len(client.Username) != 0 { //change client name - fmt.Println("Changing nick from", client.Nickname, "to", newNickname) client.UpdateNick(newNickname) //fmt.Println("Updating client name") } else { diff --git a/server.go b/server.go index f1c5978..3185f4a 100644 --- a/server.go +++ b/server.go @@ -99,6 +99,7 @@ func (s *Server) UpdateClientNick(client *Client, oldNick string) { defer s.clientByNickMutex.Unlock() delete(s.clientsByNick, oldNick) s.clientsByNick[client.Nickname] = client + } // GetClientByNick returns a client with the corresponding nickname