dispatch/server/irc.go

51 lines
1020 B
Go
Raw Normal View History

2016-01-04 18:26:32 +00:00
package server
import (
2016-01-11 20:04:57 +00:00
"crypto/tls"
2016-01-14 04:56:53 +00:00
"net"
2016-01-11 20:04:57 +00:00
2016-01-04 18:26:32 +00:00
"github.com/khlieng/dispatch/irc"
"github.com/khlieng/dispatch/storage"
)
func reconnectIRC() {
for _, user := range storage.LoadUsers() {
session := NewSession(user)
sessions[user.ID] = session
2016-01-04 18:26:32 +00:00
go session.write()
channels := user.GetChannels()
for _, server := range user.GetServers() {
i := irc.NewClient(server.Nick, server.Username)
i.TLS = server.TLS
i.Password = server.Password
i.Realname = server.Realname
2016-01-11 23:32:40 +00:00
if cert := user.GetCertificate(); cert != nil {
2016-01-11 20:04:57 +00:00
i.TLSConfig = &tls.Config{
2016-01-11 23:32:40 +00:00
Certificates: []tls.Certificate{*cert},
2016-01-11 20:04:57 +00:00
}
}
2016-01-14 04:56:53 +00:00
session.setIRC(server.Host, i)
if server.Port != "" {
i.Connect(net.JoinHostPort(server.Host, server.Port))
} else {
i.Connect(server.Host)
}
2016-01-04 18:26:32 +00:00
go newIRCHandler(i, session).run()
var joining []string
for _, channel := range channels {
2016-01-14 04:56:53 +00:00
if channel.Server == server.Host {
2016-01-04 18:26:32 +00:00
joining = append(joining, channel.Name)
}
}
i.Join(joining...)
}
}
}