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