]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_setidle.cpp
Sync helpop chmodes s and p with docs
[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, 2020 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) 2009 Uli Schlachter <psychon@inspircd.org>
9  *   Copyright (C) 2009 Robin Burchell <robin+git@viroteck.net>
10  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
11  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
12  *   Copyright (C) 2005, 2010 Craig Edwards <brain@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';
45                 syntax = "<duration>";
46         }
47
48         CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
49         {
50                 unsigned long idle;
51                 if (!InspIRCd::Duration(parameters[0], idle))
52                 {
53                         user->WriteNumeric(ERR_INVALIDIDLETIME, "Invalid idle time.");
54                         return CMD_FAILURE;
55                 }
56                 user->idle_lastmsg = (ServerInstance->Time() - idle);
57                 // minor tweak - we cant have signon time shorter than our idle time!
58                 if (user->signon > user->idle_lastmsg)
59                         user->signon = user->idle_lastmsg;
60                 ServerInstance->SNO->WriteToSnoMask('a', user->nick+" used SETIDLE to set their idle time to "+ConvToStr(idle)+" seconds");
61                 user->WriteNumeric(RPL_IDLETIMESET, "Idle time set.");
62
63                 return CMD_SUCCESS;
64         }
65 };
66
67
68 class ModuleSetIdle : public Module
69 {
70         CommandSetidle cmd;
71  public:
72         ModuleSetIdle()
73                 : cmd(this)
74         {
75         }
76
77         Version GetVersion() CXX11_OVERRIDE
78         {
79                 return Version("Adds the /SETIDLE command which allows server operators to change their idle time.", VF_VENDOR);
80         }
81 };
82
83 MODULE_INIT(ModuleSetIdle)