2012-04-07 20:44:59 +02:00
|
|
|
package irc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Client struct {
|
2012-04-18 05:24:26 +02:00
|
|
|
conn net.Conn
|
2012-04-18 03:16:57 +02:00
|
|
|
send chan<- string
|
|
|
|
recv <-chan string
|
2012-04-08 08:32:08 +02:00
|
|
|
username string
|
|
|
|
realname string
|
|
|
|
nick string
|
2012-04-09 16:57:55 +02:00
|
|
|
registered bool
|
2012-04-18 05:24:26 +02:00
|
|
|
invisible bool
|
2012-04-07 20:44:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewClient(conn net.Conn) *Client {
|
2012-04-08 08:32:08 +02:00
|
|
|
client := new(Client)
|
2012-04-18 05:24:26 +02:00
|
|
|
client.conn = conn
|
2012-04-08 08:32:08 +02:00
|
|
|
client.send = StringWriteChan(conn)
|
|
|
|
client.recv = StringReadChan(conn)
|
|
|
|
return client
|
2012-04-07 20:44:59 +02:00
|
|
|
}
|
|
|
|
|
2012-04-08 08:32:08 +02:00
|
|
|
// Adapt `chan string` to a `chan Message`.
|
2012-04-18 03:16:57 +02:00
|
|
|
func (c *Client) Communicate(server chan<- *ClientMessage) {
|
|
|
|
for str := range c.recv {
|
|
|
|
m := ParseMessage(str)
|
|
|
|
if m != nil {
|
|
|
|
server <- &ClientMessage{c, m}
|
2012-04-08 08:32:08 +02:00
|
|
|
}
|
|
|
|
}
|
2012-04-07 20:44:59 +02:00
|
|
|
}
|
2012-04-09 16:57:55 +02:00
|
|
|
|
|
|
|
func (c *Client) Nick() string {
|
|
|
|
if c.nick != "" {
|
|
|
|
return c.nick
|
|
|
|
}
|
|
|
|
return "<guest>"
|
|
|
|
}
|
2012-04-18 05:24:26 +02:00
|
|
|
|
|
|
|
func (c *Client) UModeString() string {
|
|
|
|
if c.invisible {
|
|
|
|
return "+i"
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|