Improve port handling
This commit is contained in:
parent
2bffef825d
commit
13a3d96b44
7 changed files with 48 additions and 43 deletions
|
@ -2,6 +2,7 @@ package server
|
|||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net"
|
||||
|
||||
"github.com/khlieng/dispatch/irc"
|
||||
"github.com/khlieng/dispatch/storage"
|
||||
|
@ -28,13 +29,13 @@ func reconnectIRC() {
|
|||
}
|
||||
}
|
||||
|
||||
i.Connect(server.Address)
|
||||
session.setIRC(i.Host, i)
|
||||
session.setIRC(server.Host, i)
|
||||
i.Connect(net.JoinHostPort(server.Host, server.Port))
|
||||
go newIRCHandler(i, session).run()
|
||||
|
||||
var joining []string
|
||||
for _, channel := range channels {
|
||||
if channel.Server == server.Address {
|
||||
if channel.Server == server.Host {
|
||||
joining = append(joining, channel.Name)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"strings"
|
||||
"net"
|
||||
|
||||
"github.com/khlieng/dispatch/Godeps/_workspace/src/github.com/gorilla/websocket"
|
||||
|
||||
|
@ -98,7 +98,12 @@ func (h *wsHandler) connect(b []byte) {
|
|||
var data Connect
|
||||
json.Unmarshal(b, &data)
|
||||
|
||||
if _, ok := h.session.getIRC(data.Server); !ok {
|
||||
host, port, err := net.SplitHostPort(data.Server)
|
||||
if err != nil {
|
||||
host = data.Server
|
||||
}
|
||||
|
||||
if _, ok := h.session.getIRC(host); !ok {
|
||||
log.Println(h.addr, "connecting to", data.Server)
|
||||
|
||||
i := irc.NewClient(data.Nick, data.Username)
|
||||
|
@ -112,18 +117,14 @@ func (h *wsHandler) connect(b []byte) {
|
|||
}
|
||||
}
|
||||
|
||||
if idx := strings.Index(data.Server, ":"); idx < 0 {
|
||||
h.session.setIRC(data.Server, i)
|
||||
} else {
|
||||
h.session.setIRC(data.Server[:idx], i)
|
||||
}
|
||||
|
||||
h.session.setIRC(host, i)
|
||||
i.Connect(data.Server)
|
||||
go newIRCHandler(i, h.session).run()
|
||||
|
||||
h.session.user.AddServer(storage.Server{
|
||||
Name: data.Name,
|
||||
Address: i.Host,
|
||||
Host: host,
|
||||
Port: port,
|
||||
TLS: data.TLS,
|
||||
Password: data.Password,
|
||||
Nick: data.Nick,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue