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