|
@@ -241,12 +241,7 @@ func (channel *Channel) Names(client *Client, rb *ResponseBuffer) {
|
241
|
241
|
rb.Add(nil, client.server.name, RPL_ENDOFNAMES, client.nick, channel.name, client.t("End of NAMES list"))
|
242
|
242
|
}
|
243
|
243
|
|
244
|
|
-// ClientIsAtLeast returns whether the client has at least the given channel privilege.
|
245
|
|
-func (channel *Channel) ClientIsAtLeast(client *Client, permission modes.Mode) bool {
|
246
|
|
- channel.stateMutex.RLock()
|
247
|
|
- clientModes := channel.members[client]
|
248
|
|
- channel.stateMutex.RUnlock()
|
249
|
|
-
|
|
244
|
+func channelUserModeIsAtLeast(clientModes *modes.ModeSet, permission modes.Mode) bool {
|
250
|
245
|
if clientModes == nil {
|
251
|
246
|
return false
|
252
|
247
|
}
|
|
@@ -264,6 +259,14 @@ func (channel *Channel) ClientIsAtLeast(client *Client, permission modes.Mode) b
|
264
|
259
|
return false
|
265
|
260
|
}
|
266
|
261
|
|
|
262
|
+// ClientIsAtLeast returns whether the client has at least the given channel privilege.
|
|
263
|
+func (channel *Channel) ClientIsAtLeast(client *Client, permission modes.Mode) bool {
|
|
264
|
+ channel.stateMutex.RLock()
|
|
265
|
+ clientModes := channel.members[client]
|
|
266
|
+ channel.stateMutex.RUnlock()
|
|
267
|
+ return channelUserModeIsAtLeast(clientModes, permission)
|
|
268
|
+}
|
|
269
|
+
|
267
|
270
|
func (channel *Channel) ClientPrefixes(client *Client, isMultiPrefix bool) string {
|
268
|
271
|
channel.stateMutex.RLock()
|
269
|
272
|
defer channel.stateMutex.RUnlock()
|
|
@@ -277,24 +280,26 @@ func (channel *Channel) ClientPrefixes(client *Client, isMultiPrefix bool) strin
|
277
|
280
|
|
278
|
281
|
func (channel *Channel) ClientHasPrivsOver(client *Client, target *Client) bool {
|
279
|
282
|
channel.stateMutex.RLock()
|
280
|
|
- defer channel.stateMutex.RUnlock()
|
281
|
|
-
|
282
|
283
|
clientModes := channel.members[client]
|
283
|
284
|
targetModes := channel.members[target]
|
284
|
|
- result := false
|
285
|
|
- for _, mode := range modes.ChannelPrivModes {
|
286
|
|
- if clientModes.HasMode(mode) {
|
287
|
|
- result = true
|
288
|
|
- // admins cannot kick other admins
|
289
|
|
- if mode == modes.ChannelAdmin && targetModes.HasMode(modes.ChannelAdmin) {
|
290
|
|
- result = false
|
291
|
|
- }
|
292
|
|
- break
|
293
|
|
- } else if targetModes.HasMode(mode) {
|
294
|
|
- break
|
295
|
|
- }
|
|
285
|
+ channel.stateMutex.RUnlock()
|
|
286
|
+
|
|
287
|
+ if clientModes.HasMode(modes.ChannelFounder) {
|
|
288
|
+ // founder can kick anyone
|
|
289
|
+ return true
|
|
290
|
+ } else if clientModes.HasMode(modes.ChannelAdmin) {
|
|
291
|
+ // admins cannot kick other admins
|
|
292
|
+ return !channelUserModeIsAtLeast(targetModes, modes.ChannelAdmin)
|
|
293
|
+ } else if clientModes.HasMode(modes.ChannelOperator) {
|
|
294
|
+ // operators *can* kick other operators
|
|
295
|
+ return !channelUserModeIsAtLeast(targetModes, modes.ChannelAdmin)
|
|
296
|
+ } else if clientModes.HasMode(modes.Halfop) {
|
|
297
|
+ // halfops cannot kick other halfops
|
|
298
|
+ return !channelUserModeIsAtLeast(targetModes, modes.Halfop)
|
|
299
|
+ } else {
|
|
300
|
+ // voice and unprivileged cannot kick anyone
|
|
301
|
+ return false
|
296
|
302
|
}
|
297
|
|
- return result
|
298
|
303
|
}
|
299
|
304
|
|
300
|
305
|
func (channel *Channel) hasClient(client *Client) bool {
|
|
@@ -952,10 +957,6 @@ func (channel *Channel) Kick(client *Client, target *Client, comment string, rb
|
952
|
957
|
rb.Add(nil, client.server.name, ERR_NOTONCHANNEL, channel.name, client.t("You're not on that channel"))
|
953
|
958
|
return
|
954
|
959
|
}
|
955
|
|
- if !channel.ClientIsAtLeast(client, modes.ChannelOperator) {
|
956
|
|
- rb.Add(nil, client.server.name, ERR_CANNOTSENDTOCHAN, channel.name, client.t("Cannot send to channel"))
|
957
|
|
- return
|
958
|
|
- }
|
959
|
960
|
if !channel.hasClient(target) {
|
960
|
961
|
rb.Add(nil, client.server.name, ERR_USERNOTINCHANNEL, client.nick, channel.name, client.t("They aren't on that channel"))
|
961
|
962
|
return
|