3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00
ergo/src/irc/client.go

41 lines
698 B
Go
Raw Normal View History

2012-04-07 20:44:59 +02:00
package irc
import (
"net"
)
type Client struct {
2012-04-08 08:32:08 +02:00
addr net.Addr
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-07 20:44:59 +02:00
}
func NewClient(conn net.Conn) *Client {
2012-04-08 08:32:08 +02:00
client := new(Client)
client.addr = conn.RemoteAddr()
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`.
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>"
}