replies shouldn't contain references to client

This commit is contained in:
Jeremy Latt 2014-02-19 19:30:49 -08:00
parent 9c385ededd
commit 25ebab37d3
5 changed files with 17 additions and 17 deletions

View File

@ -38,7 +38,7 @@ func (channel *Channel) Reply(reply Reply) {
for client := range channel.members {
if (reply.Code() == ReplyCode(PRIVMSG)) &&
(reply.Source() == Identifier(client)) {
(reply.Source() == client.Id()) {
continue
}
client.Reply(reply)

View File

@ -28,7 +28,7 @@ type Client struct {
phase Phase
quitTimer *time.Timer
realname string
replies chan string
replies chan Reply
server *Server
socket *Socket
username string
@ -46,7 +46,7 @@ func NewClient(server *Server, conn net.Conn) *Client {
phase: server.InitPhase(),
server: server,
socket: NewSocket(conn),
replies: make(chan string),
replies: make(chan Reply),
}
client.loginTimer = time.AfterFunc(LOGIN_TIMEOUT, client.connectionTimeout)
@ -96,8 +96,8 @@ func (client *Client) connectionClosed() {
//
func (client *Client) writeReplies() {
for line := range client.replies {
client.socket.Write(line)
for reply := range client.replies {
client.socket.Write(reply.Format(client)...)
}
client.socket.Close()
client.doneWriting <- true
@ -195,9 +195,7 @@ func (client *Client) Reply(reply Reply) {
}
return
}
for _, line := range reply.Format(client) {
client.replies <- line
}
client.replies <- reply
}
func (client *Client) IdleTime() time.Duration {

View File

@ -10,7 +10,6 @@ type BaseReply struct {
code ReplyCode
id string
message string
source Identifier
}
func (reply *BaseReply) Code() ReplyCode {
@ -19,11 +18,10 @@ func (reply *BaseReply) Code() ReplyCode {
func (reply *BaseReply) SetSource(source Identifier) {
reply.id = source.Id()
reply.source = source
}
func (reply *BaseReply) Source() Identifier {
return reply.source
func (reply *BaseReply) Source() string {
return reply.id
}
type StringReply struct {

View File

@ -17,7 +17,7 @@ type Server struct {
channels ChannelNameMap
clients ClientNameMap
commands chan Command
conns chan net.Conn
newConns chan net.Conn
ctime time.Time
idle chan *Client
motdFile string
@ -31,7 +31,7 @@ func NewServer(config *Config) *Server {
channels: make(ChannelNameMap),
clients: make(ClientNameMap),
commands: make(chan Command),
conns: make(chan net.Conn),
newConns: make(chan net.Conn),
ctime: time.Now(),
idle: make(chan *Client),
motdFile: config.MOTD,
@ -54,7 +54,7 @@ func NewServer(config *Config) *Server {
func (server *Server) ReceiveCommands() {
for {
select {
case conn := <-server.conns:
case conn := <-server.newConns:
NewClient(server, conn)
case client := <-server.idle:
@ -126,6 +126,10 @@ func newListener(config ListenerConfig) (net.Listener, error) {
return net.Listen("tcp", config.Address)
}
//
// listen goroutine
//
func (s *Server) listen(config ListenerConfig) {
listener, err := newListener(config)
if err != nil {
@ -148,7 +152,7 @@ func (s *Server) listen(config ListenerConfig) {
log.Printf("%s accept: %s", s, conn.RemoteAddr())
}
s.conns <- conn
s.newConns <- conn
}
}

View File

@ -176,7 +176,7 @@ type Replier interface {
type Reply interface {
Code() ReplyCode
Format(*Client) []string
Source() Identifier
Source() string
}
type Command interface {