From 44bfca80a7fb9b8e1758514cbf2748729465fefb Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Tue, 19 Jan 2021 12:19:48 -0500 Subject: [PATCH] add IP addresses to UBAN ADD output --- irc/uban.go | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/irc/uban.go b/irc/uban.go index 7b574e50..2e9be18d 100644 --- a/irc/uban.go +++ b/irc/uban.go @@ -152,16 +152,8 @@ func ubanAddHandler(client *Client, target ubanTarget, params []string, rb *Resp case ubanNickmask: ubanAddNickmask(client, target, duration, operReason, rb) case ubanNick: - account := target.nickOrMask - err := client.server.accounts.Suspend(account, duration, client.Oper().Name, "UBAN") - switch err { - case nil: - rb.Notice(fmt.Sprintf(client.t("Successfully suspended account %s"), account)) - case errAccountDoesNotExist: - rb.Notice(client.t("No such account")) - default: - rb.Notice(client.t("An error occurred")) - } + ubanAddAccount(client, target, duration, operReason, rb) + } return false } @@ -227,6 +219,31 @@ func ubanAddNickmask(client *Client, target ubanTarget, duration time.Duration, } } +func ubanAddAccount(client *Client, target ubanTarget, duration time.Duration, operReason string, rb *ResponseBuffer) { + account := target.nickOrMask + // TODO this doesn't enumerate all sessions if ForceNickEqualsAccount is disabled + var sessionData []SessionData + if mcl := client.server.clients.Get(account); mcl != nil { + sessionData, _ = mcl.AllSessionData(nil, true) + } + + err := client.server.accounts.Suspend(account, duration, client.Oper().Name, operReason) + switch err { + case nil: + rb.Notice(fmt.Sprintf(client.t("Successfully suspended account %s"), account)) + if len(sessionData) != 0 { + rb.Notice(fmt.Sprintf(client.t("Disconnected %d client(s) associated with the account, using the following IPs:"), len(sessionData))) + for i, d := range sessionData { + rb.Notice(fmt.Sprintf("%d. %s", i+1, d.ip.String())) + } + } + case errAccountDoesNotExist: + rb.Notice(client.t("No such account")) + default: + rb.Notice(client.t("An error occurred")) + } +} + func ubanDelHandler(client *Client, target ubanTarget, params []string, rb *ResponseBuffer) bool { var err error var targetString string