summaryrefslogtreecommitdiff
path: root/src/commands
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 /src/commands
parent886f1ba488a5ab9d7fe4d7b4ac6b9c9dc2841738 (diff)
Make cmd_whowas act like a module, remove special handling
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/cmd_stats.cpp13
-rw-r--r--src/commands/cmd_whowas.cpp61
2 files changed, 24 insertions, 50 deletions
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);
}
};