diff options
author | Hubert Hirtz <hubert@hirtz.pm> | 2021-10-20 17:33:10 +0200 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtz.pm> | 2021-10-24 12:57:24 +0200 |
commit | 9fb4378753ddec61a504a0dec403f40d6def7e90 (patch) | |
tree | 32955930be2d97614f3ec6290f67d0556769a16e /irc | |
parent | Remove draft file (diff) |
Support for soju.im/bouncer-networks
This patch also disable the highlight on reconnect. This might be an
issue (the user would want to know when senpai is online again?), but
with multiple connections, it's bothersome to have to unread all of
them on start (it wasn't a problem with only one connection since it was
read instantly).
Now, lastbuffer.txt also contains the network ID, otherwise the user
might end up on another buffer with the same name.
This patch does not extend /r to support multiple networks (it will send
the message to the latest query, whatever the current displayed network
is).
Diffstat (limited to 'irc')
-rw-r--r-- | irc/events.go | 5 | ||||
-rw-r--r-- | irc/session.go | 48 | ||||
-rw-r--r-- | irc/tokens.go | 3 |
3 files changed, 48 insertions, 8 deletions
diff --git a/irc/events.go b/irc/events.go index 4898c26..c90f518 100644 --- a/irc/events.go +++ b/irc/events.go @@ -75,3 +75,8 @@ type HistoryEvent struct { Target string Messages []Event } + +type BouncerNetworkEvent struct { + ID string + Name string +} diff --git a/irc/session.go b/irc/session.go index e0421a7..201f50c 100644 --- a/irc/session.go +++ b/irc/session.go @@ -57,7 +57,8 @@ var SupportedCapabilities = map[string]struct{}{ "sasl": {}, "setname": {}, - "draft/chathistory": {}, + "draft/chathistory": {}, + "soju.im/bouncer-networks": {}, } // Values taken by the "@+typing=" client tag. TypingUnspec means the value or @@ -91,8 +92,8 @@ type SessionParams struct { Nickname string Username string RealName string - - Auth SASLClient + NetID string + Auth SASLClient } type Session struct { @@ -108,6 +109,7 @@ type Session struct { real string acct string host string + netID string auth SASLClient availableCaps map[string]string @@ -138,6 +140,7 @@ func NewSession(out chan<- Message, params SessionParams) *Session { nickCf: CasemapASCII(params.Nickname), user: params.Username, real: params.RealName, + netID: params.NetID, auth: params.Auth, availableCaps: map[string]string{}, enabledCaps: map[string]struct{}{}, @@ -180,6 +183,10 @@ func (s *Session) Nick() string { return s.nick } +func (s *Session) NetID() string { + return s.netID +} + // NickCf is our casemapped nickname. func (s *Session) NickCf() string { return s.nickCf @@ -486,10 +493,10 @@ func (s *Session) handleUnregistered(msg Message) (Event, error) { return nil, err } - s.out <- NewMessage("CAP", "END") + s.endRegistration() s.host = ParsePrefix(userhost).Host case errNicklocked, errSaslfail, errSasltoolong, errSaslaborted, errSaslalready, rplSaslmechs: - s.out <- NewMessage("CAP", "END") + s.endRegistration() case "CAP": var subcommand string if err := msg.ParseParams(nil, &subcommand); err != nil { @@ -525,7 +532,7 @@ func (s *Session) handleUnregistered(msg Message) (Event, error) { _, ok := s.availableCaps["sasl"] if s.auth == nil || !ok { - s.out <- NewMessage("CAP", "END") + s.endRegistration() } } default: @@ -1024,6 +1031,19 @@ func (s *Session) handleRegistered(msg Message) (Event, error) { FormerNick: msg.Prefix.Name, }, nil } + case "BOUNCER": + if len(msg.Params) < 3 { + break + } + if msg.Params[0] != "NETWORK" || s.netID != "" { + break + } + id := msg.Params[1] + attrs := parseTags(msg.Params[2]) + return BouncerNetworkEvent{ + ID: id, + Name: attrs["name"], + }, nil case "PING": var payload string if err := msg.ParseParams(&payload); err != nil { @@ -1137,6 +1157,8 @@ func (s *Session) updateFeatures(features []string) { Switch: switch key { + case "BOUNCER_NETID": + s.netID = value case "CASEMAPPING": switch value { case "ascii": @@ -1175,3 +1197,17 @@ func (s *Session) updateFeatures(features []string) { } } } + +func (s *Session) endRegistration() { + if _, ok := s.enabledCaps["soju.im/bouncer-networks"]; !ok { + s.out <- NewMessage("CAP", "END") + return + } + if s.netID == "" { + s.out <- NewMessage("CAP", "END") + s.out <- NewMessage("BOUNCER", "LISTNETWORKS") + } else { + s.out <- NewMessage("BOUNCER", "BIND", s.netID) + s.out <- NewMessage("CAP", "END") + } +} diff --git a/irc/tokens.go b/irc/tokens.go index bb5f399..a52a764 100644 --- a/irc/tokens.go +++ b/irc/tokens.go @@ -132,7 +132,6 @@ func escapeTagValue(unescaped string) string { } func parseTags(s string) (tags map[string]string) { - s = s[1:] tags = map[string]string{} for _, item := range strings.Split(s, ";") { @@ -239,7 +238,7 @@ func ParseMessage(line string) (msg Message, err error) { var tags string tags, line = word(line) - msg.Tags = parseTags(tags) + msg.Tags = parseTags(tags[1:]) } line = strings.TrimLeft(line, " ") |