mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
buffer all channels
This commit is contained in:
parent
f090c616b3
commit
95f267ea4f
@ -27,6 +27,7 @@ type Client struct {
|
|||||||
phase Phase
|
phase Phase
|
||||||
quitTimer *time.Timer
|
quitTimer *time.Timer
|
||||||
realname string
|
realname string
|
||||||
|
replies chan Reply
|
||||||
server *Server
|
server *Server
|
||||||
socket *Socket
|
socket *Socket
|
||||||
username string
|
username string
|
||||||
@ -43,10 +44,12 @@ 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 Reply, 16),
|
||||||
}
|
}
|
||||||
|
|
||||||
client.loginTimer = time.AfterFunc(LOGIN_TIMEOUT, client.connectionTimeout)
|
client.loginTimer = time.AfterFunc(LOGIN_TIMEOUT, client.connectionTimeout)
|
||||||
go client.readCommands()
|
go client.readCommands()
|
||||||
|
go client.writeReplies()
|
||||||
|
|
||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
@ -82,6 +85,16 @@ func (client *Client) connectionClosed() {
|
|||||||
client.server.commands <- msg
|
client.server.commands <- msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// reply writing goroutine
|
||||||
|
//
|
||||||
|
|
||||||
|
func (client *Client) writeReplies() {
|
||||||
|
for reply := range client.replies {
|
||||||
|
client.socket.Write(reply.Format(client)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// idle timer goroutine
|
// idle timer goroutine
|
||||||
//
|
//
|
||||||
@ -167,7 +180,7 @@ func (client *Client) Destroy() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) Reply(reply Reply) {
|
func (client *Client) Reply(reply Reply) {
|
||||||
client.socket.Write(reply.Format(client)...)
|
client.replies <- reply
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) IdleTime() time.Duration {
|
func (client *Client) IdleTime() time.Duration {
|
||||||
|
@ -213,6 +213,7 @@ func RplPart(client *Client, channel *Channel, message string) Reply {
|
|||||||
return NewStringReply(client, PART, "%s :%s", channel, message)
|
return NewStringReply(client, PART, "%s :%s", channel, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO separate source and target
|
||||||
func RplMode(client *Client, changes ModeChanges) Reply {
|
func RplMode(client *Client, changes ModeChanges) Reply {
|
||||||
return NewStringReply(client, MODE, "%s :%s", client.Nick(), changes)
|
return NewStringReply(client, MODE, "%s :%s", client.Nick(), changes)
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,10 @@ func NewServer(config *Config) *Server {
|
|||||||
server := &Server{
|
server := &Server{
|
||||||
channels: make(ChannelNameMap),
|
channels: make(ChannelNameMap),
|
||||||
clients: make(ClientNameMap),
|
clients: make(ClientNameMap),
|
||||||
commands: make(chan Command),
|
commands: make(chan Command, 16),
|
||||||
conns: make(chan net.Conn),
|
conns: make(chan net.Conn, 16),
|
||||||
ctime: time.Now(),
|
ctime: time.Now(),
|
||||||
idle: make(chan *Client),
|
idle: make(chan *Client, 16),
|
||||||
motdFile: config.MOTD,
|
motdFile: config.MOTD,
|
||||||
name: config.Name,
|
name: config.Name,
|
||||||
operators: make(map[string]string),
|
operators: make(map[string]string),
|
||||||
|
Loading…
Reference in New Issue
Block a user