]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_setidle.cpp
20863500918eb1fa2224636b36eafb14b55d0c54
[user/henk/code/inspircd.git] / src / modules / m_setidle.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 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 #include <stdio.h>
18 #include <string>
19 #include "users.h"
20 #include "channels.h"
21 #include "modules.h"
22 #include "helperfuncs.h"
23
24 /* $ModDesc: Allows opers to set their idle time */
25
26 Server *Srv = NULL;
27          
28 void handle_setidle(char **parameters, int pcnt, userrec *user)
29 {
30         if (atoi(parameters[0]) < 1)
31         {
32                 WriteServ(user->fd,"948 %s :Invalid idle time.",user->nick);
33                 return;
34         }
35         user->idle_lastmsg = time(NULL) - atoi(parameters[0]);
36         // minor tweak - we cant have signon time shorter than our idle time!
37         if (user->signon > user->idle_lastmsg)
38                 user->signon = user->idle_lastmsg;
39         Srv->SendOpers(std::string(user->nick)+" used SETIDLE to set their idle time to "+std::string(parameters[0])+" seconds");
40         WriteServ(user->fd,"944 %s :Idle time set.",user->nick);
41 }
42
43
44 class ModuleSetIdle : public Module
45 {
46  public:
47         ModuleSetIdle()
48         {
49                 Srv = new Server;
50                 Srv->AddCommand("SETIDLE",handle_setidle,'o',1,"m_setidle.so");
51         }
52         
53         virtual ~ModuleSetIdle()
54         {
55                 if (Srv)
56                         delete Srv;
57         }
58         
59         virtual Version GetVersion()
60         {
61                 return Version(1,0,0,1,VF_VENDOR);
62         }
63         
64 };
65
66 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
67
68 class ModuleSetIdleFactory : public ModuleFactory
69 {
70  public:
71         ModuleSetIdleFactory()
72         {
73         }
74         
75         ~ModuleSetIdleFactory()
76         {
77         }
78         
79         virtual Module * CreateModule()
80         {
81                 return new ModuleSetIdle;
82         }
83         
84 };
85
86
87 extern "C" void * init_module( void )
88 {
89         return new ModuleSetIdleFactory;
90 }
91