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