Explorar el Código

clean up RPL_CHANNELMODEIS logic (#2163)

Don't send RPL_CHANNELMODEIS for no-op changes to channel-user modes
tags/v2.14.0-rc1
Shivaram Lingamneni hace 3 semanas
padre
commit
1117680fdd
No account linked to committer's email address
Se han modificado 1 ficheros con 9 adiciones y 4 borrados
  1. 9
    4
      irc/modes.go

+ 9
- 4
irc/modes.go Ver fichero

@@ -158,7 +158,6 @@ func (channel *Channel) ApplyChannelModeChanges(client *Client, isSamode bool, c
158 158
 
159 159
 	var alreadySentPrivError bool
160 160
 
161
-	maskOpCount := 0
162 161
 	chname := channel.Name()
163 162
 	details := client.Details()
164 163
 
@@ -192,6 +191,11 @@ func (channel *Channel) ApplyChannelModeChanges(client *Client, isSamode bool, c
192 191
 		}
193 192
 	}
194 193
 
194
+	// should we send 324 RPL_CHANNELMODEIS? standard behavior is to send it for
195
+	// `MODE #channel`, i.e., an empty list of intended changes, but Ergo will
196
+	// also send it for no-op changes to zero-argument modes like +i
197
+	shouldSendModeIsLine := len(changes) == 0
198
+
195 199
 	for _, change := range changes {
196 200
 		if !hasPrivs(change) {
197 201
 			if !alreadySentPrivError {
@@ -203,7 +207,6 @@ func (channel *Channel) ApplyChannelModeChanges(client *Client, isSamode bool, c
203 207
 
204 208
 		switch change.Mode {
205 209
 		case modes.BanMask, modes.ExceptMask, modes.InviteMask:
206
-			maskOpCount += 1
207 210
 			if change.Op == modes.List {
208 211
 				channel.ShowMaskList(client, change.Mode, rb)
209 212
 				continue
@@ -313,11 +316,14 @@ func (channel *Channel) ApplyChannelModeChanges(client *Client, isSamode bool, c
313 316
 		default:
314 317
 			// all channel modes with no args, e.g., InviteOnly, Secret
315 318
 			if change.Op == modes.List {
319
+				shouldSendModeIsLine = true
316 320
 				continue
317 321
 			}
318 322
 
319 323
 			if channel.flags.SetMode(change.Mode, change.Op == modes.Add) {
320 324
 				applied = append(applied, change)
325
+			} else {
326
+				shouldSendModeIsLine = true
321 327
 			}
322 328
 		}
323 329
 	}
@@ -337,8 +343,7 @@ func (channel *Channel) ApplyChannelModeChanges(client *Client, isSamode bool, c
337 343
 		channel.MarkDirty(includeFlags)
338 344
 	}
339 345
 
340
-	// #649: don't send 324 RPL_CHANNELMODEIS if we were only working with mask lists
341
-	if len(applied) == 0 && !alreadySentPrivError && (maskOpCount == 0 || maskOpCount < len(changes)) {
346
+	if len(applied) == 0 && !alreadySentPrivError && shouldSendModeIsLine {
342 347
 		args := append([]string{details.nick, chname}, channel.modeStrings(client)...)
343 348
 		rb.Add(nil, client.server.name, RPL_CHANNELMODEIS, args...)
344 349
 		rb.Add(nil, client.server.name, RPL_CREATIONTIME, details.nick, chname, strconv.FormatInt(channel.createdTime.Unix(), 10))

Loading…
Cancelar
Guardar