server ctime

This commit is contained in:
Jeremy Latt 2012-04-17 22:21:41 -07:00
parent 4cee1ef909
commit 259fd40916
3 changed files with 7 additions and 3 deletions

View File

@ -65,7 +65,7 @@ func tryRegister(s *Server, c *Client) {
c.registered = true c.registered = true
c.send <- ReplyWelcome(c) c.send <- ReplyWelcome(c)
c.send <- ReplyYourHost(c.Nick(), s.name) c.send <- ReplyYourHost(c.Nick(), s.name)
c.send <- ReplyCreated(c.Nick(), "2012/04/07") c.send <- ReplyCreated(c.Nick(), s.ctime)
c.send <- ReplyMyInfo(c.Nick(), s.name) c.send <- ReplyMyInfo(c.Nick(), s.name)
} }
} }

View File

@ -2,6 +2,7 @@ package irc
import ( import (
"fmt" "fmt"
"time"
) )
func ReplyNick(oldNick string, c *Client) string { func ReplyNick(oldNick string, c *Client) string {
@ -16,8 +17,8 @@ func ReplyYourHost(nick string, server string) string {
return fmt.Sprintf("%s %s Your host is %s, running version %s", RPL_YOURHOST, nick, server, VERSION) return fmt.Sprintf("%s %s Your host is %s, running version %s", RPL_YOURHOST, nick, server, VERSION)
} }
func ReplyCreated(nick string, created string) string { func ReplyCreated(nick string, ctime time.Time) string {
return fmt.Sprintf("%s %s This server was created %s", RPL_CREATED, nick, created) return fmt.Sprintf("%s %s This server was created %s", RPL_CREATED, nick, ctime.Format(time.RFC1123))
} }
func ReplyMyInfo(nick string, servername string) string { func ReplyMyInfo(nick string, servername string) string {

View File

@ -3,9 +3,11 @@ package irc
import ( import (
"log" "log"
"net" "net"
"time"
) )
type Server struct { type Server struct {
ctime time.Time
name string name string
ch chan *ClientMessage ch chan *ClientMessage
nicks map[string]*Client nicks map[string]*Client
@ -18,6 +20,7 @@ type ClientMessage struct {
func NewServer(name string) *Server { func NewServer(name string) *Server {
server := new(Server) server := new(Server)
server.ctime = time.Now()
server.name = name server.name = name
server.ch = make(chan *ClientMessage) server.ch = make(chan *ClientMessage)
server.nicks = make(map[string]*Client) server.nicks = make(map[string]*Client)