Notification on Nick change added

This commit is contained in:
Justin 2015-08-08 19:19:02 -07:00
parent d87aeeb3fe
commit b8408ad060
4 changed files with 21 additions and 5 deletions

View File

@ -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) { func (c *Channel) UpdateMemberNick(client *Client, oldNick string) {
c.membersMutex.Lock() c.membersMutex.Lock()
defer c.membersMutex.Unlock() defer c.membersMutex.Unlock()

View File

@ -222,11 +222,26 @@ func (c *Client) UpdateNick(newNick string) {
c.Server.UpdateClientNick(c, oldNick) c.Server.UpdateClientNick(c, oldNick)
c.channelMutex.RLock() c.channelMutex.RLock()
defer c.channelMutex.RUnlock() 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) 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 c.Prefix.Name = newNick
} }

View File

@ -107,7 +107,6 @@ func NickHandler(message *irc.Message, client *Client) {
client.Server.AddClientNick(client) client.Server.AddClientNick(client)
client.Welcome() client.Welcome()
} else if len(client.Username) != 0 { //change client name } else if len(client.Username) != 0 { //change client name
fmt.Println("Changing nick from", client.Nickname, "to", newNickname)
client.UpdateNick(newNickname) client.UpdateNick(newNickname)
//fmt.Println("Updating client name") //fmt.Println("Updating client name")
} else { } else {

View File

@ -99,6 +99,7 @@ func (s *Server) UpdateClientNick(client *Client, oldNick string) {
defer s.clientByNickMutex.Unlock() defer s.clientByNickMutex.Unlock()
delete(s.clientsByNick, oldNick) delete(s.clientsByNick, oldNick)
s.clientsByNick[client.Nickname] = client s.clientsByNick[client.Nickname] = client
} }
// GetClientByNick returns a client with the corresponding nickname // GetClientByNick returns a client with the corresponding nickname