3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-26 05:49:25 +01:00

fix race in idle timeout; fix some string trimming; fix some replies

This commit is contained in:
Jeremy Latt 2014-02-17 18:10:52 -08:00
parent 1a7f56a903
commit bd3ca4ae47
4 changed files with 20 additions and 5 deletions

View File

@ -95,6 +95,10 @@ func (client *Client) Touch() {
}
}
type ClientIdle struct {
BaseCommand
}
func (client *Client) Idle() {
if client.quitTimer == nil {
client.quitTimer = time.AfterFunc(QUIT_TIMEOUT, client.connectionTimeout)
@ -102,7 +106,9 @@ func (client *Client) Idle() {
client.quitTimer.Reset(QUIT_TIMEOUT)
}
client.Reply(RplPing(client.server, client))
cmd := &ClientIdle{}
cmd.SetClient(client)
client.server.commands <- cmd
}
func (client *Client) connectionTimeout() {

View File

@ -192,17 +192,17 @@ func RplKick(channel *Channel, client *Client, target *Client, comment string) R
func RplWelcome(source Identifier, client *Client) Reply {
return NewNumericReply(source, RPL_WELCOME,
"Welcome to the Internet Relay Network %s", client.Id())
":Welcome to the Internet Relay Network %s", client.Id())
}
func RplYourHost(server *Server) Reply {
return NewNumericReply(server, RPL_YOURHOST,
"Your host is %s, running version %s", server.name, VERSION)
":Your host is %s, running version %s", server.name, VERSION)
}
func RplCreated(server *Server) Reply {
return NewNumericReply(server, RPL_CREATED,
"This server was created %s", server.ctime.Format(time.RFC1123))
":This server was created %s", server.ctime.Format(time.RFC1123))
}
func RplMyInfo(server *Server) Reply {

View File

@ -9,6 +9,7 @@ import (
"log"
"net"
"os"
"strings"
"time"
)
@ -171,6 +172,8 @@ func (s *Server) tryRegister(c *Client) {
if c.HasNick() && c.HasUsername() {
c.phase = Normal
c.loginTimer.Stop()
c.AddFriend(c)
c.Reply(RplWelcome(s, c))
c.Reply(RplYourHost(s))
c.Reply(RplCreated(s))
@ -199,6 +202,7 @@ func (server *Server) MOTD(client *Client) {
if err != nil {
break
}
line = strings.TrimRight(line, "\r\n")
if len(line) > 80 {
for len(line) > 80 {
@ -613,3 +617,8 @@ func (msg *ListCommand) HandleServer(server *Server) {
}
client.Reply(RplListEnd(server))
}
func (msg *ClientIdle) HandleServer(server *Server) {
client := msg.Client()
client.Reply(RplPing(server, client))
}

View File

@ -59,7 +59,7 @@ func (socket *Socket) readLines() {
break
}
line = strings.TrimSpace(line)
line = strings.TrimRight(line, "\r\n")
if len(line) == 0 {
continue
}