From ad00f7e35dc94c86f4252629a40c9d9c4ce2de36 Mon Sep 17 00:00:00 2001 From: clem1 Date: Sun, 6 Apr 2014 23:14:16 +0200 Subject: [PATCH 1/4] handlers: Arm a timer to get our nick back when it was already taken. --- client/handlers.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client/handlers.go b/client/handlers.go index 028267b..3b0a5f9 100644 --- a/client/handlers.go +++ b/client/handlers.go @@ -6,6 +6,7 @@ package client import ( "github.com/fluffle/goevent/event" "strings" + "time" ) // Consts for unnamed events. @@ -99,6 +100,13 @@ func (conn *Conn) h_433(line *Line) { // Args[1] is the new nick we were attempting to acquire neu := conn.NewNick(line.Args[1]) conn.Nick(neu) + // arm a timer to try get back our nick. + go func(old string) { + retry := 1 * time.Minute + for time.Sleep(retry); conn.cfg.Me.Nick != old; time.Sleep(retry) { + conn.Nick(old) + } + }(conn.cfg.Me.Nick) // if this is happening before we're properly connected (i.e. the nick // we sent in the initial NICK command is in use) we will not receive // a NICK message to confirm our change of nick, so ReNick here... From 94cee489f35c2f0fa78444e5b6c08c2aca3ae3a9 Mon Sep 17 00:00:00 2001 From: clem1 Date: Sun, 6 Apr 2014 23:23:11 +0200 Subject: [PATCH 2/4] . --- client/handlers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/handlers.go b/client/handlers.go index 3b0a5f9..773f770 100644 --- a/client/handlers.go +++ b/client/handlers.go @@ -103,10 +103,10 @@ func (conn *Conn) h_433(line *Line) { // arm a timer to try get back our nick. go func(old string) { retry := 1 * time.Minute - for time.Sleep(retry); conn.cfg.Me.Nick != old; time.Sleep(retry) { + for time.Sleep(retry); conn.Me.Nick != old; time.Sleep(retry) { conn.Nick(old) } - }(conn.cfg.Me.Nick) + }(conn.Me.Nick) // if this is happening before we're properly connected (i.e. the nick // we sent in the initial NICK command is in use) we will not receive // a NICK message to confirm our change of nick, so ReNick here... From 1a9907bfe4422e896a751bee9b98afb42540dae4 Mon Sep 17 00:00:00 2001 From: clem1 Date: Sun, 6 Apr 2014 23:24:57 +0200 Subject: [PATCH 3/4] . --- client/handlers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/handlers.go b/client/handlers.go index 773f770..4b3f936 100644 --- a/client/handlers.go +++ b/client/handlers.go @@ -106,7 +106,7 @@ func (conn *Conn) h_433(line *Line) { for time.Sleep(retry); conn.Me.Nick != old; time.Sleep(retry) { conn.Nick(old) } - }(conn.Me.Nick) + }(line.Args[1]) // if this is happening before we're properly connected (i.e. the nick // we sent in the initial NICK command is in use) we will not receive // a NICK message to confirm our change of nick, so ReNick here... From 06a1da17cf9e519fba8acb615539abb0a461510e Mon Sep 17 00:00:00 2001 From: clem1 Date: Sun, 6 Apr 2014 23:27:28 +0200 Subject: [PATCH 4/4] . --- client/mocknetconn_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/mocknetconn_test.go b/client/mocknetconn_test.go index 76835f9..992a41c 100644 --- a/client/mocknetconn_test.go +++ b/client/mocknetconn_test.go @@ -136,11 +136,11 @@ func (m *mockNetConn) Close() error { } func (m *mockNetConn) LocalAddr() net.Addr { - return &net.IPAddr{net.IPv4(127, 0, 0, 1)} + return &net.IPAddr{IP: net.IPv4(127, 0, 0, 1)} } func (m *mockNetConn) RemoteAddr() net.Addr { - return &net.IPAddr{net.IPv4(127, 0, 0, 1)} + return &net.IPAddr{IP: net.IPv4(127, 0, 0, 1)} } func (m *mockNetConn) SetDeadline(t time.Time) error {