]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_setidle.cpp
WHEEEEE!!!!!
[user/henk/code/inspircd.git] / src / modules / m_setidle.cpp
index c4d812d0068f022104e7f0b9f51b6f178a411dfe..f17f69e09e20139590e6cd4e7f828f657bddea5d 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
  *                       E-mail:
  *                <brain@chatspike.net>
  *               <Craig@chatspike.net>
  * ---------------------------------------------------
  */
 
+using namespace std;
+
 #include <stdio.h>
 #include <string>
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
+#include "helperfuncs.h"
 
 /* $ModDesc: Allows opers to set their idle time */
 
-Server *Srv = NULL;
-        
-void handle_setidle(char **parameters, int pcnt, userrec *user)
+static Server *Srv = NULL;
+
+class cmd_setidle : public command_t
 {
-       user->idle_lastmsg = time(NULL) - atoi(parameters[0]);
-       // minor tweak - we cant have signon time shorter than our idle time!
-       if (user->signon > user->idle_lastmsg)
-               user->signon = user->idle_lastmsg;
-       Srv->SendOpers(std::string(user->nick)+" used SETIDLE to set their idle time to "+std::string(parameters[0])+" seconds");
-       WriteServ(user->fd,"944 %s :Idle time set.",user->nick);
-}
+ public:
+       cmd_setidle () : command_t("SETIDLE", 'o', 1)
+       {
+               this->source = "m_setidle.so";
+               syntax = "<idle-seconds>";
+       }
+
+       void Handle (const char** parameters, int pcnt, userrec *user)
+       {
+               if (atoi(parameters[0]) < 1)
+               {
+                       user->WriteServ("948 %s :Invalid idle time.",user->nick);
+                       return;
+               }
+               user->idle_lastmsg = time(NULL) - atoi(parameters[0]);
+               // minor tweak - we cant have signon time shorter than our idle time!
+               if (user->signon > user->idle_lastmsg)
+                       user->signon = user->idle_lastmsg;
+               Srv->SendOpers(std::string(user->nick)+" used SETIDLE to set their idle time to "+std::string(parameters[0])+" seconds");
+               user->WriteServ("944 %s :Idle time set.",user->nick);
+       }
+};
 
 
 class ModuleSetIdle : public Module
 {
+       cmd_setidle*    mycommand;
  public:
-       ModuleSetIdle()
+       ModuleSetIdle(Server* Me)
+               : Module::Module(Me)
        {
-               Srv = new Server;
-               Srv->AddCommand("SETIDLE",handle_setidle,'o',1,"m_setidle.so");
+               Srv = Me;
+               mycommand = new cmd_setidle();
+               Srv->AddCommand(mycommand);
        }
        
        virtual ~ModuleSetIdle()
        {
-               if (Srv)
-                       delete Srv;
        }
        
        virtual Version GetVersion()
@@ -70,9 +89,9 @@ class ModuleSetIdleFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule()
+       virtual Module * CreateModule(Server* Me)
        {
-               return new ModuleSetIdle;
+               return new ModuleSetIdle(Me);
        }
        
 };