From 754b74c21cf16770db8196d5d436d5bc97ce1b72 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Mon, 12 Sep 2016 11:25:31 +1000 Subject: [PATCH] accounts: Add account-tag capability --- CHANGELOG.md | 2 +- irc/capability.go | 2 ++ irc/channel.go | 5 ++--- irc/client.go | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33c5750b..762afd40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ Initial release of Oragono! * Added ability to parse complex mode change syntax commonly used these days (i.e. `+h-ov dan dan dan`). * Added user mode for clients connected via TLS (`+Z`). * Added ability to register and login to accounts (with passphrase or certfp). -* Added support for IRCv3 capabilities [`extended-join`](http://ircv3.net/specs/extensions/extended-join-3.1.html), [`sasl`](http://ircv3.net/specs/extensions/sasl-3.1.html), [`server-time`](http://ircv3.net/specs/extensions/server-time-3.2.html), and [`userhost-in-names`](http://ircv3.net/specs/extensions/userhost-in-names-3.2.html). +* Added support for IRCv3 capabilities [`account-tag`](http://ircv3.net/specs/extensions/account-tag-3.2.html), [`extended-join`](http://ircv3.net/specs/extensions/extended-join-3.1.html), [`sasl`](http://ircv3.net/specs/extensions/sasl-3.1.html), [`server-time`](http://ircv3.net/specs/extensions/server-time-3.2.html), and [`userhost-in-names`](http://ircv3.net/specs/extensions/userhost-in-names-3.2.html). ### Changed * Changed channel creator (`O`) privilege to founder/admin/halfops (`qah`) privileges. diff --git a/irc/capability.go b/irc/capability.go index 77af38be..bf6a2595 100644 --- a/irc/capability.go +++ b/irc/capability.go @@ -14,6 +14,7 @@ import ( type Capability string const ( + AccountTag Capability = "account-tag" ExtendedJoin Capability = "extended-join" MultiPrefix Capability = "multi-prefix" SASL Capability = "sasl" @@ -23,6 +24,7 @@ const ( var ( SupportedCapabilities = CapabilitySet{ + AccountTag: true, ExtendedJoin: true, MultiPrefix: true, SASL: true, diff --git a/irc/channel.go b/irc/channel.go index c624622d..ab45dd57 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -304,8 +304,7 @@ func (channel *Channel) PrivMsg(client *Client, message string) { if member == client { continue } - //TODO(dan): use nickmask instead of nickString here lel - member.Send(nil, client.nickMaskString, "PRIVMSG", channel.nameString, message) + member.SendFromClient(client, nil, client.nickMaskString, "PRIVMSG", channel.nameString, message) } } @@ -452,7 +451,7 @@ func (channel *Channel) Notice(client *Client, message string) { if member == client { continue } - member.Send(nil, client.nickMaskString, "NOTICE", channel.nameString, message) + member.SendFromClient(client, nil, client.nickMaskString, "NOTICE", channel.nameString, message) } } diff --git a/irc/client.go b/irc/client.go index 7e9d13ab..30c5b909 100644 --- a/irc/client.go +++ b/irc/client.go @@ -349,6 +349,21 @@ func (client *Client) destroy() { } } +// SendFromClient sends an IRC line coming from a specific client. +// Adds account-tag to the line as well. +func (client *Client) SendFromClient(from *Client, tags *map[string]ircmsg.TagValue, prefix string, command string, params ...string) error { + // attach account-tag + if client.capabilities[AccountTag] && from.account != &NoAccount { + if tags == nil { + tags = ircmsg.MakeTags("account", from.account.Name) + } else { + (*tags)["account"] = ircmsg.MakeTagValue(from.account.Name) + } + } + + return client.Send(tags, prefix, command, params...) +} + // Send sends an IRC line to the client. func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, command string, params ...string) error { // attach server-time