forked from External/ergo
Another massive refactor to support mutliple connections per nick.
This commit is contained in:
parent
559445d9a8
commit
f2aedbaffd
11 changed files with 636 additions and 443 deletions
|
|
@ -9,7 +9,7 @@ import (
|
|||
|
||||
type Client struct {
|
||||
conn net.Conn
|
||||
send chan<- Reply
|
||||
replies chan<- Reply
|
||||
username string
|
||||
realname string
|
||||
hostname string
|
||||
|
|
@ -17,10 +17,9 @@ type Client struct {
|
|||
serverPass bool
|
||||
registered bool
|
||||
away bool
|
||||
wallOps bool
|
||||
server *Server
|
||||
channels ChannelSet
|
||||
atime time.Time
|
||||
user *User
|
||||
}
|
||||
|
||||
type ClientSet map[*Client]bool
|
||||
|
|
@ -28,21 +27,20 @@ type ClientSet map[*Client]bool
|
|||
func NewClient(server *Server, conn net.Conn) *Client {
|
||||
read := StringReadChan(conn)
|
||||
write := StringWriteChan(conn)
|
||||
send := make(chan Reply)
|
||||
replies := make(chan Reply)
|
||||
|
||||
client := &Client{
|
||||
channels: make(ChannelSet),
|
||||
conn: conn,
|
||||
hostname: LookupHostname(conn.RemoteAddr()),
|
||||
server: server,
|
||||
send: send,
|
||||
replies: replies,
|
||||
}
|
||||
|
||||
// Connect the conn to the server.
|
||||
go client.readConn(read)
|
||||
|
||||
// Connect the reply channel to the conn.
|
||||
go client.writeConn(write, send)
|
||||
go client.writeConn(write, replies)
|
||||
|
||||
return client
|
||||
}
|
||||
|
|
@ -51,19 +49,19 @@ func (c *Client) readConn(recv <-chan string) {
|
|||
for str := range recv {
|
||||
log.Printf("%s > %s", c.Id(), str)
|
||||
|
||||
m, err := ParseMessage(str)
|
||||
m, err := ParseCommand(str)
|
||||
if err != nil {
|
||||
// TODO handle error
|
||||
continue
|
||||
}
|
||||
|
||||
m.SetClient(c)
|
||||
c.server.recv <- m
|
||||
c.server.commands <- m
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) writeConn(write chan<- string, send <-chan Reply) {
|
||||
for reply := range send {
|
||||
func (c *Client) writeConn(write chan<- string, replies <-chan Reply) {
|
||||
for reply := range replies {
|
||||
replyStr := reply.String(c)
|
||||
log.Printf("%s < %s", c.Id(), replyStr)
|
||||
write <- replyStr
|
||||
|
|
@ -71,16 +69,18 @@ func (c *Client) writeConn(write chan<- string, send <-chan Reply) {
|
|||
}
|
||||
|
||||
func (c *Client) Nick() string {
|
||||
if c.user != nil {
|
||||
return c.user.nick
|
||||
}
|
||||
|
||||
if c.nick != "" {
|
||||
return c.nick
|
||||
}
|
||||
|
||||
return "*"
|
||||
}
|
||||
|
||||
func (c *Client) UModeString() string {
|
||||
if c.wallOps {
|
||||
return "+w"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
|
|
@ -106,3 +106,7 @@ func (c *Client) UserHost() string {
|
|||
func (c *Client) Id() string {
|
||||
return c.UserHost()
|
||||
}
|
||||
|
||||
func (c *Client) PublicId() string {
|
||||
return fmt.Sprintf("%s!%s@%s", c.Nick(), c.Nick(), c.server.Id())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue