Improve nick change handling

This commit is contained in:
Ken-Håvard Lieng 2017-04-11 06:04:59 +02:00
parent 0a6d8bfb20
commit e84f2dd993
4 changed files with 22 additions and 8 deletions

View File

@ -64,6 +64,12 @@ func (c *Client) GetNick() string {
return c.nick
}
func (c *Client) setNick(nick string) {
c.lock.Lock()
c.nick = nick
c.lock.Unlock()
}
func (c *Client) Connected() bool {
c.lock.Lock()
defer c.lock.Unlock()
@ -73,10 +79,6 @@ func (c *Client) Connected() bool {
func (c *Client) Nick(nick string) {
c.Write("NICK " + nick)
c.lock.Lock()
c.nick = nick
c.lock.Unlock()
}
func (c *Client) Oper(name, password string) {

View File

@ -175,7 +175,6 @@ func (c *Client) recv() {
}
msg := parseMessage(line)
c.Messages <- msg
switch msg.Command {
case Ping:
@ -186,14 +185,24 @@ func (c *Client) recv() {
c.addChannel(msg.Params[0])
}
case Nick:
if msg.Nick == c.GetNick() {
c.setNick(msg.LastParam())
}
case ReplyWelcome:
c.once.Do(c.ready.Done)
case ErrNicknameInUse:
if c.HandleNickInUse != nil {
c.nick = c.HandleNickInUse(c.nick)
c.writeNick(c.nick)
newNick := c.HandleNickInUse(msg.Params[1])
// Set the nick here aswell incase this happens during registration
// since there will be no NICK message to confirm it then
c.setNick(newNick)
go c.writeNick(newNick)
}
}
c.Messages <- msg
}
}

View File

@ -63,6 +63,10 @@ func (i *ircHandler) nick(msg *irc.Message) {
})
channelStore.RenameUser(msg.Nick, msg.LastParam(), i.client.Host)
if msg.LastParam() == i.client.GetNick() {
go i.session.user.SetNick(msg.LastParam(), i.client.Host)
}
}
func (i *ircHandler) join(msg *irc.Message) {

View File

@ -171,7 +171,6 @@ func (h *wsHandler) nick(b []byte) {
if i, ok := h.session.getIRC(data.Server); ok {
i.Nick(data.New)
go h.session.user.SetNick(data.New, data.Server)
}
}