add support for ircv3's userhost-in-names

This commit is contained in:
Liam Stanley 2017-02-08 01:19:45 -05:00
parent 8489a4860e
commit 03d0b5de8c
3 changed files with 38 additions and 16 deletions

17
cap.go
View File

@ -12,14 +12,15 @@ import (
)
var possibleCap = map[string][]string{
"account-notify": nil,
"account-tag": nil,
"away-notify": nil,
"batch": nil,
"cap-notify": nil,
"chghost": nil,
"extended-join": nil,
"message-tags": nil,
"account-notify": nil,
"account-tag": nil,
"away-notify": nil,
"batch": nil,
"cap-notify": nil,
"chghost": nil,
"extended-join": nil,
"message-tags": nil,
"userhost-in-names": nil,
}
func (c *Client) listCAP() error {

View File

@ -338,18 +338,45 @@ func handleNAMES(c *Client, e Event) {
parts := strings.Split(e.Trailing, " ")
var host, ident, modes, nick string
var ok bool
c.state.mu.Lock()
for i := 0; i < len(parts); i++ {
modes, nick, ok := parseUserPrefix(parts[i])
modes, nick, ok = parseUserPrefix(parts[i])
if !ok {
continue
}
// If userhost-in-names.
if strings.Contains(nick, "@") {
s := ParseSource(nick)
if s == nil {
continue
}
host = s.Host
nick = s.Name
ident = s.Ident
}
if !IsValidNick(nick) {
continue
}
user := c.state.createUserIfNotExists(e.Params[len(e.Params)-1], nick)
if user == nil {
continue
}
// Add necessary userhost-in-names data into the user.
if host != "" {
user.Host = host
}
if ident != "" {
user.Ident = ident
}
// Don't append modes, overwrite them.
user.Perms.set(modes, false)
}

View File

@ -452,13 +452,7 @@ func parseUserPrefix(raw string) (modes, nick string, success bool) {
}
// Assume we've gotten to the nickname part.
if !IsValidNick(raw[i:]) {
return modes, nick, false
}
nick = raw[i:]
return modes, nick, true
return modes, raw[i:], true
}
return