From f46c678ce03915d6f081cf2f78ac7fe885cdb001 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Thu, 14 Aug 2014 14:31:34 +0400 Subject: [PATCH] Ability to show server's version --- Makefile | 4 ++++ README | 2 +- daemon.go | 15 ++++++++++++--- daemon_test.go | 4 ++-- goircd.go | 5 +++-- room_test.go | 4 ++-- 6 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3a8e1ff --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +LDFLAGS="-X main.version \"$(shell git describe --tags)\"" + +goircd: + go install -ldflags $(LDFLAGS) $(BUILD_FLAGS) diff --git a/README b/README index 852e455..183e164 100644 --- a/README +++ b/README @@ -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 diff --git a/daemon.go b/daemon.go index ffd2ef1..2bf696c 100644 --- a/daemon.go +++ b/daemon.go @@ -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") } diff --git a/daemon_test.go b/daemon_test.go index 9c9db3d..d049e42 100644 --- a/daemon_test.go +++ b/daemon_test.go @@ -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") { diff --git a/goircd.go b/goircd.go index 984b47b..f70e11c 100644 --- a/goircd.go +++ b/goircd.go @@ -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() diff --git a/room_test.go b/room_test.go index 9bfbc23..0ad2cac 100644 --- a/room_test.go +++ b/room_test.go @@ -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()