diff options
author | peavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-11-13 00:45:37 +0000 |
---|---|---|
committer | peavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-11-13 00:45:37 +0000 |
commit | 41f62a2a3badd6b7dbffb4fdb995c41ef709462c (patch) | |
tree | b87fbf24939d47fe28a066716e0a61682f2d8f87 /src | |
parent | f09dc35b5b03eb19e70333fbb8e5fe6f92c7edee (diff) |
add <whowas> config option to control whowas behaviour. *may break*
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5731 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/configreader.cpp | 27 | ||||
-rw-r--r-- | src/users.cpp | 55 |
2 files changed, 79 insertions, 3 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp index 1b38e7155..ea5d09db9 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -41,6 +41,9 @@ ServerConfig::ServerConfig(InspIRCd* Instance) : ServerInstance(Instance) debugging = 0; LogLevel = DEFAULT; maxbans.clear(); + WhoWasGroupSize = 10; + WhoWasMaxGroups = WhoWasGroupSize * MAXCLIENTS; + WhoWasMaxKeep = 3600*24*3; // 3 days } void ServerConfig::ClearStack() @@ -319,6 +322,24 @@ bool ValidateRules(ServerConfig* conf, const char* tag, const char* value, void* return true; } +bool ValidateWhoWas(ServerConfig* conf, const char* tag, const char* value, void* data) +{ + const char* max = (const char*)data; + conf->WhoWasMaxKeep = conf->GetInstance()->Duration(max); + + if (conf->WhoWasGroupSize < 0) + conf->WhoWasGroupSize = 0; + + if (conf->WhoWasMaxGroups < 0) + conf->WhoWasMaxGroups = 0; + + if (conf->WhoWasMaxKeep < 3600) + conf->WhoWasMaxKeep = 3600; + + irc::whowas::PruneWhoWas(conf->GetInstance(), conf->GetInstance()->Time()); + return true; +} + /* Callback called before processing the first <connect> tag */ bool InitConnect(ServerConfig* conf, const char* tag) @@ -511,6 +532,7 @@ bool DoneMaxBans(ServerConfig* conf, const char* tag) void ServerConfig::Read(bool bail, userrec* user) { char debug[MAXBUF]; /* Temporary buffer for debugging value */ + char maxkeep[MAXBUF]; /* Temporary buffer for WhoWasMaxKeep value */ char* data[12]; /* Temporary buffers for reading multiple occurance tags into */ void* ptr[12]; /* Temporary pointers for passing to callbacks */ int r_i[12]; /* Temporary array for casting */ @@ -545,7 +567,7 @@ void ServerConfig::Read(bool bail, userrec* user) {"dns", "timeout", &this->dns_timeout, DT_INTEGER, ValidateDnsTimeout}, {"options", "moduledir", &this->ModPath, DT_CHARPTR, ValidateModPath}, {"disabled", "commands", &this->DisabledCommands, DT_CHARPTR, NoValidation}, - {"options", "userstats", &this->UserStats, DT_CHARPTR, NoValidation}, + {"options", "userstats", &this->UserStats, DT_CHARPTR, NoValidation}, {"options", "customversion", &this->CustomVersion, DT_CHARPTR, NoValidation}, {"options", "hidesplits", &this->HideSplits, DT_BOOLEAN, NoValidation}, {"options", "hidebans", &this->HideBans, DT_BOOLEAN, NoValidation}, @@ -556,6 +578,9 @@ void ServerConfig::Read(bool bail, userrec* user) {"options", "syntaxhints", &this->SyntaxHints, DT_BOOLEAN, NoValidation}, {"options", "cyclehosts", &this->CycleHosts, DT_BOOLEAN, NoValidation}, {"pid", "file", &this->PID, DT_CHARPTR, NoValidation}, + {"whowas", "groupsize", &this->WhoWasGroupSize, DT_INTEGER, NoValidation}, + {"whowas", "maxgroups", &this->WhoWasMaxGroups, DT_INTEGER, NoValidation}, + {"whowas", "maxkeep", &maxkeep, DT_CHARPTR, ValidateWhoWas}, {NULL} }; diff --git a/src/users.cpp b/src/users.cpp index 5d6ac2ce7..f3278186b 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -869,7 +869,7 @@ namespace irc whowas_set* n = (whowas_set*)iter->second; if (n->size()) { - while ((n->begin() != n->end()) && ((*n->begin())->signon < t - 259200)) // 3 days + while ((n->begin() != n->end()) && ((*n->begin())->signon < t - ServerInstance->Config->WhoWasMaxKeep)) { WhoWasGroup *a = *(n->begin()); DELETE(a); @@ -878,6 +878,51 @@ namespace irc } } } + /* on rehash, refactor maps according to new conf values */ + void PruneWhoWas(InspIRCd* ServerInstance, time_t t) + { + int groupsize = ServerInstance->Config->WhoWasGroupSize; + int maxgroups = ServerInstance->Config->WhoWasMaxGroups; + int maxkeep = ServerInstance->Config->WhoWasMaxKeep; + + int groupcount = 0; + for (whowas_users_fifo::iterator iter = ServerInstance->whowas_fifo.begin(); iter != ServerInstance->whowas_fifo.end(); iter++) + { + groupcount++; + + if (groupcount > maxgroups || iter->first < t - maxkeep) + { + whowas_set* n = (whowas_set*)ServerInstance->whowas.find(iter->second)->second; + if (n->size()) + { + while (n->begin() != n->end()) + { + WhoWasGroup *a = *(n->begin()); + DELETE(a); + n->erase(n->begin()); + } + } + ServerInstance->whowas.erase(iter->second); + ServerInstance->whowas_fifo.erase(iter->first); + } + else { + whowas_set* n = (whowas_set*)ServerInstance->whowas.find(iter->second)->second; + if (n->size()) + { + int nickcount = 0; + while (n->begin() != n->end()) + { + nickcount++; + if (nickcount > groupsize){ + WhoWasGroup *a = *(n->begin()); + DELETE(a); + n->erase(n->begin()); + } + } + } + } + } + } }; }; @@ -895,6 +940,12 @@ void userrec::AddToWhoWas() irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this); n->push_back(a); ServerInstance->whowas[this->nick] = n; + ServerInstance->whowas_fifo[ServerInstance->Time()] = this->nick; + if ((int)(ServerInstance->whowas.size()) > ServerInstance->Config->WhoWasMaxGroups) + { + ServerInstance->whowas.erase(ServerInstance->whowas_fifo.begin()->second); + ServerInstance->whowas_fifo.erase(ServerInstance->whowas_fifo.begin()); + } } else { @@ -902,7 +953,7 @@ void userrec::AddToWhoWas() ServerInstance->Log(DEBUG,"Using existing whowas group for %s",this->nick); - if (group->size() > 10) + if ((int)(group->size()) > ServerInstance->Config->WhoWasMaxGroups) { ServerInstance->Log(DEBUG,"Trimming existing group to ten entries for %s",this->nick); irc::whowas::WhoWasGroup *a = (irc::whowas::WhoWasGroup*)*(group->begin()); |