replaced some numeric handling
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
blackbeard420 2021-10-27 21:10:18 -04:00
parent b86c11aee1
commit a89349d1e3
3 changed files with 20 additions and 4 deletions

8
irc.go
View File

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

View File

@ -2,4 +2,8 @@ package irc
const (
RPL_LUSERCLIENT = 251
RPL_NAMREPLY = 353
RPL_ENDOFMOTD = 376
ERR_NOSUCHNICK = 401
)

View File

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