|
@@ -642,11 +642,11 @@ func renameHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
642
|
642
|
|
643
|
643
|
// send RENAME messages
|
644
|
644
|
for mcl := range channel.members {
|
645
|
|
- if mcl.capabilities[caps.Rename] {
|
|
645
|
+ if mcl.capabilities.Has(caps.Rename) {
|
646
|
646
|
mcl.Send(nil, client.nickMaskString, "RENAME", oldName, newName, reason)
|
647
|
647
|
} else {
|
648
|
648
|
mcl.Send(nil, mcl.nickMaskString, "PART", oldName, fmt.Sprintf("Channel renamed: %s", reason))
|
649
|
|
- if mcl.capabilities[caps.ExtendedJoin] {
|
|
649
|
+ if mcl.capabilities.Has(caps.ExtendedJoin) {
|
650
|
650
|
accountName := "*"
|
651
|
651
|
if mcl.account != nil {
|
652
|
652
|
accountName = mcl.account.Name
|
|
@@ -825,7 +825,7 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
|
825
|
825
|
message := msg.Params[1]
|
826
|
826
|
|
827
|
827
|
// split privmsg
|
828
|
|
- splitMsg := server.splitMessage(message, !client.capabilities[caps.MaxLine])
|
|
828
|
+ splitMsg := server.splitMessage(message, !client.capabilities.Has(caps.MaxLine))
|
829
|
829
|
|
830
|
830
|
for i, targetString := range targets {
|
831
|
831
|
// max of four targets per privmsg
|
|
@@ -869,7 +869,7 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
|
869
|
869
|
}
|
870
|
870
|
continue
|
871
|
871
|
}
|
872
|
|
- if !user.capabilities[caps.MessageTags] {
|
|
872
|
+ if !user.capabilities.Has(caps.MessageTags) {
|
873
|
873
|
clientOnlyTags = nil
|
874
|
874
|
}
|
875
|
875
|
msgid := server.generateMessageID()
|
|
@@ -878,7 +878,7 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
|
878
|
878
|
if !user.flags[RegisteredOnly] || client.registered {
|
879
|
879
|
user.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "PRIVMSG", user.nick, splitMsg)
|
880
|
880
|
}
|
881
|
|
- if client.capabilities[caps.EchoMessage] {
|
|
881
|
+ if client.capabilities.Has(caps.EchoMessage) {
|
882
|
882
|
client.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "PRIVMSG", user.nick, splitMsg)
|
883
|
883
|
}
|
884
|
884
|
if user.flags[Away] {
|
|
@@ -939,11 +939,11 @@ func tagmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
939
|
939
|
msgid := server.generateMessageID()
|
940
|
940
|
|
941
|
941
|
// end user can't receive tagmsgs
|
942
|
|
- if !user.capabilities[caps.MessageTags] {
|
|
942
|
+ if !user.capabilities.Has(caps.MessageTags) {
|
943
|
943
|
continue
|
944
|
944
|
}
|
945
|
945
|
user.SendFromClient(msgid, client, clientOnlyTags, "TAGMSG", user.nick)
|
946
|
|
- if client.capabilities[caps.EchoMessage] {
|
|
946
|
+ if client.capabilities.Has(caps.EchoMessage) {
|
947
|
947
|
client.SendFromClient(msgid, client, clientOnlyTags, "TAGMSG", user.nick)
|
948
|
948
|
}
|
949
|
949
|
if user.flags[Away] {
|
|
@@ -957,7 +957,7 @@ func tagmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
957
|
957
|
|
958
|
958
|
// WhoisChannelsNames returns the common channel names between two users.
|
959
|
959
|
func (client *Client) WhoisChannelsNames(target *Client) []string {
|
960
|
|
- isMultiPrefix := target.capabilities[caps.MultiPrefix]
|
|
960
|
+ isMultiPrefix := target.capabilities.Has(caps.MultiPrefix)
|
961
|
961
|
var chstrs []string
|
962
|
962
|
index := 0
|
963
|
963
|
for channel := range client.channels {
|
|
@@ -1062,7 +1062,7 @@ func (target *Client) RplWhoReplyNoMutex(channel *Channel, client *Client) {
|
1062
|
1062
|
}
|
1063
|
1063
|
|
1064
|
1064
|
if channel != nil {
|
1065
|
|
- flags += channel.members[client].Prefixes(target.capabilities[caps.MultiPrefix])
|
|
1065
|
+ flags += channel.members[client].Prefixes(target.capabilities.Has(caps.MultiPrefix))
|
1066
|
1066
|
channelName = channel.name
|
1067
|
1067
|
}
|
1068
|
1068
|
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)
|
|
@@ -1288,66 +1288,66 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
|
1288
|
1288
|
server.connectionLimitsMutex.Unlock()
|
1289
|
1289
|
|
1290
|
1290
|
// setup new and removed caps
|
1291
|
|
- addedCaps := make(CapabilitySet)
|
1292
|
|
- removedCaps := make(CapabilitySet)
|
1293
|
|
- updatedCaps := make(CapabilitySet)
|
|
1291
|
+ addedCaps := caps.NewSet()
|
|
1292
|
+ removedCaps := caps.NewSet()
|
|
1293
|
+ updatedCaps := caps.NewSet()
|
1294
|
1294
|
|
1295
|
1295
|
// SASL
|
1296
|
1296
|
if config.Accounts.AuthenticationEnabled && !server.accountAuthenticationEnabled {
|
1297
|
1297
|
// enabling SASL
|
1298
|
|
- SupportedCapabilities[caps.SASL] = true
|
1299
|
|
- addedCaps[caps.SASL] = true
|
|
1298
|
+ SupportedCapabilities.Enable(caps.SASL)
|
|
1299
|
+ CapValues.Set(caps.SASL, "PLAIN,EXTERNAL")
|
|
1300
|
+ addedCaps.Add(caps.SASL)
|
1300
|
1301
|
}
|
1301
|
1302
|
if !config.Accounts.AuthenticationEnabled && server.accountAuthenticationEnabled {
|
1302
|
1303
|
// disabling SASL
|
1303
|
|
- SupportedCapabilities[caps.SASL] = false
|
1304
|
|
- removedCaps[caps.SASL] = true
|
|
1304
|
+ SupportedCapabilities.Disable(caps.SASL)
|
|
1305
|
+ removedCaps.Add(caps.SASL)
|
1305
|
1306
|
}
|
1306
|
1307
|
server.accountAuthenticationEnabled = config.Accounts.AuthenticationEnabled
|
1307
|
1308
|
|
1308
|
1309
|
// STS
|
1309
|
1310
|
stsValue := config.Server.STS.Value()
|
1310
|
1311
|
var stsDisabled bool
|
1311
|
|
- server.logger.Debug("rehash", "STS Vals", CapValues[caps.STS], stsValue, fmt.Sprintf("server[%v] config[%v]", server.stsEnabled, config.Server.STS.Enabled))
|
|
1312
|
+ stsCurrentCapValue, _ := CapValues.Get(caps.STS)
|
|
1313
|
+ server.logger.Debug("rehash", "STS Vals", stsCurrentCapValue, stsValue, fmt.Sprintf("server[%v] config[%v]", server.stsEnabled, config.Server.STS.Enabled))
|
1312
|
1314
|
if config.Server.STS.Enabled && !server.stsEnabled {
|
1313
|
1315
|
// enabling STS
|
1314
|
|
- SupportedCapabilities[caps.STS] = true
|
1315
|
|
- addedCaps[caps.STS] = true
|
1316
|
|
- CapValues[caps.STS] = stsValue
|
|
1316
|
+ SupportedCapabilities.Enable(caps.STS)
|
|
1317
|
+ addedCaps.Add(caps.STS)
|
|
1318
|
+ CapValues.Set(caps.STS, stsValue)
|
1317
|
1319
|
} else if !config.Server.STS.Enabled && server.stsEnabled {
|
1318
|
1320
|
// disabling STS
|
1319
|
|
- SupportedCapabilities[caps.STS] = false
|
1320
|
|
- removedCaps[caps.STS] = true
|
|
1321
|
+ SupportedCapabilities.Disable(caps.STS)
|
|
1322
|
+ removedCaps.Add(caps.STS)
|
1321
|
1323
|
stsDisabled = true
|
1322
|
|
- } else if config.Server.STS.Enabled && server.stsEnabled && stsValue != CapValues[caps.STS] {
|
|
1324
|
+ } else if config.Server.STS.Enabled && server.stsEnabled && stsValue != stsCurrentCapValue {
|
1323
|
1325
|
// STS policy updated
|
1324
|
|
- CapValues[caps.STS] = stsValue
|
1325
|
|
- updatedCaps[caps.STS] = true
|
|
1326
|
+ CapValues.Set(caps.STS, stsValue)
|
|
1327
|
+ updatedCaps.Add(caps.STS)
|
1326
|
1328
|
}
|
1327
|
1329
|
server.stsEnabled = config.Server.STS.Enabled
|
1328
|
1330
|
|
1329
|
1331
|
// burst new and removed caps
|
1330
|
1332
|
var capBurstClients ClientSet
|
1331
|
|
- added := make(map[CapVersion]string)
|
|
1333
|
+ added := make(map[caps.Version]string)
|
1332
|
1334
|
var removed string
|
1333
|
1335
|
|
1334
|
1336
|
// updated caps get DEL'd and then NEW'd
|
1335
|
1337
|
// so, we can just add updated ones to both removed and added lists here and they'll be correctly handled
|
1336
|
|
- server.logger.Debug("rehash", "Updated Caps", updatedCaps.String(Cap301), strconv.Itoa(len(updatedCaps)))
|
1337
|
|
- if len(updatedCaps) > 0 {
|
1338
|
|
- for capab := range updatedCaps {
|
1339
|
|
- addedCaps[capab] = true
|
1340
|
|
- removedCaps[capab] = true
|
1341
|
|
- }
|
|
1338
|
+ server.logger.Debug("rehash", "Updated Caps", updatedCaps.String(caps.Cap301, CapValues), strconv.Itoa(updatedCaps.Count()))
|
|
1339
|
+ for _, capab := range updatedCaps.List() {
|
|
1340
|
+ addedCaps.Enable(capab)
|
|
1341
|
+ removedCaps.Enable(capab)
|
1342
|
1342
|
}
|
1343
|
1343
|
|
1344
|
|
- if len(addedCaps) > 0 || len(removedCaps) > 0 {
|
|
1344
|
+ if 0 < addedCaps.Count() || 0 < removedCaps.Count() {
|
1345
|
1345
|
capBurstClients = server.clients.AllWithCaps(caps.CapNotify)
|
1346
|
1346
|
|
1347
|
|
- added[Cap301] = addedCaps.String(Cap301)
|
1348
|
|
- added[Cap302] = addedCaps.String(Cap302)
|
1349
|
|
- // removed never has values
|
1350
|
|
- removed = removedCaps.String(Cap301)
|
|
1347
|
+ added[caps.Cap301] = addedCaps.String(caps.Cap301, CapValues)
|
|
1348
|
+ added[caps.Cap302] = addedCaps.String(caps.Cap302, CapValues)
|
|
1349
|
+ // removed never has values, so we leave it as Cap301
|
|
1350
|
+ removed = removedCaps.String(caps.Cap301, CapValues)
|
1351
|
1351
|
}
|
1352
|
1352
|
|
1353
|
1353
|
for sClient := range capBurstClients {
|
|
@@ -1355,18 +1355,18 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
|
1355
|
1355
|
// remove STS policy
|
1356
|
1356
|
//TODO(dan): this is an ugly hack. we can write this better.
|
1357
|
1357
|
stsPolicy := "sts=duration=0"
|
1358
|
|
- if len(addedCaps) > 0 {
|
1359
|
|
- added[Cap302] = added[Cap302] + " " + stsPolicy
|
|
1358
|
+ if 0 < addedCaps.Count() {
|
|
1359
|
+ added[caps.Cap302] = added[caps.Cap302] + " " + stsPolicy
|
1360
|
1360
|
} else {
|
1361
|
|
- addedCaps[caps.STS] = true
|
1362
|
|
- added[Cap302] = stsPolicy
|
|
1361
|
+ addedCaps.Enable(caps.STS)
|
|
1362
|
+ added[caps.Cap302] = stsPolicy
|
1363
|
1363
|
}
|
1364
|
1364
|
}
|
1365
|
1365
|
// DEL caps and then send NEW ones so that updated caps get removed/added correctly
|
1366
|
|
- if len(removedCaps) > 0 {
|
|
1366
|
+ if 0 < removedCaps.Count() {
|
1367
|
1367
|
sClient.Send(nil, server.name, "CAP", sClient.nick, "DEL", removed)
|
1368
|
1368
|
}
|
1369
|
|
- if len(addedCaps) > 0 {
|
|
1369
|
+ if 0 < addedCaps.Count() {
|
1370
|
1370
|
sClient.Send(nil, server.name, "CAP", sClient.nick, "NEW", added[sClient.capVersion])
|
1371
|
1371
|
}
|
1372
|
1372
|
}
|
|
@@ -1707,7 +1707,7 @@ func noticeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
1707
|
1707
|
message := msg.Params[1]
|
1708
|
1708
|
|
1709
|
1709
|
// split privmsg
|
1710
|
|
- splitMsg := server.splitMessage(message, !client.capabilities[caps.MaxLine])
|
|
1710
|
+ splitMsg := server.splitMessage(message, !client.capabilities.Has(caps.MaxLine))
|
1711
|
1711
|
|
1712
|
1712
|
for i, targetString := range targets {
|
1713
|
1713
|
// max of four targets per privmsg
|
|
@@ -1748,7 +1748,7 @@ func noticeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
1748
|
1748
|
// errors silently ignored with NOTICE as per RFC
|
1749
|
1749
|
continue
|
1750
|
1750
|
}
|
1751
|
|
- if !user.capabilities[caps.MessageTags] {
|
|
1751
|
+ if !user.capabilities.Has(caps.MessageTags) {
|
1752
|
1752
|
clientOnlyTags = nil
|
1753
|
1753
|
}
|
1754
|
1754
|
msgid := server.generateMessageID()
|
|
@@ -1757,7 +1757,7 @@ func noticeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
|
1757
|
1757
|
if !user.flags[RegisteredOnly] || client.registered {
|
1758
|
1758
|
user.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "NOTICE", user.nick, splitMsg)
|
1759
|
1759
|
}
|
1760
|
|
- if client.capabilities[caps.EchoMessage] {
|
|
1760
|
+ if client.capabilities.Has(caps.EchoMessage) {
|
1761
|
1761
|
client.SendSplitMsgFromClient(msgid, client, clientOnlyTags, "NOTICE", user.nick, splitMsg)
|
1762
|
1762
|
}
|
1763
|
1763
|
}
|