mirror of https://github.com/fluffle/goirc
Enable SSL IRC for goirc.
This commit is contained in:
parent
c4d09cd228
commit
05e3500a3c
|
@ -15,7 +15,7 @@ func main() {
|
|||
func(conn *irc.Conn, line *irc.Line) { conn.Join("#go-nuts") })
|
||||
|
||||
// connect to server
|
||||
if err := c.Connect("irc.freenode.net", ""); err != nil {
|
||||
if err := c.Connect("irc.freenode.net", false); err != nil {
|
||||
fmt.Printf("Connection error: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ func main() {
|
|||
break
|
||||
}
|
||||
fmt.Println("Reconnecting...")
|
||||
if err := c.Connect("irc.freenode.net", ""); err != nil {
|
||||
if err := c.Connect("irc.freenode.net", false); err != nil {
|
||||
fmt.Printf("Connection error: %s\n", err)
|
||||
break
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bufio"
|
||||
"os"
|
||||
"net"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -17,17 +18,20 @@ type Conn struct {
|
|||
Me *Nick
|
||||
|
||||
// I/O stuff to server
|
||||
sock *net.TCPConn
|
||||
sock net.Conn
|
||||
io *bufio.ReadWriter
|
||||
in chan *Line
|
||||
out chan string
|
||||
connected bool
|
||||
|
||||
// Are we connecting via SSL?
|
||||
SSL bool
|
||||
|
||||
// Error channel to transmit any fail back to the user
|
||||
Err chan os.Error
|
||||
|
||||
// Set this to true to disable flood protection and false to re-enable
|
||||
Flood bool;
|
||||
Flood bool
|
||||
|
||||
// Event handler mapping
|
||||
events map[string][]func(*Conn, *Line)
|
||||
|
@ -78,22 +82,36 @@ func (conn *Conn) initialise() {
|
|||
}
|
||||
|
||||
// Connect the IRC connection object to "host[:port]" which should be either
|
||||
// a hostname or an IP address, with an optional port defaulting to 6667.
|
||||
// You can also provide an optional connect password.
|
||||
func (conn *Conn) Connect(host string, pass ...string) os.Error {
|
||||
// a hostname or an IP address, with an optional port. To enable explicit SSL
|
||||
// on the connection to the IRC server, set ssl to true. The port will default
|
||||
// to 6697 if ssl is enabled, and 6667 otherwise. You can also provide an
|
||||
// optional connect password.
|
||||
func (conn *Conn) Connect(host string, ssl bool, pass ...string) os.Error {
|
||||
if conn.connected {
|
||||
return os.NewError(fmt.Sprintf("irc.Connect(): already connected to %s, cannot connect to %s", conn.Host, host))
|
||||
}
|
||||
if !hasPort(host) {
|
||||
host += ":6667"
|
||||
if ssl {
|
||||
host += ":6697"
|
||||
} else {
|
||||
host += ":6667"
|
||||
}
|
||||
}
|
||||
|
||||
if addr, err := net.ResolveTCPAddr(host); err != nil {
|
||||
return err
|
||||
} else if conn.sock, err = net.DialTCP("tcp", nil, addr); err != nil {
|
||||
var sock net.Conn;
|
||||
var err os.Error;
|
||||
if ssl {
|
||||
sock, err = tls.Dial("tcp", "", host)
|
||||
} else {
|
||||
sock, err = net.Dial("tcp", "", host)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
conn.Host = host
|
||||
conn.SSL = ssl
|
||||
conn.sock = sock
|
||||
|
||||
conn.io = bufio.NewReadWriter(
|
||||
bufio.NewReader(conn.sock),
|
||||
|
|
Loading…
Reference in New Issue