3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 21:39:25 +01:00

Move caps to their own package to prevent conflicts

This commit is contained in:
Daniel Oaks 2017-09-29 12:07:52 +10:00
parent 830484feb6
commit 9bfdc4fdfb
8 changed files with 127 additions and 112 deletions

View File

@ -15,6 +15,7 @@ import (
"github.com/goshuirc/irc-go/ircfmt" "github.com/goshuirc/irc-go/ircfmt"
"github.com/goshuirc/irc-go/ircmsg" "github.com/goshuirc/irc-go/ircmsg"
"github.com/oragono/oragono/irc/caps"
"github.com/oragono/oragono/irc/sno" "github.com/oragono/oragono/irc/sno"
"github.com/tidwall/buntdb" "github.com/tidwall/buntdb"
) )
@ -286,7 +287,7 @@ func (client *Client) LogoutOfAccount() {
client.account = nil client.account = nil
// dispatch account-notify // dispatch account-notify
for friend := range client.Friends(AccountNotify) { for friend := range client.Friends(caps.AccountNotify) {
friend.Send(nil, client.nickMaskString, "ACCOUNT", "*") friend.Send(nil, client.nickMaskString, "ACCOUNT", "*")
} }
} }
@ -349,7 +350,7 @@ func (client *Client) successfulSaslAuth() {
client.Send(nil, client.server.name, RPL_SASLSUCCESS, client.nick, "SASL authentication successful") client.Send(nil, client.server.name, RPL_SASLSUCCESS, client.nick, "SASL authentication successful")
// dispatch account-notify // dispatch account-notify
for friend := range client.Friends(AccountNotify) { for friend := range client.Friends(caps.AccountNotify) {
friend.Send(nil, client.nickMaskString, "ACCOUNT", client.account.Name) friend.Send(nil, client.nickMaskString, "ACCOUNT", client.account.Name)
} }
} }

View File

@ -8,76 +8,35 @@ import (
"strings" "strings"
"github.com/goshuirc/irc-go/ircmsg" "github.com/goshuirc/irc-go/ircmsg"
) "github.com/oragono/oragono/irc/caps"
// Capability represents an optional feature that a client may request from the server.
type Capability string
const (
// AccountNotify is this IRCv3 capability: http://ircv3.net/specs/extensions/account-notify-3.1.html
AccountNotify Capability = "account-notify"
// AccountTag is this IRCv3 capability: http://ircv3.net/specs/extensions/account-tag-3.2.html
AccountTag Capability = "account-tag"
// AwayNotify is this IRCv3 capability: http://ircv3.net/specs/extensions/away-notify-3.1.html
AwayNotify Capability = "away-notify"
// CapNotify is this IRCv3 capability: http://ircv3.net/specs/extensions/cap-notify-3.2.html
CapNotify Capability = "cap-notify"
// ChgHost is this IRCv3 capability: http://ircv3.net/specs/extensions/chghost-3.2.html
ChgHost Capability = "chghost"
// EchoMessage is this IRCv3 capability: http://ircv3.net/specs/extensions/echo-message-3.2.html
EchoMessage Capability = "echo-message"
// ExtendedJoin is this IRCv3 capability: http://ircv3.net/specs/extensions/extended-join-3.1.html
ExtendedJoin Capability = "extended-join"
// InviteNotify is this IRCv3 capability: http://ircv3.net/specs/extensions/invite-notify-3.2.html
InviteNotify Capability = "invite-notify"
// MaxLine is this proposed capability: https://github.com/DanielOaks/ircv3-specifications/blob/master+line-lengths/extensions/line-lengths.md
MaxLine Capability = "draft/maxline"
// MessageTags is this draft IRCv3 capability: http://ircv3.net/specs/core/message-tags-3.3.html
MessageTags Capability = "draft/message-tags-0.2"
// MultiPrefix is this IRCv3 capability: http://ircv3.net/specs/extensions/multi-prefix-3.1.html
MultiPrefix Capability = "multi-prefix"
// Rename is this proposed capability: https://github.com/SaberUK/ircv3-specifications/blob/rename/extensions/rename.md
Rename Capability = "draft/rename"
// SASL is this IRCv3 capability: http://ircv3.net/specs/extensions/sasl-3.2.html
SASL Capability = "sasl"
// ServerTime is this IRCv3 capability: http://ircv3.net/specs/extensions/server-time-3.2.html
ServerTime Capability = "server-time"
// STS is this draft IRCv3 capability: http://ircv3.net/specs/core/sts-3.3.html
STS Capability = "draft/sts"
// UserhostInNames is this IRCv3 capability: http://ircv3.net/specs/extensions/userhost-in-names-3.2.html
UserhostInNames Capability = "userhost-in-names"
) )
var ( var (
// SupportedCapabilities are the caps we advertise. // SupportedCapabilities are the caps we advertise.
SupportedCapabilities = CapabilitySet{ SupportedCapabilities = CapabilitySet{
AccountTag: true, caps.AccountTag: true,
AccountNotify: true, caps.AccountNotify: true,
AwayNotify: true, caps.AwayNotify: true,
CapNotify: true, caps.CapNotify: true,
ChgHost: true, caps.ChgHost: true,
EchoMessage: true, caps.EchoMessage: true,
ExtendedJoin: true, caps.ExtendedJoin: true,
InviteNotify: true, caps.InviteNotify: true,
// MaxLine is set during server startup // MaxLine is set during server startup
MessageTags: true, caps.MessageTags: true,
MultiPrefix: true, caps.MultiPrefix: true,
Rename: true, caps.Rename: true,
// SASL is set during server startup // SASL is set during server startup
ServerTime: true, caps.ServerTime: true,
// STS is set during server startup // STS is set during server startup
UserhostInNames: true, caps.UserhostInNames: true,
} }
// CapValues are the actual values we advertise to v3.2 clients. // CapValues are the actual values we advertise to v3.2 clients.
CapValues = map[Capability]string{ CapValues = map[caps.Capability]string{
SASL: "PLAIN,EXTERNAL", caps.SASL: "PLAIN,EXTERNAL",
} }
) )
func (capability Capability) String() string {
return string(capability)
}
// CapState shows whether we're negotiating caps, finished, etc for connection registration. // CapState shows whether we're negotiating caps, finished, etc for connection registration.
type CapState uint type CapState uint
@ -101,7 +60,7 @@ const (
) )
// CapabilitySet is used to track supported, enabled, and existing caps. // CapabilitySet is used to track supported, enabled, and existing caps.
type CapabilitySet map[Capability]bool type CapabilitySet map[caps.Capability]bool
func (set CapabilitySet) String(version CapVersion) string { func (set CapabilitySet) String(version CapVersion) string {
strs := make([]string, len(set)) strs := make([]string, len(set))
@ -131,7 +90,7 @@ func capHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
strs := strings.Split(capString, " ") strs := strings.Split(capString, " ")
for _, str := range strs { for _, str := range strs {
if len(str) > 0 { if len(str) > 0 {
capabilities[Capability(str)] = true capabilities[caps.Capability(str)] = true
} }
} }
} }

50
irc/caps/constants.go Normal file
View File

@ -0,0 +1,50 @@
// Package caps holds capabilities.
package caps
// Capability represents an optional feature that a client may request from the server.
type Capability string
const (
// AccountNotify is this IRCv3 capability: http://ircv3.net/specs/extensions/account-notify-3.1.html
AccountNotify Capability = "account-notify"
// AccountTag is this IRCv3 capability: http://ircv3.net/specs/extensions/account-tag-3.2.html
AccountTag Capability = "account-tag"
// AwayNotify is this IRCv3 capability: http://ircv3.net/specs/extensions/away-notify-3.1.html
AwayNotify Capability = "away-notify"
// Batch is this IRCv3 capability: http://ircv3.net/specs/extensions/batch-3.2.html
Batch Capability = "batch"
// CapNotify is this IRCv3 capability: http://ircv3.net/specs/extensions/cap-notify-3.2.html
CapNotify Capability = "cap-notify"
// ChgHost is this IRCv3 capability: http://ircv3.net/specs/extensions/chghost-3.2.html
ChgHost Capability = "chghost"
// EchoMessage is this IRCv3 capability: http://ircv3.net/specs/extensions/echo-message-3.2.html
EchoMessage Capability = "echo-message"
// ExtendedJoin is this IRCv3 capability: http://ircv3.net/specs/extensions/extended-join-3.1.html
ExtendedJoin Capability = "extended-join"
// InviteNotify is this IRCv3 capability: http://ircv3.net/specs/extensions/invite-notify-3.2.html
InviteNotify Capability = "invite-notify"
// LabeledResponse is this draft IRCv3 capability: http://ircv3.net/specs/extensions/labeled-response.html
LabeledResponse Capability = "draft/labeled-response"
// MaxLine is this proposed capability: https://github.com/DanielOaks/ircv3-specifications/blob/master+line-lengths/extensions/line-lengths.md
MaxLine Capability = "draft/maxline"
// MessageIDs is this draft IRCv3 capability: http://ircv3.net/specs/extensions/message-ids.html
MessageIDs Capability = "draft/message-ids"
// MessageTags is this draft IRCv3 capability: http://ircv3.net/specs/core/message-tags-3.3.html
MessageTags Capability = "draft/message-tags-0.2"
// MultiPrefix is this IRCv3 capability: http://ircv3.net/specs/extensions/multi-prefix-3.1.html
MultiPrefix Capability = "multi-prefix"
// Rename is this proposed capability: https://github.com/SaberUK/ircv3-specifications/blob/rename/extensions/rename.md
Rename Capability = "draft/rename"
// SASL is this IRCv3 capability: http://ircv3.net/specs/extensions/sasl-3.2.html
SASL Capability = "sasl"
// ServerTime is this IRCv3 capability: http://ircv3.net/specs/extensions/server-time-3.2.html
ServerTime Capability = "server-time"
// STS is this draft IRCv3 capability: http://ircv3.net/specs/core/sts-3.3.html
STS Capability = "draft/sts"
// UserhostInNames is this IRCv3 capability: http://ircv3.net/specs/extensions/userhost-in-names-3.2.html
UserhostInNames Capability = "userhost-in-names"
)
func (capability Capability) String() string {
return string(capability)
}

View File

@ -14,6 +14,7 @@ import (
"sync" "sync"
"github.com/goshuirc/irc-go/ircmsg" "github.com/goshuirc/irc-go/ircmsg"
"github.com/oragono/oragono/irc/caps"
"github.com/tidwall/buntdb" "github.com/tidwall/buntdb"
) )
@ -164,8 +165,8 @@ func (modes ModeSet) Prefixes(isMultiPrefix bool) string {
} }
func (channel *Channel) nicksNoMutex(target *Client) []string { func (channel *Channel) nicksNoMutex(target *Client) []string {
isMultiPrefix := (target != nil) && target.capabilities[MultiPrefix] isMultiPrefix := (target != nil) && target.capabilities[caps.MultiPrefix]
isUserhostInNames := (target != nil) && target.capabilities[UserhostInNames] isUserhostInNames := (target != nil) && target.capabilities[caps.UserhostInNames]
nicks := make([]string, len(channel.members)) nicks := make([]string, len(channel.members))
i := 0 i := 0
for client, modes := range channel.members { for client, modes := range channel.members {
@ -261,7 +262,7 @@ func (channel *Channel) Join(client *Client, key string) {
client.server.logger.Debug("join", fmt.Sprintf("%s joined channel %s", client.nick, channel.name)) client.server.logger.Debug("join", fmt.Sprintf("%s joined channel %s", client.nick, channel.name))
for member := range channel.members { for member := range channel.members {
if member.capabilities[ExtendedJoin] { if member.capabilities[caps.ExtendedJoin] {
member.Send(nil, client.nickMaskString, "JOIN", channel.name, client.account.Name, client.realname) member.Send(nil, client.nickMaskString, "JOIN", channel.name, client.account.Name, client.realname)
} else { } else {
member.Send(nil, client.nickMaskString, "JOIN", channel.name) member.Send(nil, client.nickMaskString, "JOIN", channel.name)
@ -313,7 +314,7 @@ func (channel *Channel) Join(client *Client, key string) {
return nil return nil
}) })
if client.capabilities[ExtendedJoin] { if client.capabilities[caps.ExtendedJoin] {
client.Send(nil, client.nickMaskString, "JOIN", channel.name, client.account.Name, client.realname) client.Send(nil, client.nickMaskString, "JOIN", channel.name, client.account.Name, client.realname)
} else { } else {
client.Send(nil, client.nickMaskString, "JOIN", channel.name) client.Send(nil, client.nickMaskString, "JOIN", channel.name)
@ -441,11 +442,11 @@ func (channel *Channel) CanSpeak(client *Client) bool {
// TagMsg sends a tag message to everyone in this channel who can accept them. // TagMsg sends a tag message to everyone in this channel who can accept them.
func (channel *Channel) TagMsg(msgid string, minPrefix *Mode, clientOnlyTags *map[string]ircmsg.TagValue, client *Client) { func (channel *Channel) TagMsg(msgid string, minPrefix *Mode, clientOnlyTags *map[string]ircmsg.TagValue, client *Client) {
channel.sendMessage(msgid, "TAGMSG", []Capability{MessageTags}, minPrefix, clientOnlyTags, client, nil) channel.sendMessage(msgid, "TAGMSG", []caps.Capability{caps.MessageTags}, minPrefix, clientOnlyTags, client, nil)
} }
// sendMessage sends a given message to everyone on this channel. // sendMessage sends a given message to everyone on this channel.
func (channel *Channel) sendMessage(msgid, cmd string, requiredCaps []Capability, minPrefix *Mode, clientOnlyTags *map[string]ircmsg.TagValue, client *Client, message *string) { func (channel *Channel) sendMessage(msgid, cmd string, requiredCaps []caps.Capability, minPrefix *Mode, clientOnlyTags *map[string]ircmsg.TagValue, client *Client, message *string) {
if !channel.CanSpeak(client) { if !channel.CanSpeak(client) {
client.Send(nil, client.server.name, ERR_CANNOTSENDTOCHAN, channel.name, "Cannot send to channel") client.Send(nil, client.server.name, ERR_CANNOTSENDTOCHAN, channel.name, "Cannot send to channel")
return return
@ -464,7 +465,7 @@ func (channel *Channel) sendMessage(msgid, cmd string, requiredCaps []Capability
// STATUSMSG // STATUSMSG
continue continue
} }
if member == client && !client.capabilities[EchoMessage] { if member == client && !client.capabilities[caps.EchoMessage] {
continue continue
} }
@ -479,7 +480,7 @@ func (channel *Channel) sendMessage(msgid, cmd string, requiredCaps []Capability
} }
var messageTagsToUse *map[string]ircmsg.TagValue var messageTagsToUse *map[string]ircmsg.TagValue
if member.capabilities[MessageTags] { if member.capabilities[caps.MessageTags] {
messageTagsToUse = clientOnlyTags messageTagsToUse = clientOnlyTags
} }
@ -520,11 +521,11 @@ func (channel *Channel) sendSplitMessage(msgid, cmd string, minPrefix *Mode, cli
// STATUSMSG // STATUSMSG
continue continue
} }
if member == client && !client.capabilities[EchoMessage] { if member == client && !client.capabilities[caps.EchoMessage] {
continue continue
} }
var tagsToUse *map[string]ircmsg.TagValue var tagsToUse *map[string]ircmsg.TagValue
if member.capabilities[MessageTags] { if member.capabilities[caps.MessageTags] {
tagsToUse = clientOnlyTags tagsToUse = clientOnlyTags
} }
@ -728,7 +729,7 @@ func (channel *Channel) Invite(invitee *Client, inviter *Client) {
// send invite-notify // send invite-notify
for member := range channel.members { for member := range channel.members {
if member.capabilities[InviteNotify] && member != inviter && member != invitee && channel.ClientIsAtLeast(member, Halfop) { if member.capabilities[caps.InviteNotify] && member != inviter && member != invitee && channel.ClientIsAtLeast(member, Halfop) {
member.Send(nil, inviter.nickMaskString, "INVITE", invitee.nick, channel.name) member.Send(nil, inviter.nickMaskString, "INVITE", invitee.nick, channel.name)
} }
} }

View File

@ -19,6 +19,7 @@ import (
"github.com/goshuirc/irc-go/ircfmt" "github.com/goshuirc/irc-go/ircfmt"
"github.com/goshuirc/irc-go/ircmsg" "github.com/goshuirc/irc-go/ircmsg"
ident "github.com/oragono/go-ident" ident "github.com/oragono/go-ident"
"github.com/oragono/oragono/irc/caps"
"github.com/oragono/oragono/irc/sno" "github.com/oragono/oragono/irc/sno"
) )
@ -177,10 +178,10 @@ func (client *Client) IPString() string {
func (client *Client) maxlens() (int, int) { func (client *Client) maxlens() (int, int) {
maxlenTags := 512 maxlenTags := 512
maxlenRest := 512 maxlenRest := 512
if client.capabilities[MessageTags] { if client.capabilities[caps.MessageTags] {
maxlenTags = 4096 maxlenTags = 4096
} }
if client.capabilities[MaxLine] { if client.capabilities[caps.MaxLine] {
if client.server.limits.LineLen.Tags > maxlenTags { if client.server.limits.LineLen.Tags > maxlenTags {
maxlenTags = client.server.limits.LineLen.Tags maxlenTags = client.server.limits.LineLen.Tags
} }
@ -356,7 +357,7 @@ func (client *Client) ModeString() (str string) {
} }
// Friends refers to clients that share a channel with this client. // Friends refers to clients that share a channel with this client.
func (client *Client) Friends(Capabilities ...Capability) ClientSet { func (client *Client) Friends(Capabilities ...caps.Capability) ClientSet {
friends := make(ClientSet) friends := make(ClientSet)
// make sure that I have the right caps // make sure that I have the right caps
@ -579,7 +580,7 @@ func (client *Client) destroy() {
// SendSplitMsgFromClient sends an IRC PRIVMSG/NOTICE coming from a specific client. // SendSplitMsgFromClient sends an IRC PRIVMSG/NOTICE coming from a specific client.
// Adds account-tag to the line as well. // Adds account-tag to the line as well.
func (client *Client) SendSplitMsgFromClient(msgid string, from *Client, tags *map[string]ircmsg.TagValue, command, target string, message SplitMessage) { func (client *Client) SendSplitMsgFromClient(msgid string, from *Client, tags *map[string]ircmsg.TagValue, command, target string, message SplitMessage) {
if client.capabilities[MaxLine] { if client.capabilities[caps.MaxLine] {
client.SendFromClient(msgid, from, tags, command, target, message.ForMaxLine) client.SendFromClient(msgid, from, tags, command, target, message.ForMaxLine)
} else { } else {
for _, str := range message.For512 { for _, str := range message.For512 {
@ -592,7 +593,7 @@ func (client *Client) SendSplitMsgFromClient(msgid string, from *Client, tags *m
// Adds account-tag to the line as well. // Adds account-tag to the line as well.
func (client *Client) SendFromClient(msgid string, from *Client, tags *map[string]ircmsg.TagValue, command string, params ...string) error { func (client *Client) SendFromClient(msgid string, from *Client, tags *map[string]ircmsg.TagValue, command string, params ...string) error {
// attach account-tag // attach account-tag
if client.capabilities[AccountTag] && from.account != &NoAccount { if client.capabilities[caps.AccountTag] && from.account != &NoAccount {
if tags == nil { if tags == nil {
tags = ircmsg.MakeTags("account", from.account.Name) tags = ircmsg.MakeTags("account", from.account.Name)
} else { } else {
@ -600,7 +601,7 @@ func (client *Client) SendFromClient(msgid string, from *Client, tags *map[strin
} }
} }
// attach message-id // attach message-id
if len(msgid) > 0 && client.capabilities[MessageTags] { if len(msgid) > 0 && client.capabilities[caps.MessageTags] {
if tags == nil { if tags == nil {
tags = ircmsg.MakeTags("draft/msgid", msgid) tags = ircmsg.MakeTags("draft/msgid", msgid)
} else { } else {
@ -627,7 +628,7 @@ var (
// Send sends an IRC line to the client. // Send sends an IRC line to the client.
func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, command string, params ...string) error { func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, command string, params ...string) error {
// attach server-time // attach server-time
if client.capabilities[ServerTime] { if client.capabilities[caps.ServerTime] {
t := time.Now().UTC().Format("2006-01-02T15:04:05.999Z") t := time.Now().UTC().Format("2006-01-02T15:04:05.999Z")
if tags == nil { if tags == nil {
tags = ircmsg.MakeTags("time", t) tags = ircmsg.MakeTags("time", t)
@ -677,7 +678,7 @@ func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, comm
// Notice sends the client a notice from the server. // Notice sends the client a notice from the server.
func (client *Client) Notice(text string) { func (client *Client) Notice(text string) {
limit := 400 limit := 400
if client.capabilities[MaxLine] { if client.capabilities[caps.MaxLine] {
limit = client.server.limits.LineLen.Rest - 110 limit = client.server.limits.LineLen.Rest - 110
} }
lines := wordWrap(text, limit) lines := wordWrap(text, limit)

View File

@ -12,6 +12,7 @@ import (
"strings" "strings"
"github.com/goshuirc/irc-go/ircmatch" "github.com/goshuirc/irc-go/ircmatch"
"github.com/oragono/oragono/irc/caps"
"sync" "sync"
) )
@ -155,7 +156,7 @@ func (clients *ClientLookupSet) Replace(oldNick, newNick string, client *Client)
} }
// AllWithCaps returns all clients with the given capabilities. // AllWithCaps returns all clients with the given capabilities.
func (clients *ClientLookupSet) AllWithCaps(caps ...Capability) (set ClientSet) { func (clients *ClientLookupSet) AllWithCaps(caps ...caps.Capability) (set ClientSet) {
set = make(ClientSet) set = make(ClientSet)
clients.ByNickMutex.RLock() clients.ByNickMutex.RLock()

View File

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"github.com/goshuirc/irc-go/ircmsg" "github.com/goshuirc/irc-go/ircmsg"
"github.com/oragono/oragono/irc/caps"
) )
const ( const (
@ -89,7 +90,7 @@ func sendRoleplayMessage(server *Server, client *Client, source string, targetSt
channel.membersMutex.RLock() channel.membersMutex.RLock()
for member := range channel.members { for member := range channel.members {
if member == client && !client.capabilities[EchoMessage] { if member == client && !client.capabilities[caps.EchoMessage] {
continue continue
} }
member.Send(nil, source, "PRIVMSG", channel.name, message) member.Send(nil, source, "PRIVMSG", channel.name, message)
@ -109,7 +110,7 @@ func sendRoleplayMessage(server *Server, client *Client, source string, targetSt
} }
user.Send(nil, source, "PRIVMSG", user.nick, message) user.Send(nil, source, "PRIVMSG", user.nick, message)
if client.capabilities[EchoMessage] { if client.capabilities[caps.EchoMessage] {
client.Send(nil, source, "PRIVMSG", user.nick, message) client.Send(nil, source, "PRIVMSG", user.nick, message)
} }
if user.flags[Away] { if user.flags[Away] {

View File

@ -25,6 +25,7 @@ import (
"github.com/goshuirc/irc-go/ircfmt" "github.com/goshuirc/irc-go/ircfmt"
"github.com/goshuirc/irc-go/ircmsg" "github.com/goshuirc/irc-go/ircmsg"
"github.com/oragono/oragono/irc/caps"
"github.com/oragono/oragono/irc/logger" "github.com/oragono/oragono/irc/logger"
"github.com/oragono/oragono/irc/sno" "github.com/oragono/oragono/irc/sno"
"github.com/tidwall/buntdb" "github.com/tidwall/buntdb"
@ -641,11 +642,11 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
// send RENAME messages // send RENAME messages
for mcl := range channel.members { for mcl := range channel.members {
if mcl.capabilities[Rename] { if mcl.capabilities[caps.Rename] {
mcl.Send(nil, client.nickMaskString, "RENAME", oldName, newName, reason) mcl.Send(nil, client.nickMaskString, "RENAME", oldName, newName, reason)
} else { } else {
mcl.Send(nil, mcl.nickMaskString, "PART", oldName, fmt.Sprintf("Channel renamed: %s", reason)) mcl.Send(nil, mcl.nickMaskString, "PART", oldName, fmt.Sprintf("Channel renamed: %s", reason))
if mcl.capabilities[ExtendedJoin] { if mcl.capabilities[caps.ExtendedJoin] {
accountName := "*" accountName := "*"
if mcl.account != nil { if mcl.account != nil {
accountName = mcl.account.Name accountName = mcl.account.Name
@ -824,7 +825,7 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
message := msg.Params[1] message := msg.Params[1]
// split privmsg // split privmsg
splitMsg := server.splitMessage(message, !client.capabilities[MaxLine]) splitMsg := server.splitMessage(message, !client.capabilities[caps.MaxLine])
for i, targetString := range targets { for i, targetString := range targets {
// max of four targets per privmsg // max of four targets per privmsg
@ -868,7 +869,7 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
} }
continue continue
} }
if !user.capabilities[MessageTags] { if !user.capabilities[caps.MessageTags] {
clientOnlyTags = nil clientOnlyTags = nil
} }
msgid := server.generateMessageID() msgid := server.generateMessageID()
@ -877,7 +878,7 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
if !user.flags[RegisteredOnly] || client.registered { if !user.flags[RegisteredOnly] || client.registered {
user.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "PRIVMSG", user.nick, splitMsg) user.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "PRIVMSG", user.nick, splitMsg)
} }
if client.capabilities[EchoMessage] { if client.capabilities[caps.EchoMessage] {
client.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "PRIVMSG", user.nick, splitMsg) client.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "PRIVMSG", user.nick, splitMsg)
} }
if user.flags[Away] { if user.flags[Away] {
@ -938,11 +939,11 @@ func tagmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
msgid := server.generateMessageID() msgid := server.generateMessageID()
// end user can't receive tagmsgs // end user can't receive tagmsgs
if !user.capabilities[MessageTags] { if !user.capabilities[caps.MessageTags] {
continue continue
} }
user.SendFromClient(msgid, client, clientOnlyTags, "TAGMSG", user.nick) user.SendFromClient(msgid, client, clientOnlyTags, "TAGMSG", user.nick)
if client.capabilities[EchoMessage] { if client.capabilities[caps.EchoMessage] {
client.SendFromClient(msgid, client, clientOnlyTags, "TAGMSG", user.nick) client.SendFromClient(msgid, client, clientOnlyTags, "TAGMSG", user.nick)
} }
if user.flags[Away] { if user.flags[Away] {
@ -956,7 +957,7 @@ func tagmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
// WhoisChannelsNames returns the common channel names between two users. // WhoisChannelsNames returns the common channel names between two users.
func (client *Client) WhoisChannelsNames(target *Client) []string { func (client *Client) WhoisChannelsNames(target *Client) []string {
isMultiPrefix := target.capabilities[MultiPrefix] isMultiPrefix := target.capabilities[caps.MultiPrefix]
var chstrs []string var chstrs []string
index := 0 index := 0
for channel := range client.channels { for channel := range client.channels {
@ -1061,7 +1062,7 @@ func (target *Client) RplWhoReplyNoMutex(channel *Channel, client *Client) {
} }
if channel != nil { if channel != nil {
flags += channel.members[client].Prefixes(target.capabilities[MultiPrefix]) flags += channel.members[client].Prefixes(target.capabilities[caps.MultiPrefix])
channelName = channel.name channelName = channel.name
} }
target.Send(nil, target.server.name, RPL_WHOREPLY, target.nick, channelName, client.username, client.hostname, client.server.name, client.nick, flags, strconv.Itoa(client.hops)+" "+client.realname) target.Send(nil, target.server.name, RPL_WHOREPLY, target.nick, channelName, client.username, client.hostname, client.server.name, client.nick, flags, strconv.Itoa(client.hops)+" "+client.realname)
@ -1151,7 +1152,7 @@ func operHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
// push new vhost if one is set // push new vhost if one is set
if len(server.operators[name].Vhost) > 0 { if len(server.operators[name].Vhost) > 0 {
for fClient := range client.Friends(ChgHost) { for fClient := range client.Friends(caps.ChgHost) {
fClient.SendFromClient("", client, nil, "CHGHOST", client.username, server.operators[name].Vhost) fClient.SendFromClient("", client, nil, "CHGHOST", client.username, server.operators[name].Vhost)
} }
// CHGHOST requires prefix nickmask to have original hostname, so do that before updating nickmask // CHGHOST requires prefix nickmask to have original hostname, so do that before updating nickmask
@ -1294,34 +1295,34 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
// SASL // SASL
if config.Accounts.AuthenticationEnabled && !server.accountAuthenticationEnabled { if config.Accounts.AuthenticationEnabled && !server.accountAuthenticationEnabled {
// enabling SASL // enabling SASL
SupportedCapabilities[SASL] = true SupportedCapabilities[caps.SASL] = true
addedCaps[SASL] = true addedCaps[caps.SASL] = true
} }
if !config.Accounts.AuthenticationEnabled && server.accountAuthenticationEnabled { if !config.Accounts.AuthenticationEnabled && server.accountAuthenticationEnabled {
// disabling SASL // disabling SASL
SupportedCapabilities[SASL] = false SupportedCapabilities[caps.SASL] = false
removedCaps[SASL] = true removedCaps[caps.SASL] = true
} }
server.accountAuthenticationEnabled = config.Accounts.AuthenticationEnabled server.accountAuthenticationEnabled = config.Accounts.AuthenticationEnabled
// STS // STS
stsValue := config.Server.STS.Value() stsValue := config.Server.STS.Value()
var stsDisabled bool var stsDisabled bool
server.logger.Debug("rehash", "STS Vals", CapValues[STS], stsValue, fmt.Sprintf("server[%v] config[%v]", server.stsEnabled, config.Server.STS.Enabled)) server.logger.Debug("rehash", "STS Vals", CapValues[caps.STS], stsValue, fmt.Sprintf("server[%v] config[%v]", server.stsEnabled, config.Server.STS.Enabled))
if config.Server.STS.Enabled && !server.stsEnabled { if config.Server.STS.Enabled && !server.stsEnabled {
// enabling STS // enabling STS
SupportedCapabilities[STS] = true SupportedCapabilities[caps.STS] = true
addedCaps[STS] = true addedCaps[caps.STS] = true
CapValues[STS] = stsValue CapValues[caps.STS] = stsValue
} else if !config.Server.STS.Enabled && server.stsEnabled { } else if !config.Server.STS.Enabled && server.stsEnabled {
// disabling STS // disabling STS
SupportedCapabilities[STS] = false SupportedCapabilities[caps.STS] = false
removedCaps[STS] = true removedCaps[caps.STS] = true
stsDisabled = true stsDisabled = true
} else if config.Server.STS.Enabled && server.stsEnabled && stsValue != CapValues[STS] { } else if config.Server.STS.Enabled && server.stsEnabled && stsValue != CapValues[caps.STS] {
// STS policy updated // STS policy updated
CapValues[STS] = stsValue CapValues[caps.STS] = stsValue
updatedCaps[STS] = true updatedCaps[caps.STS] = true
} }
server.stsEnabled = config.Server.STS.Enabled server.stsEnabled = config.Server.STS.Enabled
@ -1341,7 +1342,7 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
} }
if len(addedCaps) > 0 || len(removedCaps) > 0 { if len(addedCaps) > 0 || len(removedCaps) > 0 {
capBurstClients = server.clients.AllWithCaps(CapNotify) capBurstClients = server.clients.AllWithCaps(caps.CapNotify)
added[Cap301] = addedCaps.String(Cap301) added[Cap301] = addedCaps.String(Cap301)
added[Cap302] = addedCaps.String(Cap302) added[Cap302] = addedCaps.String(Cap302)
@ -1357,7 +1358,7 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
if len(addedCaps) > 0 { if len(addedCaps) > 0 {
added[Cap302] = added[Cap302] + " " + stsPolicy added[Cap302] = added[Cap302] + " " + stsPolicy
} else { } else {
addedCaps[STS] = true addedCaps[caps.STS] = true
added[Cap302] = stsPolicy added[Cap302] = stsPolicy
} }
} }
@ -1655,7 +1656,7 @@ func awayHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
client.Send(nil, server.name, "MODE", client.nick, modech.String()) client.Send(nil, server.name, "MODE", client.nick, modech.String())
// dispatch away-notify // dispatch away-notify
for friend := range client.Friends(AwayNotify) { for friend := range client.Friends(caps.AwayNotify) {
if client.flags[Away] { if client.flags[Away] {
friend.SendFromClient("", client, nil, "AWAY", client.awayMessage) friend.SendFromClient("", client, nil, "AWAY", client.awayMessage)
} else { } else {
@ -1706,7 +1707,7 @@ func noticeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
message := msg.Params[1] message := msg.Params[1]
// split privmsg // split privmsg
splitMsg := server.splitMessage(message, !client.capabilities[MaxLine]) splitMsg := server.splitMessage(message, !client.capabilities[caps.MaxLine])
for i, targetString := range targets { for i, targetString := range targets {
// max of four targets per privmsg // max of four targets per privmsg
@ -1747,7 +1748,7 @@ func noticeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
// errors silently ignored with NOTICE as per RFC // errors silently ignored with NOTICE as per RFC
continue continue
} }
if !user.capabilities[MessageTags] { if !user.capabilities[caps.MessageTags] {
clientOnlyTags = nil clientOnlyTags = nil
} }
msgid := server.generateMessageID() msgid := server.generateMessageID()
@ -1756,7 +1757,7 @@ func noticeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
if !user.flags[RegisteredOnly] || client.registered { if !user.flags[RegisteredOnly] || client.registered {
user.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "NOTICE", user.nick, splitMsg) user.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "NOTICE", user.nick, splitMsg)
} }
if client.capabilities[EchoMessage] { if client.capabilities[caps.EchoMessage] {
client.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "NOTICE", user.nick, splitMsg) client.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "NOTICE", user.nick, splitMsg)
} }
} }