mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
add more logging
This commit is contained in:
parent
b6a7d98b64
commit
b8bbc7eeb5
@ -15,6 +15,7 @@ type Client struct {
|
|||||||
awayMessage string
|
awayMessage string
|
||||||
channels ChannelSet
|
channels ChannelSet
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
|
ctime time.Time
|
||||||
destroyed bool
|
destroyed bool
|
||||||
hostname string
|
hostname string
|
||||||
idleTimer *time.Timer
|
idleTimer *time.Timer
|
||||||
@ -32,9 +33,12 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(server *Server, conn net.Conn) *Client {
|
func NewClient(server *Server, conn net.Conn) *Client {
|
||||||
|
now := time.Now()
|
||||||
client := &Client{
|
client := &Client{
|
||||||
|
atime: now,
|
||||||
channels: make(ChannelSet),
|
channels: make(ChannelSet),
|
||||||
conn: conn,
|
conn: conn,
|
||||||
|
ctime: now,
|
||||||
hostname: AddrLookupHostname(conn.RemoteAddr()),
|
hostname: AddrLookupHostname(conn.RemoteAddr()),
|
||||||
replies: make(chan Reply),
|
replies: make(chan Reply),
|
||||||
server: server,
|
server: server,
|
||||||
@ -136,7 +140,7 @@ func (client *Client) writeConn() {
|
|||||||
|
|
||||||
for reply := range client.replies {
|
for reply := range client.replies {
|
||||||
if DEBUG_CLIENT {
|
if DEBUG_CLIENT {
|
||||||
log.Printf("%s ← %s %s", client, reply.Source(), reply)
|
log.Printf("%s ← %s", client, reply)
|
||||||
}
|
}
|
||||||
for _, str := range reply.Format(client) {
|
for _, str := range reply.Format(client) {
|
||||||
if DEBUG_NET {
|
if DEBUG_NET {
|
||||||
@ -161,6 +165,12 @@ func (client *Client) Destroy() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if DEBUG_CLIENT {
|
||||||
|
log.Printf("%s destroy", client)
|
||||||
|
}
|
||||||
|
|
||||||
|
client.destroyed = true
|
||||||
|
|
||||||
client.conn.Close()
|
client.conn.Close()
|
||||||
|
|
||||||
close(client.replies)
|
close(client.replies)
|
||||||
@ -179,11 +189,13 @@ func (client *Client) Destroy() {
|
|||||||
|
|
||||||
client.server.clients.Remove(client)
|
client.server.clients.Remove(client)
|
||||||
|
|
||||||
client.destroyed = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) Reply(replies ...Reply) {
|
func (client *Client) Reply(replies ...Reply) {
|
||||||
if client.replies == nil {
|
if client.destroyed {
|
||||||
|
if DEBUG_CLIENT {
|
||||||
|
log.Printf("%s.Reply: destroyed", client)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, reply := range replies {
|
for _, reply := range replies {
|
||||||
|
11
irc/net.go
11
irc/net.go
@ -1,6 +1,7 @@
|
|||||||
package irc
|
package irc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -19,9 +20,17 @@ func AddrLookupHostname(addr net.Addr) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func LookupHostname(addr string) string {
|
func LookupHostname(addr string) string {
|
||||||
|
if DEBUG_NET {
|
||||||
|
log.Printf("LookupHostname(%s)", addr)
|
||||||
|
}
|
||||||
names, err := net.LookupAddr(addr)
|
names, err := net.LookupAddr(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
return strings.TrimSuffix(names[0], ".")
|
|
||||||
|
hostname := strings.TrimSuffix(names[0], ".")
|
||||||
|
if DEBUG_NET {
|
||||||
|
log.Printf("LookupHostname(%s) → %s", addr, hostname)
|
||||||
|
}
|
||||||
|
return hostname
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ func NewServer(config *Config) *Server {
|
|||||||
func (server *Server) receiveCommands(commands <-chan Command) {
|
func (server *Server) receiveCommands(commands <-chan Command) {
|
||||||
for command := range commands {
|
for command := range commands {
|
||||||
if DEBUG_SERVER {
|
if DEBUG_SERVER {
|
||||||
log.Printf("%s → %s %s", command.Client(), server, command)
|
log.Printf("%s → %s %+v", command.Client(), server, command)
|
||||||
}
|
}
|
||||||
client := command.Client()
|
client := command.Client()
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ func (server *Server) receiveCommands(commands <-chan Command) {
|
|||||||
command.HandleServer(server)
|
command.HandleServer(server)
|
||||||
|
|
||||||
if DEBUG_SERVER {
|
if DEBUG_SERVER {
|
||||||
log.Printf("%s → %s %s processed", command.Client(), server, command)
|
log.Printf("%s → %s %+v processed", command.Client(), server, command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user