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