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

49 lines
791 B
Go
Raw Normal View History

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
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`.
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 ""
}