summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/commands/cmd_whowas.h92
-rw-r--r--include/inspircd.h8
-rw-r--r--include/users.h63
-rw-r--r--src/cmd_stats.cpp21
-rw-r--r--src/cmd_whowas.cpp264
-rw-r--r--src/configreader.cpp10
-rw-r--r--src/inspircd.cpp5
-rw-r--r--src/users.cpp173
8 files changed, 378 insertions, 258 deletions
diff --git a/include/commands/cmd_whowas.h b/include/commands/cmd_whowas.h
index 3dc69bfdc..1181b7ae8 100644
--- a/include/commands/cmd_whowas.h
+++ b/include/commands/cmd_whowas.h
@@ -17,18 +17,106 @@
#ifndef __CMD_WHOWAS_H__
#define __CMD_WHOWAS_H__
+
// include the common header files
#include "users.h"
#include "channels.h"
+class MaintainTimer;
+
+/** InspTimer that is used to maintain the whowas list, called once an hour
+ */
+MaintainTimer* timer;
+
/** Handle /WHOWAS
*/
class cmd_whowas : public command_t
{
+ public:
+ cmd_whowas(InspIRCd* Instance);
+ CmdResult Handle(const char** parameters, int pcnt, userrec *user);
+ CmdResult HandleInternal(const unsigned int id, const std::deque<classbase*> &parameters);
+ void AddToWhoWas(userrec* user);
+ void GetStats(Extensible* ext);
+ void PruneWhoWas(time_t t);
+ virtual ~cmd_whowas();
+};
+
+enum Internals
+{
+ WHOWAS_ADD = 1,
+ WHOWAS_STATS = 2,
+ WHOWAS_PRUNE = 3
+};
+
+
+/** Used to hold WHOWAS information
+ */
+class WhoWasGroup : public classbase
+{
public:
- cmd_whowas (InspIRCd* Instance) : command_t(Instance,"WHOWAS",0,1) { syntax = "<nick>{,<nick>}"; }
- CmdResult Handle(const char** parameters, int pcnt, userrec *user);
+ /** Real host
+ */
+ char* host;
+ /** Displayed host
+ */
+ char* dhost;
+ /** Ident
+ */
+ char* ident;
+ /** Server name
+ */
+ const char* server;
+ /** Fullname (GECOS)
+ */
+ char* gecos;
+ /** Signon time
+ */
+ time_t signon;
+
+ /** Initialize this WhoQasFroup with a user
+ */
+ WhoWasGroup(userrec* user);
+ /** Destructor
+ */
+ ~WhoWasGroup();
+};
+
+class MaintainTimer : public InspTimer
+{
+ private:
+ InspIRCd* ServerInstance;
+ public:
+ MaintainTimer(InspIRCd* Instance, long interval)
+ : InspTimer(interval, Instance->Time()), ServerInstance(Instance)
+ {
+ }
+ virtual void Tick(time_t TIME);
};
+/** A group of users related by nickname
+ */
+typedef std::deque<WhoWasGroup*> whowas_set;
+
+/** Sets of users in the whowas system
+ */
+typedef std::map<irc::string,whowas_set*> whowas_users;
+
+/** Sets of time and users in whowas list
+ */
+typedef std::deque<std::pair<time_t,irc::string> > whowas_users_fifo;
+
+/** Called every hour by the core to remove expired entries
+ */
+void MaintainWhoWas(InspIRCd* ServerInstance, time_t TIME);
+
+/** Whowas container, contains a map of vectors of users tracked by WHOWAS
+ */
+whowas_users whowas;
+
+/** Whowas container, contains a map of time_t to users tracked by WHOWAS
+ */
+whowas_users_fifo whowas_fifo;
+
#endif
diff --git a/include/inspircd.h b/include/inspircd.h
index 1e5104322..3f6b702f1 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -445,14 +445,6 @@ class InspIRCd : public classbase
clonemap global_clones;
- /** Whowas container, contains a map of vectors of users tracked by WHOWAS
- */
- irc::whowas::whowas_users whowas;
-
- /** Whowas container, contains a map of time_t to users tracked by WHOWAS
- */
- irc::whowas::whowas_users_fifo whowas_fifo;
-
/** DNS class, provides resolver facilities to the core and modules
*/
DNS* Res;
diff --git a/include/users.h b/include/users.h
index c34b60693..749030894 100644
--- a/include/users.h
+++ b/include/users.h
@@ -846,69 +846,6 @@ class userrec : public connection
virtual ~userrec();
};
-
-namespace irc
-{
- /** Holds whowas related functions and classes
- */
- namespace whowas
- {
-
- /** Used to hold WHOWAS information
- */
- class WhoWasGroup : public classbase
- {
- public:
- /** Real host
- */
- char* host;
- /** Displayed host
- */
- char* dhost;
- /** Ident
- */
- char* ident;
- /** Server name
- */
- const char* server;
- /** Fullname (GECOS)
- */
- char* gecos;
- /** Signon time
- */
- time_t signon;
-
- /** Initialize this WhoQasFroup with a user
- */
- WhoWasGroup(userrec* user);
- /** Destructor
- */
- ~WhoWasGroup();
- };
-
- /** A group of users related by nickname
- */
- typedef std::deque<WhoWasGroup*> whowas_set;
-
- /** Sets of users in the whowas system
- */
- typedef std::map<irc::string,whowas_set*> whowas_users;
-
- /** Sets of time and users in whowas list
- */
- typedef std::deque<std::pair<time_t,irc::string> > whowas_users_fifo;
-
- /** Called every hour by the core to remove expired entries
- */
- void MaintainWhoWas(InspIRCd* ServerInstance, time_t TIME);
-
- /** Prune for WhoWasGroupSize, WhoWasMaxGroups and
- * WhoWasMaxKeep on rehash
- */
- void PruneWhoWas(InspIRCd* ServerInstance, time_t TIME);
- };
-};
-
/* Configuration callbacks */
class ServerConfig;
diff --git a/src/cmd_stats.cpp b/src/cmd_stats.cpp
index f6f68677c..b6e44e93c 100644
--- a/src/cmd_stats.cpp
+++ b/src/cmd_stats.cpp
@@ -18,7 +18,7 @@
#include "modules.h"
#include "xline.h"
#include "commands/cmd_stats.h"
-
+#include "commands/cmd_whowas.h"
extern "C" command_t* init_command(InspIRCd* Instance)
@@ -174,19 +174,20 @@ void DoStats(InspIRCd* ServerInstance, char statschar, userrec* user, string_lis
if (!ServerInstance->Config->WhoWasGroupSize == 0 && !ServerInstance->Config->WhoWasMaxGroups == 0)
{
- int whowas_size = 0;
- int whowas_bytes = 0;
- irc::whowas::whowas_users_fifo::iterator iter;
- for (iter = ServerInstance->whowas_fifo.begin(); iter != ServerInstance->whowas_fifo.end(); iter++)
+ command_t* whowas_command = ServerInstance->Parser->GetHandler("WHOWAS");
+ if (whowas_command)
{
- irc::whowas::whowas_set* n = (irc::whowas::whowas_set*)ServerInstance->whowas.find(iter->second)->second;
- if (n->size())
+ std::deque<classbase*> params;
+ Extensible whowas_stats;
+ params.push_back(&whowas_stats);
+ whowas_command->HandleInternal(WHOWAS_STATS, params);
+ if (whowas_stats.GetExt("stats"))
{
- whowas_size += n->size();
- whowas_bytes += (sizeof(irc::whowas::whowas_set) + ( sizeof(irc::whowas::WhoWasGroup) * n->size() ) );
+ char* stats;
+ whowas_stats.GetExt("stats", stats);
+ results.push_back(sn+" 249 "+user->nick+" :"+ConvToStr(stats));
}
}
- results.push_back(sn+" 249 "+user->nick+" :Whowas(MAPSETS) "+ConvToStr(whowas_size)+" ("+ConvToStr(whowas_bytes)+" bytes)");
}
results.push_back(sn+" 249 "+user->nick+" :MOTD(VECTOR) "+ConvToStr(ServerInstance->Config->MOTD.size())+", RULES(VECTOR) "+ConvToStr(ServerInstance->Config->RULES.size()));
diff --git a/src/cmd_whowas.cpp b/src/cmd_whowas.cpp
index be3ee0add..ee18b8079 100644
--- a/src/cmd_whowas.cpp
+++ b/src/cmd_whowas.cpp
@@ -20,6 +20,14 @@ extern "C" command_t* init_command(InspIRCd* Instance)
return new cmd_whowas(Instance);
}
+cmd_whowas::cmd_whowas(InspIRCd* Instance)
+: command_t(Instance, "WHOWAS", 0, 1)
+{
+ syntax = "<nick>{,<nick>}";
+ timer = new MaintainTimer(Instance, 3600);
+ Instance->Timers->AddTimer(timer);
+}
+
CmdResult cmd_whowas::Handle (const char** parameters, int pcnt, userrec* user)
{
/* if whowas disabled in config */
@@ -29,11 +37,11 @@ CmdResult cmd_whowas::Handle (const char** parameters, int pcnt, userrec* user)
return CMD_FAILURE;
}
- irc::whowas::whowas_users::iterator i = ServerInstance->whowas.find(parameters[0]);
+ whowas_users::iterator i = whowas.find(parameters[0]);
ServerInstance->Log(DEBUG,"Entered cmd_whowas");
- if (i == ServerInstance->whowas.end())
+ if (i == whowas.end())
{
ServerInstance->Log(DEBUG,"No such nick in whowas");
user->WriteServ("406 %s %s :There was no such nickname",user->nick,parameters[0]);
@@ -43,13 +51,13 @@ CmdResult cmd_whowas::Handle (const char** parameters, int pcnt, userrec* user)
else
{
ServerInstance->Log(DEBUG,"Whowas set found");
- irc::whowas::whowas_set* grp = i->second;
+ whowas_set* grp = i->second;
if (grp->size())
{
- for (irc::whowas::whowas_set::iterator ux = grp->begin(); ux != grp->end(); ux++)
+ for (whowas_set::iterator ux = grp->begin(); ux != grp->end(); ux++)
{
ServerInstance->Log(DEBUG,"Spool whowas entry");
- irc::whowas::WhoWasGroup* u = *ux;
+ WhoWasGroup* u = *ux;
time_t rawtime = u->signon;
tm *timeinfo;
char b[MAXBUF];
@@ -82,4 +90,250 @@ CmdResult cmd_whowas::Handle (const char** parameters, int pcnt, userrec* user)
user->WriteServ("369 %s %s :End of WHOWAS",user->nick,parameters[0]);
return CMD_SUCCESS;
+};
+
+CmdResult cmd_whowas::HandleInternal(const unsigned int id, const std::deque<classbase*> &parameters)
+{
+ switch (id)
+ {
+ case WHOWAS_ADD:
+ AddToWhoWas((userrec*)parameters[0]);
+ break;
+
+ case WHOWAS_STATS:
+ GetStats((Extensible*)parameters[0]);
+ break;
+
+ case WHOWAS_PRUNE:
+ PruneWhoWas(ServerInstance->Time());
+ break;
+
+ default:
+ break;
+ }
+ return CMD_SUCCESS;
+};
+
+void cmd_whowas::GetStats(Extensible* ext)
+{
+ int whowas_size = 0;
+ int whowas_bytes = 0;
+ whowas_users_fifo::iterator iter;
+ for (iter = whowas_fifo.begin(); iter != whowas_fifo.end(); iter++)
+ {
+ whowas_set* n = (whowas_set*)whowas.find(iter->second)->second;
+ if (n->size())
+ {
+ whowas_size += n->size();
+ whowas_bytes += (sizeof(whowas_set) + ( sizeof(WhoWasGroup) * n->size() ) );
+ }
+ }
+ ext->Extend("stats", std::string("Whowas(MAPSETS) " +ConvToStr(whowas_size)+" ("+ConvToStr(whowas_bytes)+" bytes)").c_str());
+}
+
+void cmd_whowas::AddToWhoWas(userrec* user)
+{
+ /* if whowas disabled */
+ if (ServerInstance->Config->WhoWasGroupSize == 0 || ServerInstance->Config->WhoWasMaxGroups == 0)
+ {
+ return;
+ }
+
+ whowas_users::iterator iter = whowas.find(user->nick);
+
+ ServerInstance->Log(DEBUG,"Add to whowas lists");
+
+ if (iter == whowas.end())
+ {
+ ServerInstance->Log(DEBUG,"Adding new whowas set for %s",user->nick);
+
+ whowas_set* n = new whowas_set;
+ WhoWasGroup *a = new WhoWasGroup(user);
+ n->push_back(a);
+ whowas[user->nick] = n;
+ whowas_fifo.push_back(std::make_pair(ServerInstance->Time(),user->nick));
+
+ if ((int)(whowas.size()) > ServerInstance->Config->WhoWasMaxGroups)
+ {
+ ServerInstance->Log(DEBUG,"Maxgroups of %d reached deleting oldest group '%s'",ServerInstance->Config->WhoWasMaxGroups, whowas_fifo[0].second.c_str());
+
+ whowas_users::iterator iter = whowas.find(whowas_fifo[0].second);
+ if (iter != whowas.end())
+ {
+ whowas_set* n = (whowas_set*)iter->second;
+ if (n->size())
+ {
+ while (n->begin() != n->end())
+ {
+ WhoWasGroup *a = *(n->begin());
+ DELETE(a);
+ n->pop_front();
+ }
+ }
+ whowas.erase(iter);
+ }
+ whowas_fifo.pop_front();
+ }
+ }
+ else
+ {
+ whowas_set* group = (whowas_set*)iter->second;
+
+ ServerInstance->Log(DEBUG,"Using existing whowas group for %s",user->nick);
+
+ WhoWasGroup *a = new WhoWasGroup(user);
+ group->push_back(a);
+
+ if ((int)(group->size()) > ServerInstance->Config->WhoWasGroupSize)
+ {
+ ServerInstance->Log(DEBUG,"Trimming existing group '%s' to %d entries",user->nick, ServerInstance->Config->WhoWasGroupSize);
+ WhoWasGroup *a = (WhoWasGroup*)*(group->begin());
+ DELETE(a);
+ group->pop_front();
+ }
+ }
+}
+
+/* on rehash, refactor maps according to new conf values */
+void cmd_whowas::PruneWhoWas(time_t t)
+{
+ /* config values */
+ int groupsize = ServerInstance->Config->WhoWasGroupSize;
+ int maxgroups = ServerInstance->Config->WhoWasMaxGroups;
+ int maxkeep = ServerInstance->Config->WhoWasMaxKeep;
+
+ /* first cut the list to new size (maxgroups) and also prune entries that are timed out. */
+ whowas_users::iterator iter;
+ int fifosize;
+ while ((fifosize = (int)whowas_fifo.size()) > 0)
+ {
+ if (fifosize > maxgroups || whowas_fifo[0].first < t - maxkeep)
+ {
+ iter = whowas.find(whowas_fifo[0].second);
+ /* hopefully redundant integrity check, but added while debugging r6216 */
+ if (iter == whowas.end())
+ {
+ /* this should never happen, if it does maps are corrupt */
+ ServerInstance->Log(DEBUG, "Whowas maps got corrupted! (1)");
+ return;
+ }
+ whowas_set* n = (whowas_set*)iter->second;
+ if (n->size())
+ {
+ while (n->begin() != n->end())
+ {
+ WhoWasGroup *a = *(n->begin());
+ DELETE(a);
+ n->pop_front();
+ }
+ }
+ DELETE(n);
+ whowas.erase(iter);
+ whowas_fifo.pop_front();
+ }
+ else
+ break;
+ }
+
+ /* Then cut the whowas sets to new size (groupsize) */
+ fifosize = (int)whowas_fifo.size();
+ for (int i = 0; i < fifosize; i++)
+ {
+ iter = whowas.find(whowas_fifo[0].second);
+ /* hopefully redundant integrity check, but added while debugging r6216 */
+ if (iter == whowas.end())
+ {
+ /* this should never happen, if it does maps are corrupt */
+ ServerInstance->Log(DEBUG, "Whowas maps got corrupted! (2)");
+ return;
+ }
+ whowas_set* n = (whowas_set*)iter->second;
+ if (n->size())
+ {
+ int nickcount = n->size();
+ while (n->begin() != n->end() && nickcount > groupsize)
+ {
+ WhoWasGroup *a = *(n->begin());
+ DELETE(a);
+ n->pop_front();
+ nickcount--;
+ }
+ }
+ }
+}
+
+cmd_whowas::~cmd_whowas()
+{
+ if (timer)
+ {
+ ServerInstance->Timers->DelTimer(timer);
+ }
+
+ whowas_users::iterator iter;
+ int fifosize;
+ while ((fifosize = (int)whowas_fifo.size()) > 0)
+ {
+ iter = whowas.find(whowas_fifo[0].second);
+ /* hopefully redundant integrity check, but added while debugging r6216 */
+ if (iter == whowas.end())
+ {
+ /* this should never happen, if it does maps are corrupt */
+ ServerInstance->Log(DEBUG, "Whowas maps got corrupted! (1)");
+ return;
+ }
+ whowas_set* n = (whowas_set*)iter->second;
+ if (n->size())
+ {
+ while (n->begin() != n->end())
+ {
+ WhoWasGroup *a = *(n->begin());
+ DELETE(a);
+ n->pop_front();
+ }
+ }
+ DELETE(n);
+ whowas.erase(iter);
+ whowas_fifo.pop_front();
+ }
+}
+
+WhoWasGroup::WhoWasGroup(userrec* user) : host(NULL), dhost(NULL), ident(NULL), server(NULL), gecos(NULL), signon(user->signon)
+{
+ this->host = strdup(user->host);
+ this->dhost = strdup(user->dhost);
+ this->ident = strdup(user->ident);
+ this->server = user->server;
+ this->gecos = strdup(user->fullname);
+}
+
+WhoWasGroup::~WhoWasGroup()
+{
+ if (host)
+ free(host);
+ if (dhost)
+ free(dhost);
+ if (ident)
+ free(ident);
+ if (gecos)
+ free(gecos);
+}
+
+/* every hour, run this function which removes all entries older than Config->WhoWasMaxKeep */
+void MaintainTimer::Tick(time_t t)
+{
+ for (whowas_users::iterator iter = whowas.begin(); iter != whowas.end(); iter++)
+ {
+ whowas_set* n = (whowas_set*)iter->second;
+ if (n->size())
+ {
+ while ((n->begin() != n->end()) && ((*n->begin())->signon < t - ServerInstance->Config->WhoWasMaxKeep))
+ {
+ WhoWasGroup *a = *(n->begin());
+ DELETE(a);
+ n->erase(n->begin());
+ }
+ }
+ }
+ timer = new MaintainTimer(ServerInstance, 3600);
+ ServerInstance->Timers->AddTimer(timer);
}
diff --git a/src/configreader.cpp b/src/configreader.cpp
index e3455818a..68904318f 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -17,6 +17,7 @@
#include "inspircd.h"
#include "xline.h"
#include "exitcodes.h"
+#include "commands/cmd_whowas.h"
std::vector<std::string> old_module_names, new_module_names, added_modules, removed_modules;
@@ -369,7 +370,14 @@ bool ValidateWhoWas(ServerConfig* conf, const char* tag, const char* value, Valu
conf->GetInstance()->Log(DEFAULT,"WARNING: <whowas:maxkeep> value less than 3600, setting to default 3600");
}
conf->GetInstance()->Log(DEBUG,"whowas:groupsize:%d maxgroups:%d maxkeep:%d",conf->WhoWasGroupSize,conf->WhoWasMaxGroups,conf->WhoWasMaxKeep);
- irc::whowas::PruneWhoWas(conf->GetInstance(), conf->GetInstance()->Time());
+
+ command_t* whowas_command = conf->GetInstance()->Parser->GetHandler("WHOWAS");
+ if (whowas_command)
+ {
+ std::deque<classbase*> params;
+ whowas_command->HandleInternal(WHOWAS_PRUNE, params);
+ }
+
return true;
}
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 0bdffba64..47b6d278b 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -30,6 +30,7 @@
#include <dlfcn.h>
#include <getopt.h>
+
using irc::sockets::NonBlocking;
using irc::sockets::Blocking;
using irc::sockets::insp_ntoa;
@@ -339,8 +340,8 @@ InspIRCd::InspIRCd(int argc, char** argv)
this->OpenLog(argv, argc);
this->stats = new serverstats();
- this->Parser = new CommandParser(this);
this->Timers = new TimerManager();
+ this->Parser = new CommandParser(this);
this->XLines = new XLineManager(this);
Config->ClearStack();
Config->Read(true, NULL);
@@ -820,7 +821,7 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
WriteOpers("*** \002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %d secs.",abs(OLDTIME-TIME));
if ((TIME % 3600) == 0)
{
- irc::whowas::MaintainWhoWas(this, TIME);
+ //MaintainWhoWas(this, TIME);
this->RehashUsersAndChans();
FOREACH_MOD_I(this, I_OnGarbageCollect, OnGarbageCollect());
}
diff --git a/src/users.cpp b/src/users.cpp
index 7ed3d2d40..0e25f8e55 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -20,6 +20,7 @@
#include "wildcard.h"
#include "xline.h"
#include "cull_list.h"
+#include "commands/cmd_whowas.h"
static unsigned long already_sent[MAX_DESCRIPTORS] = {0};
@@ -875,178 +876,16 @@ void userrec::QuitUser(InspIRCd* Instance, userrec *user, const std::string &qui
}
}
-namespace irc
-{
- namespace whowas
- {
-
- WhoWasGroup::WhoWasGroup(userrec* user) : host(NULL), dhost(NULL), ident(NULL), server(NULL), gecos(NULL), signon(user->signon)
- {
- this->host = strdup(user->host);
- this->dhost = strdup(user->dhost);
- this->ident = strdup(user->ident);
- this->server = user->server;
- this->gecos = strdup(user->fullname);
- }
-
- WhoWasGroup::~WhoWasGroup()
- {
- if (host)
- free(host);
- if (dhost)
- free(dhost);
- if (ident)
- free(ident);
- if (gecos)
- free(gecos);
- }
-
- /* 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 - ServerInstance->Config->WhoWasMaxKeep))
- {
- WhoWasGroup *a = *(n->begin());
- DELETE(a);
- n->erase(n->begin());
- }
- }
- }
- }
- /* 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;
-
- /* first cut the list to new size (maxgroups) and also prune entries that are timed out. */
- whowas_users::iterator iter;
- int fifosize;
- while ((fifosize = (int)ServerInstance->whowas_fifo.size()) > 0)
- {
- if (fifosize > maxgroups || ServerInstance->whowas_fifo[0].first < t - maxkeep)
- {
- iter = ServerInstance->whowas.find(ServerInstance->whowas_fifo[0].second);
- /* hopefully redundant integrity check, but added while debugging r6216 */
- if (iter == ServerInstance->whowas.end())
- {
- /* this should never happen, if it does maps are corrupt */
- ServerInstance->Log(DEBUG, "Whowas maps got corrupted! (1)");
- return;
- }
- whowas_set* n = (whowas_set*)iter->second;
- if (n->size())
- {
- while (n->begin() != n->end())
- {
- WhoWasGroup *a = *(n->begin());
- DELETE(a);
- n->pop_front();
- }
- }
- ServerInstance->whowas.erase(iter);
- ServerInstance->whowas_fifo.pop_front();
- }
- else
- break;
- }
-
- /* Then cut the whowas sets to new size (groupsize) */
- for (int i = 0; i < fifosize; i++)
- {
- iter = ServerInstance->whowas.find(ServerInstance->whowas_fifo[0].second);
- /* hopefully redundant integrity check, but added while debugging r6216 */
- if (iter == ServerInstance->whowas.end())
- {
- /* this should never happen, if it does maps are corrupt */
- ServerInstance->Log(DEBUG, "Whowas maps got corrupted! (2)");
- return;
- }
- whowas_set* n = (whowas_set*)iter->second;
- if (n->size())
- {
- int nickcount = n->size();
- while (n->begin() != n->end() && nickcount > groupsize)
- {
- WhoWasGroup *a = *(n->begin());
- DELETE(a);
- n->pop_front();
- nickcount--;
- }
- }
- }
- }
- };
-};
/* 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");
-
- if (iter == ServerInstance->whowas.end())
- {
- ServerInstance->Log(DEBUG,"Adding new whowas set for %s",this->nick);
-
- irc::whowas::whowas_set* n = new irc::whowas::whowas_set;
- irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this);
- n->push_back(a);
- ServerInstance->whowas[this->nick] = n;
- ServerInstance->whowas_fifo.push_back(std::make_pair(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[0].second.c_str());
-
- irc::whowas::whowas_users::iterator iter = ServerInstance->whowas.find(ServerInstance->whowas_fifo[0].second);
- if (iter != ServerInstance->whowas.end())
- {
- irc::whowas::whowas_set* n = (irc::whowas::whowas_set*)iter->second;
- if (n->size())
- {
- while (n->begin() != n->end())
- {
- irc::whowas::WhoWasGroup *a = *(n->begin());
- DELETE(a);
- n->pop_front();
- }
- }
- ServerInstance->whowas.erase(iter);
- }
- ServerInstance->whowas_fifo.pop_front();
- }
- }
- else
+ command_t* whowas_command = ServerInstance->Parser->GetHandler("WHOWAS");
+ if (whowas_command)
{
- irc::whowas::whowas_set* group = (irc::whowas::whowas_set*)iter->second;
-
- ServerInstance->Log(DEBUG,"Using existing whowas group for %s",this->nick);
-
- irc::whowas::WhoWasGroup *a = new irc::whowas::WhoWasGroup(this);
- group->push_back(a);
-
- if ((int)(group->size()) > ServerInstance->Config->WhoWasGroupSize)
- {
- 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();
- }
+ std::deque<classbase*> params;
+ params.push_back(this);
+ whowas_command->HandleInternal(WHOWAS_ADD, params);
}
}