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