From eb2dfa78c9388d2d55611d348a551b5d172d14aa Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Sun, 18 Apr 2021 20:18:02 -0400 Subject: [PATCH] fix #1617 Prevent LUSERS stats from getting out of sync when modes are modified on offline clients. --- irc/modes.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/irc/modes.go b/irc/modes.go index 9d95966f..c4c4beb7 100644 --- a/irc/modes.go +++ b/irc/modes.go @@ -32,6 +32,9 @@ var ( // to confirm that the client actually has a valid operclass) func ApplyUserModeChanges(client *Client, changes modes.ModeChanges, force bool, oper *Oper) modes.ModeChanges { applied := make(modes.ModeChanges, 0) + // #1617: if the user is offline, they are not counted in LUSERS, + // so don't modify the LUSERS stats for +i or +o. + present := len(client.Sessions()) != 0 for _, change := range changes { if change.Mode != modes.ServerNotice { @@ -42,9 +45,9 @@ func ApplyUserModeChanges(client *Client, changes modes.ModeChanges, force bool, } if client.SetMode(change.Mode, true) { - if change.Mode == modes.Invisible { + if change.Mode == modes.Invisible && present { client.server.stats.ChangeInvisible(1) - } else if change.Mode == modes.Operator { + } else if change.Mode == modes.Operator && present { client.server.stats.ChangeOperators(1) } applied = append(applied, change) @@ -53,11 +56,13 @@ func ApplyUserModeChanges(client *Client, changes modes.ModeChanges, force bool, case modes.Remove: var removedSnomasks string if client.SetMode(change.Mode, false) { - if change.Mode == modes.Invisible { + if change.Mode == modes.Invisible && present { client.server.stats.ChangeInvisible(-1) } else if change.Mode == modes.Operator { removedSnomasks = client.server.snomasks.String(client) - client.server.stats.ChangeOperators(-1) + if present { + client.server.stats.ChangeOperators(-1) + } applyOper(client, nil, nil) if removedSnomasks != "" { client.server.snomasks.RemoveClient(client)