Fix the whowas database not being updated on nick change.

This commit is contained in:
Sadie Powell 2024-08-27 18:16:26 +01:00
parent f4b650b4a9
commit e6ff406b06
2 changed files with 19 additions and 6 deletions

View File

@ -938,7 +938,6 @@
# This tag lets you define the behaviour of the /WHOWAS command of # # This tag lets you define the behaviour of the /WHOWAS command of #
# your server. # # your server. #
# # # #
<whowas <whowas
# groupsize: Maximum entries per nick shown when performing # groupsize: Maximum entries per nick shown when performing
# a /WHOWAS <nick>. # a /WHOWAS <nick>.
@ -953,7 +952,12 @@
# before being pruned. Time may be specified in seconds, # before being pruned. Time may be specified in seconds,
# or in the following format: 1y2w3d4h5m6s. Minimum is # or in the following format: 1y2w3d4h5m6s. Minimum is
# 1 hour. # 1 hour.
maxkeep="3d"> maxkeep="3d"
# nickupdate: Whether to update the WHOWAS database on nick
# change as well as quit. This can significantly increase the
# memory usage of your IRC server.
nickupdate="no">
#-#-#-#-#-#-#-#-#-#-#-#-#-#- BAN OPTIONS -#-#-#-#-#-#-#-#-#-#-#-#-#-# #-#-#-#-#-#-#-#-#-#-#-#-#-#- BAN OPTIONS -#-#-#-#-#-#-#-#-#-#-#-#-#-#
# # # #

View File

@ -112,7 +112,7 @@ namespace WhoWas
/** Add a user to the whowas database. Called when a user quits. /** Add a user to the whowas database. Called when a user quits.
* @param user The user to add to the database * @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 /** Retrieves statistics about the whowas database
* @return Whowas statistics as a WhoWas::Manager::Stats struct * @return Whowas statistics as a WhoWas::Manager::Stats struct
@ -269,14 +269,14 @@ WhoWas::Manager::Stats WhoWas::Manager::GetStats() const
return stats; return stats;
} }
void WhoWas::Manager::Add(User* user) void WhoWas::Manager::Add(User* user, const std::string& nickname)
{ {
if (!IsEnabled()) if (!IsEnabled())
return; return;
// Insert nick if it doesn't exist // Insert nick if it doesn't exist
// 'first' will point to the newly inserted element or to the existing element with an equivalent key // 'first' will point to the newly inserted element or to the existing element with an equivalent key
std::pair<whowas_users::iterator, bool> ret = whowas.emplace(user->nick, nullptr); std::pair<whowas_users::iterator, bool> ret = whowas.emplace(nickname, nullptr);
if (ret.second) // If inserted if (ret.second) // If inserted
{ {
@ -429,7 +429,9 @@ class ModuleWhoWas final
: public Module : public Module
, public Stats::EventListener , public Stats::EventListener
{ {
public:
CommandWhowas cmd; CommandWhowas cmd;
bool nickupdate;
public: public:
ModuleWhoWas() ModuleWhoWas()
@ -447,7 +449,13 @@ public:
void OnUserQuit(User* user, const std::string& message, const std::string& oper_message) override 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 ModResult OnStats(Stats::Context& stats) override
@ -464,6 +472,7 @@ public:
unsigned int NewGroupSize = tag->getNum<unsigned int>("groupsize", 10, 0, 10000); unsigned int NewGroupSize = tag->getNum<unsigned int>("groupsize", 10, 0, 10000);
unsigned int NewMaxGroups = tag->getNum<unsigned int>("maxgroups", 10240, 0, 1000000); unsigned int NewMaxGroups = tag->getNum<unsigned int>("maxgroups", 10240, 0, 1000000);
unsigned int NewMaxKeep = static_cast<unsigned int>(tag->getDuration("maxkeep", 3600, 3600)); unsigned int NewMaxKeep = static_cast<unsigned int>(tag->getDuration("maxkeep", 3600, 3600));
nickupdate = tag->getBool("nickupdate");
cmd.manager.UpdateConfig(NewGroupSize, NewMaxGroups, NewMaxKeep); cmd.manager.UpdateConfig(NewGroupSize, NewMaxGroups, NewMaxKeep);
} }