|
@@ -15,6 +15,7 @@ type Client struct {
|
15
|
15
|
awayMessage string
|
16
|
16
|
channels ChannelSet
|
17
|
17
|
conn net.Conn
|
|
18
|
+ ctime time.Time
|
18
|
19
|
destroyed bool
|
19
|
20
|
hostname string
|
20
|
21
|
idleTimer *time.Timer
|
|
@@ -32,9 +33,12 @@ type Client struct {
|
32
|
33
|
}
|
33
|
34
|
|
34
|
35
|
func NewClient(server *Server, conn net.Conn) *Client {
|
|
36
|
+ now := time.Now()
|
35
|
37
|
client := &Client{
|
|
38
|
+ atime: now,
|
36
|
39
|
channels: make(ChannelSet),
|
37
|
40
|
conn: conn,
|
|
41
|
+ ctime: now,
|
38
|
42
|
hostname: AddrLookupHostname(conn.RemoteAddr()),
|
39
|
43
|
replies: make(chan Reply),
|
40
|
44
|
server: server,
|
|
@@ -136,7 +140,7 @@ func (client *Client) writeConn() {
|
136
|
140
|
|
137
|
141
|
for reply := range client.replies {
|
138
|
142
|
if DEBUG_CLIENT {
|
139
|
|
- log.Printf("%s ← %s %s", client, reply.Source(), reply)
|
|
143
|
+ log.Printf("%s ← %s", client, reply)
|
140
|
144
|
}
|
141
|
145
|
for _, str := range reply.Format(client) {
|
142
|
146
|
if DEBUG_NET {
|
|
@@ -161,6 +165,12 @@ func (client *Client) Destroy() {
|
161
|
165
|
return
|
162
|
166
|
}
|
163
|
167
|
|
|
168
|
+ if DEBUG_CLIENT {
|
|
169
|
+ log.Printf("%s destroy", client)
|
|
170
|
+ }
|
|
171
|
+
|
|
172
|
+ client.destroyed = true
|
|
173
|
+
|
164
|
174
|
client.conn.Close()
|
165
|
175
|
|
166
|
176
|
close(client.replies)
|
|
@@ -179,11 +189,13 @@ func (client *Client) Destroy() {
|
179
|
189
|
|
180
|
190
|
client.server.clients.Remove(client)
|
181
|
191
|
|
182
|
|
- client.destroyed = true
|
183
|
192
|
}
|
184
|
193
|
|
185
|
194
|
func (client *Client) Reply(replies ...Reply) {
|
186
|
|
- if client.replies == nil {
|
|
195
|
+ if client.destroyed {
|
|
196
|
+ if DEBUG_CLIENT {
|
|
197
|
+ log.Printf("%s.Reply: destroyed", client)
|
|
198
|
+ }
|
187
|
199
|
return
|
188
|
200
|
}
|
189
|
201
|
for _, reply := range replies {
|