Add identd
This commit is contained in:
parent
67fe5d263d
commit
e0d2243248
9 changed files with 140 additions and 6 deletions
|
@ -46,6 +46,8 @@ func newIRCHandler(client *irc.Client, state *State) *ircHandler {
|
|||
|
||||
func (i *ircHandler) run() {
|
||||
var lastConnErr error
|
||||
var localPort string
|
||||
|
||||
for {
|
||||
select {
|
||||
case msg, ok := <-i.client.Messages:
|
||||
|
@ -57,6 +59,16 @@ func (i *ircHandler) run() {
|
|||
i.dispatchMessage(msg)
|
||||
|
||||
case state := <-i.client.ConnectionChanged:
|
||||
if identd := i.state.srv.identd; identd != nil {
|
||||
if state.Connected {
|
||||
if localPort = i.client.LocalPort(); localPort != "" {
|
||||
identd.Add(localPort, i.client.Config.Port, i.client.Config.Username)
|
||||
}
|
||||
} else {
|
||||
identd.Remove(localPort, i.client.Config.Port)
|
||||
}
|
||||
}
|
||||
|
||||
i.state.sendJSON("connection_update", newConnectionUpdate(i.client.Host(), state))
|
||||
|
||||
if network, ok := i.state.network(i.client.Host()); ok {
|
||||
|
@ -297,6 +309,16 @@ func (i *ircHandler) info(msg *irc.Message) {
|
|||
i.client.List()
|
||||
}
|
||||
|
||||
if identd := i.state.srv.identd; identd != nil {
|
||||
if localPort := i.client.LocalPort(); localPort != "" {
|
||||
identd.Remove(localPort, i.client.Config.Port)
|
||||
}
|
||||
}
|
||||
|
||||
if network, ok := i.state.network(i.client.Host()); ok {
|
||||
network.SetNick(msg.Params[0])
|
||||
}
|
||||
|
||||
go i.state.user.SetNick(msg.Params[0], i.client.Host())
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ func dispatchMessageMulti(msg *irc.Message) chan WSResponse {
|
|||
Username: "user",
|
||||
Host: "host.com",
|
||||
})
|
||||
s := NewState(user, nil)
|
||||
s := NewState(user, &Dispatch{})
|
||||
|
||||
newIRCHandler(c, s).dispatchMessage(msg)
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/gorilla/websocket"
|
||||
"github.com/khlieng/dispatch/config"
|
||||
"github.com/khlieng/dispatch/pkg/https"
|
||||
"github.com/khlieng/dispatch/pkg/ident"
|
||||
"github.com/khlieng/dispatch/pkg/session"
|
||||
"github.com/khlieng/dispatch/storage"
|
||||
)
|
||||
|
@ -24,6 +25,7 @@ type Dispatch struct {
|
|||
cfg *config.Config
|
||||
upgrader websocket.Upgrader
|
||||
states *stateStore
|
||||
identd *ident.Server
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
|
@ -47,17 +49,24 @@ func (d *Dispatch) SetConfig(cfg *config.Config) {
|
|||
}
|
||||
|
||||
func (d *Dispatch) Run() {
|
||||
cfg := d.Config()
|
||||
|
||||
d.upgrader = websocket.Upgrader{
|
||||
ReadBufferSize: 1024,
|
||||
WriteBufferSize: 1024,
|
||||
}
|
||||
|
||||
if d.Config().Dev {
|
||||
if cfg.Dev {
|
||||
d.upgrader.CheckOrigin = func(r *http.Request) bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.Identd {
|
||||
d.identd = ident.NewServer()
|
||||
go d.identd.Listen()
|
||||
}
|
||||
|
||||
session.CookieName = "dispatch"
|
||||
|
||||
d.states = newStateStore(d.SessionStore)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue