From 309ec8191ecc43ca17d7e04f3a088e8ca6466b96 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sun, 11 Jun 2017 10:01:39 -0600 Subject: [PATCH] Add 'k' snomask for kills (including those coming from dlines and klines) --- irc/client.go | 5 ++++- irc/dline.go | 10 ++++++++++ irc/kline.go | 10 ++++++++++ irc/server.go | 4 ++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/irc/client.go b/irc/client.go index c4b6461e..1d685f47 100644 --- a/irc/client.go +++ b/irc/client.go @@ -47,6 +47,7 @@ type Client struct { class *OperClass ctime time.Time destroyMutex sync.Mutex + exitedSnomaskSent bool flags map[Mode]bool hasQuit bool hops int @@ -530,7 +531,9 @@ func (client *Client) destroy() { //TODO(dan): store quit message in user, if exists use that instead here friend.Send(nil, client.nickMaskString, "QUIT", "Exited") } - client.server.snomasks.Send(sno.LocalQuits, fmt.Sprintf(ircfmt.Unescape("%s$r quit"), client.nick)) + if !client.exitedSnomaskSent { + client.server.snomasks.Send(sno.LocalQuits, fmt.Sprintf(ircfmt.Unescape("%s$r exited the network"), client.nick)) + } } // SendSplitMsgFromClient sends an IRC PRIVMSG/NOTICE coming from a specific client. diff --git a/irc/dline.go b/irc/dline.go index 13e72793..3ce085da 100644 --- a/irc/dline.go +++ b/irc/dline.go @@ -7,14 +7,17 @@ import ( "errors" "fmt" "net" + "sort" "time" "strings" "encoding/json" + "github.com/DanielOaks/girc-go/ircfmt" "github.com/DanielOaks/girc-go/ircmsg" "github.com/DanielOaks/oragono/irc/custime" + "github.com/DanielOaks/oragono/irc/sno" "github.com/tidwall/buntdb" ) @@ -325,6 +328,7 @@ func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { var killClient bool if andKill { var clientsToKill []*Client + var killedClientNicks []string var toKill bool server.clients.ByNickMutex.RLock() @@ -337,11 +341,13 @@ func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { if toKill { clientsToKill = append(clientsToKill, mcl) + killedClientNicks = append(killedClientNicks, mcl.nick) } } server.clients.ByNickMutex.RUnlock() for _, mcl := range clientsToKill { + mcl.exitedSnomaskSent = true mcl.Quit(fmt.Sprintf("You have been banned from this server (%s)", reason)) if mcl == client { killClient = true @@ -350,6 +356,10 @@ func dlineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { mcl.destroy() } } + + // send snomask + sort.Strings(killedClientNicks) + 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, ", "))) } return killClient diff --git a/irc/kline.go b/irc/kline.go index c3e5f2c1..1ff4d5c2 100644 --- a/irc/kline.go +++ b/irc/kline.go @@ -6,12 +6,15 @@ package irc import ( "encoding/json" "fmt" + "sort" "strings" "time" + "github.com/DanielOaks/girc-go/ircfmt" "github.com/DanielOaks/girc-go/ircmatch" "github.com/DanielOaks/girc-go/ircmsg" "github.com/DanielOaks/oragono/irc/custime" + "github.com/DanielOaks/oragono/irc/sno" "github.com/tidwall/buntdb" ) @@ -236,18 +239,21 @@ func klineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { var killClient bool if andKill { var clientsToKill []*Client + var killedClientNicks []string server.clients.ByNickMutex.RLock() for _, mcl := range server.clients.ByNick { for _, clientMask := range mcl.AllNickmasks() { if matcher.Match(clientMask) { clientsToKill = append(clientsToKill, mcl) + killedClientNicks = append(killedClientNicks, mcl.nick) } } } server.clients.ByNickMutex.RUnlock() for _, mcl := range clientsToKill { + mcl.exitedSnomaskSent = true mcl.Quit(fmt.Sprintf("You have been banned from this server (%s)", reason)) if mcl == client { killClient = true @@ -256,6 +262,10 @@ func klineHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { mcl.destroy() } } + + // send snomask + sort.Strings(killedClientNicks) + 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, ", "))) } return killClient diff --git a/irc/server.go b/irc/server.go index fc825b43..7f5ad912 100644 --- a/irc/server.go +++ b/irc/server.go @@ -2121,6 +2121,10 @@ func killHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { } quitMsg := fmt.Sprintf("Killed (%s (%s))", client.nick, comment) + + 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)) + target.exitedSnomaskSent = true + target.Quit(quitMsg) target.destroy() return false