Pull reconnect code out of main(), add missing params and error handling
This commit is contained in:
parent
6e223c172f
commit
ae78ac5017
62
main.go
62
main.go
@ -19,6 +19,41 @@ var (
|
||||
fs http.Handler
|
||||
)
|
||||
|
||||
func reconnect() {
|
||||
for _, user := range storage.LoadUsers() {
|
||||
channels := user.GetChannels()
|
||||
|
||||
for _, server := range user.GetServers() {
|
||||
session := NewSession()
|
||||
session.user = user
|
||||
sessions[user.UUID] = session
|
||||
|
||||
irc := NewIRC(server.Nick, server.Username)
|
||||
irc.TLS = server.TLS
|
||||
irc.Password = server.Password
|
||||
irc.Realname = server.Realname
|
||||
|
||||
err := irc.Connect(server.Address)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
session.setIRC(irc.Host, irc)
|
||||
|
||||
go session.write()
|
||||
go handleMessages(irc, session)
|
||||
|
||||
var joining []string
|
||||
for _, channel := range channels {
|
||||
if channel.Server == server.Address {
|
||||
joining = append(joining, channel.Name)
|
||||
}
|
||||
}
|
||||
irc.Join(joining...)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func serveFiles(w http.ResponseWriter, r *http.Request) {
|
||||
var ext string
|
||||
|
||||
@ -48,32 +83,7 @@ func main() {
|
||||
sessions = make(map[string]*Session)
|
||||
fs = http.FileServer(http.Dir("client/dist"))
|
||||
|
||||
/*for _, user := range storage.LoadUsers() {
|
||||
channels := user.GetChannels()
|
||||
|
||||
for _, server := range user.GetServers() {
|
||||
session := NewSession()
|
||||
session.user = user
|
||||
sessions[user.UUID] = session
|
||||
|
||||
irc := NewIRC(server.Nick, server.Username)
|
||||
irc.TLS = server.TLS
|
||||
irc.Connect(server.Address)
|
||||
|
||||
session.setIRC(irc.Host, irc)
|
||||
|
||||
go session.write()
|
||||
go handleMessages(irc, session)
|
||||
|
||||
var joining []string
|
||||
for _, channel := range channels {
|
||||
if channel.Server == server.Address {
|
||||
joining = append(joining, channel.Name)
|
||||
}
|
||||
}
|
||||
irc.Join(joining...)
|
||||
}
|
||||
}*/
|
||||
//reconnect()
|
||||
|
||||
router := httprouter.New()
|
||||
|
||||
|
@ -85,7 +85,8 @@ func handleWS(ws *websocket.Conn) {
|
||||
irc.Password = data.Password
|
||||
irc.Realname = data.Realname
|
||||
|
||||
if err := irc.Connect(data.Server); err != nil {
|
||||
err := irc.Connect(data.Server)
|
||||
if err != nil {
|
||||
session.sendError(err, irc.Host)
|
||||
log.Println(err)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user