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: README.md client.go client/connection.go client/connection_test.go client/dispatch.go client/dispatch_test.go client/handlers.go client/handlers_test.go
This commit is contained in:
		
						commit
						930f29959b
					
				
					 10 changed files with 219 additions and 186 deletions
				
			
		
							
								
								
									
										10
									
								
								README.md
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								README.md
									
										
									
									
									
								
							| 
						 | 
					@ -18,17 +18,25 @@ Synopsis:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	func main() {
 | 
						func main() {
 | 
				
			||||||
        flag.Parse() // parses the logging flags.
 | 
					        flag.Parse() // parses the logging flags.
 | 
				
			||||||
		c := irc.SimpleClient("nick")
 | 
							c := irc.Client("nick")
 | 
				
			||||||
		// Optionally, enable SSL
 | 
							// Optionally, enable SSL
 | 
				
			||||||
		c.SSL = true
 | 
							c.SSL = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 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.
 | 
				
			||||||
 | 
					<<<<<<< HEAD
 | 
				
			||||||
		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") })
 | 
				
			||||||
		// And a signal on disconnect
 | 
							// And a signal on disconnect
 | 
				
			||||||
		quit := make(chan bool)
 | 
							quit := make(chan bool)
 | 
				
			||||||
		c.HandleFunc(irc.DISCONNECTED,
 | 
							c.HandleFunc(irc.DISCONNECTED,
 | 
				
			||||||
 | 
					=======
 | 
				
			||||||
 | 
							c.HandleFunc("connected",
 | 
				
			||||||
 | 
								func(conn *irc.Conn, line *irc.Line) { conn.Join("#channel") })
 | 
				
			||||||
 | 
							// And a signal on disconnect
 | 
				
			||||||
 | 
							quit := make(chan bool)
 | 
				
			||||||
 | 
							c.HandleFunc("disconnected",
 | 
				
			||||||
 | 
					>>>>>>> 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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,9 +3,9 @@ package client
 | 
				
			||||||
import "strings"
 | 
					import "strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	INIT         = "init"
 | 
						REGISTER     = "REGISTER"
 | 
				
			||||||
	CONNECTED    = "connected"
 | 
						CONNECTED    = "CONNECTED"
 | 
				
			||||||
	DISCONNECTED = "disconnected"
 | 
						DISCONNECTED = "DISCONNECTED"
 | 
				
			||||||
	ACTION       = "ACTION"
 | 
						ACTION       = "ACTION"
 | 
				
			||||||
	AWAY         = "AWAY"
 | 
						AWAY         = "AWAY"
 | 
				
			||||||
	CTCP         = "CTCP"
 | 
						CTCP         = "CTCP"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,36 +14,46 @@ import (
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// An IRC connection is represented by this struct.
 | 
					// An IRC connection is represented by this struct.
 | 
				
			||||||
type Conn struct {
 | 
					type Conn struct {
 | 
				
			||||||
	// Connection Hostname and Nickname
 | 
						// Connection related vars people will care about
 | 
				
			||||||
	Host     string
 | 
						Me        *state.Nick
 | 
				
			||||||
	Me       *state.Nick
 | 
						Host      string
 | 
				
			||||||
	Network  string
 | 
						Network   string
 | 
				
			||||||
	password 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.
 | 
				
			||||||
 | 
						cfg *Config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Handlers and Commands
 | 
						// Handlers and Commands
 | 
				
			||||||
	handlers *handlerSet
 | 
						handlers *handlerSet
 | 
				
			||||||
	commands *commandList
 | 
						commands *commandList
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// State tracker for nicks and channels
 | 
						// State tracker for nicks and channels
 | 
				
			||||||
	ST         state.StateTracker
 | 
						st         state.Tracker
 | 
				
			||||||
	st         bool
 | 
					 | 
				
			||||||
	stRemovers []Remover
 | 
						stRemovers []Remover
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Use the State field to store external state that handlers might need.
 | 
					 | 
				
			||||||
	// Remember ... you might need locking for this ;-)
 | 
					 | 
				
			||||||
	State interface{}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// I/O stuff to server
 | 
						// I/O stuff to server
 | 
				
			||||||
	sock      net.Conn
 | 
						sock net.Conn
 | 
				
			||||||
	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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Misc knobs to tweak client behaviour:
 | 
						// Internal counters for flood protection
 | 
				
			||||||
 | 
						badness  time.Duration
 | 
				
			||||||
 | 
						lastsent time.Time
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Misc knobs to tweak client behaviour go in here
 | 
				
			||||||
 | 
					type Config struct {
 | 
				
			||||||
 | 
						// Set this to provide the Nick, Ident and Name for the client to use.
 | 
				
			||||||
 | 
						Me *state.Nick
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 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
 | 
				
			||||||
| 
						 | 
					@ -59,16 +69,9 @@ type Conn struct {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Set this to true to disable flood protection and false to re-enable
 | 
						// Set this to true to disable flood protection and false to re-enable
 | 
				
			||||||
	Flood bool
 | 
						Flood bool
 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Internal counters for flood protection
 | 
					 | 
				
			||||||
	badness  time.Duration
 | 
					 | 
				
			||||||
	lastsent time.Time
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Creates a new IRC connection object, but doesn't connect to anything so
 | 
					func NewConfig(nick string, args ...string) *Config {
 | 
				
			||||||
// that you can add event handlers to it. See AddHandler() for details
 | 
					 | 
				
			||||||
func Client(nick string, args ...string) *Conn {
 | 
					 | 
				
			||||||
	logging.InitFromFlags()
 | 
					 | 
				
			||||||
	ident := "goirc"
 | 
						ident := "goirc"
 | 
				
			||||||
	name := "Powered by GoIRC"
 | 
						name := "Powered by GoIRC"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -78,7 +81,30 @@ func Client(nick string, args ...string) *Conn {
 | 
				
			||||||
	if len(args) > 1 && args[1] != "" {
 | 
						if len(args) > 1 && args[1] != "" {
 | 
				
			||||||
		name = args[1]
 | 
							name = args[1]
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						cfg := &Config{
 | 
				
			||||||
 | 
							PingFreq: 3 * time.Minute,
 | 
				
			||||||
 | 
							NewNick:  func(s string) string { return s + "_" },
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						cfg.Me = state.NewNick(nick)
 | 
				
			||||||
 | 
						cfg.Me.Ident = ident
 | 
				
			||||||
 | 
						cfg.Me.Name = name
 | 
				
			||||||
 | 
						return cfg
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 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
 | 
				
			||||||
 | 
					func SimpleClient(nick string, args ...string) (*Conn, error) {
 | 
				
			||||||
 | 
						return Client(NewConfig(nick, args...))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Client(cfg *Config) (*Conn, error) {
 | 
				
			||||||
 | 
						logging.InitFromFlags()
 | 
				
			||||||
 | 
						if cfg.Me == nil || cfg.Me.Nick == "" || cfg.Me.Ident == "" {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("Must provide a valid state.Nick in cfg.Me.")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	conn := &Conn{
 | 
						conn := &Conn{
 | 
				
			||||||
 | 
							Me:         cfg.Me,
 | 
				
			||||||
 | 
							cfg:        cfg,
 | 
				
			||||||
		in:         make(chan *Line, 32),
 | 
							in:         make(chan *Line, 32),
 | 
				
			||||||
		out:        make(chan string, 32),
 | 
							out:        make(chan string, 32),
 | 
				
			||||||
		cSend:      make(chan bool),
 | 
							cSend:      make(chan bool),
 | 
				
			||||||
| 
						 | 
					@ -87,46 +113,46 @@ func Client(nick string, args ...string) *Conn {
 | 
				
			||||||
		handlers:   newHandlerSet(),
 | 
							handlers:   newHandlerSet(),
 | 
				
			||||||
		commands:   newCommandList(),
 | 
							commands:   newCommandList(),
 | 
				
			||||||
		stRemovers: make([]Remover, 0, len(stHandlers)),
 | 
							stRemovers: make([]Remover, 0, len(stHandlers)),
 | 
				
			||||||
		PingFreq:   3 * time.Minute,
 | 
					 | 
				
			||||||
		NewNick:    func(s string) string { return s + "_" },
 | 
					 | 
				
			||||||
		lastsent:   time.Now(),
 | 
							lastsent:   time.Now(),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	conn.addIntHandlers()
 | 
						conn.addIntHandlers()
 | 
				
			||||||
	conn.Me = state.NewNick(nick)
 | 
					 | 
				
			||||||
	conn.Me.Ident = ident
 | 
					 | 
				
			||||||
	conn.Me.Name = name
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	conn.initialise()
 | 
						conn.initialise()
 | 
				
			||||||
	return conn
 | 
						return conn, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (conn *Conn) Config() *Config {
 | 
				
			||||||
 | 
						return conn.cfg
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (conn *Conn) EnableStateTracking() {
 | 
					func (conn *Conn) EnableStateTracking() {
 | 
				
			||||||
	if !conn.st {
 | 
						if conn.st == nil {
 | 
				
			||||||
		n := conn.Me
 | 
							n := conn.Me
 | 
				
			||||||
		conn.ST = state.NewTracker(n.Nick)
 | 
							conn.st = state.NewTracker(n.Nick)
 | 
				
			||||||
		conn.Me = conn.ST.Me()
 | 
							conn.Me = conn.st.Me()
 | 
				
			||||||
		conn.Me.Ident = n.Ident
 | 
							conn.Me.Ident = n.Ident
 | 
				
			||||||
		conn.Me.Name = n.Name
 | 
							conn.Me.Name = n.Name
 | 
				
			||||||
		conn.addSTHandlers()
 | 
							conn.addSTHandlers()
 | 
				
			||||||
		conn.st = true
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (conn *Conn) DisableStateTracking() {
 | 
					func (conn *Conn) DisableStateTracking() {
 | 
				
			||||||
	if conn.st {
 | 
						if conn.st != nil {
 | 
				
			||||||
		conn.st = false
 | 
					 | 
				
			||||||
		conn.delSTHandlers()
 | 
							conn.delSTHandlers()
 | 
				
			||||||
		conn.ST.Wipe()
 | 
							conn.st.Wipe()
 | 
				
			||||||
		conn.ST = nil
 | 
							conn.st = nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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
 | 
				
			||||||
	conn.sock = nil
 | 
						conn.sock = nil
 | 
				
			||||||
	if conn.st {
 | 
						if conn.st != nil {
 | 
				
			||||||
		conn.ST.Wipe()
 | 
							conn.st.Wipe()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -142,12 +168,12 @@ func (conn *Conn) Connect(host string, pass ...string) error {
 | 
				
			||||||
			conn.Host, host))
 | 
								conn.Host, host))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if conn.SSL {
 | 
						if conn.cfg.SSL {
 | 
				
			||||||
		if !hasPort(host) {
 | 
							if !hasPort(host) {
 | 
				
			||||||
			host += ":6697"
 | 
								host += ":6697"
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		logging.Info("irc.Connect(): Connecting to %s with SSL.", host)
 | 
							logging.Info("irc.Connect(): Connecting to %s with SSL.", host)
 | 
				
			||||||
		if s, err := tls.Dial("tcp", host, conn.SSLConfig); err == nil {
 | 
							if s, err := tls.Dial("tcp", host, conn.cfg.SSLConfig); err == nil {
 | 
				
			||||||
			conn.sock = s
 | 
								conn.sock = s
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
| 
						 | 
					@ -165,13 +191,13 @@ func (conn *Conn) Connect(host string, pass ...string) error {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	conn.Host = host
 | 
						conn.Host = host
 | 
				
			||||||
	conn.Connected = true
 | 
						conn.Connected = true
 | 
				
			||||||
	if len(pass) > 0 {
 | 
					 | 
				
			||||||
		conn.password = pass[0]
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		conn.password = ""
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	conn.postConnect()
 | 
						conn.postConnect()
 | 
				
			||||||
	conn.dispatch(&Line{Cmd: INIT})
 | 
					
 | 
				
			||||||
 | 
						if len(pass) > 0 {
 | 
				
			||||||
 | 
							conn.Pass(pass[0])
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						conn.Nick(conn.Me.Nick)
 | 
				
			||||||
 | 
						conn.User(conn.Me.Ident, conn.Me.Name)
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -182,7 +208,7 @@ func (conn *Conn) postConnect() {
 | 
				
			||||||
		bufio.NewWriter(conn.sock))
 | 
							bufio.NewWriter(conn.sock))
 | 
				
			||||||
	go conn.send()
 | 
						go conn.send()
 | 
				
			||||||
	go conn.recv()
 | 
						go conn.recv()
 | 
				
			||||||
	if conn.PingFreq > 0 {
 | 
						if conn.cfg.PingFreq > 0 {
 | 
				
			||||||
		go conn.ping()
 | 
							go conn.ping()
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		// Otherwise the send in shutdown will hang :-/
 | 
							// Otherwise the send in shutdown will hang :-/
 | 
				
			||||||
| 
						 | 
					@ -232,11 +258,11 @@ func (conn *Conn) recv() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Repeatedly pings the server every PingFreq seconds (no matter what)
 | 
					// Repeatedly pings the server every PingFreq seconds (no matter what)
 | 
				
			||||||
func (conn *Conn) ping() {
 | 
					func (conn *Conn) ping() {
 | 
				
			||||||
	tick := time.NewTicker(conn.PingFreq)
 | 
						tick := time.NewTicker(conn.cfg.PingFreq)
 | 
				
			||||||
	for {
 | 
						for {
 | 
				
			||||||
		select {
 | 
							select {
 | 
				
			||||||
		case <-tick.C:
 | 
							case <-tick.C:
 | 
				
			||||||
			conn.Ping(fmt.Sprintf("%d", time.Now().UnixNano()))
 | 
								conn.Raw(fmt.Sprintf("PING :%d", time.Now().UnixNano()))
 | 
				
			||||||
		case <-conn.cPing:
 | 
							case <-conn.cPing:
 | 
				
			||||||
			tick.Stop()
 | 
								tick.Stop()
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
| 
						 | 
					@ -258,9 +284,9 @@ func (conn *Conn) runLoop() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Write a \r\n terminated line of output to the connected server,
 | 
					// Write a \r\n terminated line of output to the connected server,
 | 
				
			||||||
// using Hybrid's algorithm to rate limit if conn.Flood is false.
 | 
					// using Hybrid's algorithm to rate limit if conn.cfg.Flood is false.
 | 
				
			||||||
func (conn *Conn) write(line string) {
 | 
					func (conn *Conn) write(line string) {
 | 
				
			||||||
	if !conn.Flood {
 | 
						if !conn.cfg.Flood {
 | 
				
			||||||
		if t := conn.rateLimit(len(line)); t != 0 {
 | 
							if t := conn.rateLimit(len(line)); t != 0 {
 | 
				
			||||||
			// sleep for the current line's time value before sending it
 | 
								// sleep for the current line's time value before sending it
 | 
				
			||||||
			logging.Debug("irc.rateLimit(): Flood! Sleeping for %.2f secs.",
 | 
								logging.Debug("irc.rateLimit(): Flood! Sleeping for %.2f secs.",
 | 
				
			||||||
| 
						 | 
					@ -303,10 +329,10 @@ 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 recieve EOF in readstring()
 | 
						// as calling sock.Close() will cause recv() to receive EOF in readstring()
 | 
				
			||||||
	if conn.Connected {
 | 
						if conn.Connected {
 | 
				
			||||||
		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
 | 
				
			||||||
| 
						 | 
					@ -329,8 +355,8 @@ func (conn *Conn) String() string {
 | 
				
			||||||
		str += "Not currently connected!\n\n"
 | 
							str += "Not currently connected!\n\n"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	str += conn.Me.String() + "\n"
 | 
						str += conn.Me.String() + "\n"
 | 
				
			||||||
	if conn.st {
 | 
						if conn.st != nil {
 | 
				
			||||||
		str += conn.ST.String() + "\n"
 | 
							str += conn.st.String() + "\n"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return str
 | 
						return str
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,22 +12,21 @@ import (
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type testState struct {
 | 
					type testState struct {
 | 
				
			||||||
	ctrl *gomock.Controller
 | 
						ctrl *gomock.Controller
 | 
				
			||||||
	st   *state.MockStateTracker
 | 
						st   *state.MockTracker
 | 
				
			||||||
	nc   *mockNetConn
 | 
						nc   *mockNetConn
 | 
				
			||||||
	c    *Conn
 | 
						c    *Conn
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func setUp(t *testing.T, start ...bool) (*Conn, *testState) {
 | 
					func setUp(t *testing.T, start ...bool) (*Conn, *testState) {
 | 
				
			||||||
	ctrl := gomock.NewController(t)
 | 
						ctrl := gomock.NewController(t)
 | 
				
			||||||
	st := state.NewMockStateTracker(ctrl)
 | 
						st := state.NewMockTracker(ctrl)
 | 
				
			||||||
	nc := MockNetConn(t)
 | 
						nc := MockNetConn(t)
 | 
				
			||||||
	c := Client("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.st = true
 | 
					 | 
				
			||||||
	c.sock = nc
 | 
						c.sock = nc
 | 
				
			||||||
	c.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.
 | 
				
			||||||
| 
						 | 
					@ -83,8 +82,8 @@ 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.NewMockStateTracker(ctrl)
 | 
						st := state.NewMockTracker(ctrl)
 | 
				
			||||||
	c := Client("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 c.Me.Nick != "test" || c.Me.Ident != "test" ||
 | 
				
			||||||
| 
						 | 
					@ -115,16 +114,16 @@ func TestClientAndStateTracking(t *testing.T) {
 | 
				
			||||||
		c.Me.Name != "Testing IRC" || c.Me.Host != "" {
 | 
							c.Me.Name != "Testing IRC" || c.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 || c.ST == nil || c.Me != c.ST.Me() {
 | 
						if c.st == nil || c.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.Me
 | 
				
			||||||
	c.ST = st
 | 
						c.st = st
 | 
				
			||||||
	st.EXPECT().Wipe()
 | 
						st.EXPECT().Wipe()
 | 
				
			||||||
	c.DisableStateTracking()
 | 
						c.DisableStateTracking()
 | 
				
			||||||
	if c.st || c.ST != nil || c.Me != me {
 | 
						if c.st != nil || c.Me != me {
 | 
				
			||||||
		t.Errorf("State tracker not disabled correctly.")
 | 
							t.Errorf("State tracker not disabled correctly.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -280,7 +279,7 @@ func TestPing(t *testing.T) {
 | 
				
			||||||
	defer s.ctrl.Finish()
 | 
						defer s.ctrl.Finish()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Set a low ping frequency for testing.
 | 
						// Set a low ping frequency for testing.
 | 
				
			||||||
	c.PingFreq = 50 * time.Millisecond
 | 
						c.cfg.PingFreq = 50 * time.Millisecond
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// reader is a helper to do a "non-blocking" read of c.out
 | 
						// reader is a helper to do a "non-blocking" read of c.out
 | 
				
			||||||
	reader := func() string {
 | 
						reader := func() string {
 | 
				
			||||||
| 
						 | 
					@ -431,13 +430,13 @@ func TestWrite(t *testing.T) {
 | 
				
			||||||
	c.write("yo momma")
 | 
						c.write("yo momma")
 | 
				
			||||||
	s.nc.Expect("yo momma")
 | 
						s.nc.Expect("yo momma")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Flood control is disabled -- setUp sets c.Flood = true -- so we should
 | 
						// Flood control is disabled -- setUp sets c.cfg.Flood = true -- so we should
 | 
				
			||||||
	// not have set c.badness at this point.
 | 
						// not have set c.badness at this point.
 | 
				
			||||||
	if c.badness != 0 {
 | 
						if c.badness != 0 {
 | 
				
			||||||
		t.Errorf("Flood control used when Flood = true.")
 | 
							t.Errorf("Flood control used when Flood = true.")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c.Flood = false
 | 
						c.cfg.Flood = false
 | 
				
			||||||
	c.write("she so useless")
 | 
						c.write("she so useless")
 | 
				
			||||||
	s.nc.Expect("she so useless")
 | 
						s.nc.Expect("she so useless")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -185,7 +185,7 @@ var SimpleCommandRegex string = `^!%v(\s|$)`
 | 
				
			||||||
func (conn *Conn) SimpleCommand(prefix string, handler Handler) Remover {
 | 
					func (conn *Conn) SimpleCommand(prefix string, handler Handler) Remover {
 | 
				
			||||||
	stripHandler := func(conn *Conn, line *Line) {
 | 
						stripHandler := func(conn *Conn, line *Line) {
 | 
				
			||||||
		text := line.Message()
 | 
							text := line.Message()
 | 
				
			||||||
		if conn.SimpleCommandStripPrefix {
 | 
							if conn.cfg.SimpleCommandStripPrefix {
 | 
				
			||||||
			text = strings.TrimSpace(text[len(prefix):])
 | 
								text = strings.TrimSpace(text[len(prefix):])
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if text != line.Message() {
 | 
							if text != line.Message() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,13 +9,13 @@ import (
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// sets up the internal event handlers to do essential IRC protocol things
 | 
					// sets up the internal event handlers to do essential IRC protocol things
 | 
				
			||||||
var intHandlers = map[string]HandlerFunc{
 | 
					var intHandlers = map[string]HandlerFunc{
 | 
				
			||||||
	INIT:    (*Conn).h_init,
 | 
						REGISTER: (*Conn).h_REGISTER,
 | 
				
			||||||
	"001":   (*Conn).h_001,
 | 
						"001":    (*Conn).h_001,
 | 
				
			||||||
	"433":   (*Conn).h_433,
 | 
						"433":    (*Conn).h_433,
 | 
				
			||||||
	CTCP:    (*Conn).h_CTCP,
 | 
						CTCP:     (*Conn).h_CTCP,
 | 
				
			||||||
	NICK:    (*Conn).h_NICK,
 | 
						NICK:     (*Conn).h_NICK,
 | 
				
			||||||
	PING:    (*Conn).h_PING,
 | 
						PING:     (*Conn).h_PING,
 | 
				
			||||||
	PRIVMSG: (*Conn).h_PRIVMSG,
 | 
						PRIVMSG:  (*Conn).h_PRIVMSG,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (conn *Conn) addIntHandlers() {
 | 
					func (conn *Conn) addIntHandlers() {
 | 
				
			||||||
| 
						 | 
					@ -26,20 +26,20 @@ func (conn *Conn) addIntHandlers() {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Password/User/Nick broadcast on connection.
 | 
					 | 
				
			||||||
func (conn *Conn) h_init(line *Line) {
 | 
					 | 
				
			||||||
	if conn.password != "" {
 | 
					 | 
				
			||||||
		conn.Pass(conn.password)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	conn.Nick(conn.Me.Nick)
 | 
					 | 
				
			||||||
	conn.User(conn.Me.Ident, conn.Me.Name)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Basic ping/pong handler
 | 
					// Basic ping/pong handler
 | 
				
			||||||
func (conn *Conn) h_PING(line *Line) {
 | 
					func (conn *Conn) h_PING(line *Line) {
 | 
				
			||||||
	conn.Pong(line.Args[0])
 | 
						conn.Pong(line.Args[0])
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Handler for initial registration with server once tcp connection is made.
 | 
				
			||||||
 | 
					func (conn *Conn) h_REGISTER(line *Line) {
 | 
				
			||||||
 | 
						if conn.cfg.Pass != "" {
 | 
				
			||||||
 | 
							conn.Pass(conn.cfg.Pass)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						conn.Nick(conn.cfg.Me.Nick)
 | 
				
			||||||
 | 
						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!
 | 
				
			||||||
| 
						 | 
					@ -65,14 +65,14 @@ func (conn *Conn) h_001(line *Line) {
 | 
				
			||||||
// Handler to deal with "433 :Nickname already in use"
 | 
					// Handler to deal with "433 :Nickname already in use"
 | 
				
			||||||
func (conn *Conn) h_433(line *Line) {
 | 
					func (conn *Conn) h_433(line *Line) {
 | 
				
			||||||
	// Args[1] is the new nick we were attempting to acquire
 | 
						// Args[1] is the new nick we were attempting to acquire
 | 
				
			||||||
	neu := conn.NewNick(line.Args[1])
 | 
						neu := conn.cfg.NewNick(line.Args[1])
 | 
				
			||||||
	conn.Nick(neu)
 | 
						conn.Nick(neu)
 | 
				
			||||||
	// 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.Me.Nick {
 | 
				
			||||||
		if conn.st {
 | 
							if conn.st != nil {
 | 
				
			||||||
			conn.ST.ReNick(conn.Me.Nick, neu)
 | 
								conn.st.ReNick(conn.Me.Nick, neu)
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			conn.Me.Nick = neu
 | 
								conn.Me.Nick = neu
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -90,15 +90,15 @@ func (conn *Conn) h_CTCP(line *Line) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Handle updating our own NICK if we're not using the state tracker
 | 
					// Handle updating our own NICK if we're not using the state tracker
 | 
				
			||||||
func (conn *Conn) h_NICK(line *Line) {
 | 
					func (conn *Conn) h_NICK(line *Line) {
 | 
				
			||||||
	if !conn.st && line.Nick == conn.Me.Nick {
 | 
						if conn.st == nil && line.Nick == conn.cfg.Me.Nick {
 | 
				
			||||||
		conn.Me.Nick = line.Args[0]
 | 
							conn.cfg.Me.Nick = line.Args[0]
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 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.CommandStripNick && strings.HasPrefix(text, conn.Me.Nick) {
 | 
						if conn.cfg.CommandStripNick && strings.HasPrefix(text, conn.Me.Nick) {
 | 
				
			||||||
		// Look for '^${nick}[:;>,-]? '
 | 
							// Look for '^${nick}[:;>,-]? '
 | 
				
			||||||
		l := len(conn.Me.Nick)
 | 
							l := len(conn.Me.Nick)
 | 
				
			||||||
		switch text[l] {
 | 
							switch text[l] {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -74,14 +74,14 @@ func Test433(t *testing.T) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Test the code path that *doesn't* involve state tracking.
 | 
						// Test the code path that *doesn't* involve state tracking.
 | 
				
			||||||
	c.st = false
 | 
						c.st = nil
 | 
				
			||||||
	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.Me.Nick != "test_" {
 | 
				
			||||||
		t.Errorf("My nick not updated from '%s'.", c.Me.Nick)
 | 
							t.Errorf("My nick not updated from '%s'.", c.Me.Nick)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	c.st = true
 | 
						c.st = s.st
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Test the handler for NICK messages when state tracking is disabled
 | 
					// Test the handler for NICK messages when state tracking is disabled
 | 
				
			||||||
| 
						 | 
					@ -90,7 +90,7 @@ func TestNICK(t *testing.T) {
 | 
				
			||||||
	defer s.tearDown()
 | 
						defer s.tearDown()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// State tracking is enabled by default in setUp
 | 
						// State tracking is enabled by default in setUp
 | 
				
			||||||
	c.st = false
 | 
						c.st = nil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Call handler with a NICK line changing "our" nick to test1.
 | 
						// Call handler with a NICK line changing "our" nick to test1.
 | 
				
			||||||
	c.h_NICK(parseLine(":test!test@somehost.com NICK :test1"))
 | 
						c.h_NICK(parseLine(":test!test@somehost.com NICK :test1"))
 | 
				
			||||||
| 
						 | 
					@ -109,7 +109,7 @@ func TestNICK(t *testing.T) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Re-enable state tracking and send a line that *should* change nick.
 | 
						// Re-enable state tracking and send a line that *should* change nick.
 | 
				
			||||||
	c.st = true
 | 
						c.st = s.st
 | 
				
			||||||
	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).
 | 
				
			||||||
| 
						 | 
					@ -159,26 +159,26 @@ func TestPRIVMSG(t *testing.T) {
 | 
				
			||||||
	c.h_PRIVMSG(parseLine(":blah!moo@cows.com PRIVMSG #foo :test: prefix bar"))
 | 
						c.h_PRIVMSG(parseLine(":blah!moo@cows.com PRIVMSG #foo :test: prefix bar"))
 | 
				
			||||||
	s.nc.ExpectNothing()
 | 
						s.nc.ExpectNothing()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c.CommandStripNick = true
 | 
						c.cfg.CommandStripNick = true
 | 
				
			||||||
	c.h_PRIVMSG(parseLine(":blah!moo@cows.com PRIVMSG #foo :prefix bar"))
 | 
						c.h_PRIVMSG(parseLine(":blah!moo@cows.com PRIVMSG #foo :prefix bar"))
 | 
				
			||||||
	s.nc.Expect("PRIVMSG #foo :prefix bar")
 | 
						s.nc.Expect("PRIVMSG #foo :prefix bar")
 | 
				
			||||||
	c.h_PRIVMSG(parseLine(":blah!moo@cows.com PRIVMSG #foo :test: prefix bar"))
 | 
						c.h_PRIVMSG(parseLine(":blah!moo@cows.com PRIVMSG #foo :test: prefix bar"))
 | 
				
			||||||
	s.nc.Expect("PRIVMSG #foo :prefix bar")
 | 
						s.nc.Expect("PRIVMSG #foo :prefix bar")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c.SimpleCommandStripPrefix = true
 | 
						c.cfg.SimpleCommandStripPrefix = true
 | 
				
			||||||
	c.h_PRIVMSG(parseLine(":blah!moo@cows.com PRIVMSG #foo :prefix bar"))
 | 
						c.h_PRIVMSG(parseLine(":blah!moo@cows.com PRIVMSG #foo :prefix bar"))
 | 
				
			||||||
	s.nc.Expect("PRIVMSG #foo :bar")
 | 
						s.nc.Expect("PRIVMSG #foo :bar")
 | 
				
			||||||
	c.h_PRIVMSG(parseLine(":blah!moo@cows.com PRIVMSG #foo :test: prefix bar"))
 | 
						c.h_PRIVMSG(parseLine(":blah!moo@cows.com PRIVMSG #foo :test: prefix bar"))
 | 
				
			||||||
	s.nc.Expect("PRIVMSG #foo :bar")
 | 
						s.nc.Expect("PRIVMSG #foo :bar")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c.CommandStripNick = false
 | 
						c.cfg.CommandStripNick = false
 | 
				
			||||||
	c.h_PRIVMSG(parseLine(":blah!moo@cows.com PRIVMSG #foo :prefix bar"))
 | 
						c.h_PRIVMSG(parseLine(":blah!moo@cows.com PRIVMSG #foo :prefix bar"))
 | 
				
			||||||
	s.nc.Expect("PRIVMSG #foo :bar")
 | 
						s.nc.Expect("PRIVMSG #foo :bar")
 | 
				
			||||||
	c.h_PRIVMSG(parseLine(":blah!moo@cows.com PRIVMSG #foo :test: prefix bar"))
 | 
						c.h_PRIVMSG(parseLine(":blah!moo@cows.com PRIVMSG #foo :test: prefix bar"))
 | 
				
			||||||
	s.nc.ExpectNothing()
 | 
						s.nc.ExpectNothing()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check the various nick addressing notations that are supported.
 | 
						// Check the various nick addressing notations that are supported.
 | 
				
			||||||
	c.CommandStripNick = true
 | 
						c.cfg.CommandStripNick = true
 | 
				
			||||||
	for _, addr := range []string{":", ";", ",", ">", "-", ""} {
 | 
						for _, addr := range []string{":", ";", ",", ">", "-", ""} {
 | 
				
			||||||
		c.h_PRIVMSG(parseLine(fmt.Sprintf(
 | 
							c.h_PRIVMSG(parseLine(fmt.Sprintf(
 | 
				
			||||||
			":blah!moo@cows.com PRIVMSG #foo :test%s prefix bar", addr)))
 | 
								":blah!moo@cows.com PRIVMSG #foo :test%s prefix bar", addr)))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,13 +40,13 @@ func (conn *Conn) delSTHandlers() {
 | 
				
			||||||
// Handle NICK messages that need to update the state tracker
 | 
					// Handle NICK messages that need to update the state tracker
 | 
				
			||||||
func (conn *Conn) h_STNICK(line *Line) {
 | 
					func (conn *Conn) h_STNICK(line *Line) {
 | 
				
			||||||
	// all nicks should be handled the same way, our own included
 | 
						// all nicks should be handled the same way, our own included
 | 
				
			||||||
	conn.ST.ReNick(line.Nick, line.Args[0])
 | 
						conn.st.ReNick(line.Nick, line.Args[0])
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Handle JOINs to channels to maintain state
 | 
					// Handle JOINs to channels to maintain state
 | 
				
			||||||
func (conn *Conn) h_JOIN(line *Line) {
 | 
					func (conn *Conn) h_JOIN(line *Line) {
 | 
				
			||||||
	ch := conn.ST.GetChannel(line.Args[0])
 | 
						ch := conn.st.GetChannel(line.Args[0])
 | 
				
			||||||
	nk := conn.ST.GetNick(line.Nick)
 | 
						nk := conn.st.GetNick(line.Nick)
 | 
				
			||||||
	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
 | 
				
			||||||
| 
						 | 
					@ -55,7 +55,7 @@ func (conn *Conn) h_JOIN(line *Line) {
 | 
				
			||||||
				"from (non-me) nick %s", line.Args[0], line.Nick)
 | 
									"from (non-me) nick %s", line.Args[0], line.Nick)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		ch = conn.ST.NewChannel(line.Args[0])
 | 
							ch = conn.st.NewChannel(line.Args[0])
 | 
				
			||||||
		// since we don't know much about this channel, ask server for info
 | 
							// since we don't know much about this channel, ask server for info
 | 
				
			||||||
		// we get the channel users automatically in 353 and the channel
 | 
							// we get the channel users automatically in 353 and the channel
 | 
				
			||||||
		// topic in 332 on join, so we just need to get the modes
 | 
							// topic in 332 on join, so we just need to get the modes
 | 
				
			||||||
| 
						 | 
					@ -66,41 +66,41 @@ func (conn *Conn) h_JOIN(line *Line) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if nk == nil {
 | 
						if nk == nil {
 | 
				
			||||||
		// this is the first we've seen of this nick
 | 
							// this is the first we've seen of this nick
 | 
				
			||||||
		nk = conn.ST.NewNick(line.Nick)
 | 
							nk = conn.st.NewNick(line.Nick)
 | 
				
			||||||
		nk.Ident = line.Ident
 | 
							nk.Ident = line.Ident
 | 
				
			||||||
		nk.Host = line.Host
 | 
							nk.Host = line.Host
 | 
				
			||||||
		// since we don't know much about this nick, ask server for info
 | 
							// since we don't know much about this nick, ask server for info
 | 
				
			||||||
		conn.Who(nk.Nick)
 | 
							conn.Who(nk.Nick)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// this takes care of both nick and channel linking \o/
 | 
						// this takes care of both nick and channel linking \o/
 | 
				
			||||||
	conn.ST.Associate(ch, nk)
 | 
						conn.st.Associate(ch, nk)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Handle PARTs from channels to maintain state
 | 
					// Handle PARTs from channels to maintain state
 | 
				
			||||||
func (conn *Conn) h_PART(line *Line) {
 | 
					func (conn *Conn) h_PART(line *Line) {
 | 
				
			||||||
	conn.ST.Dissociate(conn.ST.GetChannel(line.Args[0]),
 | 
						conn.st.Dissociate(conn.st.GetChannel(line.Args[0]),
 | 
				
			||||||
		conn.ST.GetNick(line.Nick))
 | 
							conn.st.GetNick(line.Nick))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Handle KICKs from channels to maintain state
 | 
					// Handle KICKs from channels to maintain state
 | 
				
			||||||
func (conn *Conn) h_KICK(line *Line) {
 | 
					func (conn *Conn) h_KICK(line *Line) {
 | 
				
			||||||
	// XXX: this won't handle autorejoining channels on KICK
 | 
						// XXX: this won't handle autorejoining channels on KICK
 | 
				
			||||||
	// it's trivial to do this in a seperate handler...
 | 
						// it's trivial to do this in a seperate handler...
 | 
				
			||||||
	conn.ST.Dissociate(conn.ST.GetChannel(line.Args[0]),
 | 
						conn.st.Dissociate(conn.st.GetChannel(line.Args[0]),
 | 
				
			||||||
		conn.ST.GetNick(line.Args[1]))
 | 
							conn.st.GetNick(line.Args[1]))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Handle other people's QUITs
 | 
					// Handle other people's QUITs
 | 
				
			||||||
func (conn *Conn) h_QUIT(line *Line) {
 | 
					func (conn *Conn) h_QUIT(line *Line) {
 | 
				
			||||||
	conn.ST.DelNick(line.Nick)
 | 
						conn.st.DelNick(line.Nick)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Handle MODE changes for channels we know about (and our nick personally)
 | 
					// Handle MODE changes for channels we know about (and our nick personally)
 | 
				
			||||||
func (conn *Conn) h_MODE(line *Line) {
 | 
					func (conn *Conn) h_MODE(line *Line) {
 | 
				
			||||||
	if ch := conn.ST.GetChannel(line.Args[0]); ch != nil {
 | 
						if ch := conn.st.GetChannel(line.Args[0]); ch != nil {
 | 
				
			||||||
		// channel modes first
 | 
							// channel modes first
 | 
				
			||||||
		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.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",
 | 
				
			||||||
| 
						 | 
					@ -116,7 +116,7 @@ func (conn *Conn) h_MODE(line *Line) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Handle TOPIC changes for channels
 | 
					// Handle TOPIC changes for channels
 | 
				
			||||||
func (conn *Conn) h_TOPIC(line *Line) {
 | 
					func (conn *Conn) h_TOPIC(line *Line) {
 | 
				
			||||||
	if ch := conn.ST.GetChannel(line.Args[0]); ch != nil {
 | 
						if ch := conn.st.GetChannel(line.Args[0]); ch != nil {
 | 
				
			||||||
		ch.Topic = line.Args[1]
 | 
							ch.Topic = line.Args[1]
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		logging.Warn("irc.TOPIC(): topic change on unknown channel %s",
 | 
							logging.Warn("irc.TOPIC(): topic change on unknown channel %s",
 | 
				
			||||||
| 
						 | 
					@ -126,7 +126,7 @@ func (conn *Conn) h_TOPIC(line *Line) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Handle 311 whois reply
 | 
					// Handle 311 whois reply
 | 
				
			||||||
func (conn *Conn) h_311(line *Line) {
 | 
					func (conn *Conn) h_311(line *Line) {
 | 
				
			||||||
	if nk := conn.ST.GetNick(line.Args[1]); nk != nil {
 | 
						if nk := conn.st.GetNick(line.Args[1]); nk != nil {
 | 
				
			||||||
		nk.Ident = line.Args[2]
 | 
							nk.Ident = line.Args[2]
 | 
				
			||||||
		nk.Host = line.Args[3]
 | 
							nk.Host = line.Args[3]
 | 
				
			||||||
		nk.Name = line.Args[5]
 | 
							nk.Name = line.Args[5]
 | 
				
			||||||
| 
						 | 
					@ -138,7 +138,7 @@ func (conn *Conn) h_311(line *Line) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Handle 324 mode reply
 | 
					// Handle 324 mode reply
 | 
				
			||||||
func (conn *Conn) h_324(line *Line) {
 | 
					func (conn *Conn) h_324(line *Line) {
 | 
				
			||||||
	if ch := conn.ST.GetChannel(line.Args[1]); ch != nil {
 | 
						if ch := conn.st.GetChannel(line.Args[1]); ch != nil {
 | 
				
			||||||
		ch.ParseModes(line.Args[2], line.Args[3:]...)
 | 
							ch.ParseModes(line.Args[2], line.Args[3:]...)
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		logging.Warn("irc.324(): received MODE settings for unknown channel %s",
 | 
							logging.Warn("irc.324(): received MODE settings for unknown channel %s",
 | 
				
			||||||
| 
						 | 
					@ -148,7 +148,7 @@ func (conn *Conn) h_324(line *Line) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Handle 332 topic reply on join to channel
 | 
					// Handle 332 topic reply on join to channel
 | 
				
			||||||
func (conn *Conn) h_332(line *Line) {
 | 
					func (conn *Conn) h_332(line *Line) {
 | 
				
			||||||
	if ch := conn.ST.GetChannel(line.Args[1]); ch != nil {
 | 
						if ch := conn.st.GetChannel(line.Args[1]); ch != nil {
 | 
				
			||||||
		ch.Topic = line.Args[2]
 | 
							ch.Topic = line.Args[2]
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		logging.Warn("irc.332(): received TOPIC value for unknown channel %s",
 | 
							logging.Warn("irc.332(): received TOPIC value for unknown channel %s",
 | 
				
			||||||
| 
						 | 
					@ -158,7 +158,7 @@ func (conn *Conn) h_332(line *Line) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Handle 352 who reply
 | 
					// Handle 352 who reply
 | 
				
			||||||
func (conn *Conn) h_352(line *Line) {
 | 
					func (conn *Conn) h_352(line *Line) {
 | 
				
			||||||
	if nk := conn.ST.GetNick(line.Args[5]); nk != nil {
 | 
						if nk := conn.st.GetNick(line.Args[5]); nk != nil {
 | 
				
			||||||
		nk.Ident = line.Args[2]
 | 
							nk.Ident = line.Args[2]
 | 
				
			||||||
		nk.Host = line.Args[3]
 | 
							nk.Host = line.Args[3]
 | 
				
			||||||
		// XXX: do we care about the actual server the nick is on?
 | 
							// XXX: do we care about the actual server the nick is on?
 | 
				
			||||||
| 
						 | 
					@ -180,7 +180,7 @@ func (conn *Conn) h_352(line *Line) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Handle 353 names reply
 | 
					// Handle 353 names reply
 | 
				
			||||||
func (conn *Conn) h_353(line *Line) {
 | 
					func (conn *Conn) h_353(line *Line) {
 | 
				
			||||||
	if ch := conn.ST.GetChannel(line.Args[2]); ch != nil {
 | 
						if ch := conn.st.GetChannel(line.Args[2]); ch != nil {
 | 
				
			||||||
		nicks := strings.Split(line.Args[len(line.Args)-1], " ")
 | 
							nicks := strings.Split(line.Args[len(line.Args)-1], " ")
 | 
				
			||||||
		for _, nick := range nicks {
 | 
							for _, nick := range nicks {
 | 
				
			||||||
			// UnrealIRCd's coders are lazy and leave a trailing space
 | 
								// UnrealIRCd's coders are lazy and leave a trailing space
 | 
				
			||||||
| 
						 | 
					@ -192,15 +192,15 @@ func (conn *Conn) h_353(line *Line) {
 | 
				
			||||||
				nick = nick[1:]
 | 
									nick = nick[1:]
 | 
				
			||||||
				fallthrough
 | 
									fallthrough
 | 
				
			||||||
			default:
 | 
								default:
 | 
				
			||||||
				nk := conn.ST.GetNick(nick)
 | 
									nk := conn.st.GetNick(nick)
 | 
				
			||||||
				if nk == nil {
 | 
									if nk == nil {
 | 
				
			||||||
					// we don't know this nick yet!
 | 
										// we don't know this nick yet!
 | 
				
			||||||
					nk = conn.ST.NewNick(nick)
 | 
										nk = conn.st.NewNick(nick)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				cp, ok := conn.ST.IsOn(ch.Name, nick)
 | 
									cp, ok := conn.st.IsOn(ch.Name, nick)
 | 
				
			||||||
				if !ok {
 | 
									if !ok {
 | 
				
			||||||
					// This nick isn't associated with this channel yet!
 | 
										// This nick isn't associated with this channel yet!
 | 
				
			||||||
					cp = conn.ST.Associate(ch, nk)
 | 
										cp = conn.st.Associate(ch, nk)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				switch c {
 | 
									switch c {
 | 
				
			||||||
				case '~':
 | 
									case '~':
 | 
				
			||||||
| 
						 | 
					@ -224,7 +224,7 @@ func (conn *Conn) h_353(line *Line) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Handle 671 whois reply (nick connected via SSL)
 | 
					// Handle 671 whois reply (nick connected via SSL)
 | 
				
			||||||
func (conn *Conn) h_671(line *Line) {
 | 
					func (conn *Conn) h_671(line *Line) {
 | 
				
			||||||
	if nk := conn.ST.GetNick(line.Args[1]); nk != nil {
 | 
						if nk := conn.st.GetNick(line.Args[1]); nk != nil {
 | 
				
			||||||
		nk.Modes.SSL = true
 | 
							nk.Modes.SSL = true
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		logging.Warn("irc.671(): received WHOIS SSL info for unknown nick %s",
 | 
							logging.Warn("irc.671(): received WHOIS SSL info for unknown nick %s",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,144 +7,144 @@ import (
 | 
				
			||||||
	gomock "code.google.com/p/gomock/gomock"
 | 
						gomock "code.google.com/p/gomock/gomock"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Mock of StateTracker interface
 | 
					// Mock of Tracker interface
 | 
				
			||||||
type MockStateTracker struct {
 | 
					type MockTracker struct {
 | 
				
			||||||
	ctrl     *gomock.Controller
 | 
						ctrl     *gomock.Controller
 | 
				
			||||||
	recorder *_MockStateTrackerRecorder
 | 
						recorder *_MockTrackerRecorder
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Recorder for MockStateTracker (not exported)
 | 
					// Recorder for MockTracker (not exported)
 | 
				
			||||||
type _MockStateTrackerRecorder struct {
 | 
					type _MockTrackerRecorder struct {
 | 
				
			||||||
	mock *MockStateTracker
 | 
						mock *MockTracker
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewMockStateTracker(ctrl *gomock.Controller) *MockStateTracker {
 | 
					func NewMockTracker(ctrl *gomock.Controller) *MockTracker {
 | 
				
			||||||
	mock := &MockStateTracker{ctrl: ctrl}
 | 
						mock := &MockTracker{ctrl: ctrl}
 | 
				
			||||||
	mock.recorder = &_MockStateTrackerRecorder{mock}
 | 
						mock.recorder = &_MockTrackerRecorder{mock}
 | 
				
			||||||
	return mock
 | 
						return mock
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_m *MockStateTracker) EXPECT() *_MockStateTrackerRecorder {
 | 
					func (_m *MockTracker) EXPECT() *_MockTrackerRecorder {
 | 
				
			||||||
	return _m.recorder
 | 
						return _m.recorder
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_m *MockStateTracker) NewNick(nick string) *Nick {
 | 
					func (_m *MockTracker) NewNick(nick string) *Nick {
 | 
				
			||||||
	ret := _m.ctrl.Call(_m, "NewNick", nick)
 | 
						ret := _m.ctrl.Call(_m, "NewNick", nick)
 | 
				
			||||||
	ret0, _ := ret[0].(*Nick)
 | 
						ret0, _ := ret[0].(*Nick)
 | 
				
			||||||
	return ret0
 | 
						return ret0
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_mr *_MockStateTrackerRecorder) NewNick(arg0 interface{}) *gomock.Call {
 | 
					func (_mr *_MockTrackerRecorder) NewNick(arg0 interface{}) *gomock.Call {
 | 
				
			||||||
	return _mr.mock.ctrl.RecordCall(_mr.mock, "NewNick", arg0)
 | 
						return _mr.mock.ctrl.RecordCall(_mr.mock, "NewNick", arg0)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_m *MockStateTracker) GetNick(nick string) *Nick {
 | 
					func (_m *MockTracker) GetNick(nick string) *Nick {
 | 
				
			||||||
	ret := _m.ctrl.Call(_m, "GetNick", nick)
 | 
						ret := _m.ctrl.Call(_m, "GetNick", nick)
 | 
				
			||||||
	ret0, _ := ret[0].(*Nick)
 | 
						ret0, _ := ret[0].(*Nick)
 | 
				
			||||||
	return ret0
 | 
						return ret0
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_mr *_MockStateTrackerRecorder) GetNick(arg0 interface{}) *gomock.Call {
 | 
					func (_mr *_MockTrackerRecorder) GetNick(arg0 interface{}) *gomock.Call {
 | 
				
			||||||
	return _mr.mock.ctrl.RecordCall(_mr.mock, "GetNick", arg0)
 | 
						return _mr.mock.ctrl.RecordCall(_mr.mock, "GetNick", arg0)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_m *MockStateTracker) ReNick(old string, neu string) {
 | 
					func (_m *MockTracker) ReNick(old string, neu string) {
 | 
				
			||||||
	_m.ctrl.Call(_m, "ReNick", old, neu)
 | 
						_m.ctrl.Call(_m, "ReNick", old, neu)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_mr *_MockStateTrackerRecorder) ReNick(arg0, arg1 interface{}) *gomock.Call {
 | 
					func (_mr *_MockTrackerRecorder) ReNick(arg0, arg1 interface{}) *gomock.Call {
 | 
				
			||||||
	return _mr.mock.ctrl.RecordCall(_mr.mock, "ReNick", arg0, arg1)
 | 
						return _mr.mock.ctrl.RecordCall(_mr.mock, "ReNick", arg0, arg1)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_m *MockStateTracker) DelNick(nick string) {
 | 
					func (_m *MockTracker) DelNick(nick string) {
 | 
				
			||||||
	_m.ctrl.Call(_m, "DelNick", nick)
 | 
						_m.ctrl.Call(_m, "DelNick", nick)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_mr *_MockStateTrackerRecorder) DelNick(arg0 interface{}) *gomock.Call {
 | 
					func (_mr *_MockTrackerRecorder) DelNick(arg0 interface{}) *gomock.Call {
 | 
				
			||||||
	return _mr.mock.ctrl.RecordCall(_mr.mock, "DelNick", arg0)
 | 
						return _mr.mock.ctrl.RecordCall(_mr.mock, "DelNick", arg0)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_m *MockStateTracker) NewChannel(channel string) *Channel {
 | 
					func (_m *MockTracker) NewChannel(channel string) *Channel {
 | 
				
			||||||
	ret := _m.ctrl.Call(_m, "NewChannel", channel)
 | 
						ret := _m.ctrl.Call(_m, "NewChannel", channel)
 | 
				
			||||||
	ret0, _ := ret[0].(*Channel)
 | 
						ret0, _ := ret[0].(*Channel)
 | 
				
			||||||
	return ret0
 | 
						return ret0
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_mr *_MockStateTrackerRecorder) NewChannel(arg0 interface{}) *gomock.Call {
 | 
					func (_mr *_MockTrackerRecorder) NewChannel(arg0 interface{}) *gomock.Call {
 | 
				
			||||||
	return _mr.mock.ctrl.RecordCall(_mr.mock, "NewChannel", arg0)
 | 
						return _mr.mock.ctrl.RecordCall(_mr.mock, "NewChannel", arg0)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_m *MockStateTracker) GetChannel(channel string) *Channel {
 | 
					func (_m *MockTracker) GetChannel(channel string) *Channel {
 | 
				
			||||||
	ret := _m.ctrl.Call(_m, "GetChannel", channel)
 | 
						ret := _m.ctrl.Call(_m, "GetChannel", channel)
 | 
				
			||||||
	ret0, _ := ret[0].(*Channel)
 | 
						ret0, _ := ret[0].(*Channel)
 | 
				
			||||||
	return ret0
 | 
						return ret0
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_mr *_MockStateTrackerRecorder) GetChannel(arg0 interface{}) *gomock.Call {
 | 
					func (_mr *_MockTrackerRecorder) GetChannel(arg0 interface{}) *gomock.Call {
 | 
				
			||||||
	return _mr.mock.ctrl.RecordCall(_mr.mock, "GetChannel", arg0)
 | 
						return _mr.mock.ctrl.RecordCall(_mr.mock, "GetChannel", arg0)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_m *MockStateTracker) DelChannel(channel string) {
 | 
					func (_m *MockTracker) DelChannel(channel string) {
 | 
				
			||||||
	_m.ctrl.Call(_m, "DelChannel", channel)
 | 
						_m.ctrl.Call(_m, "DelChannel", channel)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_mr *_MockStateTrackerRecorder) DelChannel(arg0 interface{}) *gomock.Call {
 | 
					func (_mr *_MockTrackerRecorder) DelChannel(arg0 interface{}) *gomock.Call {
 | 
				
			||||||
	return _mr.mock.ctrl.RecordCall(_mr.mock, "DelChannel", arg0)
 | 
						return _mr.mock.ctrl.RecordCall(_mr.mock, "DelChannel", arg0)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_m *MockStateTracker) Me() *Nick {
 | 
					func (_m *MockTracker) Me() *Nick {
 | 
				
			||||||
	ret := _m.ctrl.Call(_m, "Me")
 | 
						ret := _m.ctrl.Call(_m, "Me")
 | 
				
			||||||
	ret0, _ := ret[0].(*Nick)
 | 
						ret0, _ := ret[0].(*Nick)
 | 
				
			||||||
	return ret0
 | 
						return ret0
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_mr *_MockStateTrackerRecorder) Me() *gomock.Call {
 | 
					func (_mr *_MockTrackerRecorder) Me() *gomock.Call {
 | 
				
			||||||
	return _mr.mock.ctrl.RecordCall(_mr.mock, "Me")
 | 
						return _mr.mock.ctrl.RecordCall(_mr.mock, "Me")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_m *MockStateTracker) IsOn(channel string, nick string) (*ChanPrivs, bool) {
 | 
					func (_m *MockTracker) IsOn(channel string, nick string) (*ChanPrivs, bool) {
 | 
				
			||||||
	ret := _m.ctrl.Call(_m, "IsOn", channel, nick)
 | 
						ret := _m.ctrl.Call(_m, "IsOn", channel, nick)
 | 
				
			||||||
	ret0, _ := ret[0].(*ChanPrivs)
 | 
						ret0, _ := ret[0].(*ChanPrivs)
 | 
				
			||||||
	ret1, _ := ret[1].(bool)
 | 
						ret1, _ := ret[1].(bool)
 | 
				
			||||||
	return ret0, ret1
 | 
						return ret0, ret1
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_mr *_MockStateTrackerRecorder) IsOn(arg0, arg1 interface{}) *gomock.Call {
 | 
					func (_mr *_MockTrackerRecorder) IsOn(arg0, arg1 interface{}) *gomock.Call {
 | 
				
			||||||
	return _mr.mock.ctrl.RecordCall(_mr.mock, "IsOn", arg0, arg1)
 | 
						return _mr.mock.ctrl.RecordCall(_mr.mock, "IsOn", arg0, arg1)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_m *MockStateTracker) Associate(channel *Channel, nick *Nick) *ChanPrivs {
 | 
					func (_m *MockTracker) Associate(channel *Channel, nick *Nick) *ChanPrivs {
 | 
				
			||||||
	ret := _m.ctrl.Call(_m, "Associate", channel, nick)
 | 
						ret := _m.ctrl.Call(_m, "Associate", channel, nick)
 | 
				
			||||||
	ret0, _ := ret[0].(*ChanPrivs)
 | 
						ret0, _ := ret[0].(*ChanPrivs)
 | 
				
			||||||
	return ret0
 | 
						return ret0
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_mr *_MockStateTrackerRecorder) Associate(arg0, arg1 interface{}) *gomock.Call {
 | 
					func (_mr *_MockTrackerRecorder) Associate(arg0, arg1 interface{}) *gomock.Call {
 | 
				
			||||||
	return _mr.mock.ctrl.RecordCall(_mr.mock, "Associate", arg0, arg1)
 | 
						return _mr.mock.ctrl.RecordCall(_mr.mock, "Associate", arg0, arg1)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_m *MockStateTracker) Dissociate(channel *Channel, nick *Nick) {
 | 
					func (_m *MockTracker) Dissociate(channel *Channel, nick *Nick) {
 | 
				
			||||||
	_m.ctrl.Call(_m, "Dissociate", channel, nick)
 | 
						_m.ctrl.Call(_m, "Dissociate", channel, nick)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_mr *_MockStateTrackerRecorder) Dissociate(arg0, arg1 interface{}) *gomock.Call {
 | 
					func (_mr *_MockTrackerRecorder) Dissociate(arg0, arg1 interface{}) *gomock.Call {
 | 
				
			||||||
	return _mr.mock.ctrl.RecordCall(_mr.mock, "Dissociate", arg0, arg1)
 | 
						return _mr.mock.ctrl.RecordCall(_mr.mock, "Dissociate", arg0, arg1)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_m *MockStateTracker) Wipe() {
 | 
					func (_m *MockTracker) Wipe() {
 | 
				
			||||||
	_m.ctrl.Call(_m, "Wipe")
 | 
						_m.ctrl.Call(_m, "Wipe")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_mr *_MockStateTrackerRecorder) Wipe() *gomock.Call {
 | 
					func (_mr *_MockTrackerRecorder) Wipe() *gomock.Call {
 | 
				
			||||||
	return _mr.mock.ctrl.RecordCall(_mr.mock, "Wipe")
 | 
						return _mr.mock.ctrl.RecordCall(_mr.mock, "Wipe")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_m *MockStateTracker) String() string {
 | 
					func (_m *MockTracker) String() string {
 | 
				
			||||||
	ret := _m.ctrl.Call(_m, "String")
 | 
						ret := _m.ctrl.Call(_m, "String")
 | 
				
			||||||
	ret0, _ := ret[0].(string)
 | 
						ret0, _ := ret[0].(string)
 | 
				
			||||||
	return ret0
 | 
						return ret0
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (_mr *_MockStateTrackerRecorder) String() *gomock.Call {
 | 
					func (_mr *_MockTrackerRecorder) String() *gomock.Call {
 | 
				
			||||||
	return _mr.mock.ctrl.RecordCall(_mr.mock, "String")
 | 
						return _mr.mock.ctrl.RecordCall(_mr.mock, "String")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,7 @@ import (
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// The state manager interface
 | 
					// The state manager interface
 | 
				
			||||||
type StateTracker interface {
 | 
					type Tracker interface {
 | 
				
			||||||
	// Nick methods
 | 
						// Nick methods
 | 
				
			||||||
	NewNick(nick string) *Nick
 | 
						NewNick(nick string) *Nick
 | 
				
			||||||
	GetNick(nick string) *Nick
 | 
						GetNick(nick string) *Nick
 | 
				
			||||||
| 
						 | 
					@ -63,7 +63,7 @@ func (st *stateTracker) Wipe() {
 | 
				
			||||||
// can be properly tracked for state management purposes.
 | 
					// can be properly tracked for state management purposes.
 | 
				
			||||||
func (st *stateTracker) NewNick(n string) *Nick {
 | 
					func (st *stateTracker) NewNick(n string) *Nick {
 | 
				
			||||||
	if _, ok := st.nicks[n]; ok {
 | 
						if _, ok := st.nicks[n]; ok {
 | 
				
			||||||
		logging.Warn("StateTracker.NewNick(): %s already tracked.", n)
 | 
							logging.Warn("Tracker.NewNick(): %s already tracked.", n)
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	st.nicks[n] = NewNick(n)
 | 
						st.nicks[n] = NewNick(n)
 | 
				
			||||||
| 
						 | 
					@ -93,10 +93,10 @@ func (st *stateTracker) ReNick(old, neu string) {
 | 
				
			||||||
				ch.lookup[neu] = nk
 | 
									ch.lookup[neu] = nk
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			logging.Warn("StateTracker.ReNick(): %s already exists.", neu)
 | 
								logging.Warn("Tracker.ReNick(): %s already exists.", neu)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		logging.Warn("StateTracker.ReNick(): %s not tracked.", old)
 | 
							logging.Warn("Tracker.ReNick(): %s not tracked.", old)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -106,17 +106,17 @@ func (st *stateTracker) DelNick(n string) {
 | 
				
			||||||
		if nk != st.me {
 | 
							if nk != st.me {
 | 
				
			||||||
			st.delNick(nk)
 | 
								st.delNick(nk)
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			logging.Warn("StateTracker.DelNick(): won't delete myself.")
 | 
								logging.Warn("Tracker.DelNick(): won't delete myself.")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		logging.Warn("StateTracker.DelNick(): %s not tracked.", n)
 | 
							logging.Warn("Tracker.DelNick(): %s not tracked.", n)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (st *stateTracker) delNick(nk *Nick) {
 | 
					func (st *stateTracker) delNick(nk *Nick) {
 | 
				
			||||||
	if nk == st.me {
 | 
						if nk == st.me {
 | 
				
			||||||
		// Shouldn't get here => internal state tracking code is fubar.
 | 
							// Shouldn't get here => internal state tracking code is fubar.
 | 
				
			||||||
		logging.Error("StateTracker.DelNick(): TRYING TO DELETE ME :-(")
 | 
							logging.Error("Tracker.DelNick(): TRYING TO DELETE ME :-(")
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	delete(st.nicks, nk.Nick)
 | 
						delete(st.nicks, nk.Nick)
 | 
				
			||||||
| 
						 | 
					@ -126,7 +126,7 @@ func (st *stateTracker) delNick(nk *Nick) {
 | 
				
			||||||
		if len(ch.nicks) == 0 {
 | 
							if len(ch.nicks) == 0 {
 | 
				
			||||||
			// Deleting a nick from tracking shouldn't empty any channels as
 | 
								// Deleting a nick from tracking shouldn't empty any channels as
 | 
				
			||||||
			// *we* should be on the channel with them to be tracking them.
 | 
								// *we* should be on the channel with them to be tracking them.
 | 
				
			||||||
			logging.Error("StateTracker.delNick(): deleting nick %s emptied "+
 | 
								logging.Error("Tracker.delNick(): deleting nick %s emptied "+
 | 
				
			||||||
				"channel %s, this shouldn't happen!", nk.Nick, ch.Name)
 | 
									"channel %s, this shouldn't happen!", nk.Nick, ch.Name)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -136,7 +136,7 @@ func (st *stateTracker) delNick(nk *Nick) {
 | 
				
			||||||
// can be properly tracked for state management purposes.
 | 
					// can be properly tracked for state management purposes.
 | 
				
			||||||
func (st *stateTracker) NewChannel(c string) *Channel {
 | 
					func (st *stateTracker) NewChannel(c string) *Channel {
 | 
				
			||||||
	if _, ok := st.chans[c]; ok {
 | 
						if _, ok := st.chans[c]; ok {
 | 
				
			||||||
		logging.Warn("StateTracker.NewChannel(): %s already tracked.", c)
 | 
							logging.Warn("Tracker.NewChannel(): %s already tracked.", c)
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	st.chans[c] = NewChannel(c)
 | 
						st.chans[c] = NewChannel(c)
 | 
				
			||||||
| 
						 | 
					@ -156,7 +156,7 @@ func (st *stateTracker) DelChannel(c string) {
 | 
				
			||||||
	if ch, ok := st.chans[c]; ok {
 | 
						if ch, ok := st.chans[c]; ok {
 | 
				
			||||||
		st.delChannel(ch)
 | 
							st.delChannel(ch)
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		logging.Warn("StateTracker.DelChannel(): %s not tracked.", c)
 | 
							logging.Warn("Tracker.DelChannel(): %s not tracked.", c)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -191,21 +191,21 @@ func (st *stateTracker) IsOn(c, n string) (*ChanPrivs, bool) {
 | 
				
			||||||
// Associates an already known nick with an already known channel.
 | 
					// Associates an already known nick with an already known channel.
 | 
				
			||||||
func (st *stateTracker) Associate(ch *Channel, nk *Nick) *ChanPrivs {
 | 
					func (st *stateTracker) Associate(ch *Channel, nk *Nick) *ChanPrivs {
 | 
				
			||||||
	if ch == nil || nk == nil {
 | 
						if ch == nil || nk == nil {
 | 
				
			||||||
		logging.Error("StateTracker.Associate(): passed nil values :-(")
 | 
							logging.Error("Tracker.Associate(): passed nil values :-(")
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	} else if _ch, ok := st.chans[ch.Name]; !ok || ch != _ch {
 | 
						} else if _ch, ok := st.chans[ch.Name]; !ok || ch != _ch {
 | 
				
			||||||
		// As we can implicitly delete both nicks and channels from being
 | 
							// As we can implicitly delete both nicks and channels from being
 | 
				
			||||||
		// tracked by dissociating one from the other, we should verify that
 | 
							// tracked by dissociating one from the other, we should verify that
 | 
				
			||||||
		// we're not being passed an old Nick or Channel.
 | 
							// we're not being passed an old Nick or Channel.
 | 
				
			||||||
		logging.Error("StateTracker.Associate(): channel %s not found in "+
 | 
							logging.Error("Tracker.Associate(): channel %s not found in "+
 | 
				
			||||||
			"(or differs from) internal state.", ch.Name)
 | 
								"(or differs from) internal state.", ch.Name)
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	} else if _nk, ok := st.nicks[nk.Nick]; !ok || nk != _nk {
 | 
						} else if _nk, ok := st.nicks[nk.Nick]; !ok || nk != _nk {
 | 
				
			||||||
		logging.Error("StateTracker.Associate(): nick %s not found in "+
 | 
							logging.Error("Tracker.Associate(): nick %s not found in "+
 | 
				
			||||||
			"(or differs from) internal state.", nk.Nick)
 | 
								"(or differs from) internal state.", nk.Nick)
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	} else if _, ok := nk.IsOn(ch); ok {
 | 
						} else if _, ok := nk.IsOn(ch); ok {
 | 
				
			||||||
		logging.Warn("StateTracker.Associate(): %s already on %s.",
 | 
							logging.Warn("Tracker.Associate(): %s already on %s.",
 | 
				
			||||||
			nk.Nick, ch.Name)
 | 
								nk.Nick, ch.Name)
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -220,18 +220,18 @@ func (st *stateTracker) Associate(ch *Channel, nk *Nick) *ChanPrivs {
 | 
				
			||||||
// any common channels with, and channels we're no longer on.
 | 
					// any common channels with, and channels we're no longer on.
 | 
				
			||||||
func (st *stateTracker) Dissociate(ch *Channel, nk *Nick) {
 | 
					func (st *stateTracker) Dissociate(ch *Channel, nk *Nick) {
 | 
				
			||||||
	if ch == nil || nk == nil {
 | 
						if ch == nil || nk == nil {
 | 
				
			||||||
		logging.Error("StateTracker.Dissociate(): passed nil values :-(")
 | 
							logging.Error("Tracker.Dissociate(): passed nil values :-(")
 | 
				
			||||||
	} else if _ch, ok := st.chans[ch.Name]; !ok || ch != _ch {
 | 
						} else if _ch, ok := st.chans[ch.Name]; !ok || ch != _ch {
 | 
				
			||||||
		// As we can implicitly delete both nicks and channels from being
 | 
							// As we can implicitly delete both nicks and channels from being
 | 
				
			||||||
		// tracked by dissociating one from the other, we should verify that
 | 
							// tracked by dissociating one from the other, we should verify that
 | 
				
			||||||
		// we're not being passed an old Nick or Channel.
 | 
							// we're not being passed an old Nick or Channel.
 | 
				
			||||||
		logging.Error("StateTracker.Dissociate(): channel %s not found in "+
 | 
							logging.Error("Tracker.Dissociate(): channel %s not found in "+
 | 
				
			||||||
			"(or differs from) internal state.", ch.Name)
 | 
								"(or differs from) internal state.", ch.Name)
 | 
				
			||||||
	} else if _nk, ok := st.nicks[nk.Nick]; !ok || nk != _nk {
 | 
						} else if _nk, ok := st.nicks[nk.Nick]; !ok || nk != _nk {
 | 
				
			||||||
		logging.Error("StateTracker.Dissociate(): nick %s not found in "+
 | 
							logging.Error("Tracker.Dissociate(): nick %s not found in "+
 | 
				
			||||||
			"(or differs from) internal state.", nk.Nick)
 | 
								"(or differs from) internal state.", nk.Nick)
 | 
				
			||||||
	} else if _, ok := nk.IsOn(ch); !ok {
 | 
						} else if _, ok := nk.IsOn(ch); !ok {
 | 
				
			||||||
		logging.Warn("StateTracker.Dissociate(): %s not on %s.",
 | 
							logging.Warn("Tracker.Dissociate(): %s not on %s.",
 | 
				
			||||||
			nk.Nick, ch.Name)
 | 
								nk.Nick, ch.Name)
 | 
				
			||||||
	} else if nk == st.me {
 | 
						} else if nk == st.me {
 | 
				
			||||||
		// I'm leaving the channel for some reason, so it won't be tracked.
 | 
							// I'm leaving the channel for some reason, so it won't be tracked.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue