Merge pull request #10 from mjard/master
Fixes against weekly.2012-02-22
This commit is contained in:
commit
67c1c92623
12
irc.go
12
irc.go
@ -26,7 +26,7 @@ func reader(irc *IRCConnection) {
|
||||
irc.Error <- err
|
||||
break
|
||||
}
|
||||
irc.lastMessage = time.Seconds()
|
||||
irc.lastMessage = time.Now()
|
||||
msg = msg[0 : len(msg)-2] //Remove \r\n
|
||||
event := &IRCEvent{Raw: msg}
|
||||
if msg[0] == ':' {
|
||||
@ -75,18 +75,18 @@ func writer(irc *IRCConnection) {
|
||||
|
||||
//Pings the server if we have not recived any messages for 5 minutes
|
||||
func pinger(i *IRCConnection) {
|
||||
i.ticker = time.Tick(1000 * 1000 * 1000 * 60 * 1) //Tick every minute.
|
||||
i.ticker2 = time.Tick(1000 * 1000 * 1000 * 60 * 15) //Tick every 15 minutes.
|
||||
i.ticker = time.Tick(1 * time.Minute) //Tick every minute.
|
||||
i.ticker2 = time.Tick(15 * time.Minute) //Tick every 15 minutes.
|
||||
for {
|
||||
select {
|
||||
case <-i.ticker:
|
||||
//Ping if we haven't recived anything from the server within 4 minutes
|
||||
if time.Seconds()-i.lastMessage >= 60*4 {
|
||||
i.SendRaw(fmt.Sprintf("PING %d", time.Nanoseconds()))
|
||||
if time.Since(i.lastMessage) >= (4 * time.Minute) {
|
||||
i.SendRaw(fmt.Sprintf("PING %d", time.Now().UnixNano()))
|
||||
}
|
||||
case <-i.ticker2:
|
||||
//Ping every 15 minutes.
|
||||
i.SendRaw(fmt.Sprintf("PING %d", time.Nanoseconds()))
|
||||
i.SendRaw(fmt.Sprintf("PING %d", time.Now().UnixNano()))
|
||||
//Try to recapture nickname if it's not as configured.
|
||||
if i.nick != i.nickcurrent {
|
||||
i.nickcurrent = i.nick
|
||||
|
@ -1,10 +1,10 @@
|
||||
package irc
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"fmt"
|
||||
"time"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (irc *IRCConnection) AddCallback(eventcode string, callback func(*IRCEvent)) {
|
||||
@ -80,7 +80,7 @@ func (irc *IRCConnection) setupCallbacks() {
|
||||
})
|
||||
|
||||
irc.AddCallback("CTCP_TIME", func(e *IRCEvent) {
|
||||
ltime := time.LocalTime()
|
||||
ltime := time.Now()
|
||||
irc.SendRaw(fmt.Sprintf("NOTICE %s :\x01TIME %s\x01", e.Nick, ltime.String()))
|
||||
})
|
||||
|
||||
@ -101,8 +101,9 @@ func (irc *IRCConnection) setupCallbacks() {
|
||||
})
|
||||
|
||||
irc.AddCallback("PONG", func(e *IRCEvent) {
|
||||
ns, _ := strconv.Atoi64(e.Message)
|
||||
fmt.Printf("Lag: %fs\n", float32((time.Nanoseconds()-ns))/1000/1000/1000)
|
||||
ns, _ := strconv.ParseInt(e.Message, 10, 64)
|
||||
delta := time.Duration(time.Now().UnixNano() - ns)
|
||||
fmt.Printf("Lag: %vs\n", delta)
|
||||
})
|
||||
|
||||
irc.AddCallback("NICK", func(e *IRCEvent) {
|
||||
|
@ -4,7 +4,10 @@
|
||||
|
||||
package irc
|
||||
|
||||
import "net"
|
||||
import (
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
type IRCConnection struct {
|
||||
socket net.Conn
|
||||
@ -19,9 +22,9 @@ type IRCConnection struct {
|
||||
Password string
|
||||
events map[string][]func(*IRCEvent)
|
||||
|
||||
lastMessage int64
|
||||
ticker <-chan int64
|
||||
ticker2 <-chan int64
|
||||
lastMessage time.Time
|
||||
ticker <-chan time.Time
|
||||
ticker2 <-chan time.Time
|
||||
|
||||
VerboseCallbackHandler bool
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user