Ability to show server's version

This commit is contained in:
Sergey Matveev 2014-08-14 14:31:34 +04:00
parent a939b027fd
commit f46c678ce0
6 changed files with 24 additions and 10 deletions

4
Makefile Normal file
View File

@ -0,0 +1,4 @@
LDFLAGS="-X main.version \"$(shell git describe --tags)\""
goircd:
go install -ldflags $(LDFLAGS) $(BUILD_FLAGS)

2
README
View File

@ -40,7 +40,7 @@ SUPPORTED IRC COMMANDS
* PASS/NICK/USER during registration workflow
* PING/PONGs
* NOTICE/PRIVMSG
* MOTD, LUSERS, WHO, WHOIS, QUIT
* MOTD, LUSERS, WHO, WHOIS, VERSION, QUIT
* LIST, JOIN, TOPIC, +k/-k channel MODE
USAGE

View File

@ -43,6 +43,7 @@ var passwordsRefreshLock sync.Mutex
type Daemon struct {
Verbose bool
version string
hostname string
motd string
clients map[*Client]bool
@ -55,8 +56,8 @@ type Daemon struct {
passwords map[string]string
}
func NewDaemon(hostname, motd string, logSink chan<- LogEvent, stateSink chan<- StateEvent) *Daemon {
daemon := Daemon{hostname: hostname, motd: motd}
func NewDaemon(version, hostname, motd string, logSink chan<- LogEvent, stateSink chan<- StateEvent) *Daemon {
daemon := Daemon{version: version, hostname: hostname, motd: motd}
daemon.clients = make(map[*Client]bool)
daemon.clientAliveness = make(map[*Client]*ClientAlivenessState)
daemon.rooms = make(map[string]*Room)
@ -205,7 +206,7 @@ func (daemon *Daemon) ClientRegister(client *Client, command string, cols []stri
passwordsRefreshLock.Unlock()
client.registered = true
client.ReplyNicknamed("001", "Hi, welcome to IRC")
client.ReplyNicknamed("002", "Your host is "+daemon.hostname+", running goircd")
client.ReplyNicknamed("002", "Your host is "+daemon.hostname+", running goircd "+daemon.version)
client.ReplyNicknamed("003", "This server was created sometime")
client.ReplyNicknamed("004", daemon.hostname+" goircd o o")
daemon.SendLusers(client)
@ -458,6 +459,14 @@ func (daemon *Daemon) Processor(events <-chan ClientEvent) {
cols := strings.Split(cols[1], " ")
nicknames := strings.Split(cols[len(cols)-1], ",")
daemon.SendWhois(client, nicknames)
case "VERSION":
var debug string
if daemon.Verbose {
debug = "debug"
} else {
debug = ""
}
client.ReplyNicknamed("351", fmt.Sprintf("%s.%s %s :", daemon.version, debug, daemon.hostname))
default:
client.ReplyNicknamed("421", command, "Unknown command")
}

View File

@ -25,7 +25,7 @@ import (
)
func TestRegistrationWorkflow(t *testing.T) {
daemon := NewDaemon("foohost", "", nil, nil)
daemon := NewDaemon("ver1", "foohost", "", nil, nil)
events := make(chan ClientEvent)
go daemon.Processor(events)
conn := NewTestingConn()
@ -120,7 +120,7 @@ func TestMotd(t *testing.T) {
conn := NewTestingConn()
client := NewClient("foohost", conn)
daemon := NewDaemon("foohost", fd.Name(), nil, nil)
daemon := NewDaemon("ver1", "foohost", fd.Name(), nil, nil)
daemon.SendMotd(client)
if r := <-conn.outbound; !strings.HasPrefix(r, ":foohost 375") {

View File

@ -32,6 +32,7 @@ import (
)
var (
version string
hostname = flag.String("hostname", "localhost", "Hostname")
bind = flag.String("bind", ":6667", "Address to bind to")
motd = flag.String("motd", "", "Path to MOTD file")
@ -67,7 +68,7 @@ func Run() {
}
stateSink := make(chan StateEvent)
daemon := NewDaemon(*hostname, *motd, logSink, stateSink)
daemon := NewDaemon(version, *hostname, *motd, logSink, stateSink)
daemon.Verbose = *verbose
if *statedir == "" {
// Dummy statekeeper
@ -120,7 +121,7 @@ func Run() {
log.Fatalf("Can not listen on %s: %v", *bind, err)
}
}
log.Println("Listening on", *bind)
log.Println("goircd "+daemon.version+" listening on", *bind)
if *passwords != "" {
daemon.PasswordsRefresh()

View File

@ -26,7 +26,7 @@ func notEnoughParams(t *testing.T, c *TestingConn) {
func TestTwoUsers(t *testing.T) {
logSink := make(chan LogEvent, 8)
stateSink := make(chan StateEvent, 8)
daemon := NewDaemon("foohost", "", logSink, stateSink)
daemon := NewDaemon("ver1", "foohost", "", logSink, stateSink)
events := make(chan ClientEvent)
go daemon.Processor(events)
@ -100,7 +100,7 @@ func TestTwoUsers(t *testing.T) {
func TestJoin(t *testing.T) {
logSink := make(chan LogEvent, 8)
stateSink := make(chan StateEvent, 8)
daemon := NewDaemon("foohost", "", logSink, stateSink)
daemon := NewDaemon("ver1", "foohost", "", logSink, stateSink)
events := make(chan ClientEvent)
go daemon.Processor(events)
conn := NewTestingConn()