summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorattilamolnar <attilamolnar@hush.com>2012-07-06 15:39:11 +0200
committerattilamolnar <attilamolnar@hush.com>2013-04-04 19:05:20 +0200
commit8c08130e19247f4a0798613ba6b931cd599115b6 (patch)
treefc26068109abc1719c8fb26bcf0f8fe22a19a13b
parent886f1ba488a5ab9d7fe4d7b4ac6b9c9dc2841738 (diff)
Make cmd_whowas act like a module, remove special handling
-rw-r--r--include/commands/cmd_whowas.h36
-rw-r--r--include/users.h4
-rw-r--r--src/commands/cmd_stats.cpp13
-rw-r--r--src/commands/cmd_whowas.cpp61
-rw-r--r--src/configreader.cpp5
-rw-r--r--src/usermanager.cpp1
-rw-r--r--src/users.cpp13
7 files changed, 24 insertions, 109 deletions
diff --git a/include/commands/cmd_whowas.h b/include/commands/cmd_whowas.h
index d33354122..8033f1796 100644
--- a/include/commands/cmd_whowas.h
+++ b/include/commands/cmd_whowas.h
@@ -23,35 +23,9 @@
#define CMD_WHOWAS_H
#include "modules.h"
-struct WhowasRequest : public Request
-{
- /* list of available internal commands */
- enum Internals
- {
- WHOWAS_ADD = 1,
- WHOWAS_STATS = 2,
- WHOWAS_PRUNE = 3,
- WHOWAS_MAINTAIN = 4
- };
-
- const Internals type;
- std::string value;
- User* user;
-
- WhowasRequest(Module* src, Module* whowas, Internals Type) : Request(src, whowas, "WHOWAS"), type(Type)
- {}
-};
-
-/* Forward ref for timer */
-class WhoWasMaintainTimer;
-
/* Forward ref for typedefs */
class WhoWasGroup;
-/** Timer that is used to maintain the whowas list, called once an hour
- */
-extern WhoWasMaintainTimer* timer;
-
/** A group of users related by nickname
*/
typedef std::deque<WhoWasGroup*> whowas_set;
@@ -128,14 +102,4 @@ class WhoWasGroup
~WhoWasGroup();
};
-class WhoWasMaintainTimer : public Timer
-{
- public:
- WhoWasMaintainTimer(long interval)
- : Timer(interval, ServerInstance->Time(), true)
- {
- }
- virtual void Tick(time_t TIME);
-};
-
#endif
diff --git a/include/users.h b/include/users.h
index 102e7783f..b9807a158 100644
--- a/include/users.h
+++ b/include/users.h
@@ -485,10 +485,6 @@ class CoreExport User : public Extensible
*/
const std::string& MakeHostIP();
- /** Add the user to WHOWAS system
- */
- void AddToWhoWas();
-
/** Oper up the user using the given opertype.
* This will also give the +o usermode.
*/
diff --git a/src/commands/cmd_stats.cpp b/src/commands/cmd_stats.cpp
index c37b041a9..86512417c 100644
--- a/src/commands/cmd_stats.cpp
+++ b/src/commands/cmd_stats.cpp
@@ -21,7 +21,6 @@
#include "inspircd.h"
#include "xline.h"
-#include "commands/cmd_whowas.h"
#ifdef _WIN32
#include <psapi.h>
@@ -218,18 +217,6 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
results.push_back(sn+" 249 "+user->nick+" :Channels: "+ConvToStr(ServerInstance->chanlist->size()));
results.push_back(sn+" 249 "+user->nick+" :Commands: "+ConvToStr(ServerInstance->Parser->cmdlist.size()));
- if (!ServerInstance->Config->WhoWasGroupSize == 0 && !ServerInstance->Config->WhoWasMaxGroups == 0)
- {
- Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so");
- if (whowas)
- {
- WhowasRequest req(NULL, whowas, WhowasRequest::WHOWAS_STATS);
- req.user = user;
- req.Send();
- results.push_back(sn+" 249 "+user->nick+" :"+req.value);
- }
- }
-
float kbitpersec_in, kbitpersec_out, kbitpersec_total;
char kbitpersec_in_s[30], kbitpersec_out_s[30], kbitpersec_total_s[30];
diff --git a/src/commands/cmd_whowas.cpp b/src/commands/cmd_whowas.cpp
index 17a779ec3..dfe513dff 100644
--- a/src/commands/cmd_whowas.cpp
+++ b/src/commands/cmd_whowas.cpp
@@ -23,14 +23,10 @@
#include "inspircd.h"
#include "commands/cmd_whowas.h"
-WhoWasMaintainTimer * timer;
-
CommandWhowas::CommandWhowas( Module* parent) : Command(parent, "WHOWAS", 1)
{
syntax = "<nick>{,<nick>}";
Penalty = 2;
- timer = new WhoWasMaintainTimer(3600);
- ServerInstance->Timers->AddTimer(timer);
}
CmdResult CommandWhowas::Handle (const std::vector<std::string>& parameters, User* user)
@@ -257,11 +253,6 @@ void CommandWhowas::MaintainWhoWas(time_t t)
CommandWhowas::~CommandWhowas()
{
- if (timer)
- {
- ServerInstance->Timers->DelTimer(timer);
- }
-
whowas_users::iterator iter;
int fifosize;
while ((fifosize = (int)whowas_fifo.size()) > 0)
@@ -303,16 +294,6 @@ WhoWasGroup::~WhoWasGroup()
{
}
-/* every hour, run this function which removes all entries older than Config->WhoWasMaxKeep */
-void WhoWasMaintainTimer::Tick(time_t)
-{
- Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so");
- if (whowas)
- {
- WhowasRequest(whowas, whowas, WhowasRequest::WHOWAS_MAINTAIN).Send();
- }
-}
-
class ModuleWhoWas : public Module
{
CommandWhowas cmd;
@@ -324,31 +305,37 @@ class ModuleWhoWas : public Module
void init()
{
ServerInstance->Modules->AddService(cmd);
+ Implementation eventlist[] = { I_OnGarbageCollect, I_OnUserQuit, I_OnStats, I_OnRehash };
+ ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
}
- void OnRequest(Request& request)
+ void OnGarbageCollect()
{
- WhowasRequest& req = static_cast<WhowasRequest&>(request);
- switch (req.type)
- {
- case WhowasRequest::WHOWAS_ADD:
- cmd.AddToWhoWas(req.user);
- break;
- case WhowasRequest::WHOWAS_STATS:
- req.value = cmd.GetStats();
- break;
- case WhowasRequest::WHOWAS_PRUNE:
- cmd.PruneWhoWas(ServerInstance->Time());
- break;
- case WhowasRequest::WHOWAS_MAINTAIN:
- cmd.MaintainWhoWas(ServerInstance->Time());
- break;
- }
+ /* Removes all entries older than WhoWasMaxKeep */
+ cmd.MaintainWhoWas(ServerInstance->Time());
+ }
+
+ void OnUserQuit(User* user, const std::string& message, const std::string& oper_message)
+ {
+ cmd.AddToWhoWas(user);
+ }
+
+ ModResult OnStats(char symbol, User* user, string_list &results)
+ {
+ if (symbol == 'z')
+ results.push_back(ServerInstance->Config->ServerName+" 249 "+user->nick+" :"+cmd.GetStats());
+
+ return MOD_RES_PASSTHRU;
+ }
+
+ void OnRehash(User* user)
+ {
+ cmd.PruneWhoWas(ServerInstance->Time());
}
Version GetVersion()
{
- return Version("WHOWAS Command", VF_VENDOR);
+ return Version("WHOWAS", VF_VENDOR);
}
};
diff --git a/src/configreader.cpp b/src/configreader.cpp
index 2d918cb74..e2ddd4d27 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -26,7 +26,6 @@
#include <fstream>
#include "xline.h"
#include "exitcodes.h"
-#include "commands/cmd_whowas.h"
#include "configparser.h"
#include <iostream>
#ifdef _WIN32
@@ -805,10 +804,6 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid)
void ServerConfig::ApplyModules(User* user)
{
- Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so");
- if (whowas)
- WhowasRequest(NULL, whowas, WhowasRequest::WHOWAS_PRUNE).Send();
-
const std::vector<std::string> v = ServerInstance->Modules->GetAllModuleNames(0);
std::vector<std::string> added_modules;
std::set<std::string> removed_modules(v.begin(), v.end());
diff --git a/src/usermanager.cpp b/src/usermanager.cpp
index 0088d1c7f..58cbb7e5b 100644
--- a/src/usermanager.cpp
+++ b/src/usermanager.cpp
@@ -231,7 +231,6 @@ void UserManager::QuitUser(User *user, const std::string &quitreason, const char
user->server.c_str(), user->GetFullRealHost().c_str(), user->GetIPString().c_str(), oper_reason.c_str());
}
}
- user->AddToWhoWas();
}
user_hash::iterator iter = this->clientlist->find(user->nick);
diff --git a/src/users.cpp b/src/users.cpp
index 4241b8f81..5058cfcc2 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -28,7 +28,6 @@
#include "socketengine.h"
#include "xline.h"
#include "bancache.h"
-#include "commands/cmd_whowas.h"
already_sent_t LocalUser::already_sent_id = 0;
@@ -688,18 +687,6 @@ void User::UnOper()
this->modes[UM_OPERATOR] = 0;
}
-/* adds or updates an entry in the whowas list */
-void User::AddToWhoWas()
-{
- Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so");
- if (whowas)
- {
- WhowasRequest req(NULL, whowas, WhowasRequest::WHOWAS_ADD);
- req.user = this;
- req.Send();
- }
-}
-
/*
* Check class restrictions
*/