Notification on Nick change added
This commit is contained in:
parent
d87aeeb3fe
commit
b8408ad060
@ -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()
|
||||||
|
23
client.go
23
client.go
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user