From a89349d1e351a5c428a3ae87e72f37c624a77c2d Mon Sep 17 00:00:00 2001 From: blackbeard420 Date: Wed, 27 Oct 2021 21:10:18 -0400 Subject: [PATCH] replaced some numeric handling --- irc.go | 8 ++++---- irc_replies.go | 4 ++++ irc_test.go | 12 ++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/irc.go b/irc.go index 9380405..86178d0 100644 --- a/irc.go +++ b/irc.go @@ -225,10 +225,10 @@ func (c *Connection) parseMessage(line string) { cmd := params[1] args := params[2] - if _, e := strconv.Atoi(cmd); e == nil { + if code, e := strconv.Atoi(cmd); e == nil { //numeric message if !c.joined { - if cmd == "376" { + if code == RPL_ENDOFMOTD { for _, v := range c.channels { c.SendJoin(v) } @@ -236,7 +236,7 @@ func (c *Connection) parseMessage(line string) { } } - if cmd == "353" { + if code == RPL_NAMREPLY { params := strings.SplitN(args, " ", 4) target := strings.TrimSpace(params[2]) c.updateNicks(target, strings.Split(params[3][1:], " ")) @@ -289,7 +289,7 @@ func (c *Connection) parseMessage(line string) { c.NickCallback(from, msg) } default: - log.Printf("unhandled command: %s %s %s", cmd, target, msg) + //log.Printf("unhandled command: %s %s %s", cmd, target, msg) } } } diff --git a/irc_replies.go b/irc_replies.go index 1939bf4..644a60c 100644 --- a/irc_replies.go +++ b/irc_replies.go @@ -2,4 +2,8 @@ package irc const ( RPL_LUSERCLIENT = 251 + RPL_NAMREPLY = 353 + RPL_ENDOFMOTD = 376 + + ERR_NOSUCHNICK = 401 ) diff --git a/irc_test.go b/irc_test.go index e14061e..4beff36 100644 --- a/irc_test.go +++ b/irc_test.go @@ -1,7 +1,9 @@ package irc import ( + "fmt" "log" + "strings" "testing" "time" ) @@ -39,6 +41,16 @@ func TestLusers(t *testing.T) { con.NumericCallback = func(from string, i int, args string) { if i == RPL_LUSERCLIENT { log.Printf("luser reply: %s\n", args) + con.SendJoin(channel) + + s := strings.Split(args, ":") + if len(s) > 1 { + users := 0 + invis := 0 + servers := 0 + fmt.Sscanf(s[1], "There are %d users and %d invisible on %d servers", &users, &invis, &servers) + con.SendPrivmsg(channel, fmt.Sprintf("total users on network: %d, invisible %d, servers %d", users, invis, servers)) + } con.SendQuit("scan complete") } }