From 169debea93cf8cf9995a7e0ae0efafabf70602b8 Mon Sep 17 00:00:00 2001 From: "." <.@.> Date: Mon, 9 May 2016 18:30:24 +1200 Subject: [PATCH] set proper clientversion, better version/tag extraction --HG-- branch : nmdc-ircfrontend --- server.go | 31 +++++++++++++++++++++---------- typedefs.go | 4 ++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/server.go b/server.go index ba99f00..495ec89 100644 --- a/server.go +++ b/server.go @@ -57,7 +57,8 @@ type Server struct { func NewServer(name string, upstream libnmdc.HubAddress, conn net.Conn) *Server { self := libnmdc.NewUserInfo("") - self.ClientTag = APP_DESCRIPTION + self.ClientTag = APP_NAME + self.ClientVersion = APP_VERSION return &Server{ name: name, @@ -280,10 +281,10 @@ func (s *Server) handleCommand(command string, args []string) { // do nothing case "INFO": - s.reply(rplInfo, APP_DESCRIPTION) + s.reply(rplInfo, APP_NAME+" v"+APP_VERSION) case "VERSION": - s.reply(rplVersion, VERSION) + s.reply(rplVersion, APP_VERSION) case "MOTD": s.sendMOTD(s.motd) @@ -430,18 +431,28 @@ func (s *Server) SetClientSoftwareVersion(ver string) { // "liteIRC for Android 1.1.8" // ":Relay:1.0:Android" - // A bit long and unwieldy. Heuristic: stop after the first word containing digits + // A bit long and unwieldy. + // Heuristic: keep the first word, and the the first word containing digits - parts := regexp.MustCompilePOSIX("^([^0-9]*[0-9]+[^ ]*) ").FindStringSubmatch(ver) + tag := APP_NAME + version := APP_VERSION - if len(parts) > 0 { - ver = strings.TrimRight(parts[0], " ") + words := strings.Split(ver, " ") + + for _, word := range words[1:] { + if strings.ContainsAny(word, "0123456789") { + tag = words[0] + version = strings.Replace(word, "(", "", -1) // AndroIRC + break + } } - s.verbosef("Replacing client tag with '%s'...", ver) + s.verbosef("Replacing client tag with '%s' version '%s'", tag, version) - s.upstreamLauncher.Self.ClientTag = ver - s.upstream.Hco.Self.ClientTag = ver + s.upstreamLauncher.Self.ClientTag = tag + s.upstreamLauncher.Self.ClientVersion = version + s.upstream.Hco.Self.ClientTag = tag + s.upstream.Hco.Self.ClientVersion = version s.upstream.SayInfo() } diff --git a/typedefs.go b/typedefs.go index 752bc32..9a56a62 100644 --- a/typedefs.go +++ b/typedefs.go @@ -19,8 +19,8 @@ along with this program. If not, see . */ const ( - VERSION = "1.0.0" - APP_DESCRIPTION = "nmdc-ircfrontend v" + VERSION + APP_VERSION = "1.0.0" + APP_NAME = "nmdc-ircfrontend" BLESSED_CHANNEL = "#chat" // must be lowercase BLESSED_CHANNEL_MODE = "n" // means that you have to be in the channel to chat, but that's it