diff --git a/irc/client.go b/irc/client.go index 0c64fe2e..a11ae61f 100644 --- a/irc/client.go +++ b/irc/client.go @@ -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) { diff --git a/irc/conn.go b/irc/conn.go index 5bab21ab..157a2759 100644 --- a/irc/conn.go +++ b/irc/conn.go @@ -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 } } diff --git a/server/irc_handler.go b/server/irc_handler.go index 7850076f..b6946fb8 100644 --- a/server/irc_handler.go +++ b/server/irc_handler.go @@ -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) { diff --git a/server/websocket_handler.go b/server/websocket_handler.go index e25ced65..05b27087 100644 --- a/server/websocket_handler.go +++ b/server/websocket_handler.go @@ -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) } }