]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_setidle.cpp
New 'Implements' system
[user/henk/code/inspircd.git] / src / modules / m_setidle.cpp
index 658e6ad1f1040365586d00910306bf3fa2b70457..ffa84d479e9f18bcb8bc02cb0f34a68f51f06cc3 100644 (file)
  * ---------------------------------------------------
  */
 
+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)
+
+class cmd_setidle : public command_t
 {
-       if (atoi(parameters[0]) < 1)
+ public:
+       cmd_setidle () : command_t("SETIDLE", 'o', 1)
        {
-               WriteServ(user->fd,"943 %s :Invalid idle time.",user->nick);
-               return;
+               this->source = "m_setidle.so";
        }
-       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);
-}
+
+       void Handle (char **parameters, int pcnt, userrec *user)
+       {
+               if (atoi(parameters[0]) < 1)
+               {
+                       WriteServ(user->fd,"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");
+               WriteServ(user->fd,"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()
@@ -75,9 +88,9 @@ class ModuleSetIdleFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule()
+       virtual Module * CreateModule(Server* Me)
        {
-               return new ModuleSetIdle;
+               return new ModuleSetIdle(Me);
        }
        
 };