Exemple #1
0
// NewClientWithOpts ...
func NewClientWithOpts(conn net.Conn, user *User, options *ClientOpts) *Client {
	c := &Client{
		User:       user,
		remoteAddr: conn.RemoteAddr(),
		localAddr:  conn.LocalAddr(),
		connection: irc.NewConn(conn),
		err:        make(chan error, 1000000),
		reg:        make(chan bool, 1),
	}

	if options != nil {
		c.requestInterceptor = options.RequestInterceptor
		c.responseInterceptor = options.ResponseInterceptor
		c.logger = options.Logger
	}

	return c
}
Exemple #2
0
func (cc *ClientConn) Connect(h *Handlers) (err error) {

	conn, err := cc.dial("tcp", cc.Address)
	if err != nil {

		return
	}
	if cc.TlsConfig != nil {

		conn = tls.Client(conn, cc.TlsConfig)
	}
	cc.Conn = irc.NewConn(conn)

	// Run the RegisterConnection handler if ClientConnected not defined
	if h.ClientConnected == nil {

		if err = cc.RegisterClient(); err != nil {

			return
		}
	} else {

		if err = h.ClientConnected(); err != nil {

			return
		}
	}

	// Run the handlers
	if h != nil {

		for {

			err = cc.RunHandlers(h)
			if err != nil {

				return
			}
		}
	}

	return
}