mirror of
				https://github.com/fluffle/goirc
				synced 2025-11-04 03:58:03 +00:00 
			
		
		
		
	Merge remote-tracking branch 'fluffle/master' into commandmerge
Conflicts: client.go client/connection.go client/handlers.go
This commit is contained in:
		
						commit
						a0f52c076f
					
				
					 7 changed files with 171 additions and 124 deletions
				
			
		
							
								
								
									
										26
									
								
								README.md
									
										
									
									
									
								
							
							
						
						
									
										26
									
								
								README.md
									
										
									
									
									
								
							| 
						 | 
					@ -13,14 +13,18 @@ There is some example code that demonstrates usage of the library in `client.go`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Synopsis:
 | 
					Synopsis:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    import "flag"
 | 
					 | 
				
			||||||
	import irc "github.com/fluffle/goirc/client"
 | 
						import irc "github.com/fluffle/goirc/client"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	func main() {
 | 
						func main() {
 | 
				
			||||||
        flag.Parse() // parses the logging flags.
 | 
							// Creating a simple IRC client is simple.
 | 
				
			||||||
		c := irc.Client("nick")
 | 
							c := irc.SimpleClient("nick")
 | 
				
			||||||
		// Optionally, enable SSL
 | 
					
 | 
				
			||||||
		c.SSL = true
 | 
							// Or, create a config and fiddle with it first:
 | 
				
			||||||
 | 
							cfg := irc.NewConfig("nick")
 | 
				
			||||||
 | 
							cfg.SSL = true
 | 
				
			||||||
 | 
							cfg.Server = "irc.freenode.net:7000"
 | 
				
			||||||
 | 
							cfg.NewNick = func(n string) string { return n + "^" }
 | 
				
			||||||
 | 
							c := irc.Client(cfg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Add handlers to do things here!
 | 
							// Add handlers to do things here!
 | 
				
			||||||
		// e.g. join a channel on connect.
 | 
							// e.g. join a channel on connect.
 | 
				
			||||||
| 
						 | 
					@ -39,8 +43,16 @@ Synopsis:
 | 
				
			||||||
>>>>>>> fluffle/master
 | 
					>>>>>>> fluffle/master
 | 
				
			||||||
			func(conn *irc.Conn, line *irc.Line) { quit <- true })
 | 
								func(conn *irc.Conn, line *irc.Line) { quit <- true })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Tell client to connect
 | 
							// Tell client to connect.
 | 
				
			||||||
		if err := c.Connect("irc.freenode.net"); err != nil {
 | 
							if err := c.Connect(); err != nil {
 | 
				
			||||||
 | 
								fmt.Printf("Connection error: %s\n", err.String())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// With a "simple" client, set Server before calling Connect...
 | 
				
			||||||
 | 
							c.Config().Server = "irc.freenode.net"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// ... or, use ConnectTo instead.
 | 
				
			||||||
 | 
							if err := c.ConnectTo("irc.freenode.net"); err != nil {
 | 
				
			||||||
			fmt.Printf("Connection error: %s\n", err.String())
 | 
								fmt.Printf("Connection error: %s\n", err.String())
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										11
									
								
								client.go
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								client.go
									
										
									
									
									
								
							| 
						 | 
					@ -21,7 +21,7 @@ func main() {
 | 
				
			||||||
	flag.Parse()
 | 
						flag.Parse()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// create new IRC connection
 | 
						// create new IRC connection
 | 
				
			||||||
	c := irc.Client(*nick, *ident, *name)
 | 
						c := irc.SimpleClient(*nick, *ident, *name)
 | 
				
			||||||
	c.EnableStateTracking()
 | 
						c.EnableStateTracking()
 | 
				
			||||||
	c.HandleFunc(irc.CONNECTED,
 | 
						c.HandleFunc(irc.CONNECTED,
 | 
				
			||||||
		func(conn *irc.Conn, line *irc.Line) { conn.Join(*channel) })
 | 
							func(conn *irc.Conn, line *irc.Line) { conn.Join(*channel) })
 | 
				
			||||||
| 
						 | 
					@ -88,10 +88,10 @@ func main() {
 | 
				
			||||||
				case cmd[1] == 'f':
 | 
									case cmd[1] == 'f':
 | 
				
			||||||
					if len(cmd) > 2 && cmd[2] == 'e' {
 | 
										if len(cmd) > 2 && cmd[2] == 'e' {
 | 
				
			||||||
						// enable flooding
 | 
											// enable flooding
 | 
				
			||||||
						c.Flood = true
 | 
											c.Config().Flood = true
 | 
				
			||||||
					} else if len(cmd) > 2 && cmd[2] == 'd' {
 | 
										} else if len(cmd) > 2 && cmd[2] == 'd' {
 | 
				
			||||||
						// disable flooding
 | 
											// disable flooding
 | 
				
			||||||
						c.Flood = false
 | 
											c.Config().Flood = false
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					for i := 0; i < 20; i++ {
 | 
										for i := 0; i < 20; i++ {
 | 
				
			||||||
						c.Privmsg("#", "flood test!")
 | 
											c.Privmsg("#", "flood test!")
 | 
				
			||||||
| 
						 | 
					@ -114,8 +114,13 @@ func main() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for !reallyquit {
 | 
						for !reallyquit {
 | 
				
			||||||
		// connect to server
 | 
							// connect to server
 | 
				
			||||||
 | 
					<<<<<<< HEAD
 | 
				
			||||||
		if err := c.Connect(*host); err != nil {
 | 
							if err := c.Connect(*host); err != nil {
 | 
				
			||||||
			fmt.Printf("Error %v", err)
 | 
								fmt.Printf("Error %v", err)
 | 
				
			||||||
 | 
					=======
 | 
				
			||||||
 | 
							if err := c.ConnectTo(*host); err != nil {
 | 
				
			||||||
 | 
								fmt.Printf("Connection error: %s\n", err)
 | 
				
			||||||
 | 
					>>>>>>> fluffle/master
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		// wait on quit channel
 | 
							// wait on quit channel
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,26 +3,19 @@ package client
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"bufio"
 | 
						"bufio"
 | 
				
			||||||
	"crypto/tls"
 | 
						"crypto/tls"
 | 
				
			||||||
	"errors"
 | 
					 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"github.com/fluffle/goirc/state"
 | 
						"github.com/fluffle/goirc/state"
 | 
				
			||||||
	"github.com/fluffle/golog/logging"
 | 
						"github.com/fluffle/golog/logging"
 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
						"sync"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// An IRC connection is represented by this struct.
 | 
					// An IRC connection is represented by this struct.
 | 
				
			||||||
type Conn struct {
 | 
					type Conn struct {
 | 
				
			||||||
	// Connection related vars people will care about
 | 
						// For preventing races on (dis)connect.
 | 
				
			||||||
	Me        *state.Nick
 | 
						mu sync.Mutex
 | 
				
			||||||
	Host      string
 | 
					 | 
				
			||||||
	Network   string
 | 
					 | 
				
			||||||
	Connected bool
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Deprecated: future work to turn Conn into an interface will break this.
 | 
					 | 
				
			||||||
	// Use the State field to store external state that handlers might need.
 | 
					 | 
				
			||||||
	State interface{}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Contains parameters that people can tweak to change client behaviour.
 | 
						// Contains parameters that people can tweak to change client behaviour.
 | 
				
			||||||
	cfg *Config
 | 
						cfg *Config
 | 
				
			||||||
| 
						 | 
					@ -40,6 +33,7 @@ type Conn struct {
 | 
				
			||||||
	io        *bufio.ReadWriter
 | 
						io        *bufio.ReadWriter
 | 
				
			||||||
	in        chan *Line
 | 
						in        chan *Line
 | 
				
			||||||
	out       chan string
 | 
						out       chan string
 | 
				
			||||||
 | 
						connected bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Control channels to goroutines
 | 
						// Control channels to goroutines
 | 
				
			||||||
	cSend, cLoop, cPing chan bool
 | 
						cSend, cLoop, cPing chan bool
 | 
				
			||||||
| 
						 | 
					@ -54,6 +48,9 @@ type Config struct {
 | 
				
			||||||
	// Set this to provide the Nick, Ident and Name for the client to use.
 | 
						// Set this to provide the Nick, Ident and Name for the client to use.
 | 
				
			||||||
	Me *state.Nick
 | 
						Me *state.Nick
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Hostname to connect to and optional connect password.
 | 
				
			||||||
 | 
						Server, Pass string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Are we connecting via SSL? Do we care about certificate validity?
 | 
						// Are we connecting via SSL? Do we care about certificate validity?
 | 
				
			||||||
	SSL       bool
 | 
						SSL       bool
 | 
				
			||||||
	SSLConfig *tls.Config
 | 
						SSLConfig *tls.Config
 | 
				
			||||||
| 
						 | 
					@ -72,38 +69,35 @@ type Config struct {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewConfig(nick string, args ...string) *Config {
 | 
					func NewConfig(nick string, args ...string) *Config {
 | 
				
			||||||
	ident := "goirc"
 | 
					 | 
				
			||||||
	name := "Powered by GoIRC"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if len(args) > 0 && args[0] != "" {
 | 
					 | 
				
			||||||
		ident = args[0]
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if len(args) > 1 && args[1] != "" {
 | 
					 | 
				
			||||||
		name = args[1]
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	cfg := &Config{
 | 
						cfg := &Config{
 | 
				
			||||||
 | 
							Me:       state.NewNick(nick),
 | 
				
			||||||
		PingFreq: 3 * time.Minute,
 | 
							PingFreq: 3 * time.Minute,
 | 
				
			||||||
		NewNick:  func(s string) string { return s + "_" },
 | 
							NewNick:  func(s string) string { return s + "_" },
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	cfg.Me = state.NewNick(nick)
 | 
						cfg.Me.Ident = "goirc"
 | 
				
			||||||
	cfg.Me.Ident = ident
 | 
						if len(args) > 0 && args[0] != "" {
 | 
				
			||||||
	cfg.Me.Name = name
 | 
							cfg.Me.Ident = args[0]
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						cfg.Me.Name = "Powered by GoIRC"
 | 
				
			||||||
 | 
						if len(args) > 1 && args[1] != "" {
 | 
				
			||||||
 | 
							cfg.Me.Name = args[1]
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return cfg
 | 
						return cfg
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Creates a new IRC connection object, but doesn't connect to anything so
 | 
					// Creates a new IRC connection object, but doesn't connect to anything so
 | 
				
			||||||
// that you can add event handlers to it. See AddHandler() for details
 | 
					// that you can add event handlers to it. See AddHandler() for details
 | 
				
			||||||
func SimpleClient(nick string, args ...string) (*Conn, error) {
 | 
					func SimpleClient(nick string, args ...string) *Conn {
 | 
				
			||||||
	return Client(NewConfig(nick, args...))
 | 
						conn, _ := Client(NewConfig(nick, args...))
 | 
				
			||||||
 | 
						return conn
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func Client(cfg *Config) (*Conn, error) {
 | 
					func Client(cfg *Config) (*Conn, error) {
 | 
				
			||||||
	logging.InitFromFlags()
 | 
						logging.InitFromFlags()
 | 
				
			||||||
	if cfg.Me == nil || cfg.Me.Nick == "" || cfg.Me.Ident == "" {
 | 
						if cfg.Me == nil || cfg.Me.Nick == "" || cfg.Me.Ident == "" {
 | 
				
			||||||
		return nil, fmt.Errorf("Must provide a valid state.Nick in cfg.Me.")
 | 
							return nil, fmt.Errorf("irc.Client(): Both cfg.Nick and cfg.Ident must be non-empty.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	conn := &Conn{
 | 
						conn := &Conn{
 | 
				
			||||||
		Me:         cfg.Me,
 | 
					 | 
				
			||||||
		cfg:        cfg,
 | 
							cfg:        cfg,
 | 
				
			||||||
		in:         make(chan *Line, 32),
 | 
							in:         make(chan *Line, 32),
 | 
				
			||||||
		out:        make(chan string, 32),
 | 
							out:        make(chan string, 32),
 | 
				
			||||||
| 
						 | 
					@ -120,17 +114,29 @@ func Client(cfg *Config) (*Conn, error) {
 | 
				
			||||||
	return conn, nil
 | 
						return conn, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (conn *Conn) Connected() bool {
 | 
				
			||||||
 | 
						return conn.connected
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (conn *Conn) Config() *Config {
 | 
					func (conn *Conn) Config() *Config {
 | 
				
			||||||
	return conn.cfg
 | 
						return conn.cfg
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (conn *Conn) Me() *state.Nick {
 | 
				
			||||||
 | 
						return conn.cfg.Me
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (conn *Conn) StateTracker() state.Tracker {
 | 
				
			||||||
 | 
						return conn.st
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (conn *Conn) EnableStateTracking() {
 | 
					func (conn *Conn) EnableStateTracking() {
 | 
				
			||||||
	if conn.st == nil {
 | 
						if conn.st == nil {
 | 
				
			||||||
		n := conn.Me
 | 
							n := conn.cfg.Me
 | 
				
			||||||
		conn.st = state.NewTracker(n.Nick)
 | 
							conn.st = state.NewTracker(n.Nick)
 | 
				
			||||||
		conn.Me = conn.st.Me()
 | 
							conn.cfg.Me = conn.st.Me()
 | 
				
			||||||
		conn.Me.Ident = n.Ident
 | 
							conn.cfg.Me.Ident = n.Ident
 | 
				
			||||||
		conn.Me.Name = n.Name
 | 
							conn.cfg.Me.Name = n.Name
 | 
				
			||||||
		conn.addSTHandlers()
 | 
							conn.addSTHandlers()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -143,10 +149,6 @@ func (conn *Conn) DisableStateTracking() {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (conn *Conn) StateTracker() state.Tracker {
 | 
					 | 
				
			||||||
	return conn.st
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Per-connection state initialisation.
 | 
					// Per-connection state initialisation.
 | 
				
			||||||
func (conn *Conn) initialise() {
 | 
					func (conn *Conn) initialise() {
 | 
				
			||||||
	conn.io = nil
 | 
						conn.io = nil
 | 
				
			||||||
| 
						 | 
					@ -161,43 +163,48 @@ func (conn *Conn) initialise() {
 | 
				
			||||||
// on the connection to the IRC server, set Conn.SSL to true before calling
 | 
					// on the connection to the IRC server, set Conn.SSL to true before calling
 | 
				
			||||||
// Connect(). The port will default to 6697 if ssl is enabled, and 6667
 | 
					// Connect(). The port will default to 6697 if ssl is enabled, and 6667
 | 
				
			||||||
// otherwise. You can also provide an optional connect password.
 | 
					// otherwise. You can also provide an optional connect password.
 | 
				
			||||||
func (conn *Conn) Connect(host string, pass ...string) error {
 | 
					func (conn *Conn) ConnectTo(host string, pass ...string) error {
 | 
				
			||||||
	if conn.Connected {
 | 
						conn.cfg.Server = host
 | 
				
			||||||
		return errors.New(fmt.Sprintf(
 | 
					 | 
				
			||||||
			"irc.Connect(): already connected to %s, cannot connect to %s",
 | 
					 | 
				
			||||||
			conn.Host, host))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if conn.cfg.SSL {
 | 
					 | 
				
			||||||
		if !hasPort(host) {
 | 
					 | 
				
			||||||
			host += ":6697"
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		logging.Info("irc.Connect(): Connecting to %s with SSL.", host)
 | 
					 | 
				
			||||||
		if s, err := tls.Dial("tcp", host, conn.cfg.SSLConfig); err == nil {
 | 
					 | 
				
			||||||
			conn.sock = s
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			return err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		if !hasPort(host) {
 | 
					 | 
				
			||||||
			host += ":6667"
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		logging.Info("irc.Connect(): Connecting to %s without SSL.", host)
 | 
					 | 
				
			||||||
		if s, err := net.Dial("tcp", host); err == nil {
 | 
					 | 
				
			||||||
			conn.sock = s
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			return err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	conn.Host = host
 | 
					 | 
				
			||||||
	conn.Connected = true
 | 
					 | 
				
			||||||
	conn.postConnect()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if len(pass) > 0 {
 | 
						if len(pass) > 0 {
 | 
				
			||||||
		conn.Pass(pass[0])
 | 
							conn.cfg.Pass = pass[0]
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	conn.Nick(conn.Me.Nick)
 | 
						return conn.Connect()
 | 
				
			||||||
	conn.User(conn.Me.Ident, conn.Me.Name)
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (conn *Conn) Connect() error {
 | 
				
			||||||
 | 
						conn.mu.Lock()
 | 
				
			||||||
 | 
						defer conn.mu.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if conn.cfg.Server == "" {
 | 
				
			||||||
 | 
							return fmt.Errorf("irc.Connect(): cfg.Server must be non-empty")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if conn.connected {
 | 
				
			||||||
 | 
							return fmt.Errorf("irc.Connect(): Cannot connect to %s, already connected.", conn.cfg.Server)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if conn.cfg.SSL {
 | 
				
			||||||
 | 
							if !hasPort(conn.cfg.Server) {
 | 
				
			||||||
 | 
								conn.cfg.Server += ":6697"
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							logging.Info("irc.Connect(): Connecting to %s with SSL.", conn.cfg.Server)
 | 
				
			||||||
 | 
							if s, err := tls.Dial("tcp", conn.cfg.Server, conn.cfg.SSLConfig); err == nil {
 | 
				
			||||||
 | 
								conn.sock = s
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							if !hasPort(conn.cfg.Server) {
 | 
				
			||||||
 | 
								conn.cfg.Server += ":6667"
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							logging.Info("irc.Connect(): Connecting to %s without SSL.", conn.cfg.Server)
 | 
				
			||||||
 | 
							if s, err := net.Dial("tcp", conn.cfg.Server); err == nil {
 | 
				
			||||||
 | 
								conn.sock = s
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						conn.connected = true
 | 
				
			||||||
 | 
						conn.postConnect()
 | 
				
			||||||
 | 
						conn.dispatch(&Line{Cmd: REGISTER})
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -330,10 +337,14 @@ func (conn *Conn) rateLimit(chars int) time.Duration {
 | 
				
			||||||
func (conn *Conn) shutdown() {
 | 
					func (conn *Conn) shutdown() {
 | 
				
			||||||
	// Guard against double-call of shutdown() if we get an error in send()
 | 
						// Guard against double-call of shutdown() if we get an error in send()
 | 
				
			||||||
	// as calling sock.Close() will cause recv() to receive EOF in readstring()
 | 
						// as calling sock.Close() will cause recv() to receive EOF in readstring()
 | 
				
			||||||
	if conn.Connected {
 | 
						conn.mu.Lock()
 | 
				
			||||||
 | 
						defer conn.mu.Unlock()
 | 
				
			||||||
 | 
						if !conn.connected {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	logging.Info("irc.shutdown(): Disconnected from server.")
 | 
						logging.Info("irc.shutdown(): Disconnected from server.")
 | 
				
			||||||
		conn.dispatch(&Line{Cmd: "disconnected"})
 | 
						conn.dispatch(&Line{Cmd: DISCONNECTED})
 | 
				
			||||||
		conn.Connected = false
 | 
						conn.connected = false
 | 
				
			||||||
	conn.sock.Close()
 | 
						conn.sock.Close()
 | 
				
			||||||
	conn.cSend <- true
 | 
						conn.cSend <- true
 | 
				
			||||||
	conn.cLoop <- true
 | 
						conn.cLoop <- true
 | 
				
			||||||
| 
						 | 
					@ -342,19 +353,18 @@ func (conn *Conn) shutdown() {
 | 
				
			||||||
	// do this here rather than after runLoop()'s for due to race
 | 
						// do this here rather than after runLoop()'s for due to race
 | 
				
			||||||
	conn.initialise()
 | 
						conn.initialise()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Dumps a load of information about the current state of the connection to a
 | 
					// Dumps a load of information about the current state of the connection to a
 | 
				
			||||||
// string for debugging state tracking and other such things.
 | 
					// string for debugging state tracking and other such things.
 | 
				
			||||||
func (conn *Conn) String() string {
 | 
					func (conn *Conn) String() string {
 | 
				
			||||||
	str := "GoIRC Connection\n"
 | 
						str := "GoIRC Connection\n"
 | 
				
			||||||
	str += "----------------\n\n"
 | 
						str += "----------------\n\n"
 | 
				
			||||||
	if conn.Connected {
 | 
						if conn.connected {
 | 
				
			||||||
		str += "Connected to " + conn.Host + "\n\n"
 | 
							str += "Connected to " + conn.cfg.Server + "\n\n"
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		str += "Not currently connected!\n\n"
 | 
							str += "Not currently connected!\n\n"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	str += conn.Me.String() + "\n"
 | 
						str += conn.cfg.Me.String() + "\n"
 | 
				
			||||||
	if conn.st != nil {
 | 
						if conn.st != nil {
 | 
				
			||||||
		str += conn.st.String() + "\n"
 | 
							str += conn.st.String() + "\n"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,13 +21,13 @@ func setUp(t *testing.T, start ...bool) (*Conn, *testState) {
 | 
				
			||||||
	ctrl := gomock.NewController(t)
 | 
						ctrl := gomock.NewController(t)
 | 
				
			||||||
	st := state.NewMockTracker(ctrl)
 | 
						st := state.NewMockTracker(ctrl)
 | 
				
			||||||
	nc := MockNetConn(t)
 | 
						nc := MockNetConn(t)
 | 
				
			||||||
	c, _ := SimpleClient("test", "test", "Testing IRC")
 | 
						c := SimpleClient("test", "test", "Testing IRC")
 | 
				
			||||||
	logging.SetLogLevel(logging.LogFatal)
 | 
						logging.SetLogLevel(logging.LogFatal)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c.st = st
 | 
						c.st = st
 | 
				
			||||||
	c.sock = nc
 | 
						c.sock = nc
 | 
				
			||||||
	c.cfg.Flood = true // Tests can take a while otherwise
 | 
						c.cfg.Flood = true // Tests can take a while otherwise
 | 
				
			||||||
	c.Connected = true
 | 
						c.connected = true
 | 
				
			||||||
	if len(start) == 0 {
 | 
						if len(start) == 0 {
 | 
				
			||||||
		// Hack to allow tests of send, recv, write etc.
 | 
							// Hack to allow tests of send, recv, write etc.
 | 
				
			||||||
		// NOTE: the value of the boolean doesn't matter.
 | 
							// NOTE: the value of the boolean doesn't matter.
 | 
				
			||||||
| 
						 | 
					@ -70,7 +70,7 @@ func TestEOF(t *testing.T) {
 | 
				
			||||||
	<-time.After(time.Millisecond)
 | 
						<-time.After(time.Millisecond)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Verify that the connection no longer thinks it's connected
 | 
						// Verify that the connection no longer thinks it's connected
 | 
				
			||||||
	if c.Connected {
 | 
						if c.connected {
 | 
				
			||||||
		t.Errorf("Conn still thinks it's connected to the server.")
 | 
							t.Errorf("Conn still thinks it's connected to the server.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -83,12 +83,12 @@ func TestEOF(t *testing.T) {
 | 
				
			||||||
func TestClientAndStateTracking(t *testing.T) {
 | 
					func TestClientAndStateTracking(t *testing.T) {
 | 
				
			||||||
	ctrl := gomock.NewController(t)
 | 
						ctrl := gomock.NewController(t)
 | 
				
			||||||
	st := state.NewMockTracker(ctrl)
 | 
						st := state.NewMockTracker(ctrl)
 | 
				
			||||||
	c, _ := SimpleClient("test", "test", "Testing IRC")
 | 
						c := SimpleClient("test", "test", "Testing IRC")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Assert some basic things about the initial state of the Conn struct
 | 
						// Assert some basic things about the initial state of the Conn struct
 | 
				
			||||||
	if c.Me.Nick != "test" || c.Me.Ident != "test" ||
 | 
						if me := c.cfg.Me; me.Nick != "test" || me.Ident != "test" ||
 | 
				
			||||||
		c.Me.Name != "Testing IRC" || c.Me.Host != "" {
 | 
							me.Name != "Testing IRC" || me.Host != "" {
 | 
				
			||||||
		t.Errorf("Conn.Me not correctly initialised.")
 | 
							t.Errorf("Conn.cfg.Me not correctly initialised.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// Check that the internal handlers are correctly set up
 | 
						// Check that the internal handlers are correctly set up
 | 
				
			||||||
	for k, _ := range intHandlers {
 | 
						for k, _ := range intHandlers {
 | 
				
			||||||
| 
						 | 
					@ -110,20 +110,20 @@ func TestClientAndStateTracking(t *testing.T) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// We're expecting the untracked me to be replaced by a tracked one
 | 
						// We're expecting the untracked me to be replaced by a tracked one
 | 
				
			||||||
	if c.Me.Nick != "test" || c.Me.Ident != "test" ||
 | 
						if me := c.cfg.Me; me.Nick != "test" || me.Ident != "test" ||
 | 
				
			||||||
		c.Me.Name != "Testing IRC" || c.Me.Host != "" {
 | 
							me.Name != "Testing IRC" || me.Host != "" {
 | 
				
			||||||
		t.Errorf("Enabling state tracking did not replace Me correctly.")
 | 
							t.Errorf("Enabling state tracking did not replace Me correctly.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if c.st == nil || c.Me != c.st.Me() {
 | 
						if c.st == nil || c.cfg.Me != c.st.Me() {
 | 
				
			||||||
		t.Errorf("State tracker not enabled correctly.")
 | 
							t.Errorf("State tracker not enabled correctly.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Now, shim in the mock state tracker and test disabling state tracking
 | 
						// Now, shim in the mock state tracker and test disabling state tracking
 | 
				
			||||||
	me := c.Me
 | 
						me := c.cfg.Me
 | 
				
			||||||
	c.st = st
 | 
						c.st = st
 | 
				
			||||||
	st.EXPECT().Wipe()
 | 
						st.EXPECT().Wipe()
 | 
				
			||||||
	c.DisableStateTracking()
 | 
						c.DisableStateTracking()
 | 
				
			||||||
	if c.st != nil || c.Me != me {
 | 
						if c.st != nil || c.cfg.Me != me {
 | 
				
			||||||
		t.Errorf("State tracker not disabled correctly.")
 | 
							t.Errorf("State tracker not disabled correctly.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,7 +40,7 @@ func (conn *Conn) h_REGISTER(line *Line) {
 | 
				
			||||||
	conn.User(conn.cfg.Me.Ident, conn.cfg.Me.Name)
 | 
						conn.User(conn.cfg.Me.Ident, conn.cfg.Me.Name)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Handler to trigger a "CONNECTED" event on receipt of numeric 001
 | 
					// Handler to trigger a CONNECTED event on receipt of numeric 001
 | 
				
			||||||
func (conn *Conn) h_001(line *Line) {
 | 
					func (conn *Conn) h_001(line *Line) {
 | 
				
			||||||
	// we're connected!
 | 
						// we're connected!
 | 
				
			||||||
	conn.dispatch(&Line{Cmd: CONNECTED})
 | 
						conn.dispatch(&Line{Cmd: CONNECTED})
 | 
				
			||||||
| 
						 | 
					@ -49,7 +49,7 @@ func (conn *Conn) h_001(line *Line) {
 | 
				
			||||||
	if idx := strings.LastIndex(t, " "); idx != -1 {
 | 
						if idx := strings.LastIndex(t, " "); idx != -1 {
 | 
				
			||||||
		t = t[idx+1:]
 | 
							t = t[idx+1:]
 | 
				
			||||||
		if idx = strings.Index(t, "@"); idx != -1 {
 | 
							if idx = strings.Index(t, "@"); idx != -1 {
 | 
				
			||||||
			conn.Me.Host = t[idx+1:]
 | 
								conn.cfg.Me.Host = t[idx+1:]
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -70,11 +70,11 @@ func (conn *Conn) h_433(line *Line) {
 | 
				
			||||||
	// if this is happening before we're properly connected (i.e. the 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
 | 
						// 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...
 | 
						// a NICK message to confirm our change of nick, so ReNick here...
 | 
				
			||||||
	if line.Args[1] == conn.Me.Nick {
 | 
						if line.Args[1] == conn.cfg.Me.Nick {
 | 
				
			||||||
		if conn.st != nil {
 | 
							if conn.st != nil {
 | 
				
			||||||
			conn.st.ReNick(conn.Me.Nick, neu)
 | 
								conn.st.ReNick(conn.cfg.Me.Nick, neu)
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			conn.Me.Nick = neu
 | 
								conn.cfg.Me.Nick = neu
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -98,9 +98,9 @@ func (conn *Conn) h_NICK(line *Line) {
 | 
				
			||||||
// Handle PRIVMSGs that trigger Commands
 | 
					// Handle PRIVMSGs that trigger Commands
 | 
				
			||||||
func (conn *Conn) h_PRIVMSG(line *Line) {
 | 
					func (conn *Conn) h_PRIVMSG(line *Line) {
 | 
				
			||||||
	text := line.Message()
 | 
						text := line.Message()
 | 
				
			||||||
	if conn.cfg.CommandStripNick && strings.HasPrefix(text, conn.Me.Nick) {
 | 
						if conn.cfg.CommandStripNick && strings.HasPrefix(text, conn.cfg.Me.Nick) {
 | 
				
			||||||
		// Look for '^${nick}[:;>,-]? '
 | 
							// Look for '^${nick}[:;>,-]? '
 | 
				
			||||||
		l := len(conn.Me.Nick)
 | 
							l := len(conn.cfg.Me.Nick)
 | 
				
			||||||
		switch text[l] {
 | 
							switch text[l] {
 | 
				
			||||||
		case ':', ';', '>', ',', '-':
 | 
							case ':', ';', '>', ',', '-':
 | 
				
			||||||
			l++
 | 
								l++
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,6 +19,26 @@ func TestPING(t *testing.T) {
 | 
				
			||||||
	s.nc.Expect("PONG :1234567890")
 | 
						s.nc.Expect("PONG :1234567890")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Test the REGISTER handler matches section 3.1 of rfc2812
 | 
				
			||||||
 | 
					func TestREGISTER(t *testing.T) {
 | 
				
			||||||
 | 
						c, s := setUp(t)
 | 
				
			||||||
 | 
						defer s.tearDown()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						c.h_REGISTER(&Line{Cmd: REGISTER})
 | 
				
			||||||
 | 
						s.nc.Expect("NICK test")
 | 
				
			||||||
 | 
						s.nc.Expect("USER test 12 * :Testing IRC")
 | 
				
			||||||
 | 
						s.nc.ExpectNothing()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						c.cfg.Pass = "12345"
 | 
				
			||||||
 | 
						c.cfg.Me.Ident = "idiot"
 | 
				
			||||||
 | 
						c.cfg.Me.Name = "I've got the same combination on my luggage!"
 | 
				
			||||||
 | 
						c.h_REGISTER(&Line{Cmd: REGISTER})
 | 
				
			||||||
 | 
						s.nc.Expect("PASS 12345")
 | 
				
			||||||
 | 
						s.nc.Expect("NICK test")
 | 
				
			||||||
 | 
						s.nc.Expect("USER idiot 12 * :I've got the same combination on my luggage!")
 | 
				
			||||||
 | 
						s.nc.ExpectNothing()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Test the handler for 001 / RPL_WELCOME
 | 
					// Test the handler for 001 / RPL_WELCOME
 | 
				
			||||||
func Test001(t *testing.T) {
 | 
					func Test001(t *testing.T) {
 | 
				
			||||||
	c, s := setUp(t)
 | 
						c, s := setUp(t)
 | 
				
			||||||
| 
						 | 
					@ -39,8 +59,8 @@ func Test001(t *testing.T) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check host parsed correctly
 | 
						// Check host parsed correctly
 | 
				
			||||||
	if c.Me.Host != "somehost.com" {
 | 
						if c.cfg.Me.Host != "somehost.com" {
 | 
				
			||||||
		t.Errorf("Host parsing failed, host is '%s'.", c.Me.Host)
 | 
							t.Errorf("Host parsing failed, host is '%s'.", c.cfg.Me.Host)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,13 +69,13 @@ func Test433(t *testing.T) {
 | 
				
			||||||
	c, s := setUp(t)
 | 
						c, s := setUp(t)
 | 
				
			||||||
	defer s.tearDown()
 | 
						defer s.tearDown()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Call handler with a 433 line, not triggering c.Me.Renick()
 | 
						// Call handler with a 433 line, not triggering c.cfg.Me.Renick()
 | 
				
			||||||
	c.h_433(parseLine(":irc.server.org 433 test new :Nickname is already in use."))
 | 
						c.h_433(parseLine(":irc.server.org 433 test new :Nickname is already in use."))
 | 
				
			||||||
	s.nc.Expect("NICK new_")
 | 
						s.nc.Expect("NICK new_")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// In this case, we're expecting the server to send a NICK line
 | 
						// In this case, we're expecting the server to send a NICK line
 | 
				
			||||||
	if c.Me.Nick != "test" {
 | 
						if c.cfg.Me.Nick != "test" {
 | 
				
			||||||
		t.Errorf("ReNick() called unexpectedly, Nick == '%s'.", c.Me.Nick)
 | 
							t.Errorf("ReNick() called unexpectedly, Nick == '%s'.", c.cfg.Me.Nick)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Send a line that will trigger a renick. This happens when our wanted
 | 
						// Send a line that will trigger a renick. This happens when our wanted
 | 
				
			||||||
| 
						 | 
					@ -66,11 +86,11 @@ func Test433(t *testing.T) {
 | 
				
			||||||
	c.h_433(parseLine(":irc.server.org 433 test test :Nickname is already in use."))
 | 
						c.h_433(parseLine(":irc.server.org 433 test test :Nickname is already in use."))
 | 
				
			||||||
	s.nc.Expect("NICK test_")
 | 
						s.nc.Expect("NICK test_")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Counter-intuitively, c.Me.Nick will not change in this case. This is an
 | 
						// Counter-intuitively, c.cfg.Me.Nick will not change in this case. This
 | 
				
			||||||
	// artifact of the test set-up, with a mocked out state tracker that
 | 
						// is an artifact of the test set-up, with a mocked out state tracker that
 | 
				
			||||||
	// doesn't actually change any state. Normally, this would be fine :-)
 | 
						// doesn't actually change any state. Normally, this would be fine :-)
 | 
				
			||||||
	if c.Me.Nick != "test" {
 | 
						if c.cfg.Me.Nick != "test" {
 | 
				
			||||||
		t.Errorf("My nick changed from '%s'.", c.Me.Nick)
 | 
							t.Errorf("My nick changed from '%s'.", c.cfg.Me.Nick)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Test the code path that *doesn't* involve state tracking.
 | 
						// Test the code path that *doesn't* involve state tracking.
 | 
				
			||||||
| 
						 | 
					@ -78,8 +98,8 @@ func Test433(t *testing.T) {
 | 
				
			||||||
	c.h_433(parseLine(":irc.server.org 433 test test :Nickname is already in use."))
 | 
						c.h_433(parseLine(":irc.server.org 433 test test :Nickname is already in use."))
 | 
				
			||||||
	s.nc.Expect("NICK test_")
 | 
						s.nc.Expect("NICK test_")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if c.Me.Nick != "test_" {
 | 
						if c.cfg.Me.Nick != "test_" {
 | 
				
			||||||
		t.Errorf("My nick not updated from '%s'.", c.Me.Nick)
 | 
							t.Errorf("My nick not updated from '%s'.", c.cfg.Me.Nick)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	c.st = s.st
 | 
						c.st = s.st
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -96,7 +116,7 @@ func TestNICK(t *testing.T) {
 | 
				
			||||||
	c.h_NICK(parseLine(":test!test@somehost.com NICK :test1"))
 | 
						c.h_NICK(parseLine(":test!test@somehost.com NICK :test1"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Verify that our Nick has changed
 | 
						// Verify that our Nick has changed
 | 
				
			||||||
	if c.Me.Nick != "test1" {
 | 
						if c.cfg.Me.Nick != "test1" {
 | 
				
			||||||
		t.Errorf("NICK did not result in changing our nick.")
 | 
							t.Errorf("NICK did not result in changing our nick.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -104,7 +124,7 @@ func TestNICK(t *testing.T) {
 | 
				
			||||||
	c.h_NICK(parseLine(":blah!moo@cows.com NICK :milk"))
 | 
						c.h_NICK(parseLine(":blah!moo@cows.com NICK :milk"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Verify that our Nick hasn't changed
 | 
						// Verify that our Nick hasn't changed
 | 
				
			||||||
	if c.Me.Nick != "test1" {
 | 
						if c.cfg.Me.Nick != "test1" {
 | 
				
			||||||
		t.Errorf("NICK did not result in changing our nick.")
 | 
							t.Errorf("NICK did not result in changing our nick.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -113,7 +133,7 @@ func TestNICK(t *testing.T) {
 | 
				
			||||||
	c.h_NICK(parseLine(":test1!test@somehost.com NICK :test2"))
 | 
						c.h_NICK(parseLine(":test1!test@somehost.com NICK :test2"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Verify that our Nick hasn't changed (should be handled by h_STNICK).
 | 
						// Verify that our Nick hasn't changed (should be handled by h_STNICK).
 | 
				
			||||||
	if c.Me.Nick != "test1" {
 | 
						if c.cfg.Me.Nick != "test1" {
 | 
				
			||||||
		t.Errorf("NICK changed our nick when state tracking enabled.")
 | 
							t.Errorf("NICK changed our nick when state tracking enabled.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -202,9 +222,9 @@ func TestJOIN(t *testing.T) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gomock.InOrder(
 | 
						gomock.InOrder(
 | 
				
			||||||
		s.st.EXPECT().GetChannel("#test1").Return(nil),
 | 
							s.st.EXPECT().GetChannel("#test1").Return(nil),
 | 
				
			||||||
		s.st.EXPECT().GetNick("test").Return(c.Me),
 | 
							s.st.EXPECT().GetNick("test").Return(c.cfg.Me),
 | 
				
			||||||
		s.st.EXPECT().NewChannel("#test1").Return(chan1),
 | 
							s.st.EXPECT().NewChannel("#test1").Return(chan1),
 | 
				
			||||||
		s.st.EXPECT().Associate(chan1, c.Me),
 | 
							s.st.EXPECT().Associate(chan1, c.cfg.Me),
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Use #test1 to test expected behaviour
 | 
						// Use #test1 to test expected behaviour
 | 
				
			||||||
| 
						 | 
					@ -321,10 +341,10 @@ func TestMODE(t *testing.T) {
 | 
				
			||||||
	// Send a nick mode line, returning Me
 | 
						// Send a nick mode line, returning Me
 | 
				
			||||||
	gomock.InOrder(
 | 
						gomock.InOrder(
 | 
				
			||||||
		s.st.EXPECT().GetChannel("test").Return(nil),
 | 
							s.st.EXPECT().GetChannel("test").Return(nil),
 | 
				
			||||||
		s.st.EXPECT().GetNick("test").Return(c.Me),
 | 
							s.st.EXPECT().GetNick("test").Return(c.cfg.Me),
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	c.h_MODE(parseLine(":test!test@somehost.com MODE test +i"))
 | 
						c.h_MODE(parseLine(":test!test@somehost.com MODE test +i"))
 | 
				
			||||||
	if !c.Me.Modes.Invisible {
 | 
						if !c.cfg.Me.Modes.Invisible {
 | 
				
			||||||
		t.Errorf("Nick.ParseModes() not called correctly.")
 | 
							t.Errorf("Nick.ParseModes() not called correctly.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -484,7 +504,7 @@ func Test353(t *testing.T) {
 | 
				
			||||||
	nicks := make(map[string]*state.Nick)
 | 
						nicks := make(map[string]*state.Nick)
 | 
				
			||||||
	privs := make(map[string]*state.ChanPrivs)
 | 
						privs := make(map[string]*state.ChanPrivs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	nicks["test"] = c.Me
 | 
						nicks["test"] = c.cfg.Me
 | 
				
			||||||
	privs["test"] = new(state.ChanPrivs)
 | 
						privs["test"] = new(state.ChanPrivs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, n := range []string{"user1", "user2", "voice", "halfop",
 | 
						for _, n := range []string{"user1", "user2", "voice", "halfop",
 | 
				
			||||||
| 
						 | 
					@ -497,7 +517,7 @@ func Test353(t *testing.T) {
 | 
				
			||||||
	s.st.EXPECT().GetChannel("#test1").Return(chan1).Times(2)
 | 
						s.st.EXPECT().GetChannel("#test1").Return(chan1).Times(2)
 | 
				
			||||||
	gomock.InOrder(
 | 
						gomock.InOrder(
 | 
				
			||||||
		// "test" is Me, i am known, and already on the channel
 | 
							// "test" is Me, i am known, and already on the channel
 | 
				
			||||||
		s.st.EXPECT().GetNick("test").Return(c.Me),
 | 
							s.st.EXPECT().GetNick("test").Return(c.cfg.Me),
 | 
				
			||||||
		s.st.EXPECT().IsOn("#test1", "test").Return(privs["test"], true),
 | 
							s.st.EXPECT().IsOn("#test1", "test").Return(privs["test"], true),
 | 
				
			||||||
		// user1 is known, but not on the channel, so should be associated
 | 
							// user1 is known, but not on the channel, so should be associated
 | 
				
			||||||
		s.st.EXPECT().GetNick("user1").Return(nicks["user1"]),
 | 
							s.st.EXPECT().GetNick("user1").Return(nicks["user1"]),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -50,7 +50,7 @@ func (conn *Conn) h_JOIN(line *Line) {
 | 
				
			||||||
	if ch == nil {
 | 
						if ch == nil {
 | 
				
			||||||
		// first we've seen of this channel, so should be us joining it
 | 
							// first we've seen of this channel, so should be us joining it
 | 
				
			||||||
		// NOTE this will also take care of nk == nil && ch == nil
 | 
							// NOTE this will also take care of nk == nil && ch == nil
 | 
				
			||||||
		if nk != conn.Me {
 | 
							if nk != conn.cfg.Me {
 | 
				
			||||||
			logging.Warn("irc.JOIN(): JOIN to unknown channel %s received "+
 | 
								logging.Warn("irc.JOIN(): JOIN to unknown channel %s received "+
 | 
				
			||||||
				"from (non-me) nick %s", line.Args[0], line.Nick)
 | 
									"from (non-me) nick %s", line.Args[0], line.Nick)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
| 
						 | 
					@ -102,7 +102,7 @@ func (conn *Conn) h_MODE(line *Line) {
 | 
				
			||||||
		ch.ParseModes(line.Args[1], line.Args[2:]...)
 | 
							ch.ParseModes(line.Args[1], line.Args[2:]...)
 | 
				
			||||||
	} else if nk := conn.st.GetNick(line.Args[0]); nk != nil {
 | 
						} else if nk := conn.st.GetNick(line.Args[0]); nk != nil {
 | 
				
			||||||
		// nick mode change, should be us
 | 
							// nick mode change, should be us
 | 
				
			||||||
		if nk != conn.Me {
 | 
							if nk != conn.cfg.Me {
 | 
				
			||||||
			logging.Warn("irc.MODE(): recieved MODE %s for (non-me) nick %s",
 | 
								logging.Warn("irc.MODE(): recieved MODE %s for (non-me) nick %s",
 | 
				
			||||||
				line.Args[1], line.Args[0])
 | 
									line.Args[1], line.Args[0])
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue