Browse Source

Add 'k' snomask for kills (including those coming from dlines and klines)

tags/v0.8.1
Daniel Oaks 7 years ago
parent
commit
309ec8191e
4 changed files with 28 additions and 1 deletions
  1. 4
    1
      irc/client.go
  2. 10
    0
      irc/dline.go
  3. 10
    0
      irc/kline.go
  4. 4
    0
      irc/server.go

+ 4
- 1
irc/client.go View File

@@ -47,6 +47,7 @@ type Client struct {
47 47
 	class              *OperClass
48 48
 	ctime              time.Time
49 49
 	destroyMutex       sync.Mutex
50
+	exitedSnomaskSent  bool
50 51
 	flags              map[Mode]bool
51 52
 	hasQuit            bool
52 53
 	hops               int
@@ -530,7 +531,9 @@ func (client *Client) destroy() {
530 531
 		//TODO(dan): store quit message in user, if exists use that instead here
531 532
 		friend.Send(nil, client.nickMaskString, "QUIT", "Exited")
532 533
 	}
533
-	client.server.snomasks.Send(sno.LocalQuits, fmt.Sprintf(ircfmt.Unescape("%s$r quit"), client.nick))
534
+	if !client.exitedSnomaskSent {
535
+		client.server.snomasks.Send(sno.LocalQuits, fmt.Sprintf(ircfmt.Unescape("%s$r exited the network"), client.nick))
536
+	}
534 537
 }
535 538
 
536 539
 // SendSplitMsgFromClient sends an IRC PRIVMSG/NOTICE coming from a specific client.

+ 10
- 0
irc/dline.go View File

@@ -7,14 +7,17 @@ import (
7 7
 	"errors"
8 8
 	"fmt"
9 9
 	"net"
10
+	"sort"
10 11
 	"time"
11 12
 
12 13
 	"strings"
13 14
 
14 15
 	"encoding/json"
15 16
 
17
+	"github.com/DanielOaks/girc-go/ircfmt"
16 18
 	"github.com/DanielOaks/girc-go/ircmsg"
17 19
 	"github.com/DanielOaks/oragono/irc/custime"
20
+	"github.com/DanielOaks/oragono/irc/sno"
18 21
 	"github.com/tidwall/buntdb"
19 22
 )
20 23
 
@@ -325,6 +328,7 @@ func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
325 328
 	var killClient bool
326 329
 	if andKill {
327 330
 		var clientsToKill []*Client
331
+		var killedClientNicks []string
328 332
 		var toKill bool
329 333
 
330 334
 		server.clients.ByNickMutex.RLock()
@@ -337,11 +341,13 @@ func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
337 341
 
338 342
 			if toKill {
339 343
 				clientsToKill = append(clientsToKill, mcl)
344
+				killedClientNicks = append(killedClientNicks, mcl.nick)
340 345
 			}
341 346
 		}
342 347
 		server.clients.ByNickMutex.RUnlock()
343 348
 
344 349
 		for _, mcl := range clientsToKill {
350
+			mcl.exitedSnomaskSent = true
345 351
 			mcl.Quit(fmt.Sprintf("You have been banned from this server (%s)", reason))
346 352
 			if mcl == client {
347 353
 				killClient = true
@@ -350,6 +356,10 @@ func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
350 356
 				mcl.destroy()
351 357
 			}
352 358
 		}
359
+
360
+		// send snomask
361
+		sort.Strings(killedClientNicks)
362
+		server.snomasks.Send(sno.LocalKills, fmt.Sprintf(ircfmt.Unescape("%s killed %d clients with a DLINE $c[grey][$r%s$c[grey]]"), client.nick, len(killedClientNicks), strings.Join(killedClientNicks, ", ")))
353 363
 	}
354 364
 
355 365
 	return killClient

+ 10
- 0
irc/kline.go View File

@@ -6,12 +6,15 @@ package irc
6 6
 import (
7 7
 	"encoding/json"
8 8
 	"fmt"
9
+	"sort"
9 10
 	"strings"
10 11
 	"time"
11 12
 
13
+	"github.com/DanielOaks/girc-go/ircfmt"
12 14
 	"github.com/DanielOaks/girc-go/ircmatch"
13 15
 	"github.com/DanielOaks/girc-go/ircmsg"
14 16
 	"github.com/DanielOaks/oragono/irc/custime"
17
+	"github.com/DanielOaks/oragono/irc/sno"
15 18
 	"github.com/tidwall/buntdb"
16 19
 )
17 20
 
@@ -236,18 +239,21 @@ func klineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
236 239
 	var killClient bool
237 240
 	if andKill {
238 241
 		var clientsToKill []*Client
242
+		var killedClientNicks []string
239 243
 
240 244
 		server.clients.ByNickMutex.RLock()
241 245
 		for _, mcl := range server.clients.ByNick {
242 246
 			for _, clientMask := range mcl.AllNickmasks() {
243 247
 				if matcher.Match(clientMask) {
244 248
 					clientsToKill = append(clientsToKill, mcl)
249
+					killedClientNicks = append(killedClientNicks, mcl.nick)
245 250
 				}
246 251
 			}
247 252
 		}
248 253
 		server.clients.ByNickMutex.RUnlock()
249 254
 
250 255
 		for _, mcl := range clientsToKill {
256
+			mcl.exitedSnomaskSent = true
251 257
 			mcl.Quit(fmt.Sprintf("You have been banned from this server (%s)", reason))
252 258
 			if mcl == client {
253 259
 				killClient = true
@@ -256,6 +262,10 @@ func klineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
256 262
 				mcl.destroy()
257 263
 			}
258 264
 		}
265
+
266
+		// send snomask
267
+		sort.Strings(killedClientNicks)
268
+		server.snomasks.Send(sno.LocalKills, fmt.Sprintf(ircfmt.Unescape("%s killed %d clients with a KLINE $c[grey][$r%s$c[grey]]"), client.nick, len(killedClientNicks), strings.Join(killedClientNicks, ", ")))
259 269
 	}
260 270
 
261 271
 	return killClient

+ 4
- 0
irc/server.go View File

@@ -2121,6 +2121,10 @@ func killHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
2121 2121
 	}
2122 2122
 
2123 2123
 	quitMsg := fmt.Sprintf("Killed (%s (%s))", client.nick, comment)
2124
+
2125
+	server.snomasks.Send(sno.LocalKills, fmt.Sprintf(ircfmt.Unescape("%s$r was killed by %s $c[grey][$r%s$c[grey]]"), target.nick, client.nick, comment))
2126
+	target.exitedSnomaskSent = true
2127
+
2124 2128
 	target.Quit(quitMsg)
2125 2129
 	target.destroy()
2126 2130
 	return false

Loading…
Cancel
Save