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