diff options
author | attilamolnar <attilamolnar@hush.com> | 2012-07-06 15:39:11 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-04-04 19:05:20 +0200 |
commit | 8c08130e19247f4a0798613ba6b931cd599115b6 (patch) | |
tree | fc26068109abc1719c8fb26bcf0f8fe22a19a13b /src | |
parent | 886f1ba488a5ab9d7fe4d7b4ac6b9c9dc2841738 (diff) |
Make cmd_whowas act like a module, remove special handling
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/cmd_stats.cpp | 13 | ||||
-rw-r--r-- | src/commands/cmd_whowas.cpp | 61 | ||||
-rw-r--r-- | src/configreader.cpp | 5 | ||||
-rw-r--r-- | src/usermanager.cpp | 1 | ||||
-rw-r--r-- | src/users.cpp | 13 |
5 files changed, 24 insertions, 69 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); } }; 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 */ |