]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/commands/cmd_whowas.cpp
Make cmd_whowas act like a module, remove special handling
[user/henk/code/inspircd.git] / src / commands / cmd_whowas.cpp
index eb82d1630b011c0c3b28c0c409d8e011614fe73c..dfe513dff78c8d34ef36f87d51bad701542ee9c7 100644 (file)
@@ -1,27 +1,32 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
  *
- *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
+ *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
+ *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
  *
- * This program is free but copyrighted software; see
- *            the file COPYING for details.
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
  *
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+
 #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)
@@ -248,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)
@@ -294,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<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;
-               }
+               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);
        }
 };