mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
replies shouldn't contain references to client
This commit is contained in:
parent
9c385ededd
commit
25ebab37d3
@ -38,7 +38,7 @@ func (channel *Channel) Reply(reply Reply) {
|
|||||||
|
|
||||||
for client := range channel.members {
|
for client := range channel.members {
|
||||||
if (reply.Code() == ReplyCode(PRIVMSG)) &&
|
if (reply.Code() == ReplyCode(PRIVMSG)) &&
|
||||||
(reply.Source() == Identifier(client)) {
|
(reply.Source() == client.Id()) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
client.Reply(reply)
|
client.Reply(reply)
|
||||||
|
@ -28,7 +28,7 @@ type Client struct {
|
|||||||
phase Phase
|
phase Phase
|
||||||
quitTimer *time.Timer
|
quitTimer *time.Timer
|
||||||
realname string
|
realname string
|
||||||
replies chan string
|
replies chan Reply
|
||||||
server *Server
|
server *Server
|
||||||
socket *Socket
|
socket *Socket
|
||||||
username string
|
username string
|
||||||
@ -46,7 +46,7 @@ func NewClient(server *Server, conn net.Conn) *Client {
|
|||||||
phase: server.InitPhase(),
|
phase: server.InitPhase(),
|
||||||
server: server,
|
server: server,
|
||||||
socket: NewSocket(conn),
|
socket: NewSocket(conn),
|
||||||
replies: make(chan string),
|
replies: make(chan Reply),
|
||||||
}
|
}
|
||||||
|
|
||||||
client.loginTimer = time.AfterFunc(LOGIN_TIMEOUT, client.connectionTimeout)
|
client.loginTimer = time.AfterFunc(LOGIN_TIMEOUT, client.connectionTimeout)
|
||||||
@ -96,8 +96,8 @@ func (client *Client) connectionClosed() {
|
|||||||
//
|
//
|
||||||
|
|
||||||
func (client *Client) writeReplies() {
|
func (client *Client) writeReplies() {
|
||||||
for line := range client.replies {
|
for reply := range client.replies {
|
||||||
client.socket.Write(line)
|
client.socket.Write(reply.Format(client)...)
|
||||||
}
|
}
|
||||||
client.socket.Close()
|
client.socket.Close()
|
||||||
client.doneWriting <- true
|
client.doneWriting <- true
|
||||||
@ -195,9 +195,7 @@ func (client *Client) Reply(reply Reply) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, line := range reply.Format(client) {
|
client.replies <- reply
|
||||||
client.replies <- line
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) IdleTime() time.Duration {
|
func (client *Client) IdleTime() time.Duration {
|
||||||
|
@ -10,7 +10,6 @@ type BaseReply struct {
|
|||||||
code ReplyCode
|
code ReplyCode
|
||||||
id string
|
id string
|
||||||
message string
|
message string
|
||||||
source Identifier
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (reply *BaseReply) Code() ReplyCode {
|
func (reply *BaseReply) Code() ReplyCode {
|
||||||
@ -19,11 +18,10 @@ func (reply *BaseReply) Code() ReplyCode {
|
|||||||
|
|
||||||
func (reply *BaseReply) SetSource(source Identifier) {
|
func (reply *BaseReply) SetSource(source Identifier) {
|
||||||
reply.id = source.Id()
|
reply.id = source.Id()
|
||||||
reply.source = source
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (reply *BaseReply) Source() Identifier {
|
func (reply *BaseReply) Source() string {
|
||||||
return reply.source
|
return reply.id
|
||||||
}
|
}
|
||||||
|
|
||||||
type StringReply struct {
|
type StringReply struct {
|
||||||
|
@ -17,7 +17,7 @@ type Server struct {
|
|||||||
channels ChannelNameMap
|
channels ChannelNameMap
|
||||||
clients ClientNameMap
|
clients ClientNameMap
|
||||||
commands chan Command
|
commands chan Command
|
||||||
conns chan net.Conn
|
newConns chan net.Conn
|
||||||
ctime time.Time
|
ctime time.Time
|
||||||
idle chan *Client
|
idle chan *Client
|
||||||
motdFile string
|
motdFile string
|
||||||
@ -31,7 +31,7 @@ func NewServer(config *Config) *Server {
|
|||||||
channels: make(ChannelNameMap),
|
channels: make(ChannelNameMap),
|
||||||
clients: make(ClientNameMap),
|
clients: make(ClientNameMap),
|
||||||
commands: make(chan Command),
|
commands: make(chan Command),
|
||||||
conns: make(chan net.Conn),
|
newConns: make(chan net.Conn),
|
||||||
ctime: time.Now(),
|
ctime: time.Now(),
|
||||||
idle: make(chan *Client),
|
idle: make(chan *Client),
|
||||||
motdFile: config.MOTD,
|
motdFile: config.MOTD,
|
||||||
@ -54,7 +54,7 @@ func NewServer(config *Config) *Server {
|
|||||||
func (server *Server) ReceiveCommands() {
|
func (server *Server) ReceiveCommands() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case conn := <-server.conns:
|
case conn := <-server.newConns:
|
||||||
NewClient(server, conn)
|
NewClient(server, conn)
|
||||||
|
|
||||||
case client := <-server.idle:
|
case client := <-server.idle:
|
||||||
@ -126,6 +126,10 @@ func newListener(config ListenerConfig) (net.Listener, error) {
|
|||||||
return net.Listen("tcp", config.Address)
|
return net.Listen("tcp", config.Address)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// listen goroutine
|
||||||
|
//
|
||||||
|
|
||||||
func (s *Server) listen(config ListenerConfig) {
|
func (s *Server) listen(config ListenerConfig) {
|
||||||
listener, err := newListener(config)
|
listener, err := newListener(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -148,7 +152,7 @@ func (s *Server) listen(config ListenerConfig) {
|
|||||||
log.Printf("%s accept: %s", s, conn.RemoteAddr())
|
log.Printf("%s accept: %s", s, conn.RemoteAddr())
|
||||||
}
|
}
|
||||||
|
|
||||||
s.conns <- conn
|
s.newConns <- conn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ type Replier interface {
|
|||||||
type Reply interface {
|
type Reply interface {
|
||||||
Code() ReplyCode
|
Code() ReplyCode
|
||||||
Format(*Client) []string
|
Format(*Client) []string
|
||||||
Source() Identifier
|
Source() string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Command interface {
|
type Command interface {
|
||||||
|
Loading…
Reference in New Issue
Block a user