]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_setidle.cpp
68df49a335b0e6be8b35ba527290776e8b7713b1
[user/henk/code/inspircd.git] / src / modules / m_setidle.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Allows opers to set their idle time */
17
18 /** Handle /SETIDLE
19  */
20 class CommandSetidle : public Command
21 {
22  public:
23         CommandSetidle(Module* Creator) : Command(Creator,"SETIDLE", 1)
24         {
25                 flags_needed = 'o'; syntax = "<duration>";
26                 TRANSLATE2(TR_TEXT, TR_END);
27         }
28
29         CmdResult Handle (const std::vector<std::string>& parameters, User *user)
30         {
31                 time_t idle = ServerInstance->Duration(parameters[0]);
32                 if (idle < 1)
33                 {
34                         user->WriteNumeric(948, "%s :Invalid idle time.",user->nick.c_str());
35                         return CMD_FAILURE;
36                 }
37                 user->idle_lastmsg = (ServerInstance->Time() - idle);
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                 ServerInstance->SNO->WriteToSnoMask('a', std::string(user->nick)+" used SETIDLE to set their idle time to "+ConvToStr(idle)+" seconds");
42                 user->WriteNumeric(944, "%s :Idle time set.",user->nick.c_str());
43
44                 return CMD_SUCCESS;
45         }
46 };
47
48
49 class ModuleSetIdle : public Module
50 {
51         CommandSetidle cmd;
52  public:
53         ModuleSetIdle(InspIRCd* Me)
54                 : Module(Me), cmd(this)
55         {
56                 ServerInstance->AddCommand(&cmd);
57         }
58
59         virtual ~ModuleSetIdle()
60         {
61         }
62
63         virtual Version GetVersion()
64         {
65                 return Version("Allows opers to set their idle time", VF_VENDOR, API_VERSION);
66         }
67 };
68
69 MODULE_INIT(ModuleSetIdle)