]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_setidle.cpp
Gah, im forgetting to SetMode!
[user/henk/code/inspircd.git] / src / modules / m_setidle.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include <stdio.h>
20 #include <string>
21 #include "users.h"
22 #include "channels.h"
23 #include "modules.h"
24 #include "helperfuncs.h"
25
26 /* $ModDesc: Allows opers to set their idle time */
27
28 static Server *Srv = NULL;
29
30 class cmd_setidle : public command_t
31 {
32  public:
33         cmd_setidle () : command_t("SETIDLE", 'o', 1)
34         {
35                 this->source = "m_setidle.so";
36         }
37
38         void Handle (char **parameters, int pcnt, userrec *user)
39         {
40                 if (atoi(parameters[0]) < 1)
41                 {
42                         WriteServ(user->fd,"948 %s :Invalid idle time.",user->nick);
43                         return;
44                 }
45                 user->idle_lastmsg = time(NULL) - atoi(parameters[0]);
46                 // minor tweak - we cant have signon time shorter than our idle time!
47                 if (user->signon > user->idle_lastmsg)
48                         user->signon = user->idle_lastmsg;
49                 Srv->SendOpers(std::string(user->nick)+" used SETIDLE to set their idle time to "+std::string(parameters[0])+" seconds");
50                 WriteServ(user->fd,"944 %s :Idle time set.",user->nick);
51         }
52 };
53
54
55 class ModuleSetIdle : public Module
56 {
57         cmd_setidle*    mycommand;
58  public:
59         ModuleSetIdle(Server* Me)
60                 : Module::Module(Me)
61         {
62                 Srv = Me;
63                 mycommand = new cmd_setidle();
64                 Srv->AddCommand(mycommand);
65         }
66         
67         virtual ~ModuleSetIdle()
68         {
69         }
70         
71         virtual Version GetVersion()
72         {
73                 return Version(1,0,0,1,VF_VENDOR);
74         }
75         
76 };
77
78 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
79
80 class ModuleSetIdleFactory : public ModuleFactory
81 {
82  public:
83         ModuleSetIdleFactory()
84         {
85         }
86         
87         ~ModuleSetIdleFactory()
88         {
89         }
90         
91         virtual Module * CreateModule(Server* Me)
92         {
93                 return new ModuleSetIdle(Me);
94         }
95         
96 };
97
98
99 extern "C" void * init_module( void )
100 {
101         return new ModuleSetIdleFactory;
102 }
103