1
0
Fork 0
forked from External/ergo

Massive refactor to support multiple connections and NickServ.

This commit is contained in:
Jeremy Latt 2012-12-16 19:13:53 -08:00
parent f2aedbaffd
commit 4b0cfa816c
10 changed files with 487 additions and 258 deletions

View file

@ -7,9 +7,13 @@ import (
"time"
)
type Replier interface {
Identifier
Replies() chan<- Reply
}
type Client struct {
conn net.Conn
replies chan<- Reply
username string
realname string
hostname string
@ -20,6 +24,12 @@ type Client struct {
server *Server
atime time.Time
user *User
replies chan<- Reply
}
type ClientMessage interface {
Client() *Client
SetClient(*Client)
}
type ClientSet map[*Client]bool
@ -36,10 +46,7 @@ func NewClient(server *Server, conn net.Conn) *Client {
replies: replies,
}
// Connect the conn to the server.
go client.readConn(read)
// Connect the reply channel to the conn.
go client.writeConn(write, replies)
return client
@ -51,7 +58,7 @@ func (c *Client) readConn(recv <-chan string) {
m, err := ParseCommand(str)
if err != nil {
// TODO handle error
c.replies <- ErrNeedMoreParams(c.server, str)
continue
}
@ -68,6 +75,14 @@ func (c *Client) writeConn(write chan<- string, replies <-chan Reply) {
}
}
func (c *Client) Replies() chan<- Reply {
return c.replies
}
func (c *Client) Server() *Server {
return c.server
}
func (c *Client) Nick() string {
if c.user != nil {
return c.user.nick