From 8c08130e19247f4a0798613ba6b931cd599115b6 Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Fri, 6 Jul 2012 15:39:11 +0200 Subject: Make cmd_whowas act like a module, remove special handling --- src/commands/cmd_stats.cpp | 13 ---------- src/commands/cmd_whowas.cpp | 61 ++++++++++++++++++--------------------------- src/configreader.cpp | 5 ---- src/usermanager.cpp | 1 - src/users.cpp | 13 ---------- 5 files changed, 24 insertions(+), 69 deletions(-) (limited to 'src') 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 @@ -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 = "{,}"; Penalty = 2; - timer = new WhoWasMaintainTimer(3600); - ServerInstance->Timers->AddTimer(timer); } CmdResult CommandWhowas::Handle (const std::vector& 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(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 #include "xline.h" #include "exitcodes.h" -#include "commands/cmd_whowas.h" #include "configparser.h" #include #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 v = ServerInstance->Modules->GetAllModuleNames(0); std::vector added_modules; std::set 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 */ -- cgit v1.2.3