Changeset 660 in code for trunk/irc.go


Ignore:
Timestamp:
Nov 2, 2021, 5:25:43 PM (4 years ago)
Author:
contact
Message:

Add support for WHOX

This adds support for WHOX, without bothering about flags and mask2
because Solanum and Ergo [1] don't support it either.

The motivation is to allow clients to reliably query account names.

It's not possible to use WHOX tokens to route replies to the right
client, because RPL_ENDOFWHO doesn't contain it.

[1]: https://github.com/ergochat/ergo/pull/1184

Closes: https://todo.sr.ht/~emersion/soju/135

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/irc.go

    r636 r660  
    1818        rpl_creationtime  = "329"
    1919        rpl_topicwhotime  = "333"
     20        rpl_whospcrpl     = "354"
    2021        err_invalidcapcmd = "410"
    2122)
     
    683684        }
    684685}
     686
     687type whoxInfo struct {
     688        Token    string
     689        Username string
     690        Hostname string
     691        Server   string
     692        Nickname string
     693        Flags    string
     694        Account  string
     695        Realname string
     696}
     697
     698func generateWHOXReply(prefix *irc.Prefix, nick, fields string, info *whoxInfo) *irc.Message {
     699        if fields == "" {
     700                return &irc.Message{
     701                        Prefix:  prefix,
     702                        Command: irc.RPL_WHOREPLY,
     703                        Params:  []string{nick, "*", info.Username, info.Hostname, info.Server, info.Nickname, info.Flags, "0 " + info.Realname},
     704                }
     705        }
     706
     707        fieldSet := make(map[byte]bool)
     708        for i := 0; i < len(fields); i++ {
     709                fieldSet[fields[i]] = true
     710        }
     711
     712        var params []string
     713        if fieldSet['t'] {
     714                params = append(params, info.Token)
     715        }
     716        if fieldSet['c'] {
     717                params = append(params, "*")
     718        }
     719        if fieldSet['u'] {
     720                params = append(params, info.Username)
     721        }
     722        if fieldSet['i'] {
     723                params = append(params, "255.255.255.255")
     724        }
     725        if fieldSet['h'] {
     726                params = append(params, info.Hostname)
     727        }
     728        if fieldSet['s'] {
     729                params = append(params, info.Server)
     730        }
     731        if fieldSet['n'] {
     732                params = append(params, info.Nickname)
     733        }
     734        if fieldSet['f'] {
     735                params = append(params, info.Flags)
     736        }
     737        if fieldSet['d'] {
     738                params = append(params, "0")
     739        }
     740        if fieldSet['l'] { // idle time
     741                params = append(params, "0")
     742        }
     743        if fieldSet['a'] {
     744                account := "0" // WHOX uses "0" to mean "no account"
     745                if info.Account != "" && info.Account != "*" {
     746                        account = info.Account
     747                }
     748                params = append(params, account)
     749        }
     750        if fieldSet['o'] {
     751                params = append(params, "0")
     752        }
     753        if fieldSet['r'] {
     754                params = append(params, info.Realname)
     755        }
     756
     757        return &irc.Message{
     758                Prefix:  prefix,
     759                Command: rpl_whospcrpl,
     760                Params:  append([]string{nick}, params...),
     761        }
     762}
Note: See TracChangeset for help on using the changeset viewer.