From e6ff406b062ce5a16f5a8285ce2dd952b7aa3286 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 27 Aug 2024 18:16:26 +0100 Subject: Fix the whowas database not being updated on nick change. --- src/coremods/core_whowas.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/coremods/core_whowas.cpp b/src/coremods/core_whowas.cpp index 8acdff084..cd671db7c 100644 --- a/src/coremods/core_whowas.cpp +++ b/src/coremods/core_whowas.cpp @@ -112,7 +112,7 @@ namespace WhoWas /** Add a user to the whowas database. Called when a user quits. * @param user The user to add to the database */ - void Add(User* user); + void Add(User* user, const std::string& nickname); /** Retrieves statistics about the whowas database * @return Whowas statistics as a WhoWas::Manager::Stats struct @@ -269,14 +269,14 @@ WhoWas::Manager::Stats WhoWas::Manager::GetStats() const return stats; } -void WhoWas::Manager::Add(User* user) +void WhoWas::Manager::Add(User* user, const std::string& nickname) { if (!IsEnabled()) return; // Insert nick if it doesn't exist // 'first' will point to the newly inserted element or to the existing element with an equivalent key - std::pair ret = whowas.emplace(user->nick, nullptr); + std::pair ret = whowas.emplace(nickname, nullptr); if (ret.second) // If inserted { @@ -429,7 +429,9 @@ class ModuleWhoWas final : public Module , public Stats::EventListener { +public: CommandWhowas cmd; + bool nickupdate; public: ModuleWhoWas() @@ -447,7 +449,13 @@ public: void OnUserQuit(User* user, const std::string& message, const std::string& oper_message) override { - cmd.manager.Add(user); + cmd.manager.Add(user, user->nick); + } + + void OnUserPostNick(User* user, const std::string& oldnick) override + { + if (nickupdate) + cmd.manager.Add(user, oldnick); } ModResult OnStats(Stats::Context& stats) override @@ -464,6 +472,7 @@ public: unsigned int NewGroupSize = tag->getNum("groupsize", 10, 0, 10000); unsigned int NewMaxGroups = tag->getNum("maxgroups", 10240, 0, 1000000); unsigned int NewMaxKeep = static_cast(tag->getDuration("maxkeep", 3600, 3600)); + nickupdate = tag->getBool("nickupdate"); cmd.manager.UpdateConfig(NewGroupSize, NewMaxGroups, NewMaxKeep); } -- cgit v1.3.1-10-gc9f91