From d50c4c2bd60bad0f9b25527a85d2a6433d1d67c7 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Fri, 6 Mar 2020 04:21:21 -0500 Subject: [PATCH] fix #848 --- irc/client.go | 10 ++++++---- irc/client_lookup_set.go | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/irc/client.go b/irc/client.go index 58be9196..9f5e1092 100644 --- a/irc/client.go +++ b/irc/client.go @@ -1185,9 +1185,11 @@ func (client *Client) destroy(session *Session) { // should we destroy the whole client this time? // BRB is not respected if this is a destroy of the whole client (i.e., session == nil) - brbEligible := session != nil && (brbState == BrbEnabled || alwaysOn) - alreadyDestroyed := client.destroyed - shouldDestroy := !alreadyDestroyed && remainingSessions == 0 && !brbEligible + brbEligible := session != nil && brbState == BrbEnabled + shouldDestroy := !client.destroyed && remainingSessions == 0 && !brbEligible && !alwaysOn + // decrement stats on a true destroy, or for the removal of the last connected session + // of an always-on client + shouldDecrement := shouldDestroy || (alwaysOn && len(sessionsToDestroy) != 0 && len(client.sessions) == 0) if shouldDestroy { // if it's our job to destroy it, don't let anyone else try client.destroyed = true @@ -1237,7 +1239,7 @@ func (client *Client) destroy(session *Session) { } // decrement stats if we have no more sessions, even if the client will not be destroyed - if shouldDestroy || (!alreadyDestroyed && remainingSessions == 0) { + if shouldDecrement { invisible := client.HasMode(modes.Invisible) operator := client.HasMode(modes.LocalOperator) || client.HasMode(modes.Operator) client.server.stats.Remove(registered, invisible, operator) diff --git a/irc/client_lookup_set.go b/irc/client_lookup_set.go index 799d4b05..6e0986d3 100644 --- a/irc/client_lookup_set.go +++ b/irc/client_lookup_set.go @@ -179,8 +179,8 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick return "", errNicknameInUse } if numSessions == 1 { - invisible := client.HasMode(modes.Invisible) - operator := client.HasMode(modes.Operator) || client.HasMode(modes.LocalOperator) + invisible := currentClient.HasMode(modes.Invisible) + operator := currentClient.HasMode(modes.Operator) || currentClient.HasMode(modes.LocalOperator) client.server.stats.AddRegistered(invisible, operator) } session.autoreplayMissedSince = lastSeen