Show last IRC connection error in status tab, log IRC connection errors
This commit is contained in:
parent
786d8013b9
commit
18aff3ded6
19 changed files with 294 additions and 189 deletions
|
@ -1,6 +1,7 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
@ -37,6 +38,7 @@ func newIRCHandler(client *irc.Client, session *Session) *ircHandler {
|
|||
}
|
||||
|
||||
func (i *ircHandler) run() {
|
||||
var lastConnErr error
|
||||
for {
|
||||
select {
|
||||
case msg, ok := <-i.client.Messages:
|
||||
|
@ -47,11 +49,17 @@ func (i *ircHandler) run() {
|
|||
|
||||
i.dispatchMessage(msg)
|
||||
|
||||
case connected := <-i.client.ConnectionChanged:
|
||||
i.session.sendJSON("connection_update", map[string]bool{
|
||||
i.client.Host: connected,
|
||||
})
|
||||
i.session.setConnectionState(i.client.Host, connected)
|
||||
case state := <-i.client.ConnectionChanged:
|
||||
i.session.sendJSON("connection_update", newConnectionUpdate(i.client.Host, state))
|
||||
i.session.setConnectionState(i.client.Host, state)
|
||||
|
||||
if state.Error != nil && (lastConnErr == nil ||
|
||||
state.Error.Error() != lastConnErr.Error()) {
|
||||
lastConnErr = state.Error
|
||||
i.log("Connection error:", state.Error)
|
||||
} else if state.Connected {
|
||||
i.log("Connected")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -312,6 +320,11 @@ func (i *ircHandler) initHandlers() {
|
|||
}
|
||||
}
|
||||
|
||||
func (i *ircHandler) log(v ...interface{}) {
|
||||
s := fmt.Sprintln(v...)
|
||||
log.Println("[IRC]", i.session.user.ID, i.client.Host, s[:len(s)-1])
|
||||
}
|
||||
|
||||
func parseMode(mode string) *Mode {
|
||||
m := Mode{}
|
||||
add := false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue