mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
increase max cap line length
Workaround for #661: this makes the `CAP LS 302` line from the default config fit on a single line, as long as the server name is at most 35 characters.
This commit is contained in:
parent
a75d26a46b
commit
ae9aecbbb0
@ -89,12 +89,15 @@ func (s *Set) Empty() bool {
|
|||||||
return utils.BitsetEmpty(s[:])
|
return utils.BitsetEmpty(s[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxPayloadLength = 440
|
const defaultMaxPayloadLength = 450
|
||||||
|
|
||||||
// Strings returns all of our enabled capabilities as a slice of strings.
|
// Strings returns all of our enabled capabilities as a slice of strings.
|
||||||
func (s *Set) Strings(version Version, values Values) (result []string) {
|
func (s *Set) Strings(version Version, values Values, maxLen int) (result []string) {
|
||||||
|
if maxLen == 0 {
|
||||||
|
maxLen = defaultMaxPayloadLength
|
||||||
|
}
|
||||||
var t utils.TokenLineBuilder
|
var t utils.TokenLineBuilder
|
||||||
t.Initialize(maxPayloadLength, " ")
|
t.Initialize(maxLen, " ")
|
||||||
|
|
||||||
var capab Capability
|
var capab Capability
|
||||||
asSlice := s[:]
|
asSlice := s[:]
|
||||||
|
@ -47,13 +47,13 @@ func TestSets(t *testing.T) {
|
|||||||
values := make(Values)
|
values := make(Values)
|
||||||
values[InviteNotify] = "invitemepls"
|
values[InviteNotify] = "invitemepls"
|
||||||
|
|
||||||
actualCap301ValuesString := s1.Strings(Cap301, values)
|
actualCap301ValuesString := s1.Strings(Cap301, values, 0)
|
||||||
expectedCap301ValuesString := []string{"invite-notify userhost-in-names"}
|
expectedCap301ValuesString := []string{"invite-notify userhost-in-names"}
|
||||||
if !reflect.DeepEqual(actualCap301ValuesString, expectedCap301ValuesString) {
|
if !reflect.DeepEqual(actualCap301ValuesString, expectedCap301ValuesString) {
|
||||||
t.Errorf("Generated Cap301 values string [%v] did not match expected values string [%v]", actualCap301ValuesString, expectedCap301ValuesString)
|
t.Errorf("Generated Cap301 values string [%v] did not match expected values string [%v]", actualCap301ValuesString, expectedCap301ValuesString)
|
||||||
}
|
}
|
||||||
|
|
||||||
actualCap302ValuesString := s1.Strings(Cap302, values)
|
actualCap302ValuesString := s1.Strings(Cap302, values, 0)
|
||||||
expectedCap302ValuesString := []string{"invite-notify=invitemepls userhost-in-names"}
|
expectedCap302ValuesString := []string{"invite-notify=invitemepls userhost-in-names"}
|
||||||
if !reflect.DeepEqual(actualCap302ValuesString, expectedCap302ValuesString) {
|
if !reflect.DeepEqual(actualCap302ValuesString, expectedCap302ValuesString) {
|
||||||
t.Errorf("Generated Cap302 values string [%s] did not match expected values string [%s]", actualCap302ValuesString, expectedCap302ValuesString)
|
t.Errorf("Generated Cap302 values string [%s] did not match expected values string [%s]", actualCap302ValuesString, expectedCap302ValuesString)
|
||||||
|
@ -569,9 +569,14 @@ func capHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Respo
|
|||||||
|
|
||||||
sendCapLines := func(cset *caps.Set, values caps.Values) {
|
sendCapLines := func(cset *caps.Set, values caps.Values) {
|
||||||
version := rb.session.capVersion
|
version := rb.session.capVersion
|
||||||
capLines := cset.Strings(version, values)
|
// we're working around two bugs:
|
||||||
// weechat 1.4 has a bug here where it won't accept the CAP reply unless it contains
|
// 1. weechat 1.4 won't accept the CAP reply unless it contains the server.name source
|
||||||
// the server.name source:
|
// 2. old versions of Kiwi and The Lounge can't parse multiline CAP LS 302 (#661),
|
||||||
|
// so try as hard as possible to get the response to fit on one line.
|
||||||
|
// :server.name CAP * LS * :<tokens>
|
||||||
|
// 1 7 4
|
||||||
|
maxLen := 510 - 1 - len(server.name) - 7 - len(subCommand) - 4
|
||||||
|
capLines := cset.Strings(version, values, maxLen)
|
||||||
for i, capStr := range capLines {
|
for i, capStr := range capLines {
|
||||||
if version >= caps.Cap302 && i < len(capLines)-1 {
|
if version >= caps.Cap302 && i < len(capLines)-1 {
|
||||||
rb.Add(nil, server.name, "CAP", details.nick, subCommand, "*", capStr)
|
rb.Add(nil, server.name, "CAP", details.nick, subCommand, "*", capStr)
|
||||||
|
@ -710,17 +710,17 @@ func (server *Server) applyConfig(config *Config, initial bool) (err error) {
|
|||||||
|
|
||||||
// updated caps get DEL'd and then NEW'd
|
// updated caps get DEL'd and then NEW'd
|
||||||
// so, we can just add updated ones to both removed and added lists here and they'll be correctly handled
|
// so, we can just add updated ones to both removed and added lists here and they'll be correctly handled
|
||||||
server.logger.Debug("server", "Updated Caps", strings.Join(updatedCaps.Strings(caps.Cap301, config.Server.capValues), " "))
|
server.logger.Debug("server", "Updated Caps", strings.Join(updatedCaps.Strings(caps.Cap301, config.Server.capValues, 0), " "))
|
||||||
addedCaps.Union(updatedCaps)
|
addedCaps.Union(updatedCaps)
|
||||||
removedCaps.Union(updatedCaps)
|
removedCaps.Union(updatedCaps)
|
||||||
|
|
||||||
if !addedCaps.Empty() || !removedCaps.Empty() {
|
if !addedCaps.Empty() || !removedCaps.Empty() {
|
||||||
capBurstSessions = server.clients.AllWithCapsNotify()
|
capBurstSessions = server.clients.AllWithCapsNotify()
|
||||||
|
|
||||||
added[caps.Cap301] = addedCaps.Strings(caps.Cap301, config.Server.capValues)
|
added[caps.Cap301] = addedCaps.Strings(caps.Cap301, config.Server.capValues, 0)
|
||||||
added[caps.Cap302] = addedCaps.Strings(caps.Cap302, config.Server.capValues)
|
added[caps.Cap302] = addedCaps.Strings(caps.Cap302, config.Server.capValues, 0)
|
||||||
// removed never has values, so we leave it as Cap301
|
// removed never has values, so we leave it as Cap301
|
||||||
removed = removedCaps.Strings(caps.Cap301, config.Server.capValues)
|
removed = removedCaps.Strings(caps.Cap301, config.Server.capValues, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, sSession := range capBurstSessions {
|
for _, sSession := range capBurstSessions {
|
||||||
|
Loading…
Reference in New Issue
Block a user