Improve port handling
This commit is contained in:
parent
2bffef825d
commit
13a3d96b44
File diff suppressed because one or more lines are too long
@ -2,9 +2,15 @@ import * as actions from '../actions';
|
|||||||
import { updateSelection } from './tab';
|
import { updateSelection } from './tab';
|
||||||
|
|
||||||
export function connect(server, nick, options) {
|
export function connect(server, nick, options) {
|
||||||
|
let host = server;
|
||||||
|
const i = server.indexOf(':');
|
||||||
|
if (i > 0) {
|
||||||
|
host = server.slice(0, i);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: actions.CONNECT,
|
type: actions.CONNECT,
|
||||||
server,
|
host,
|
||||||
nick,
|
nick,
|
||||||
options,
|
options,
|
||||||
socket: {
|
socket: {
|
||||||
|
@ -168,22 +168,20 @@ export default createReducer(Map(), {
|
|||||||
|
|
||||||
return state.withMutations(s => {
|
return state.withMutations(s => {
|
||||||
action.data.forEach(server => {
|
action.data.forEach(server => {
|
||||||
if (!state.has(server.address)) {
|
if (!state.has(server.host)) {
|
||||||
s.set(server.address, Map());
|
s.set(server.host, Map());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
[actions.CONNECT](state, action) {
|
[actions.CONNECT](state, action) {
|
||||||
let { server } = action;
|
const { host } = action;
|
||||||
const i = server.indexOf(':');
|
|
||||||
if (i > 0) {
|
if (!state.has(host)) {
|
||||||
server = server.slice(0, i);
|
return state.set(host, Map());
|
||||||
}
|
|
||||||
if (!state.has(server)) {
|
|
||||||
return state.set(server, Map());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -11,18 +11,16 @@ const Server = Record({
|
|||||||
|
|
||||||
export default createReducer(Map(), {
|
export default createReducer(Map(), {
|
||||||
[actions.CONNECT](state, action) {
|
[actions.CONNECT](state, action) {
|
||||||
let { server } = action;
|
const { host, nick, options } = action;
|
||||||
const { nick, options } = action;
|
|
||||||
|
|
||||||
const i = server.indexOf(':');
|
if (!state.has(host)) {
|
||||||
if (i > 0) {
|
return state.set(host, new Server({
|
||||||
server = server.slice(0, i);
|
nick,
|
||||||
|
name: options.name || host
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return state.set(server, new Server({
|
return state;
|
||||||
nick,
|
|
||||||
name: options.name || server
|
|
||||||
}));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
[actions.DISCONNECT](state, action) {
|
[actions.DISCONNECT](state, action) {
|
||||||
@ -41,7 +39,7 @@ export default createReducer(Map(), {
|
|||||||
|
|
||||||
return state.withMutations(s => {
|
return state.withMutations(s => {
|
||||||
action.data.forEach(server => {
|
action.data.forEach(server => {
|
||||||
s.set(server.address, new Server(server));
|
s.set(server.host, new Server(server));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -2,6 +2,7 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"net"
|
||||||
|
|
||||||
"github.com/khlieng/dispatch/irc"
|
"github.com/khlieng/dispatch/irc"
|
||||||
"github.com/khlieng/dispatch/storage"
|
"github.com/khlieng/dispatch/storage"
|
||||||
@ -28,13 +29,13 @@ func reconnectIRC() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i.Connect(server.Address)
|
session.setIRC(server.Host, i)
|
||||||
session.setIRC(i.Host, i)
|
i.Connect(net.JoinHostPort(server.Host, server.Port))
|
||||||
go newIRCHandler(i, session).run()
|
go newIRCHandler(i, session).run()
|
||||||
|
|
||||||
var joining []string
|
var joining []string
|
||||||
for _, channel := range channels {
|
for _, channel := range channels {
|
||||||
if channel.Server == server.Address {
|
if channel.Server == server.Host {
|
||||||
joining = append(joining, channel.Name)
|
joining = append(joining, channel.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"net"
|
||||||
|
|
||||||
"github.com/khlieng/dispatch/Godeps/_workspace/src/github.com/gorilla/websocket"
|
"github.com/khlieng/dispatch/Godeps/_workspace/src/github.com/gorilla/websocket"
|
||||||
|
|
||||||
@ -98,7 +98,12 @@ func (h *wsHandler) connect(b []byte) {
|
|||||||
var data Connect
|
var data Connect
|
||||||
json.Unmarshal(b, &data)
|
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)
|
log.Println(h.addr, "connecting to", data.Server)
|
||||||
|
|
||||||
i := irc.NewClient(data.Nick, data.Username)
|
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(host, i)
|
||||||
h.session.setIRC(data.Server, i)
|
|
||||||
} else {
|
|
||||||
h.session.setIRC(data.Server[:idx], i)
|
|
||||||
}
|
|
||||||
|
|
||||||
i.Connect(data.Server)
|
i.Connect(data.Server)
|
||||||
go newIRCHandler(i, h.session).run()
|
go newIRCHandler(i, h.session).run()
|
||||||
|
|
||||||
h.session.user.AddServer(storage.Server{
|
h.session.user.AddServer(storage.Server{
|
||||||
Name: data.Name,
|
Name: data.Name,
|
||||||
Address: i.Host,
|
Host: host,
|
||||||
|
Port: port,
|
||||||
TLS: data.TLS,
|
TLS: data.TLS,
|
||||||
Password: data.Password,
|
Password: data.Password,
|
||||||
Nick: data.Nick,
|
Nick: data.Nick,
|
||||||
|
@ -16,7 +16,8 @@ import (
|
|||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Address string `json:"address"`
|
Host string `json:"host"`
|
||||||
|
Port string `json:"port,omitempty"`
|
||||||
TLS bool `json:"tls"`
|
TLS bool `json:"tls"`
|
||||||
Password string `json:"password,omitempty"`
|
Password string `json:"password,omitempty"`
|
||||||
Nick string `json:"nick"`
|
Nick string `json:"nick"`
|
||||||
@ -134,7 +135,7 @@ func (u *User) AddServer(server Server) {
|
|||||||
b := tx.Bucket([]byte("Servers"))
|
b := tx.Bucket([]byte("Servers"))
|
||||||
data, _ := json.Marshal(server)
|
data, _ := json.Marshal(server)
|
||||||
|
|
||||||
b.Put([]byte(u.UUID+":"+server.Address), data)
|
b.Put([]byte(u.UUID+":"+server.Host), data)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user