client tags: better detection for Revolution IRC and HoloIRC
--HG-- branch : nmdc-ircfrontend
This commit is contained in:
parent
458ab0a054
commit
ef36fc0c24
21
clientTag.go
21
clientTag.go
@ -10,14 +10,22 @@ type clientTag struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseVersion(ver string) clientTag {
|
func parseVersion(ver string) clientTag {
|
||||||
// A bit long and unwieldy.
|
// Try our best to turn the supplied text into a structured version
|
||||||
// Heuristic: keep the first word, and the the first word containing digits
|
|
||||||
|
|
||||||
ret := clientTag{
|
ret := clientTag{
|
||||||
AppName: APP_NAME,
|
AppName: APP_NAME,
|
||||||
Version: APP_VERSION,
|
Version: APP_VERSION,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Special case: Some clients use a structured version AppName:Version:Metadata
|
||||||
|
// If we check for that, we can support clients with spaces in the name
|
||||||
|
if cParts := strings.Split(ver, ":"); len(cParts) == 3 {
|
||||||
|
ret.AppName = cParts[0]
|
||||||
|
ret.Version = cParts[1]
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Special cases all failed, time for heuristics
|
||||||
|
// Turn colons to spaces; keep the first word, and the the first word containing digits
|
||||||
ver = strings.Trim(strings.Replace(ver, ":", " ", -1), " ")
|
ver = strings.Trim(strings.Replace(ver, ":", " ", -1), " ")
|
||||||
|
|
||||||
words := strings.Split(ver, " ")
|
words := strings.Split(ver, " ")
|
||||||
@ -29,11 +37,18 @@ func parseVersion(ver string) clientTag {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Strip leading v from mIRC
|
// Strip leading v from mIRC
|
||||||
if len(ret.Version) >= 2 && (ret.Version[0] == 'v' || ret.Version[0] == 'V') && strings.ContainsAny(string(ret.Version[1]), "0123456789") {
|
if len(ret.Version) >= 2 && (ret.Version[0] == 'v' || ret.Version[0] == 'V') && strings.ContainsAny(string(ret.Version[1]), "0123456789") {
|
||||||
ret.Version = ret.Version[1:]
|
ret.Version = ret.Version[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Special case: "Relay" means "HoloIRC"
|
||||||
|
if ret.AppName == "Relay" && ret.Version == "1.0" && strings.Contains(ver, "Android") {
|
||||||
|
ret.AppName = "HoloIRC"
|
||||||
|
ret.Version = "4"
|
||||||
|
}
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,13 @@ func TestParseVersion(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[3]string{
|
[3]string{
|
||||||
":Relay:1.0:Android",
|
":Relay:1.0:Android", // HoloIRC before 4.1.0
|
||||||
"Relay", "1.0",
|
"HoloIRC", "4",
|
||||||
|
},
|
||||||
|
|
||||||
|
[3]string{
|
||||||
|
"Relay:1.0:Android", // HoloIRC after 4.1.0
|
||||||
|
"HoloIRC", "4",
|
||||||
},
|
},
|
||||||
|
|
||||||
[3]string{
|
[3]string{
|
||||||
@ -40,7 +45,7 @@ func TestParseVersion(t *testing.T) {
|
|||||||
|
|
||||||
[3]string{
|
[3]string{
|
||||||
"Revolution IRC:0.3.2:Android",
|
"Revolution IRC:0.3.2:Android",
|
||||||
"Revolution", "0.3.2",
|
"Revolution IRC", "0.3.2",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,7 +413,8 @@ func (s *Server) handleRegisteredCommand(command string, args []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
message := strings.Join(args[1:], " ")[1:] // strip leading colon
|
// Strip leading colon (work around a bug in HoloIRC 4.1.0 and older)
|
||||||
|
message := strings.Join(args[1:], " ")[1:]
|
||||||
|
|
||||||
if strings.HasPrefix(message, "\x01VERSION ") {
|
if strings.HasPrefix(message, "\x01VERSION ") {
|
||||||
// Not a real message - a reply to our internal request. Change the user's tag to match the actual client software
|
// Not a real message - a reply to our internal request. Change the user's tag to match the actual client software
|
||||||
|
Loading…
Reference in New Issue
Block a user