Skip to content

Commit

Permalink
Merge pull request #60 from go-irc/nick-collision-startup
Browse files Browse the repository at this point in the history
Only handle nick collisions during the handshake
  • Loading branch information
belak committed Dec 13, 2017
2 parents cbbf18f + 8bddab3 commit a56998f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions client.go
Expand Up @@ -14,12 +14,23 @@ import (
var clientFilters = map[string]func(*Client, *Message){
"001": func(c *Client, m *Message) {
c.currentNick = m.Params[0]
c.connected = true
},
"433": func(c *Client, m *Message) {
// We only want to try and handle nick collisions during the initial
// handshake.
if c.connected {
return
}
c.currentNick = c.currentNick + "_"
c.Writef("NICK :%s", c.currentNick)
},
"437": func(c *Client, m *Message) {
// We only want to try and handle nick collisions during the initial
// handshake.
if c.connected {
return
}
c.currentNick = c.currentNick + "_"
c.Writef("NICK :%s", c.currentNick)
},
Expand Down Expand Up @@ -87,6 +98,7 @@ type Client struct {
limiter chan struct{}
incomingPongChan chan string
errChan chan error
connected bool
}

// NewClient creates a client given an io stream and a client config.
Expand Down
22 changes: 22 additions & 0 deletions client_test.go
Expand Up @@ -84,6 +84,28 @@ func TestClient(t *testing.T) {
SendLine("437\r\n"),
ExpectLine("NICK :test_nick_\r\n"),
})

assert.Equal(t, "test_nick_", c.CurrentNick())
c = runClientTest(t, config, io.EOF, []TestAction{
ExpectLine("PASS :test_pass\r\n"),
ExpectLine("NICK :test_nick\r\n"),
ExpectLine("USER test_user 0.0.0.0 0.0.0.0 :test_name\r\n"),
SendLine("433\r\n"),
ExpectLine("NICK :test_nick_\r\n"),
SendLine("001 :test_nick_\r\n"),
SendLine("433\r\n"),
})
assert.Equal(t, "test_nick_", c.CurrentNick())

c = runClientTest(t, config, io.EOF, []TestAction{
ExpectLine("PASS :test_pass\r\n"),
ExpectLine("NICK :test_nick\r\n"),
ExpectLine("USER test_user 0.0.0.0 0.0.0.0 :test_name\r\n"),
SendLine("437\r\n"),
ExpectLine("NICK :test_nick_\r\n"),
SendLine("001 :test_nick_\r\n"),
SendLine("437\r\n"),
})
assert.Equal(t, "test_nick_", c.CurrentNick())
}

Expand Down

0 comments on commit a56998f

Please sign in to comment.