reorder registration to comply with rfc2812/section-2.3

This commit is contained in:
blackbeard420 2020-09-02 23:02:03 -04:00
parent 3c49159982
commit 87867c7352
2 changed files with 19 additions and 5 deletions

22
irc.go
View File

@ -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
}

View File

@ -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")