X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fcommands%2Fcmd_whowas.cpp;h=dfe513dff78c8d34ef36f87d51bad701542ee9c7;hb=8c08130e19247f4a0798613ba6b931cd599115b6;hp=c7cb8efb410922fb3c227820d183ffbb14e08cda;hpb=44f42a13de52c8025942ddab42f51feb36821782;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/commands/cmd_whowas.cpp b/src/commands/cmd_whowas.cpp index c7cb8efb4..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,48 +294,48 @@ 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; public: ModuleWhoWas() : cmd(this) { - ServerInstance->AddCommand(&cmd); } - void OnRequest(Request& request) + void init() { - 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; - } + ServerInstance->Modules->AddService(cmd); + Implementation eventlist[] = { I_OnGarbageCollect, I_OnUserQuit, I_OnStats, I_OnRehash }; + ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); + } + + void OnGarbageCollect() + { + /* 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); } };