return true;
}
-bool DoType(ServerConfig* conf, const char* tag, char** entries, void** values, int* types)
+bool DoType(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
{
- char* TypeName = (char*)values[0];
- char* Classes = (char*)values[1];
+ const char* TypeName = values[0].GetString();
+ const char* Classes = values[1].GetString();
conf->opertypes[TypeName] = strdup(Classes);
conf->GetInstance()->Log(DEBUG,"Read oper TYPE '%s' with classes '%s'",TypeName,Classes);
return true;
}
-bool DoClass(ServerConfig* conf, const char* tag, char** entries, void** values, int* types)
+bool DoClass(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types)
{
- char* ClassName = (char*)values[0];
- char* CommandList = (char*)values[1];
+ const char* ClassName = values[0].GetString();
+ const char* CommandList = values[1].GetString();
conf->operclass[ClassName] = strdup(CommandList);
conf->GetInstance()->Log(DEBUG,"Read oper CLASS '%s' with commands '%s'",ClassName,CommandList);
free(gecos);
}
- /* every hour, run this function which removes all entries over 3 days */
+ /* every hour, run this function which removes all entries older than Config->WhoWasMaxKeep */
void MaintainWhoWas(InspIRCd* ServerInstance, time_t t)
{
for (whowas_users::iterator iter = ServerInstance->whowas.begin(); iter != ServerInstance->whowas.end(); iter++)
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);
}
}
}
+ /* on rehash, refactor maps according to new conf values */
+ void PruneWhoWas(InspIRCd* ServerInstance, time_t t)
+ {
+ /* config values */
+ int groupsize = ServerInstance->Config->WhoWasGroupSize;
+ int maxgroups = ServerInstance->Config->WhoWasMaxGroups;
+ int maxkeep = ServerInstance->Config->WhoWasMaxKeep;
+
+ int groupcount = ServerInstance->whowas.size();
+ /* iterate whowas_fifo oldest first */
+ whowas_users_fifo::iterator iter, safeiter;
+ for (iter = ServerInstance->whowas_fifo.begin(); iter != ServerInstance->whowas_fifo.end(); iter++)
+ {
+ /** prune all groups that has expired due to new maxkeep time and
+ * also any group number higher than new maxgroups. The oldest are
+ * removed first due to iteration over whowas_fifo
+ */
+ 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);
+ /* use a safe iter copy for erase and set the orig iter old valid ref by decrementing it */
+ safeiter = iter;
+ --iter;
+ ServerInstance->whowas_fifo.erase(safeiter);
+ }
+ else {
+ /* also trim individual groupsizes in case groupsize should have been lowered */
+ whowas_set* n = (whowas_set*)ServerInstance->whowas.find(iter->second)->second;
+ if (n->size())
+ {
+ int nickcount = n->size();
+ while (n->begin() != n->end() && nickcount > groupsize)
+ {
+ WhoWasGroup *a = *(n->begin());
+ DELETE(a);
+ n->erase(n->begin());
+ nickcount--;
+ }
+ }
+ }
+ groupcount--;
+ }
+ }
};
};
/* adds or updates an entry in the whowas list */
void userrec::AddToWhoWas()
{
+ /* if whowas disabled */
+ if (ServerInstance->Config->WhoWasGroupSize == 0 || ServerInstance->Config->WhoWasMaxGroups == 0)
+ {
+ return;
+ }
+
irc::whowas::whowas_users::iterator iter = ServerInstance->whowas.find(this->nick);
ServerInstance->Log(DEBUG,"Add to whowas lists");
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->Log(DEBUG,"Maxgroups of %d reached deleting oldest group '%s'",ServerInstance->Config->WhoWasMaxGroups, ServerInstance->whowas_fifo.begin()->second.c_str());
+ ServerInstance->whowas.erase(ServerInstance->whowas_fifo.begin()->second);
+ ServerInstance->whowas_fifo.erase(ServerInstance->whowas_fifo.begin());
+ }
}
else
{
ServerInstance->Log(DEBUG,"Using existing whowas group for %s",this->nick);
- if (group->size() > 10)
+ if ((int)(group->size()) >= ServerInstance->Config->WhoWasGroupSize)
{
- ServerInstance->Log(DEBUG,"Trimming existing group to ten entries for %s",this->nick);
+ ServerInstance->Log(DEBUG,"Trimming existing group '%s' to %d entries",this->nick, ServerInstance->Config->WhoWasGroupSize);
irc::whowas::WhoWasGroup *a = (irc::whowas::WhoWasGroup*)*(group->begin());
DELETE(a);
group->pop_front();
if (line.length() + namelen + length - start > 510)
{
- this->Write(line);
+ ServerInstance->SendWhoisLine(this, dest, 319, "%s", line.c_str());
line = prefix.str();
}