Can now change nickname using IRC NICK command
This commit is contained in:
parent
e49c459365
commit
7b23d2015d
@ -254,6 +254,14 @@ func (c *Channel) RemoveMember(client *Client) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Channel) UpdateMemberNick(client *Client, oldNick string) {
|
||||
c.membersMutex.Lock()
|
||||
defer c.membersMutex.Unlock()
|
||||
modes := c.members[oldNick]
|
||||
delete(c.members, oldNick)
|
||||
c.members[client.Nickname] = modes
|
||||
}
|
||||
|
||||
// HasMember returns if a client is an existing member of this channel
|
||||
func (c *Channel) HasMember(client *Client) bool {
|
||||
c.membersMutex.RLock()
|
||||
|
19
client.go
19
client.go
@ -32,7 +32,7 @@ type Client struct {
|
||||
AwayMessage string
|
||||
|
||||
channels map[string]*Channel
|
||||
channelMutex sync.Mutex
|
||||
channelMutex sync.RWMutex
|
||||
|
||||
*UserModeSet
|
||||
}
|
||||
@ -213,3 +213,20 @@ func (c *Client) RemoveChannel(channel *Channel) {
|
||||
func (c *Client) GetChannels() map[string]*Channel {
|
||||
return c.channels
|
||||
}
|
||||
|
||||
// UpdateNick updates the clients nicknamae to a new nickname
|
||||
func (c *Client) UpdateNick(newNick string) {
|
||||
oldNick := c.Nickname
|
||||
c.Nickname = newNick
|
||||
|
||||
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}
|
||||
|
||||
c.Encode(&m)
|
||||
c.Prefix.Name = newNick
|
||||
}
|
||||
|
10
commands.go
10
commands.go
@ -63,7 +63,7 @@ func NickHandler(message *irc.Message, client *Client) {
|
||||
|
||||
var m irc.Message
|
||||
name := client.Server.Config.Name
|
||||
nickname := client.Nickname
|
||||
//nickname := client.Nickname
|
||||
|
||||
if len(message.Params) == 0 {
|
||||
m = irc.Message{Prefix: &irc.Prefix{Name: name}, Command: irc.ERR_NONICKNAMEGIVEN, Trailing: "No nickname given"}
|
||||
@ -88,10 +88,12 @@ func NickHandler(message *irc.Message, client *Client) {
|
||||
client.Nickname = newNickname
|
||||
client.Server.AddClientNick(client)
|
||||
client.Welcome()
|
||||
} else { //change client name
|
||||
client.Nickname = newNickname
|
||||
client.Server.UpdateClientNick(client, nickname)
|
||||
} 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 {
|
||||
client.Nickname = newNickname
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user