]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_setidle.cpp
Fix being able to see the modes of private/secret channels.
[user/henk/code/inspircd.git] / src / modules / m_setidle.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com>
5  *   Copyright (C) 2013, 2017-2018 Sadie Powell <sadie@witchery.services>
6  *   Copyright (C) 2012-2013 Attila Molnar <attilamolnar@hush.com>
7  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
8  *   Copyright (C) 2010 Craig Edwards <brain@inspircd.org>
9  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
10  *   Copyright (C) 2009 Robin Burchell <robin+git@viroteck.net>
11  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
12  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
13  *
14  * This file is part of InspIRCd.  InspIRCd is free software: you can
15  * redistribute it and/or modify it under the terms of the GNU General Public
16  * License as published by the Free Software Foundation, version 2.
17  *
18  * This program is distributed in the hope that it will be useful, but WITHOUT
19  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
21  * details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  */
26
27
28 #include "inspircd.h"
29
30 enum
31 {
32         // InspIRCd-specific.
33         ERR_INVALIDIDLETIME = 948,
34         RPL_IDLETIMESET = 944
35 };
36
37 /** Handle /SETIDLE
38  */
39 class CommandSetidle : public SplitCommand
40 {
41  public:
42         CommandSetidle(Module* Creator) : SplitCommand(Creator,"SETIDLE", 1)
43         {
44                 flags_needed = 'o'; syntax = "<duration>";
45         }
46
47         CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
48         {
49                 unsigned long idle;
50                 if (!InspIRCd::Duration(parameters[0], idle))
51                 {
52                         user->WriteNumeric(ERR_INVALIDIDLETIME, "Invalid idle time.");
53                         return CMD_FAILURE;
54                 }
55                 user->idle_lastmsg = (ServerInstance->Time() - idle);
56                 // minor tweak - we cant have signon time shorter than our idle time!
57                 if (user->signon > user->idle_lastmsg)
58                         user->signon = user->idle_lastmsg;
59                 ServerInstance->SNO->WriteToSnoMask('a', user->nick+" used SETIDLE to set their idle time to "+ConvToStr(idle)+" seconds");
60                 user->WriteNumeric(RPL_IDLETIMESET, "Idle time set.");
61
62                 return CMD_SUCCESS;
63         }
64 };
65
66
67 class ModuleSetIdle : public Module
68 {
69         CommandSetidle cmd;
70  public:
71         ModuleSetIdle()
72                 : cmd(this)
73         {
74         }
75
76         Version GetVersion() CXX11_OVERRIDE
77         {
78                 return Version("Provides the SETIDLE command, allows opers to set their idle time", VF_VENDOR);
79         }
80 };
81
82 MODULE_INIT(ModuleSetIdle)