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) {
 | 
			
		||||
	c.membersMutex.Lock()
 | 
			
		||||
	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.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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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 {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user