From 87867c735206b2b7271970d5e8a57fce94f31cf1 Mon Sep 17 00:00:00 2001 From: blackbeard420 Date: Wed, 2 Sep 2020 23:02:03 -0400 Subject: [PATCH] reorder registration to comply with rfc2812/section-2.3 --- irc.go | 22 ++++++++++++++++++---- irc_test.go | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/irc.go b/irc.go index 8ea21b5..dad801a 100644 --- a/irc.go +++ b/irc.go @@ -93,6 +93,16 @@ func (c *Connection) SendNames(channel string) { c.Sock.Write([]byte(fmt.Sprintf("NAMES %s\n", channel))) } +//SendPass sends a PASS for network +func (c *Connection) SendPass(pass string) { + c.Sock.Write([]byte(fmt.Sprintf("PASS %s\n", pass))) +} + +//SendUser sends a USER command for the network +func (c *Connection) SendUser(user, realname string) { + c.Sock.Write([]byte(fmt.Sprintf("USER %s * * :%s\n", user, realname))) +} + //DelayedSend sends a privmsg AFTER the specified delay func (c *Connection) DelayedSend(sock net.Conn, dur time.Duration, channel, msg string) { time.Sleep(dur) @@ -108,12 +118,16 @@ func NewConnection(server, nick, user string, pass *string, chans []string) *Con log.Fatalln(err.Error()) } irc.Sock = sock - irc.Sock.Write([]byte(fmt.Sprintf("USER %s * * :%s\n", user, user))) + + if pass != nil { + irc.SendPass(*pass) + } + irc.SendNick(nick) irc.curNick = nick - if pass != nil { - irc.Sock.Write([]byte(fmt.Sprintf("PASS %s\n", *pass))) - } + + irc.SendUser(user, user) + return irc } diff --git a/irc_test.go b/irc_test.go index 96be70a..c4dd64d 100644 --- a/irc_test.go +++ b/irc_test.go @@ -12,7 +12,7 @@ func TestSimpleIrc(t *testing.T) { go con.Run() - time.Sleep(30 * time.Second) + time.Sleep(10 * time.Second) con.SendPrivmsg("#freedom", "\x0356 FUCK YALL BITCHES")